提交代码
This commit is contained in:
@@ -8,6 +8,8 @@ using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using NPOI.SS.Util;
|
||||
|
||||
namespace FineUIPro.Web.HSSE.Hazard
|
||||
{
|
||||
@@ -207,6 +209,30 @@ namespace FineUIPro.Web.HSSE.Hazard
|
||||
|
||||
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
|
||||
{
|
||||
@@ -254,7 +280,7 @@ namespace FineUIPro.Web.HSSE.Hazard
|
||||
{
|
||||
if (buttonList.Contains(BLL.Const.BtnAdd))
|
||||
{
|
||||
//this.btnImport.Hidden = false;
|
||||
this.btnImport.Hidden = false;
|
||||
this.btnNew.Hidden = false;
|
||||
}
|
||||
if (buttonList.Contains(BLL.Const.BtnDelete))
|
||||
@@ -347,7 +373,7 @@ namespace FineUIPro.Web.HSSE.Hazard
|
||||
var ins = BLL.ConstructionRiskListService.GetConstructionRisk(id);
|
||||
if (ins != null)
|
||||
{
|
||||
if (ins.States.Equals(Const.ConstructionRisk_Complete))
|
||||
if (ins.States == Const.ConstructionRisk_Complete)
|
||||
{
|
||||
Alert.ShowInTop("施工已完成,无需巡检!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
@@ -357,6 +383,11 @@ namespace FineUIPro.Web.HSSE.Hazard
|
||||
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, "编辑 - ")));
|
||||
@@ -448,11 +479,19 @@ namespace FineUIPro.Web.HSSE.Hazard
|
||||
{
|
||||
if (ins.States == Const.ConstructionRisk_Audit3)
|
||||
{
|
||||
ins.States = Const.ConstructionRisk_Complete;
|
||||
BLL.ConstructionRiskListService.UpdateConstructionRisk(ins);
|
||||
BindGrid();
|
||||
Alert.ShowInTop("操作成功!", MessageBoxIcon.Success);
|
||||
return;
|
||||
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)
|
||||
{
|
||||
@@ -524,5 +563,224 @@ namespace FineUIPro.Web.HSSE.Hazard
|
||||
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("ConstructionRiskCheckSee.aspx?ConstructionRiskId={0}", ids[0])));
|
||||
}
|
||||
}
|
||||
|
||||
#region 导出按钮
|
||||
/// 导出按钮
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user