445 lines
18 KiB
C#
445 lines
18 KiB
C#
using BLL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace FineUIPro.Web.ZHGL.Plan
|
|
{
|
|
public partial class MainContract : PageBase
|
|
{
|
|
#region 加载
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
Funs.DropDownPageSize(this.ddlPageSize);
|
|
////权限按钮方法
|
|
this.GetButtonPower();
|
|
this.btnNew.OnClientClick = Window1.GetShowReference("MainContractEdit.aspx") + "return false;";
|
|
ProjectService.InitAllProjectDropDownList(this.drpProject, false);
|
|
Funs.FineUIPleaseSelect(drpProject, "按项目查询");
|
|
// 绑定表格
|
|
this.BindGrid();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string strSql = "SELECT MainContract.MainContractId,MainContract.ProjectId,MainContractCode,MainContract.MainContractName,MainContract.VersionNo,(CASE MainContract.ProjectType WHEN '1' THEN 'EPC' WHEN '2' THEN 'EPCM' WHEN '3' THEN 'C' WHEN '4' THEN '其他' END ) AS ProjectType,MainContract.MainContractContents,MainContract.CompileMan, MainContract.CompileDate,MainContract.States"
|
|
+ @" FROM ActionPlan_MainContract AS MainContract "
|
|
+ @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON MainContract.MainContractId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1"
|
|
+ @" LEFT JOIN Person_Persons AS OperateUser ON FlowOperate.OperaterId=OperateUser.PersonId "
|
|
+ @" WHERE 1=1 ";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
if (this.drpProject.SelectedValue != BLL.Const._Null)
|
|
{
|
|
if (this.drpProject.SelectedValue == "Company")
|
|
{
|
|
strSql += " AND MainContract.ProjectId is null";
|
|
}
|
|
else
|
|
{
|
|
strSql += " AND MainContract.ProjectId = @ProjectId";
|
|
listStr.Add(new SqlParameter("@ProjectId", this.drpProject.SelectedValue));
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(this.txtMainContractCode.Text.Trim()))
|
|
{
|
|
strSql += " AND MainContractCode LIKE @MainContractCode";
|
|
listStr.Add(new SqlParameter("@MainContractCode", "%" + this.txtMainContractCode.Text.Trim() + "%"));
|
|
}
|
|
if (!string.IsNullOrEmpty(this.txtMainContractName.Text.Trim()))
|
|
{
|
|
strSql += " AND MainContractName LIKE @MainContractName";
|
|
listStr.Add(new SqlParameter("@MainContractName", "%" + this.txtMainContractName.Text.Trim() + "%"));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
}
|
|
#endregion
|
|
|
|
#region 分页 排序
|
|
/// <summary>
|
|
/// 改变索引事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页下拉选择事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
|
BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 排序
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭弹出窗口
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Window1_Close(object sender, EventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 查询
|
|
/// <summary>
|
|
/// 查询
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void TextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
BLL.LogService.AddSys_Log(this.CurrUser, string.Empty, string.Empty, BLL.Const.OfficeMainContractMenuId, Const.BtnQuery);
|
|
}
|
|
#endregion
|
|
|
|
#region 编辑
|
|
/// <summary>
|
|
/// 双击事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|
{
|
|
this.EditData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 右键编辑事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuEdit_Click(object sender, EventArgs e)
|
|
{
|
|
this.EditData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑数据方法
|
|
/// </summary>
|
|
private void EditData()
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
{
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
string id = Grid1.SelectedRowID.Split(',')[0];
|
|
Model.ActionPlan_MainContract MainContract = MainContractService.GetMainContractById(id);
|
|
if (MainContract.States == Const.MainContract_Complete)
|
|
{
|
|
Alert.ShowInTop("该文件已经审批完成,无法操作,请右键查看!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
else if (MainContract.States == Const.MainContract_Compile)
|
|
{
|
|
if (MainContract.CompileMan == CurrUser.PersonId || CurrUser.PersonId == Const.sysglyId)
|
|
{
|
|
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MainContractEdit.aspx?MainContractId={0}", id)));
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("您不是编制人,无法操作!请右键查看", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
else if (MainContract.States == Const.MainContract_Reviewing || MainContract.States == Const.MainContract_ReCompile)
|
|
{
|
|
Model.ActionPlan_MainContractApprove approve = MainContractApproveService.GetMainContractApproveByApproveMan(id, CurrUser.PersonId);
|
|
if (approve != null || CurrUser.PersonId == Const.sysglyId)
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MainContractEdit.aspx?MainContractId={0}", id)));
|
|
return;
|
|
//Response.Redirect("MainContractAudit.aspx?MainContractId=" + id);
|
|
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckListView.aspx?CheckControlCode={0}", id, "查看 - ")));
|
|
}
|
|
else
|
|
{
|
|
if (MainContract.CompileMan.Equals(CurrUser.PersonId))
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MainContractEdit.aspx?MainContractId={0}", id)));
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("您不是办理用户,无法操作!请右键查看", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
protected void btnMenuView_Click(object sender, EventArgs e)
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
{
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
string id = Grid1.SelectedRowID.Split(',')[0];
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MainContractView.aspx?MainContractId={0}", id)));
|
|
|
|
}
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 右键删除事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuDelete_Click(object sender, EventArgs e)
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length > 0)
|
|
{
|
|
bool isShow = false;
|
|
if (Grid1.SelectedRowIndexArray.Length == 1)
|
|
{
|
|
isShow = true;
|
|
}
|
|
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
|
{
|
|
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
|
if (this.judgementDelete(rowID, isShow))
|
|
{
|
|
var getV = BLL.MainContractService.GetMainContractById(rowID);
|
|
if (getV != null)
|
|
{
|
|
BLL.LogService.AddSys_Log(this.CurrUser, getV.MainContractCode, getV.MainContractId, BLL.Const.OfficeMainContractMenuId, Const.BtnDelete);
|
|
BLL.MainContractService.DeleteMainContractById(rowID);
|
|
}
|
|
}
|
|
}
|
|
BindGrid();
|
|
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断是否可以删除
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private bool judgementDelete(string id, bool isShow)
|
|
{
|
|
string content = string.Empty;
|
|
|
|
if (string.IsNullOrEmpty(content))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (isShow)
|
|
{
|
|
Alert.ShowInTop(content);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取按钮权限
|
|
/// <summary>
|
|
/// 获取按钮权限
|
|
/// </summary>
|
|
/// <param name="button"></param>
|
|
/// <returns></returns>
|
|
private void GetButtonPower()
|
|
{
|
|
if (Request.Params["value"] == "0")
|
|
{
|
|
return;
|
|
}
|
|
|
|
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.OfficeMainContractMenuId);
|
|
if (buttonList.Count() > 0)
|
|
{
|
|
if (buttonList.Contains(BLL.Const.BtnAdd))
|
|
{
|
|
this.btnNew.Hidden = false;
|
|
}
|
|
if (buttonList.Contains(BLL.Const.BtnModify))
|
|
{
|
|
this.btnMenuEdit.Hidden = false;
|
|
}
|
|
if (buttonList.Contains(BLL.Const.BtnDelete))
|
|
{
|
|
this.btnMenuDelete.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 导出按钮
|
|
/// 导出按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnOut_Click(object sender, EventArgs e)
|
|
{
|
|
Response.ClearContent();
|
|
string filename = Funs.GetNewFileName();
|
|
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("总包合同" + filename, System.Text.Encoding.UTF8) + ".xls");
|
|
Response.ContentType = "application/excel";
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
this.Grid1.PageSize = 5000;
|
|
this.BindGrid();
|
|
Response.Write(GetGridTableHtml(Grid1));
|
|
Response.End();
|
|
}
|
|
|
|
/// 导出按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnOut2_Click(object sender, EventArgs e)
|
|
{
|
|
string rootPath = Server.MapPath("~/");
|
|
string initTemplatePath = string.Empty;
|
|
string uploadfilepath = string.Empty;
|
|
string newUrl = string.Empty;
|
|
string filePath = string.Empty;
|
|
initTemplatePath = Const.OpinionTemplateUrl;
|
|
uploadfilepath = rootPath + initTemplatePath;
|
|
string id = Grid1.SelectedRowID.Split(',')[0];
|
|
Model.ActionPlan_MainContract MainContract = MainContractService.GetMainContractById(id);
|
|
if (MainContract != null)
|
|
{
|
|
string projectName = MainContract.ProjectId;
|
|
newUrl = uploadfilepath.Replace(".xlsx", MainContract.MainContractCode + "(" + MainContract.MainContractName + ")" + ".xlsx");
|
|
File.Copy(uploadfilepath, newUrl);
|
|
// 第一步:读取文件流
|
|
NPOI.SS.UserModel.IWorkbook workbook;
|
|
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
|
|
{
|
|
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
|
|
}
|
|
// 创建单元格样式
|
|
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
|
|
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
|
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
|
|
var font = workbook.CreateFont();
|
|
font.FontHeightInPoints = 10;
|
|
//font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
|
|
cellStyle.SetFont(font);
|
|
// 第二步:创建新数据行
|
|
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
|
|
var opinions = MainContractOpinionService.getListData(id, null);
|
|
int i = 1;
|
|
foreach (var item in opinions)
|
|
{
|
|
// 第二步:创建新数据行
|
|
NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
|
|
NPOI.SS.UserModel.ICell cell;
|
|
// 添加数据
|
|
cell = row.CreateCell(0);
|
|
cell.CellStyle = cellStyle;
|
|
cell.SetCellValue(i.ToString());
|
|
cell = row.CreateCell(1);
|
|
cell.CellStyle = cellStyle;
|
|
cell.SetCellValue(projectName);
|
|
cell = row.CreateCell(2);
|
|
cell.CellStyle = cellStyle;
|
|
cell.SetCellValue(item.OriginalNum);
|
|
cell = row.CreateCell(3);
|
|
cell.CellStyle = cellStyle;
|
|
cell.SetCellValue(item.OriginalContent);
|
|
cell = row.CreateCell(4);
|
|
cell.CellStyle = cellStyle;
|
|
cell.SetCellValue(item.Opinion);
|
|
cell = row.CreateCell(5);
|
|
cell.CellStyle = cellStyle;
|
|
cell.SetCellValue(Person_PersonsService.GetPersonsNameById(item.OpinionMan));
|
|
i++;
|
|
}
|
|
// 第三步:写入文件流
|
|
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
|
|
{
|
|
workbook.Write(stream);
|
|
workbook.Close();
|
|
}
|
|
string fileName = Path.GetFileName(newUrl);
|
|
FileInfo info = new FileInfo(newUrl);
|
|
long fileSize = info.Length;
|
|
Response.Clear();
|
|
Response.ContentType = "application/x-zip-compressed";
|
|
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
|
Response.AddHeader("Content-Length", fileSize.ToString());
|
|
Response.TransmitFile(newUrl, 0, fileSize);
|
|
Response.Flush();
|
|
Response.Close();
|
|
File.Delete(newUrl);
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("当期无记录,无法导出!", MessageBoxIcon.Warning);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 把办理人转换代号为文字形式
|
|
/// </summary>
|
|
/// <param name="MainContractId"></param>
|
|
/// <returns></returns>
|
|
///
|
|
public static string ConvertApproveMan(object MainContractId)
|
|
{
|
|
string name = string.Empty;
|
|
if (MainContractId != null)
|
|
{
|
|
var approves = BLL.MainContractApproveService.GetMainContractApprovesNotHandleList(MainContractId.ToString());
|
|
foreach (var item in approves)
|
|
{
|
|
name += BLL.Person_PersonsService.GetPersonsNameById(item.ApproveMan) + ",";
|
|
}
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
name = name.Substring(0, name.Length - 1);
|
|
}
|
|
}
|
|
return name;
|
|
}
|
|
}
|
|
} |