using BLL;
using Model;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.Hazard
{
public partial class ConstructionRisk : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower();//权限设置
this.InitTreeMenu();//加载树
}
}
#region 加载树施工单位
///
/// 加载树
///
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
List units = null;
var user = Person_PersonsService.GetPerson_PersonsById(this.CurrUser.PersonId);
if (!string.IsNullOrEmpty(user.UnitId))
{
var projectUnit = BLL.ProjectUnitService.GetProjectUnitByUnitIdProjectId(this.CurrUser.LoginProjectId, user.UnitId);
if (projectUnit != null)
{
if (projectUnit.UnitType == BLL.Const.ProjectUnitType_1 || projectUnit.UnitType == BLL.Const.ProjectUnitType_3 || projectUnit.UnitType == BLL.Const.ProjectUnitType_4)
{
var ids = Funs.DB.HSSE_ConstructionRisk.Where(x => x.ProjectId == this.CurrUser.LoginProjectId).Select(x => x.UnitId).Distinct().ToList();
units = (from x in Funs.DB.Base_Unit
where ids.Contains(x.UnitId)
select x).OrderBy(x => x.UnitCode).ToList();
}
else
{
units = (from x in Funs.DB.Base_Unit
where x.UnitId == this.CurrUser.UnitId
select x).ToList();
}
}
}
else if (user.UnitId == Const.UnitId_SEDIN || user.PersonId == Const.hfnbdId)
{
var ids = Funs.DB.HSSE_ConstructionRisk.Where(x => x.ProjectId == this.CurrUser.LoginProjectId).Select(x => x.UnitId).Distinct().ToList();
units = (from x in Funs.DB.Base_Unit
where ids.Contains(x.UnitId)
select x).OrderBy(x => x.UnitCode).ToList();
}
if (units != null && units.Count > 0)
{
foreach (var unit in units)
{
TreeNode rootNode = new TreeNode();
rootNode.Text = unit.UnitName;
rootNode.NodeID = unit.UnitId;
rootNode.ToolTip = "单位";
rootNode.Expanded = false;
this.tvControlItem.Nodes.Add(rootNode);
this.BindNodes(rootNode);
}
}
}
#endregion
#region 关闭弹出窗口及刷新页面
///
/// 关闭弹出窗口
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
if (!string.IsNullOrEmpty(hdState.Text))
{
string[] strs = hdState.Text.Split('|');
if (strs[0] == "A")
{
var ids = Grid1.SelectedRowID.Split('|');
if (ids.Length > 1)
{
hdState.Text = "";
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../Check/RectifyNoticesAdd.aspx?ControlId={0}", strs[1], "编辑 - ")));
}
}
else if (strs[0] == "B")
{
var ids = Grid1.SelectedRowID.Split('|');
if (ids.Length > 1)
{
hdState.Text = "";
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../HiddenInspection/HiddenRectificationAdd.aspx?ControlId={0}", strs[1], "编辑 - ")));
}
}
}
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region 页索引改变事件
///
/// 页索引改变事件
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
#endregion
#region 删除
///
/// 删除
///
///
///
///
/// 右键删除明细
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var ids = rowID.Split('|');
if (ids.Length >= 1)
{
var list = Funs.DB.HSSE_ConstructionRiskControl.Where(x => x.ConstructionRiskId == ids[0]).ToList();
Funs.DB.HSSE_ConstructionRiskControl.DeleteAllOnSubmit(list);
var approves = Funs.DB.HSSE_ConstructionRiskApprove.Where(x => x.ConstructionRiskId == ids[0]).ToList();
Funs.DB.HSSE_ConstructionRiskApprove.DeleteAllOnSubmit(approves);
var constructionRisk = Funs.DB.HSSE_ConstructionRisk.Where(x => x.ConstructionRiskId == ids[0]).FirstOrDefault();
Funs.DB.HSSE_ConstructionRisk.DeleteOnSubmit(constructionRisk);
Funs.DB.SubmitChanges();
}
}
ShowNotify("删除成功!", MessageBoxIcon.Success);
this.InitTreeMenu();
this.BindGrid();
}
#endregion
///
/// 数据绑定
///
private void BindGrid()
{
if (this.tvControlItem.SelectedNode != null && this.tvControlItem.SelectedNode.NodeID.Contains("|"))
{
var ids = this.tvControlItem.SelectedNode.NodeID.Split('|');
string strSql = @"select c.MainItemName, '' Id,*
,b.CheckResult"
+ @" from [dbo].[HSSE_ConstructionRisk] a left join [dbo].[HSSE_ConstructionRiskControl] b
on a.ConstructionRiskId =b.ConstructionRiskId left join ProjectData_MainItem c on a.WorkAreaId = c.MainItemId
where a.UnitId=@UnitId and a.DateWeek=@DateWeek order by a.[ConstructionContent],b.[ShowIndex]";
List listStr = new List();
listStr.Add(new SqlParameter("@UnitId", ids[0]));
listStr.Add(new SqlParameter("@DateWeek", ids[1]));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
foreach (DataRow row in tb.Rows)
{
row["Id"] = row["ConstructionRiskId"] + "|" + row["ControlId"];
}
Grid1.DataSource = tb;
Grid1.DataBind();
for (int i = 0; i < Grid1.Rows.Count; i++)
{
string rowID = Grid1.Rows[i].DataKeys[0].ToString().Split('|')[0];
var risk = BLL.ConstructionRiskListService.GetConstructionRisk(rowID);
if (risk != null)
{
if (risk.RiskLevel == "低风险")
{
Grid1.Rows[i].RowCssClass = "Blue";
}
else if (risk.RiskLevel == "一般风险")
{ //闭环
Grid1.Rows[i].RowCssClass = "Yellow";
}
else if (risk.RiskLevel == "较大风险")
{
Grid1.Rows[i].RowCssClass = "Orange";
}
else if (risk.RiskLevel == "重大风险")
{
Grid1.Rows[i].RowCssClass = " Red ";
}
}
}
}
else
{
Grid1.DataSource = null;
Grid1.DataBind();
}
}
#region 绑定树节点
///
/// 绑定树节点
///
///
private void BindNodes(TreeNode node)
{
var DateWeek = (from x in Funs.DB.HSSE_ConstructionRisk
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.UnitId == node.NodeID
select new { x.DateWeek, x.DateA }).Distinct().ToList().OrderByDescending(x => x.DateA);
foreach (var d in DateWeek)
{
TreeNode newNode = new TreeNode();
newNode.Text = d.DateWeek; //string.Format("{0:yyyy-MM-dd}", d.AssessmentDate);
newNode.NodeID = node.NodeID + "|" + d.DateWeek;
newNode.EnableClickEvent = true;
newNode.ToolTip = "标签";
node.Nodes.Add(newNode);
}
}
#endregion
#region 获取按钮权限
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.ConstructionRiskMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnImport.Hidden = false;
this.btnNew.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDelete.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuModify.Hidden = false;
this.btnMenuCheck.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnAuditing))
{
this.btnMenuComplete.Hidden = false;
}
}
}
#endregion
#region 导入
///
/// 导入按钮
///
///
///
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskDataIn.aspx", "导入 - ")));
}
#endregion
#region 导入
///
/// 导入按钮
///
///
///
protected void btnNew_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskEdit.aspx", "添加 - ")));
}
#endregion
protected void btnAudit_Click(object sender, EventArgs e)
{
//if (Grid1.SelectedRowIndexArray.Length == 0)
//{
// Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
// return;
//}
//foreach (int rowIndex in Grid1.SelectedRowIndexArray)
//{
// string rowID = Grid1.DataKeys[rowIndex][0].ToString();
// var ids = rowID.Split('|');
// if (ids.Length >= 1)
// {
// var r = Funs.DB.HSSE_ConstructionRisk.FirstOrDefault(x => x.ConstructionRiskId == ids[0]);
// if (r != null && r.States == "2")
// {
// r.States = "3";
// }
// }
//}
var r = Funs.DB.HSSE_ConstructionRisk.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && x.States == "2");
foreach (var item in r)
{
item.States = "3";
}
Funs.DB.SubmitChanges();
BindGrid();
}
#region 点击TreeView
///
/// 点击TreeView
///
///
///
protected void tvControlItem_NodeCommand111(object sender, TreeCommandEventArgs e)
{
BindGrid();
}
#endregion
protected void btnMenuCheck_Click(object sender, EventArgs e)
{
var ids = Grid1.SelectedRowID.Split('|');
if (ids.Length > 1)
{
hdState.Text = "";
string id = ids[0];
var ins = BLL.ConstructionRiskListService.GetConstructionRisk(id);
if (ins != null)
{
if (ins.States == Const.ConstructionRisk_Complete)
{
Alert.ShowInTop("施工已完成,无需巡检!", MessageBoxIcon.Warning);
return;
}
else if (ins.States != BLL.Const.ConstructionRisk_Audit3)
{
Alert.ShowInTop("尚未实施,无法巡检!", MessageBoxIcon.Warning);
return;
}
else if (this.CurrUser.PersonId != ins.SubUnitDutyPerson && this.CurrUser.PersonId != ins.MainUnitDutyPerson && !ins.MainUnitCheckPerson.Contains(this.CurrUser.PersonId))
{
Alert.ShowInTop("只有分包责任人、总包责任人和总包核查人可以进行巡检!", MessageBoxIcon.Warning);
return;
}
}
PageContext.RegisterStartupScript(Window2.GetSaveStateReference(hdState.ClientID)
+ Window2.GetShowReference(String.Format("ConstructionRiskControlCheck.aspx?ConstructionRiskId={0}", id, "编辑 - ")));
}
}
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
btnMenuModify_Click(null, null);
}
#region 编辑
///
/// 编辑按钮
///
///
///
protected void btnMenuModify_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
var ids = Grid1.SelectedRowID.Split('|');
string id = ids[0];
var ins = BLL.ConstructionRiskListService.GetConstructionRisk(id);
if (ins != null)
{
if (ins.States.Equals(Const.ConstructionRisk_Audit3))
{
Alert.ShowInTop("实施中,无法编辑,请右键查看!", MessageBoxIcon.Warning);
return;
}
if (ins.States.Equals(Const.ConstructionRisk_Complete))
{
Alert.ShowInTop("施工已完成,无法编辑,请右键查看!", MessageBoxIcon.Warning);
return;
}
Model.HSSE_ConstructionRiskApprove approve = BLL.ConstructionRiskApproveService.GetConstructionRiskApproveByConstructionRiskId(id);
if (approve != null)
{
if (!string.IsNullOrEmpty(approve.ApproveMan))
{
if (this.CurrUser.PersonId == approve.ApproveMan || CurrUser.PersonId == Const.sysglyId)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskEdit.aspx?ConstructionRiskId={0}", id, "编辑 - ")));
return;
}
else
{
Alert.ShowInTop("您不是当前办理人,无法编辑,请右键查看!", MessageBoxIcon.Warning);
return;
}
}
}
else
{
Alert.ShowInTop("您不是当前办理人,无法编辑,请右键查看!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region 完成
///
/// 完成按钮
///
///
///
protected void btnMenuComplete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
var ids = Grid1.SelectedRowID.Split('|');
string id = ids[0];
var ins = BLL.ConstructionRiskListService.GetConstructionRisk(id);
if (ins != null)
{
if (ins.States == Const.ConstructionRisk_Audit3)
{
if (this.CurrUser.PersonId == ins.MainUnitDutyPerson)
{
ins.States = Const.ConstructionRisk_Complete;
BLL.ConstructionRiskListService.UpdateConstructionRisk(ins);
BindGrid();
Alert.ShowInTop("操作成功!", MessageBoxIcon.Success);
return;
}
else
{
Alert.ShowInTop("只有总包责任人可以操作完成!", MessageBoxIcon.Warning);
return;
}
}
else if (ins.States == Const.ConstructionRisk_Complete)
{
Alert.ShowInTop("该记录已完成!", MessageBoxIcon.Warning);
return;
}
else
{
Alert.ShowInTop("该记录尚未实施,无法操作完成!", MessageBoxIcon.Warning);
return;
}
}
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;
}
var ids = Grid1.SelectedRowID.Split('|');
string id = ids[0];
var ins = BLL.ConstructionRiskListService.GetConstructionRisk(id);
if (ins != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionRiskView.aspx?ConstructionRiskId={0}", id, "查看 - ")));
}
}
//
//获取办理人姓名
//
//
//
protected string ConvertMan(object Id)
{
if (Id != null)
{
var ids = Id.ToString().Split('|');
Model.HSSE_ConstructionRiskApprove a = BLL.ConstructionRiskApproveService.GetConstructionRiskApproveByConstructionRiskId(ids[0]);
if (a != null)
{
if (a.ApproveMan != null)
{
return BLL.Person_PersonsService.GetPersonsNameById(a.ApproveMan);
}
}
else
{
return "";
}
}
return "";
}
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
var ids = e.RowID.Split('|');
if (e.CommandName.Equals("CheckSee"))
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("ConstructionRiskCheckSee.aspx?ConstructionRiskId={0}", ids[0])));
}
}
#region 导出按钮
/// 导出按钮
///
///
///
protected void btnOut_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.ConstructionRiskOutTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
Model.SGGLDB db = Funs.DB;
if (this.tvControlItem.SelectedNode != null && this.tvControlItem.SelectedNode.ToolTip == "标签")
{
string unitId = this.tvControlItem.SelectedNode.ParentNode.NodeID;
var risks = from x in db.HSSE_ConstructionRisk
join y in db.HSSE_ConstructionRiskControl on x.ConstructionRiskId equals y.ConstructionRiskId
where x.ProjectId == this.CurrUser.LoginProjectId && x.DateWeek == this.tvControlItem.SelectedNode.Text
orderby x.ConstructionContent, y.ShowIndex
select new
{
ControlId = y.ControlId,
ConstructionRiskId = x.ConstructionRiskId,
DateA = x.DateA,
DateZ = x.DateZ,
MainItemName = db.ProjectData_MainItem.First(a => a.MainItemId == x.WorkAreaId).MainItemName,
UnitName = db.Base_Unit.First(a => a.UnitId == x.UnitId).UnitName,
ConstructionContent = x.ConstructionContent,
RefLicense = x.RefLicense,
LicenseDes = x.LicenseDes,
RiskLevel = x.RiskLevel,
Measures = y.Measures,
SubUnitDutyPerson = db.Person_Persons.First(a => a.PersonId == x.SubUnitDutyPerson).PersonName,
MainUnitDutyPerson = db.Person_Persons.First(a => a.PersonId == x.MainUnitDutyPerson).PersonName,
MainUnitCheckPerson = Person_PersonsService.getPersonsNamesPersonIds(x.MainUnitCheckPerson),
};
var checkLists = from x in db.HSSE_ConstructionRiskCheck
join y in db.HSSE_ConstructionRisk on x.ConstructionRiskId equals y.ConstructionRiskId
where y.ProjectId == this.CurrUser.LoginProjectId
select x;
if (risks.Count() > 0)
{
string projectName = BLL.ProjectService.GetProjectNameByProjectId(this.CurrUser.LoginProjectId);
string date = string.Empty;
var r = risks.First();
if (r.DateA != null)
{
date = string.Format("{0:yyyy-MM-dd}", r.DateA);
}
newUrl = uploadfilepath.Replace(".xlsx", "(" + date + ")" + ".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;
cellStyle.WrapText = true;
var font = workbook.CreateFont();
font.FontHeightInPoints = 14;
//font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
cellStyle.SetFont(font);
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle2 = workbook.CreateCellStyle();
cellStyle2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
cellStyle2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle2.WrapText = true;
cellStyle2.SetFont(font);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
int i = 0;
NPOI.SS.UserModel.IRow row;
NPOI.SS.UserModel.ICell cell;
row = sheet.GetRow(i);
cell = row.GetCell(0);
DateTime dateA = r.DateA.Value;
DateTime dateZ = r.DateZ.Value;
cell.SetCellValue(projectName + " 每周施工作业风险动态管控表(" + dateA.Month + "月" + dateA.Day + "日-" + dateZ.Month + "月" + dateZ.Day + "日" + ")");
i = 3;
int a = 0;
int b = 0;
string oldId = string.Empty;
foreach (var item in risks)
{
i++;
b++;
if (oldId != item.ConstructionRiskId)
{
if (!string.IsNullOrEmpty(oldId)) //非第一行记录
{
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 0, 0));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 1, 1));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 2, 2));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 3, 3));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 4, 4));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 5, 5));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 6, 6));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 8, 8));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 9, 9));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 10, 10));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 11, 11));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i - 1, 12, 12));
}
oldId = item.ConstructionRiskId;
a++;
b = 1;
}
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue(a.ToString());
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.MainItemName);
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.UnitName);
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.ConstructionContent);
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.RefLicense);
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.LicenseDes);
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.RiskLevel);
cell = row.CreateCell(7);
cell.CellStyle = cellStyle2;
cell.SetCellValue(b.ToString() + "、" + item.Measures);
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.SubUnitDutyPerson);
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.MainUnitDutyPerson);
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.MainUnitCheckPerson);
cell = row.CreateCell(11);
cell.CellStyle = cellStyle2;
var checks = checkLists.Where(x => x.ConstructionRiskId == item.ConstructionRiskId).OrderByDescending(x => x.CheckDate);
string checkResults = string.Empty;
string rectification = string.Empty;
foreach (var check in checks)
{
checkResults += string.Format("{0:yyyy-MM-dd}", check.CheckDate) + ":" + check.CheckResult;
if (check.CheckResult == "不符合")
{
rectification += string.Format("{0:yyyy-MM-dd}", check.CheckDate) + ":" + check.Rectification;
}
}
//row.Height = (short)(140 * checks.Count());
cell.SetCellValue(checkResults);
cell = row.CreateCell(12);
cell.CellStyle = cellStyle2;
cell.SetCellValue(rectification);
}
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 0, 0));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 1, 1));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 2, 2));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 3, 3));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 4, 4));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 5, 5));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 6, 6));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 8, 8));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 9, 9));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 10, 10));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 11, 11));
sheet.AddMergedRegion(new CellRangeAddress(i - b + 1, i, 12, 12));
// 第三步:写入文件流
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);
}
}
else
{
Alert.ShowInTop("请选择一周的记录,再点击导出!", MessageBoxIcon.Warning);
}
}
#endregion
}
}