20240419 NCR附件修改

This commit is contained in:
2024-04-19 10:13:37 +08:00
parent 0829c2c559
commit 016ea897dc
18 changed files with 1352 additions and 780 deletions
@@ -3,6 +3,7 @@ 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;
@@ -401,5 +402,188 @@ namespace FineUIPro.Web.CQMS.Check
txtEndTime.Text = "";
bindata();
}
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string initTemplatePath = Const.JointCheckTempUrl;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
uploadfilepath = rootPath + initTemplatePath;
var lists = BLL.JointCheckService.GetDriverPlanByProjectId(this.CurrUser.LoginProjectId);
if (lists != null)
{
newUrl = uploadfilepath.Replace("质量专项检查模版.xlsx", "质量专项检查.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 = 11;
cellStyle.SetFont(font);
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font0 = workbook.CreateFont();
font0.FontHeightInPoints = 12;
font0.IsBold = true;
cellStyle0.SetFont(font0);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell;
int i = 1;
foreach (var item in lists)
{
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue(i.ToString());//序号
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JointCheckCode);
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(BLL.UnitService.GetUnitNameByUnitId(item.UnitId));
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
string checkName = string.Empty;
if (item.CheckType == "1")
{
checkName = "周检查";
}
else if (item.CheckType == "2")
{
checkName = "月检查";
}
else if (item.CheckType == "3")
{
checkName = "不定期检查";
}
else if (item.CheckType == "4")
{
checkName = "专业检查";
}
cell.SetCellValue(checkName);
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.CheckName);
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.CheckDate.HasValue ? string.Format("{0:yyyy-MM-dd}", item.CheckDate) : "");
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(BLL.UserService.GetUserNameByUserId(item.CheckMan));
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
string state = string.Empty;
if (item.State.ToString() == BLL.Const.JointCheck_ReCompile)
{
state = "重新编制";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Compile)
{
state = "编制";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit1)
{
state = "分包专工回复";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit2)
{
state = "分包负责人审批";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit3)
{
state = "总包专工回复";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit4)
{
state = "总包负责人审批";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Complete)
{
state = "审批完成";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Z)
{
state = "整改中";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit1R)
{
state = "分包专工重新回复";
}
cell.SetCellValue(state);
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
string userNames = string.Empty;
List<Model.Check_JointCheckApprove> list = BLL.JointCheckApproveService.GetJointCheckApprovesByJointCheckId(item.JointCheckId);
foreach (var a in list)
{
if (a != null)
{
if (a.ApproveMan != null)
{
if (!userNames.Contains(BLL.UserService.GetUserByUserId(a.ApproveMan).UserName))
{
userNames += UserService.GetUserByUserId(a.ApproveMan).UserName + ",";
}
}
}
}
if (!string.IsNullOrEmpty(userNames))
{
userNames = userNames.Substring(0, userNames.LastIndexOf(","));
}
cell.SetCellValue(userNames);
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
}
}