666 lines
34 KiB
C#
666 lines
34 KiB
C#
|
using BLL;
|
|||
|
using NPOI.SS.UserModel;
|
|||
|
using NPOI.XSSF.UserModel;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Web;
|
|||
|
using System.Web.UI;
|
|||
|
using NPOI.SS.UserModel;
|
|||
|
using NPOI.SS.Util;
|
|||
|
using NPOI.XSSF.UserModel;
|
|||
|
using Model;
|
|||
|
using NPOI.SS.Formula.Functions;
|
|||
|
|
|||
|
namespace FineUIPro.Web.TestRun.ProduceTestRun
|
|||
|
{
|
|||
|
public partial class RunningLogManagementList : PageBase
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 系统主键
|
|||
|
/// </summary>
|
|||
|
public string SystemId { get { return (string)ViewState["SystemId"]; } set { ViewState["SystemId"] = value; } }
|
|||
|
|
|||
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (!IsPostBack)
|
|||
|
{
|
|||
|
//绑定数据
|
|||
|
InitTreeMenu();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region 树绑定
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 加载树
|
|||
|
/// </summary>
|
|||
|
private void InitTreeMenu()
|
|||
|
{
|
|||
|
this.tvControlItem.Nodes.Clear();
|
|||
|
TreeNode rootNode = new TreeNode();
|
|||
|
rootNode.Text = "检查表";
|
|||
|
rootNode.NodeID = "0";
|
|||
|
rootNode.Expanded = true;
|
|||
|
rootNode.ToolTip = "";
|
|||
|
rootNode.EnableClickEvent = true;
|
|||
|
this.tvControlItem.Nodes.Add(rootNode);
|
|||
|
var alllist = Funs.DB.PreRun_SysDevice.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && x.PreRunLevel != 4).ToList();
|
|||
|
if (alllist.Count() > 0)
|
|||
|
{
|
|||
|
var onelist = alllist.Where(x => x.PreRunLevel == 1).ToList();
|
|||
|
|
|||
|
foreach (var itemOne in onelist)
|
|||
|
{
|
|||
|
TreeNode rootOneNode = new TreeNode();
|
|||
|
rootOneNode.NodeID = itemOne.PreRunId;
|
|||
|
rootOneNode.Text = itemOne.PreRunName;
|
|||
|
rootOneNode.ToolTip = itemOne.PreRunName;
|
|||
|
rootOneNode.CommandName = "";
|
|||
|
rootOneNode.EnableClickEvent = true;
|
|||
|
rootOneNode.EnableExpandEvent = false;
|
|||
|
rootNode.Nodes.Add(rootOneNode);
|
|||
|
rootOneNode.Expanded = true;
|
|||
|
var twolist = alllist.Where(x => x.PreRunLevel == 2 && x.ParentId == itemOne.PreRunId).ToList();
|
|||
|
foreach (var itemTwo in twolist)
|
|||
|
{
|
|||
|
TreeNode rootTwoNode = new TreeNode();
|
|||
|
rootTwoNode.NodeID = itemOne.PreRunId + "|" + itemTwo.PreRunId;
|
|||
|
rootTwoNode.Text = itemTwo.PreRunName;
|
|||
|
rootTwoNode.ToolTip = itemTwo.PreRunName;
|
|||
|
rootTwoNode.CommandName = "";
|
|||
|
rootTwoNode.EnableClickEvent = true;
|
|||
|
rootTwoNode.EnableExpandEvent = false;
|
|||
|
rootOneNode.Nodes.Add(rootTwoNode);
|
|||
|
rootTwoNode.Expanded = true;
|
|||
|
var threelist = alllist.Where(x => x.PreRunLevel == 3 && x.ParentId == itemTwo.PreRunId).ToList();
|
|||
|
foreach (var itemThree in threelist)
|
|||
|
{
|
|||
|
TreeNode rootThreeNode = new TreeNode();
|
|||
|
rootThreeNode.NodeID = itemOne.PreRunId + "|" + itemTwo.PreRunId + "|" + itemThree.PreRunId;
|
|||
|
rootThreeNode.Text = itemThree.PreRunName;
|
|||
|
rootThreeNode.ToolTip = itemThree.PreRunName;
|
|||
|
rootThreeNode.CommandName = "";
|
|||
|
rootThreeNode.EnableClickEvent = true;
|
|||
|
rootThreeNode.EnableExpandEvent = false;
|
|||
|
rootTwoNode.Nodes.Add(rootThreeNode);
|
|||
|
rootThreeNode.Expanded = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 点击TreeView
|
|||
|
/// </summary>
|
|||
|
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
|
|||
|
{
|
|||
|
if (this.tvControlItem.SelectedNodeID.Split('|').Length > 2)
|
|||
|
{
|
|||
|
this.SystemId = this.tvControlItem.SelectedNodeID.Split('|').Last();
|
|||
|
}
|
|||
|
this.BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 绑定数据
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 数据绑定
|
|||
|
/// </summary>
|
|||
|
public void BindGrid()
|
|||
|
{
|
|||
|
string strSql = @"select a.RunningId,a.ProjectId,project.ProjectName as ProjectName,a.InstallationId,a.ProcessesId,a.SystemId,a.JobNo,a.ShiftType,(case a.ShiftType when 1 then '白班' else '夜班' end) as ShiftTypeName,a.ShiftUser,shiftuser.UserName as ShiftUserName,a.SuccessionUser,successuser.UserName as SuccessionUserName,a.StartData,a.EndData,a.IsDesalinated,a.DesalinatedSituation,a.DesalinatedRemarks,a.IsLoop,a.LoopSituation,a.LoopRemarks,a.IsSteam,a.SteamSituation,a.SteamRemarks,a.IsAirCompression,a.AirCompressionSituation,a.AirCompressionRemarks,a.IsCompoundAmmonia,a.CompoundAmmoniaSituation,a.CompoundAmmoniaRemarks,a.IsUrea,a.UreaSituation,a.UreaRemarks,a.HandoverCare,a.OperationReason,a.OperationHandle,a.MaintenanceReason,a.MaintenanceHandle,a.AddUser,a.AddTime,a.Sort from Running_LogManagement as a inner join Sys_User as shiftuser on shiftuser.UserId=a.ShiftUser inner join Sys_User as successuser on successuser.UserId=a.SuccessionUser inner join Base_Project as project on project.ProjectId=a.ProjectId ";
|
|||
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|||
|
listStr.Add(new SqlParameter("@projectid", this.CurrUser.LoginProjectId));
|
|||
|
if (this.tvControlItem.SelectedNodeID.Split('|').Length > 0)
|
|||
|
{
|
|||
|
var installationId = this.tvControlItem.SelectedNodeID.Split('|').First();
|
|||
|
strSql += " and a.InstallationId=@InstallationId";
|
|||
|
listStr.Add(new SqlParameter("@InstallationId", installationId));
|
|||
|
}
|
|||
|
if (this.tvControlItem.SelectedNodeID.Split('|').Length > 1)
|
|||
|
{
|
|||
|
var processesId = this.tvControlItem.SelectedNodeID.Split('|')[1];
|
|||
|
strSql += " and a.ProcessesId=@ProcessesId";
|
|||
|
listStr.Add(new SqlParameter("@ProcessesId", processesId));
|
|||
|
}
|
|||
|
if (this.tvControlItem.SelectedNodeID.Split('|').Length > 2)
|
|||
|
{
|
|||
|
var systemId = this.tvControlItem.SelectedNodeID.Split('|').Last();
|
|||
|
strSql += " and a.SystemId=@SystemId";
|
|||
|
listStr.Add(new SqlParameter("@SystemId", systemId));
|
|||
|
}
|
|||
|
if (!string.IsNullOrWhiteSpace(ddlShiftType.SelectedValue))
|
|||
|
{
|
|||
|
strSql += " and a.ShiftType=@ShiftType";
|
|||
|
listStr.Add(new SqlParameter("@ShiftType", ddlShiftType.SelectedValue));
|
|||
|
}
|
|||
|
strSql += " order by a.AddTime asc";
|
|||
|
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();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页
|
|||
|
/// </summary>
|
|||
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|||
|
{
|
|||
|
Grid1.PageIndex = e.NewPageIndex;
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页下拉框
|
|||
|
/// </summary>
|
|||
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 排序
|
|||
|
/// </summary>
|
|||
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 双击修改
|
|||
|
/// </summary>
|
|||
|
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|||
|
{
|
|||
|
btnMenuModify_Click(null, null);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 按钮
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 关闭弹框
|
|||
|
/// </summary>
|
|||
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 搜索
|
|||
|
/// </summary>
|
|||
|
protected void btnQuery_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 添加
|
|||
|
/// </summary>
|
|||
|
protected void btnAdd_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (string.IsNullOrWhiteSpace(this.SystemId))
|
|||
|
{
|
|||
|
Alert.ShowInTop("请选择系统!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RunningLogManagementEdit.aspx?RunningId=&SystemId=" + this.SystemId, "新增 - ")));
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 修改
|
|||
|
/// </summary>
|
|||
|
protected void btnModify_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|||
|
{
|
|||
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RunningLogManagementEdit.aspx?RunningId={0}&SystemId={1}", Grid1.SelectedRowID, this.SystemId, "编辑 - ")));
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 删除
|
|||
|
/// </summary>
|
|||
|
protected void btnDel_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|||
|
{
|
|||
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
var ids = Grid1.SelectedRowIDArray.ToList();
|
|||
|
var list = Funs.DB.Running_LogManagement.Where(x => ids.Contains(x.RunningId)).ToList();
|
|||
|
if (list.Count > 0)
|
|||
|
{
|
|||
|
Funs.DB.Running_LogManagement.DeleteAllOnSubmit(list);
|
|||
|
Funs.DB.SubmitChanges();
|
|||
|
BindGrid();
|
|||
|
Alert.ShowInTop("删除成功!", MessageBoxIcon.Success);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 导出
|
|||
|
/// </summary>
|
|||
|
protected void btnExport_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (Grid1.SelectedRowIndexArray.Length == 0 || Grid1.SelectedRowIndexArray.Length > 1)
|
|||
|
{
|
|||
|
Alert.ShowInTop("请至少选择记录,最大只可选择一条!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
var runningId = this.Grid1.Rows[Grid1.SelectedRowIndex].DataKeys[0].ToString();
|
|||
|
|
|||
|
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
|
|||
|
//导出文件
|
|||
|
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
|
|||
|
if (!Directory.Exists(filePath))
|
|||
|
{
|
|||
|
Directory.CreateDirectory(filePath);
|
|||
|
}
|
|||
|
|
|||
|
var data = from a in Funs.DB.Running_LogManagement
|
|||
|
join b in Funs.DB.Base_Project on a.ProjectId equals b.ProjectId
|
|||
|
join c in Funs.DB.Sys_User on a.ShiftUser equals c.UserId
|
|||
|
join d in Funs.DB.Sys_User on a.SuccessionUser equals d.UserId
|
|||
|
where a.RunningId == runningId
|
|||
|
select new
|
|||
|
{
|
|||
|
a.RunningId,
|
|||
|
a.ProjectId,
|
|||
|
a.InstallationId,
|
|||
|
a.ProcessesId,
|
|||
|
a.SystemId,
|
|||
|
a.JobNo,
|
|||
|
a.ShiftType,
|
|||
|
ShiftTypeName = a.ShiftType == "1" ? "白班" : "夜班",
|
|||
|
a.ShiftUser,
|
|||
|
ShiftUserName = c.UserName,
|
|||
|
a.SuccessionUser,
|
|||
|
SuccessionUserName = d.UserName,
|
|||
|
a.StartData,
|
|||
|
a.EndData,
|
|||
|
a.IsDesalinated,
|
|||
|
a.DesalinatedSituation,
|
|||
|
a.DesalinatedRemarks,
|
|||
|
a.IsLoop,
|
|||
|
a.LoopSituation,
|
|||
|
a.LoopRemarks,
|
|||
|
a.IsSteam,
|
|||
|
a.SteamSituation,
|
|||
|
a.SteamRemarks,
|
|||
|
a.IsAirCompression,
|
|||
|
a.AirCompressionSituation,
|
|||
|
a.AirCompressionRemarks,
|
|||
|
a.IsCompoundAmmonia,
|
|||
|
a.CompoundAmmoniaSituation,
|
|||
|
a.CompoundAmmoniaRemarks,
|
|||
|
a.IsUrea,
|
|||
|
a.UreaSituation,
|
|||
|
a.UreaRemarks,
|
|||
|
a.HandoverCare,
|
|||
|
a.OperationReason,
|
|||
|
a.OperationHandle,
|
|||
|
a.MaintenanceReason,
|
|||
|
a.MaintenanceHandle,
|
|||
|
a.AddUser,
|
|||
|
a.AddTime,
|
|||
|
a.Sort
|
|||
|
};
|
|||
|
var model = data.FirstOrDefault();
|
|||
|
if (model != null)
|
|||
|
{
|
|||
|
string ReportFileName = $"{filePath}Production report({DateTime.Now.ToString("yyyy-MM-dd")} {model.ShiftUserName}).xlsx";
|
|||
|
int rowIndex = 0;
|
|||
|
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
|
|||
|
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet($"Production report({DateTime.Now.ToString("yyyy-MM-dd")} {model.ShiftUserName})");
|
|||
|
|
|||
|
#region 列宽
|
|||
|
|
|||
|
ws.SetColumnWidth(0, (9 * 256));
|
|||
|
ws.SetColumnWidth(1, (9 * 256));
|
|||
|
ws.SetColumnWidth(2, (43 * 256));
|
|||
|
ws.SetColumnWidth(3, (7 * 256));
|
|||
|
ws.SetColumnWidth(4, (8 * 256));
|
|||
|
ws.SetColumnWidth(5, (5 * 256));
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 样式
|
|||
|
//头部样式居中
|
|||
|
ICellStyle titleStyle = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 14, true, true);
|
|||
|
//头部样式靠左
|
|||
|
ICellStyle leftTitleStyle = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 14, true, true);
|
|||
|
//公共样式
|
|||
|
ICellStyle style = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true);
|
|||
|
//公共样式靠左
|
|||
|
ICellStyle leftStyle = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10.5, true);
|
|||
|
//公共样式靠左上对其
|
|||
|
ICellStyle leftTopStyle = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Top, HorizontalAlignment.Left, 10.5, true);
|
|||
|
//公共样式加粗
|
|||
|
ICellStyle styleBold = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true, true);
|
|||
|
//公共样式靠左加粗
|
|||
|
ICellStyle styleLeftBold = SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10.5, true, true);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 头部
|
|||
|
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, rowIndex, rowIndex + 5, 0, 5);
|
|||
|
//行1
|
|||
|
var region = new CellRangeAddress(rowIndex, rowIndex + 3, 0, 1);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(0).SetCellValue("WUHUAN ENGINEERING CO.,LTD");
|
|||
|
ws.GetRow(rowIndex).GetCell(0).CellStyle = titleStyle;
|
|||
|
ws.GetRow(rowIndex).GetCell(2).SetCellValue("PT PETROKIMIA GRESIK");
|
|||
|
ws.GetRow(rowIndex).GetCell(2).CellStyle = titleStyle;
|
|||
|
region = new CellRangeAddress(rowIndex, rowIndex, 3, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(3).SetCellValue("WUHUAN Job. No.");
|
|||
|
ws.GetRow(rowIndex).GetCell(3).CellStyle = styleBold;
|
|||
|
//行2
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(2).SetCellValue("AMMONIA-Urea II PROJECT");
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(2).CellStyle = titleStyle;
|
|||
|
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 3, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
//行3行4
|
|||
|
region = new CellRangeAddress(rowIndex + 2, rowIndex + 3, 2, 2);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(2).SetCellValue("Production report");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(2).CellStyle = titleStyle;
|
|||
|
region = new CellRangeAddress(rowIndex + 2, rowIndex + 3, 3, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(3).SetCellValue("Page 1");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(3).CellStyle = titleStyle;
|
|||
|
//行5
|
|||
|
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 0, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 4).GetCell(0).SetCellValue($"Shift:({model.ShiftUserName}) Succession:({model.SuccessionUserName}) {model.StartData.Value.ToString("yyyy-MM-dd")}— {model.EndData.Value.ToString("yyyy-MM-dd")}");
|
|||
|
ws.GetRow(rowIndex + 4).GetCell(0).CellStyle = styleBold;
|
|||
|
//行6
|
|||
|
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 5).GetCell(0).SetCellValue("Operation situation");
|
|||
|
ws.GetRow(rowIndex + 5).GetCell(0).CellStyle = styleBold;
|
|||
|
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 5).GetCell(4).SetCellValue("Remarks");
|
|||
|
ws.GetRow(rowIndex + 5).GetCell(4).CellStyle = styleBold;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 数据
|
|||
|
|
|||
|
var dataIndex = 5;
|
|||
|
if (model.IsDesalinated == 1)
|
|||
|
{
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).SetCellValue("DW Station 脱盐水");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).CellStyle = styleLeftBold;
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).SetCellValue("");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).CellStyle = leftStyle;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 2, dataIndex + 2, 0, 5, 90);
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).SetCellValue(model.DesalinatedSituation);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).CellStyle = leftStyle;
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).SetCellValue(model.DesalinatedRemarks);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).CellStyle = leftStyle;
|
|||
|
dataIndex += 2;
|
|||
|
}
|
|||
|
if (model.IsLoop == 1)
|
|||
|
{
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).SetCellValue("ACW/UCW/ECW Station 循环水");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).CellStyle = styleLeftBold;
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).SetCellValue("");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).CellStyle = leftStyle;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 2, dataIndex + 2, 0, 5, 90);
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).SetCellValue(model.LoopSituation);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).CellStyle = leftStyle;
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).SetCellValue(model.LoopRemarks);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).CellStyle = leftStyle;
|
|||
|
dataIndex += 2;
|
|||
|
}
|
|||
|
if (model.IsSteam == 1)
|
|||
|
{
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).SetCellValue("Steam System蒸汽");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).CellStyle = styleLeftBold;
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).SetCellValue("");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).CellStyle = leftStyle;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 2, dataIndex + 2, 0, 5, 90);
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).SetCellValue(model.SteamSituation);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).CellStyle = leftStyle;
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).SetCellValue(model.SteamRemarks);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).CellStyle = leftStyle;
|
|||
|
dataIndex += 2;
|
|||
|
}
|
|||
|
if (model.IsAirCompression == 1)
|
|||
|
{
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).SetCellValue("Air Station 空压站");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).CellStyle = styleLeftBold;
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).SetCellValue("");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).CellStyle = leftStyle;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 2, dataIndex + 2, 0, 5, 90);
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).SetCellValue(model.AirCompressionSituation);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).CellStyle = leftStyle;
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).SetCellValue(model.AirCompressionRemarks);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).CellStyle = leftStyle;
|
|||
|
dataIndex += 2;
|
|||
|
}
|
|||
|
if (model.IsCompoundAmmonia == 1)
|
|||
|
{
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).SetCellValue("Ammonia Plant 合成氨");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).CellStyle = styleLeftBold;
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).SetCellValue("");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).CellStyle = leftStyle;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 2, dataIndex + 2, 0, 5, 90);
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).SetCellValue(model.CompoundAmmoniaSituation);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).CellStyle = leftStyle;
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).SetCellValue(model.CompoundAmmoniaRemarks);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).CellStyle = leftStyle;
|
|||
|
dataIndex += 2;
|
|||
|
}
|
|||
|
if (model.IsUrea == 1)
|
|||
|
{
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).SetCellValue("Urea Plant 尿素");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).CellStyle = styleLeftBold;
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).SetCellValue("");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(4).CellStyle = leftStyle;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 2, dataIndex + 2, 0, 5, 90);
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).SetCellValue(model.UreaSituation);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).CellStyle = leftStyle;
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 4, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).SetCellValue(model.UreaRemarks);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(4).CellStyle = leftStyle;
|
|||
|
dataIndex += 2;
|
|||
|
}
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).SetCellValue("Attention of next shift交班注意");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).CellStyle = styleLeftBold;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 2, dataIndex + 2, 0, 5, 30);
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 0, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).SetCellValue(model.HandoverCare);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).CellStyle = leftStyle;
|
|||
|
dataIndex += 2;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).SetCellValue("operation issue操作问题");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).CellStyle = styleLeftBold;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 2, dataIndex + 2, 0, 5, 30);
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 0, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).SetCellValue($"reason原因:{model.OperationReason}");
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).CellStyle = leftStyle;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 3, dataIndex + 3, 0, 5, 30);
|
|||
|
region = new CellRangeAddress(dataIndex + 3, dataIndex + 3, 0, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 3).GetCell(0).SetCellValue($"solution处理:{model.OperationHandle}");
|
|||
|
ws.GetRow(dataIndex + 3).GetCell(0).CellStyle = leftStyle;
|
|||
|
dataIndex += 3;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
region = new CellRangeAddress(dataIndex + 1, dataIndex + 1, 0, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).SetCellValue("maintenance issue维护问题");
|
|||
|
ws.GetRow(dataIndex + 1).GetCell(0).CellStyle = styleLeftBold;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 2, dataIndex + 2, 0, 5, 30);
|
|||
|
region = new CellRangeAddress(dataIndex + 2, dataIndex + 2, 0, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).SetCellValue($"reason原因:{model.MaintenanceReason}");
|
|||
|
ws.GetRow(dataIndex + 2).GetCell(0).CellStyle = leftStyle;
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, style, dataIndex + 3, dataIndex + 3, 0, 5, 30);
|
|||
|
region = new CellRangeAddress(dataIndex + 3, dataIndex + 3, 0, 5);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(dataIndex + 3).GetCell(0).SetCellValue($"solution处理:{model.MaintenanceHandle}");
|
|||
|
ws.GetRow(dataIndex + 3).GetCell(0).CellStyle = leftStyle;
|
|||
|
dataIndex += 3;
|
|||
|
#endregion
|
|||
|
|
|||
|
ws.PrintSetup.Landscape = false;
|
|||
|
ws.PrintSetup.PaperSize = 9;
|
|||
|
ws.ForceFormulaRecalculation = true;
|
|||
|
using (FileStream filess = File.OpenWrite(ReportFileName))
|
|||
|
{
|
|||
|
hssfworkbook.Write(filess);
|
|||
|
}
|
|||
|
FileInfo filet = new FileInfo(ReportFileName);
|
|||
|
Response.Clear();
|
|||
|
Response.Charset = "GB2312";
|
|||
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|||
|
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
|
|||
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode($"Production report({DateTime.Now.ToString("yyyy-MM-dd")} {model.ShiftUserName}).xlsx"));
|
|||
|
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
|
|||
|
Response.AddHeader("Content-Length", filet.Length.ToString());
|
|||
|
// 指定返回的是一个不能被客户端读取的流,必须被下载
|
|||
|
Response.ContentType = "application/ms-excel";
|
|||
|
// 把文件流发送到客户端
|
|||
|
Response.WriteFile(filet.FullName);
|
|||
|
// 停止页面的执行
|
|||
|
Response.End();
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///右击修改
|
|||
|
/// </summary>
|
|||
|
protected void btnMenuModify_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
btnModify_Click(null, null);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
#region 私有方法
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 创建样式
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public static ICellStyle SetExcelStyle(XSSFWorkbook wb, BorderStyle Bottom, BorderStyle Left, BorderStyle Right, BorderStyle Top, VerticalAlignment VerAig, HorizontalAlignment HorAig, double FontSize, bool WrapText = true, bool Bold = false, string FontName = "宋体")
|
|||
|
{
|
|||
|
ICellStyle style = wb.CreateCellStyle();
|
|||
|
style.BorderBottom = Bottom;
|
|||
|
style.BorderLeft = Left;
|
|||
|
style.BorderRight = Right;
|
|||
|
style.BorderTop = Top;
|
|||
|
style.VerticalAlignment = VerAig;
|
|||
|
style.Alignment = HorAig;
|
|||
|
IFont font = wb.CreateFont();
|
|||
|
font.FontHeightInPoints = FontSize;
|
|||
|
font.IsBold = Bold;
|
|||
|
font.FontName = FontName;
|
|||
|
style.SetFont(font);
|
|||
|
style.WrapText = WrapText;
|
|||
|
return style;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 创建头部
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
private XSSFSheet ExcelCreateRowTitle(XSSFSheet ws, XSSFWorkbook hssfworkbook, ICellStyle style, int sRows, int eRows, int cStart, int cEnd, float height = 21)
|
|||
|
{
|
|||
|
for (int i = sRows; i <= eRows; i++)
|
|||
|
{
|
|||
|
ws.CreateRow(i);
|
|||
|
ws.GetRow(i).HeightInPoints = height;
|
|||
|
for (int j = cStart; j <= cEnd; j++)
|
|||
|
{
|
|||
|
ws.GetRow(i).CreateCell(j);
|
|||
|
ws.GetRow(i).CreateCell(j).CellStyle = style;
|
|||
|
}
|
|||
|
}
|
|||
|
return ws;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
}
|