This commit is contained in:
2024-06-26 01:24:42 +08:00
parent 197b55e6bd
commit a032064afc
4 changed files with 221 additions and 208 deletions
@@ -14,6 +14,7 @@ using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using Model;
using NPOI.SS.Formula.Functions;
using FineUIPro.Web.ProjectData;
namespace FineUIPro.Web.TestRun.ProduceTestRun
{
@@ -80,17 +81,17 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
public void BindGrid()
{
var years = DateTime.Now.Year;
string strSql = @"select a.RunningId,a.ProjectId,project.ProjectName as ProjectName,a.InstallationId,a.ProcessesId,a.SystemId,inst.PreRunName as InstallationName,proce.PreRunName as ProcessesName,syst.PreRunName as SystemName,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.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 inner join PreRun_SysDevice as inst on inst.PreRunId=a.InstallationId inner join PreRun_SysDevice as proce on proce.PreRunId=a.ProcessesId inner join PreRun_SysDevice as syst on syst.PreRunId=a.SystemId where a.ProjectId=@ProjectId ";
string strSql = @"select a.MainId,a.ProjectId,project.ProjectName as ProjectName,a.JobNo,a.ShiftType,(case a.ShiftType when 1 then '白班' else '夜班' end) as ShiftTypeName,a.StartData,a.EndData,a.AddUser,a.AddTime from Running_LogMain as a inner join Base_Project as project on project.ProjectId=a.ProjectId where a.ProjectId=@ProjectId ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (!string.IsNullOrWhiteSpace(this.tvControlItem.SelectedNodeID))
{
if (this.tvControlItem.SelectedNodeID != "0" && !string.IsNullOrWhiteSpace(this.tvControlItem.SelectedNodeID))
{
strSql += " and a.InstallationId=@InstallationId";
listStr.Add(new SqlParameter("@InstallationId", this.tvControlItem.SelectedNodeID));
}
}
//if (!string.IsNullOrWhiteSpace(this.tvControlItem.SelectedNodeID))
//{
// if (this.tvControlItem.SelectedNodeID != "0" && !string.IsNullOrWhiteSpace(this.tvControlItem.SelectedNodeID))
// {
// strSql += " and a.InstallationId=@InstallationId";
// listStr.Add(new SqlParameter("@InstallationId", this.tvControlItem.SelectedNodeID));
// }
//}
if (!string.IsNullOrWhiteSpace(txtStartData.Text))
{
strSql += " and a.StartData>=@StartData";
@@ -107,16 +108,16 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
strSql += " and a.ShiftType=@ShiftType";
listStr.Add(new SqlParameter("@ShiftType", ddlShiftType.SelectedValue));
}
strSql += " order by inst.PreRunLevel,inst.Sort,proce.Sort,syst.Sort asc";
strSql += " order by a.StartData 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();
if (Funs.DB.Running_LogManagement.Count(x => x.StartData.Value.Year == years) > 0)
if (Funs.DB.Running_LogMain.Count(x => x.StartData.Value.Year == years) > 0)
{
var minTime = Funs.DB.Running_LogManagement.Where(x => x.StartData.Value.Year == years).Min(m => m.StartData);
var minTime = Funs.DB.Running_LogMain.Where(x => x.StartData.Value.Year == years).Min(m => m.StartData);
lblminTime.Text = $"{years}年日志最小日期:{minTime.Value.ToString("yyyy-MM-dd")}";
}
else
@@ -184,7 +185,7 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
/// </summary>
protected void btnAdd_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RunningLogManagementEdit.aspx?RunningId=", "新增 - ")));
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RunningLogManagementEdit.aspx?MainId=", "新增 - ")));
}
/// <summary>
@@ -197,7 +198,7 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RunningLogManagementEdit.aspx?RunningId={0}", Grid1.SelectedRowID, "编辑 - ")));
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RunningLogManagementEdit.aspx?MainId={0}", Grid1.SelectedRowID, "编辑 - ")));
}
/// <summary>
@@ -211,10 +212,10 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
return;
}
var ids = Grid1.SelectedRowIDArray.ToList();
var list = Funs.DB.Running_LogManagement.Where(x => ids.Contains(x.RunningId)).ToList();
var list = Funs.DB.Running_LogMain.Where(x => ids.Contains(x.MainId)).ToList();
if (list.Count > 0)
{
Funs.DB.Running_LogManagement.DeleteAllOnSubmit(list);
Funs.DB.Running_LogMain.DeleteAllOnSubmit(list);
Funs.DB.SubmitChanges();
BindGrid();
Alert.ShowInTop("删除成功!", MessageBoxIcon.Success);
@@ -231,7 +232,7 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
Alert.ShowInTop("请至少选择记录,最大只可选择一条!", MessageBoxIcon.Warning);
return;
}
var runningId = this.Grid1.Rows[Grid1.SelectedRowIndex].DataKeys[0].ToString();
var mainId = this.Grid1.Rows[Grid1.SelectedRowIndex].DataKeys[0].ToString();
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
//导出文件
@@ -245,14 +246,20 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
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
join init in Funs.DB.PreRun_SysDevice on a.InstallationId equals init.PreRunId
join sys in Funs.DB.PreRun_SysDevice on a.SystemId equals sys.PreRunId
where a.MainId == mainId
orderby a.Sort ascending
select new
{
a.RunningId,
a.MainId,
a.ProjectId,
a.InstallationId,
InstallationName = init.PreRunName,
a.ProcessesId,
a.SystemId,
SystemName = sys.PreRunName,
a.JobNo,
a.ShiftType,
ShiftTypeName = a.ShiftType == "1" ? "白班" : "夜班",
@@ -269,17 +276,18 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
a.AddTime,
a.Sort
};
var model = data.FirstOrDefault();
if (model != null)
var list = data.ToList();
if (list.Count > 0)
{
var firstModel = list.FirstOrDefault();
//操作问题
var operations = Funs.DB.Running_Operation.Where(x => x.RunningId == model.RunningId).ToList();
var operations = Funs.DB.Running_Operation.Where(x => x.MainId == mainId).ToList();
//维护问题
var maintes = Funs.DB.Running_Maintenance.Where(x => x.RunningId == model.RunningId).ToList();
string ReportFileName = $"{filePath}Production report{DateTime.Now.ToString("yyyy-MM-dd")} {model.ShiftUserName}).xlsx";
var maintes = Funs.DB.Running_Maintenance.Where(x => x.MainId == mainId).ToList();
string ReportFileName = $"{filePath}Production report{DateTime.Now.ToString("yyyy-MM-dd")} {firstModel.ShiftUserName}).xlsx";
int rowIndex = 0;
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet($"Production report{DateTime.Now.ToString("yyyy-MM-dd")} {model.ShiftUserName})");
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet($"Production report{DateTime.Now.ToString("yyyy-MM-dd")} {firstModel.ShiftUserName})");
#region
@@ -341,7 +349,7 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
//行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).SetCellValue($"Shift:({firstModel.ShiftUserName} Succession:({firstModel.SuccessionUserName} {firstModel.StartData.Value.ToString("yyyy-MM-dd")}— {firstModel.EndData.Value.ToString("yyyy-MM-dd")}");
ws.GetRow(rowIndex + 4).GetCell(0).CellStyle = styleBold;
//行6
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 0, 3);
@@ -359,25 +367,29 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
var dataIndex = 5;
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.Situation);
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.Remarks);
ws.GetRow(dataIndex + 2).GetCell(4).CellStyle = leftStyle;
dataIndex += 2;
foreach (var item in list)
{
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(item.SystemName);
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(item.Situation);
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(item.Remarks);
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);
@@ -387,11 +399,10 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
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).SetCellValue(firstModel.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);
@@ -449,7 +460,7 @@ namespace FineUIPro.Web.TestRun.ProduceTestRun
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-Disposition", "attachment; filename=" + Server.UrlEncode($"Production report{DateTime.Now.ToString("yyyy-MM-dd")} {firstModel.ShiftUserName}).xlsx"));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", filet.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载