using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using BLL; using AspNet = System.Web.UI.WebControls; using Aspose.Words; using Aspose.Words.Tables; using System.IO; namespace FineUIPro.Web.HSSE.Manager { public partial class ManagerMonthCNew : PageBase { public List unitList = new List(); /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { // 表头过滤 //FilterDataRowItem = FilterDataRowItemImplement; if (!IsPostBack) { unitList = Funs.DB.Base_Unit.ToList(); this.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.ProjectId) { this.ProjectId = Request.Params["projectId"]; } ////权限按钮方法 this.GetButtonPower(); this.txtReportDate.Text = string.Format("{0:yyyy-MM}", DateTime.Now); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT MonthReport.MonthReportId,MonthReport.ProjectId,MonthReport.Months,CodeRecords.Code AS MonthReportCode,Users.UserName as ReportManName" + @" FROM Manager_MonthReportC AS MonthReport " + @" LEFT JOIN Sys_User AS Users ON MonthReport.ReportMan=Users.UserId " + @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON MonthReport.MonthReportId=CodeRecords.DataId WHERE MonthReportType='1' "; List listStr = new List(); strSql += " AND MonthReport.ProjectId = @ProjectId"; listStr.Add(new SqlParameter("@ProjectId", this.ProjectId)); if (!string.IsNullOrEmpty(this.txtMonthReportCode.Text.Trim())) { strSql += " AND CodeRecords.Code LIKE @MonthReportCode"; listStr.Add(new SqlParameter("@MonthReportCode", "%" + this.txtMonthReportCode.Text.Trim() + "%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 过滤表头、排序、分页、关闭窗口 /// /// 过滤表头 /// /// /// protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region Grid双击事件 /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { btnMenuModify_Click(null, null); } #endregion #region 编辑 /// /// 编辑按钮 /// /// /// protected void btnMenuModify_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string MonthReportId = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ManagerMonthCEdit.aspx?MonthReportId={0}", MonthReportId, "编辑 - "))); //var monthReport = BLL.MonthReportCService.GetMonthReportByMonthReportId(MonthReportId); //int n = 6; //月报冻结时间 //var sysSet = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_MonthReportFreezeDay).FirstOrDefault(); //if (sysSet != null) //{ // n = Convert.ToInt32(sysSet.ConstValue); //} //if (monthReport != null) //{ // int d = Convert.ToInt32(DateTime.Now.Day); // if ((monthReport.Months.Value.Year == DateTime.Now.Year && monthReport.Months.Value.Month == DateTime.Now.Month) || // ((monthReport.Months.Value.AddMonths(1).Month == DateTime.Now.Month) && d < n + 1)) // { // PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportCEdit.aspx?MonthReportId={0}", MonthReportId, "编辑 - "))); // } // else // { // PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportCView.aspx?MonthReportId={0}", MonthReportId, "查看 - "))); // } //} } #endregion #region 删除 /// /// 批量删除 /// /// /// protected void btnMenuDel_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var mont = BLL.MonthReportCService.GetMonthReportByMonthReportId(rowID); if (mont != null) { InjuryAccidentCService.DeleteInjuryAccidengtByMonthReportId(rowID); PersonSortCService.DeleteManager_Attempted(rowID); PersonSortCService.DeleteManager_DrillRecordList(rowID); PersonSortCService.DeleteManager_EmergencyPlan(rowID); PersonSortCService.DeleteManager_ProjectAssignment(rowID); PersonSortCService.DeleteManager_HiddenDanger(rowID); ComplianceObligationsCService.DeleteComplianceObligationsCByMonthReportId(rowID); RewardAndPunishSortCService.DeleteRewardAndPunishSortCByMonthReportId(rowID); PersonSortCService.DeletePersonSortsByMonthReportId(rowID); HazardSortCService.DeleteHazardSortsByMonthReportId(rowID); AccidentSortCService.DeleteAccidentSortsByMonthReportId(rowID); HseCostCService.DeleteHseCostsByMonthReportId(rowID); TrainSortCService.DeleteTrainSortsByMonthReportId(rowID); TrainActivitySortCService.DeleteTrainActivitySortsByMonthReportId(rowID); MeetingSortCService.DeleteMeetingSortsByMonthReportId(rowID); CheckSortCService.DeleteCheckSortsByMonthReportId(rowID); CheckDetailSortCService.DeleteCheckDetailSortsByMonthReportId(rowID); PromotionalActiviteSortCService.DeletePromotionalActiviteSortsByMonthReportId(rowID); EmergencySortCService.DeleteEmergencySortsByMonthReportId(rowID); DrillSortCService.DeleteDrillSortsByMonthReportId(rowID); IncentiveSortCService.DeleteIncentiveSortsByMonthReportId(rowID); OtherActiveSortCService.DeleteOtherActiveSortsByMonthReportId(rowID); ActivityDesCService.DeleteActivityDesByMonthReportId(rowID); OtherManagementCService.DeleteOtherManagementByMonthReportId(rowID); PlanCService.DeletePlanByMonthReportId(rowID); ReviewRecordCService.DeleteReviewRecordByMonthReportId(rowID); FileManageCService.DeleteFileManageByMonthReportId(rowID); FiveExpenseCService.DeleteFiveExpenseByMonthReportId(rowID); SubExpenseCService.DeleteSubExpenseByMonthReportId(rowID); AccidentDesciptionItemCService.DeleteAccidentDesciptionItemByMonthReportId(rowID); AccidentDesciptionCService.DeleteAccidentDesciptionByMonthReportId(rowID); OtherWorkCService.DeleteOtherWorkByMonthReportId(rowID); HazardCService.DeleteHazardByMonthReportId(rowID); TrainCService.DeleteTrainByMonthReportId(rowID); CheckCService.DeleteCheckByMonthReportId(rowID); MeetingCService.DeleteMeetingByMonthReportId(rowID); ActivitiesCService.DeleteActivitiesByMonthReportId(rowID); EmergencyPlanCService.DeleteEmergencyPlanByMonthReportId(rowID); EmergencyExercisesCService.DeleteEmergencyExercisesByMonthReportId(rowID); CostInvestmentPlanCService.DeleteCostInvestmentPlanByMonthReportId(rowID); ManageDocPlanCService.DeleteManageDocPlanByMonthReportId(rowID); OtherWorkPlanCService.DeleteOtherWorkPlanByMonthReportId(rowID); MonthReportCService.DeleteMonthReportByMonthReportId(rowID); } } BindGrid(); ShowNotify("删除数据成功!(表格数据已重新绑定)"); } } #endregion #region 新增 /// /// 新增 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId); if (project.StartDate != null) { if (!string.IsNullOrEmpty(this.txtReportDate.Text.Trim())) { DateTime months = Convert.ToDateTime(this.txtReportDate.Text.Trim() + "-01"); Model.Manager_MonthReportC monthReport = BLL.MonthReportCService.GetMonthReportByMonths(months, this.CurrUser.LoginProjectId); if (monthReport != null) { Alert.ShowInTop("当前月份的月报已存在!", MessageBoxIcon.Warning); return; } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportCEdit.aspx?months={0}", string.Format("{0:yyyy-MM-dd}", months), "编辑 - "))); } } else { Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInTop("请先设置项目开工时间!", MessageBoxIcon.Warning); return; } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.ManagerMonthCNewMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuModify.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDel.Hidden = false; } } } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("管理月报B" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; this.Grid1.PageSize = 500; this.BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); foreach (GridColumn column in grid.Columns) { sb.AppendFormat("", column.HeaderText); } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfNumber") { html = (row.FindControl("lblNumber") as AspNet.Label).Text; } sb.AppendFormat("", html); } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion #region 最新新增 protected void btnNew_Click1(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.txtReportDate.Text.Trim())) { DateTime months = Convert.ToDateTime(this.txtReportDate.Text.Trim() + "-01"); PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ManagerMonthCEdit.aspx?months={0}", string.Format("{0:yyyy-MM-dd}", months), "添加 - "))); } else { Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning); return; } } #endregion #region 导出 #region 转换字符串 /// /// 把单位Id转换为单位名称 /// /// /// protected string ConvertUnitName(string UnitId) { if (UnitId != null) { var u = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == UnitId.ToString()); if (u != null) { return u.UnitName; } } return ""; } #endregion /// /// /// /// 单元格内的值 /// /// /// /// 有值的话就是序号 /// 字体居左 /// public static Cell CreateCell(String value, Document doc, double cellWidth, string cellMerge = "", string CenterPage = "", string cellUnitLeft = "") { Cell cell = new Cell(doc); Paragraph p = new Paragraph(doc); if (!string.IsNullOrEmpty(cellMerge)) { if (cellMerge == "0") { cell.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;//竖直方向合并的第一个单元格 } else { cell.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;//竖直方向合并的第一个单元格 } } else { cell.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; } if (!string.IsNullOrEmpty(CenterPage)) { //序号 value = " " + value; } if (!string.IsNullOrEmpty(cellUnitLeft)) { p.ParagraphFormat.Alignment = ParagraphAlignment.Left;//表格中字体居左 } else { p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//表格中字体居中 } p.AppendChild(new Run(doc, value)); cell.CellFormat.Width = cellWidth; cell.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; //边框宽度 cell.CellFormat.Borders.LineWidth = 0.5; cell.AppendChild(p); return cell; } /// /// 导出按钮 /// /// /// protected void btnMenuOut_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string Id = Grid1.SelectedRowID;//安全月报的主键 try { string rootPath = Server.MapPath("~/"); string initTemplatePath = string.Empty; string uploadfilepath = string.Empty; string newUrl = string.Empty; string filePath = string.Empty; Model.SGGLDB db = Funs.DB; initTemplatePath = Const.HseMonthReportNewTemplateUrl; uploadfilepath = rootPath + initTemplatePath; //根据id获取月报主表数据 var model = db.Manager_MonthReportC.FirstOrDefault(x => x.MonthReportId == Id); var startDate = Convert.ToDateTime(model.StartDate); var endDate = Convert.ToDateTime(model.EndDate); //获取project var pModel = db.Base_Project.FirstOrDefault(x => x.ProjectId == model.ProjectId); var urlHz = startDate.ToString("yyyyMMdd") + "-" + endDate.ToString("yyyyMMdd"); newUrl = uploadfilepath.Replace("项目安全月报", pModel.ShortName + "项目HSE月报(" + model.MonthReportCode + ")" + urlHz); if (File.Exists(newUrl)) { File.Delete(newUrl); } File.Copy(uploadfilepath, newUrl); //更新书签内容 Document doc = new Aspose.Words.Document(newUrl); DocumentBuilder builder = new DocumentBuilder(doc); #region 头部静态列 //业主单位 var unitsYz = (from x in db.Base_Unit join y in db.Project_ProjectUnit on x.UnitId equals y.UnitId where y.ProjectId == this.CurrUser.LoginProjectId && y.UnitType == BLL.Const.ProjectUnitType_4 orderby x.UnitName select x).FirstOrDefault(); Bookmark bkmark = doc.Range.Bookmarks["username"]; if (bkmark != null) { if (unitsYz != null) { bkmark.Text = unitsYz.UnitName; } //var uModel = db.Sys_User.FirstOrDefault(x => x.UserId == weekModel.CreateMan); //if (uModel!=null) //{ // bkmark.Text = uModel.UserName; //} } bkmark = doc.Range.Bookmarks["projectNo"]; if (bkmark != null) { bkmark.Text = pModel.ProjectCode; } bkmark = doc.Range.Bookmarks["createdate"]; if (bkmark != null) { bkmark.Text = model.EndDate.ToString().Split(' ')[0].Replace('/', '.'); } bkmark = doc.Range.Bookmarks["projectname"]; if (bkmark != null) { bkmark.Text = pModel.ProjectName; } bkmark = doc.Range.Bookmarks["quamanagername"]; if (bkmark != null) { var getPUser = Funs.DB.Project_ProjectUser.Where(x => x.ProjectId == model.ProjectId); ////安全经理 var qa = getPUser.FirstOrDefault(x => x.RoleId.Contains(BLL.Const.HSSEManager)); bkmark.Text = db.Sys_User.FirstOrDefault(x => x.UserId == qa.UserId).UserName; } bkmark = doc.Range.Bookmarks["reportAlldate"]; //20XX年XX月XX日至20XX年XX月XX日 if (bkmark != null) { var sdate = Convert.ToDateTime(model.StartDate); var edate = Convert.ToDateTime(model.EndDate); bkmark.Text = sdate.Year + "年" + sdate.Month + "月" + sdate.Day + "日至" + edate.Year + "年" + edate.Month + "月" + edate.Day + "日"; } bkmark = doc.Range.Bookmarks["reportindex"]; if (bkmark != null) { bkmark.Text = model.MonthReportCode; } bkmark = doc.Range.Bookmarks["fromcode"]; //fromcode,项目号-RM-HSE-顺序号 if (bkmark != null) { bkmark.Text = pModel.ProjectCode + "-RM-HSE-" + model.MonthReportCode; } #endregion #region 1.项目概况 bkmark = doc.Range.Bookmarks["lbProjectName"]; if (bkmark != null) { bkmark.Text = pModel.ProjectName; } bkmark = doc.Range.Bookmarks["lblMainUnitName"]; if (bkmark != null) { var mainUnit = BLL.UnitService.GetThisUnitDropDownList()[0]; if (mainUnit != null) { bkmark.Text = mainUnit.UnitName; } } bkmark = doc.Range.Bookmarks["lblProjectAddress"]; if (bkmark != null) { bkmark.Text = pModel.ProjectAddress; } bkmark = doc.Range.Bookmarks["lblProjectCode"]; if (bkmark != null) { bkmark.Text = pModel.ProjectCode; } bkmark = doc.Range.Bookmarks["lblContractNo"]; if (bkmark != null) { bkmark.Text = pModel.ContractNo; } bkmark = doc.Range.Bookmarks["lblProjectType"]; if (bkmark != null) { if (!string.IsNullOrEmpty(pModel.ProjectType)) { var c = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_ProjectType). FirstOrDefault(x => x.ID == pModel.ProjectType); if (c != null) { bkmark.Text = c.ConstText; } } } bkmark = doc.Range.Bookmarks["lblWorkRange"]; if (bkmark != null) { bkmark.Text = pModel.WorkRange; } bkmark = doc.Range.Bookmarks["lblDuration"]; if (bkmark != null) { bkmark.Text = pModel.Duration.ToString(); } bkmark = doc.Range.Bookmarks["lblStartDate"]; if (bkmark != null) { bkmark.Text = string.Format("{0:yyyy-MM-dd}", pModel.StartDate); } bkmark = doc.Range.Bookmarks["lblEndDate"]; if (bkmark != null) { bkmark.Text = string.Format("{0:yyyy-MM-dd}", pModel.EndDate); } #endregion #region 2.本月项目现场HSE人力投入情况 //获取word文档中的第二个表格 int whileIndex = 1; Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 1, true); bool isYm = true; //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 2) != "单位") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } //人力投入情况 var sorts = (from x in db.Manager_PersonSortC join y in db.Project_ProjectUnit on x.UnitId equals y.UnitId where x.MonthReportId == Id && y.ProjectId == this.ProjectId orderby y.UnitType select x).ToList(); int numberIndex = 2; foreach (var item in sorts) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(ConvertUnitName(item.UnitId), doc, table.Rows[1].Cells[0].CellFormat.Width, "", "", "unit")); if (item.UnitId == Const.UnitId_CWCEC) { row.Cells.Add(CreateCell(item.SumPersonNum.ToString(), doc, table.Rows[1].Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.SumOutPersonNum.ToString(), doc, table.Rows[1].Cells[2].CellFormat.Width)); } else { row.Cells.Add(CreateCell(item.SumPersonNum.ToString(), doc, table.Rows[1].Cells[1].CellFormat.Width+ table.Rows[1].Cells[2].CellFormat.Width)); } row.Cells.Add(CreateCell(item.HSEPersonNum.ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.ContractRange.ToString(), doc, table.Rows[1].Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remark.ToString(), doc, table.Rows[1].Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("合计", doc, table.Rows[1].Cells[0].CellFormat.Width, "", "", "unit")); rowhj.Cells.Add(CreateCell(((from x in sorts select x.SumPersonNum ?? 0).Sum() + (from x in sorts select x.SumOutPersonNum ?? 0).Sum()).ToString(), doc, table.Rows[1].Cells[1].CellFormat.Width +table.Rows[1].Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in sorts select x.HSEPersonNum ?? 0).Sum().ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.Rows[1].Cells[4].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.Rows[1].Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); #endregion #region 3.本月项目现场HSE工时/工日统计 whileIndex += 1; bkmark = doc.Range.Bookmarks["MonthHSEDay"]; if (bkmark != null) { bkmark.Text = model.MonthHSEDay.ToString(); } bkmark = doc.Range.Bookmarks["SumHSEDay"]; if (bkmark != null) { bkmark.Text = model.SumHSEDay.ToString(); } bkmark = doc.Range.Bookmarks["MonthHSEWorkDay"]; if (bkmark != null) { bkmark.Text = model.MonthHSEWorkDay.ToString(); } bkmark = doc.Range.Bookmarks["YearHSEWorkDay"]; if (bkmark != null) { bkmark.Text = model.YearHSEWorkDay.ToString(); } bkmark = doc.Range.Bookmarks["SumHSEWorkDay"]; if (bkmark != null) { bkmark.Text = model.SumHSEWorkDay.ToString(); } bkmark = doc.Range.Bookmarks["HseManhours"]; if (bkmark != null) { bkmark.Text = model.HseManhours.ToString(); } bkmark = doc.Range.Bookmarks["SubcontractManHours"]; if (bkmark != null) { bkmark.Text = model.SubcontractManHours.ToString(); } bkmark = doc.Range.Bookmarks["TotalHseManhoursYear"]; if (bkmark != null) { bkmark.Text = model.TotalHseManhoursYear.ToString(); } bkmark = doc.Range.Bookmarks["TotalHseManhours"]; if (bkmark != null) { bkmark.Text = model.TotalHseManhours.ToString(); } #endregion #region 4.1培训数据统计 whileIndex += 1; var trainSorts = BLL.TrainSortCService.GetTrainSortsByMonthReportId(Id); if (trainSorts.Count>0) { foreach (var item in trainSorts) { if (item.TrainType == "员工入场安全教育") { bkmark = doc.Range.Bookmarks["classhours1"]; if (bkmark != null) { bkmark.Text = item.TeachHour.ToString(); } bkmark = doc.Range.Bookmarks["traincounts1"]; if (bkmark != null) { bkmark.Text = item.PersonNum.ToString(); } bkmark = doc.Range.Bookmarks["traincounts4"]; if (bkmark != null) { bkmark.Text = item.TotalPersonNum.ToString(); } } else if (item.TrainType == "其他安全培训") { bkmark = doc.Range.Bookmarks["classhours2"]; if (bkmark != null) { bkmark.Text = item.TeachHour.ToString(); } bkmark = doc.Range.Bookmarks["traincounts2"]; if (bkmark != null) { bkmark.Text = item.PersonNum.ToString(); } bkmark = doc.Range.Bookmarks["traincounts5"]; if (bkmark != null) { bkmark.Text = item.TotalPersonNum.ToString(); } } else { bkmark = doc.Range.Bookmarks["classhours3"]; if (bkmark != null) { bkmark.Text = item.TeachHour.ToString(); } bkmark = doc.Range.Bookmarks["traincounts3"]; if (bkmark != null) { bkmark.Text = item.PersonNum.ToString(); } bkmark = doc.Range.Bookmarks["traincounts6"]; if (bkmark != null) { bkmark.Text = item.TotalPersonNum.ToString(); } } } bkmark = doc.Range.Bookmarks["traincounts7"]; if (bkmark != null) { bkmark.Text = trainSorts.Sum(x => x.TotalPersonNum).ToString(); } } #endregion #region 4.2 现场HSE会议及检查统计 var checkSorts = BLL.CheckSortCService.GetCheckSortsByMonthReportId(Id); if (checkSorts.Count > 0) { isYm = true; whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 4) != "检查类型") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } numberIndex = 1; foreach (var item in checkSorts) { Row row = new Row(doc); row.Cells.Add(CreateCell(item.CheckType, doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.CheckNumber.ToString(), doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.YearCheckNum.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.TotalCheckNum.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } else { whileIndex += 1; } #endregion #region 4.3 本月隐患整改情况 //人力投入情况 var HiddenDangersorts = (from x in db.Manager_HiddenDanger join y in db.Project_ProjectUnit on x.UnitId equals y.UnitId where x.MonthReportId == Id && y.ProjectId == this.ProjectId orderby y.UnitType select x).ToList(); if (HiddenDangersorts.Count > 0) { isYm = true; whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } numberIndex = 1; foreach (var item in HiddenDangersorts) { Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(ConvertUnitName(item.UnitId), doc, table.FirstRow.Cells[1].CellFormat.Width, "", "", "unit")); row.Cells.Add(CreateCell(item.CommonlyNum.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.MajorNum.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.ReRate.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //合计 rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("本月隐患总数", doc, table.FirstRow.Cells[0].CellFormat.Width + table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(model.MonthHdangerCount.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell("年度隐患总数", doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell(model.YearHdangerCount.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } else { whileIndex += 1; } #endregion #region 4.4项目作业许可管理数据 var mpModel = db.Manager_ProjectAssignment.FirstOrDefault(x => x.MonthReportId == Id); whileIndex += 1; if (mpModel!=null) { bkmark = doc.Range.Bookmarks["nbFireWorkCount"]; if (bkmark != null) { bkmark.Text = mpModel.FireWorkCount.ToString(); } bkmark = doc.Range.Bookmarks["nbBreakGroundCount"]; if (bkmark != null) { bkmark.Text = mpModel.BreakGroundCount.ToString(); } bkmark = doc.Range.Bookmarks["nbLimitedSpaceCount"]; if (bkmark != null) { bkmark.Text = mpModel.LimitedSpaceCount.ToString(); } bkmark = doc.Range.Bookmarks["nbElectricityCount"]; if (bkmark != null) { bkmark.Text = mpModel.ElectricityCount.ToString(); } bkmark = doc.Range.Bookmarks["nbHeightWorkCount"]; if (bkmark != null) { bkmark.Text = mpModel.HeightWorkCount.ToString(); } bkmark = doc.Range.Bookmarks["nbRadialWork"]; if (bkmark != null) { bkmark.Text = mpModel.RadialWork.ToString(); } bkmark = doc.Range.Bookmarks["nbLiftingWorkCount"]; if (bkmark != null) { bkmark.Text = mpModel.LiftingWorkCount.ToString(); } bkmark = doc.Range.Bookmarks["nbNightWork"]; if (bkmark != null) { bkmark.Text = mpModel.NightWork.ToString(); } bkmark = doc.Range.Bookmarks["nbMonthCount"]; if (bkmark != null) { bkmark.Text = mpModel.MonthCount.ToString(); } bkmark = doc.Range.Bookmarks["nbYearCount"]; if (bkmark != null) { bkmark.Text = mpModel.YearCount.ToString(); } bkmark = doc.Range.Bookmarks["nbProCount"]; if (bkmark != null) { bkmark.Text = mpModel.ProCount.ToString(); } } #endregion #region 4.5项目本月危大工程管理数据 bkmark = doc.Range.Bookmarks["MonthExpertNoCount"]; if (bkmark != null) { bkmark.Text =model.MonthExpertNoCount.ToString(); } bkmark = doc.Range.Bookmarks["MonthExpertCount"]; if (bkmark != null) { bkmark.Text = model.MonthExpertCount.ToString(); } whileIndex += 1; #endregion #region 4.6.1 应急预案发布情况 var emergencyPlanList = db.Manager_EmergencyPlan.Where(x => x.MonthReportId == Id).OrderBy(x => x.SortIndex).ToList(); if (emergencyPlanList.Count > 0) { isYm = true; whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } numberIndex = 1; foreach (var item in emergencyPlanList) { Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.CaType, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.MonthCount.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.YearCount.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProCount.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } else { whileIndex += 1; } #endregion #region 4.6.2 应急演练工作情况说明 var drillRecordList = db.Manager_DrillRecordList.Where(x => x.MonthReportId == Id).OrderBy(x => x.Ddate).ToList(); isYm = true; whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } if (drillRecordList.Count > 0) { numberIndex = 1; foreach (var item in drillRecordList) { Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.Dname, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(Convert.ToDateTime(item.Ddate).ToString("yyyy-MM-dd"), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.DrillRecordTypeName.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.PersonNum.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.DrillCost.ToString(), doc, table.FirstRow.Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } else { numberIndex = 1; Row row = new Row(doc); row.Cells.Add(CreateCell("暂无数据", doc, table.FirstRow.Cells[0].CellFormat.Width + table.FirstRow.Cells[1].CellFormat.Width+ table.FirstRow.Cells[2].CellFormat.Width + table.FirstRow.Cells[3].CellFormat.Width + table.FirstRow.Cells[4].CellFormat.Width + table.FirstRow.Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, row); table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 4.6.3其他应急管理工作描述 bkmark = doc.Range.Bookmarks["EmergencyManagementWorkDef"]; if (bkmark != null) { bkmark.Text = model.EmergencyManagementWorkDef.ToString(); } #endregion #region 4.7 HSE奖励与处罚 whileIndex += 1; var rewardAndPunishSortCs = db.Manager_RewardAndPunishSortC.FirstOrDefault(x=>x.MonthReportId==Id); if (rewardAndPunishSortCs!=null) { bkmark = doc.Range.Bookmarks["RewardNum"]; if (bkmark != null) { bkmark.Text = rewardAndPunishSortCs.RewardNum.ToString(); } bkmark = doc.Range.Bookmarks["RewardMoney"]; if (bkmark != null) { bkmark.Text = rewardAndPunishSortCs.RewardMoney.ToString(); } bkmark = doc.Range.Bookmarks["ProjectRewardMoney"]; if (bkmark != null) { bkmark.Text = rewardAndPunishSortCs.ProjectRewardMoney.ToString(); } bkmark = doc.Range.Bookmarks["PunishNum"]; if (bkmark != null) { bkmark.Text = rewardAndPunishSortCs.PunishNum.ToString(); } bkmark = doc.Range.Bookmarks["PunishMoney"]; if (bkmark != null) { bkmark.Text = rewardAndPunishSortCs.PunishMoney.ToString(); } bkmark = doc.Range.Bookmarks["ProjectPunishMoney"]; if (bkmark != null) { bkmark.Text = rewardAndPunishSortCs.ProjectPunishMoney.ToString(); } } #endregion #region 4.8HSE现场其他管理情况 var otherManagements = BLL.OtherManagementCService.GetOtherManagementByMonthReportId(Id); isYm = true; whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } if (otherManagements.Count > 0) { numberIndex = 1; foreach (var item in otherManagements) { Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.ManagementDes, doc, table.FirstRow.Cells[1].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } else { numberIndex = 1; Row row = new Row(doc); row.Cells.Add(CreateCell("暂无数据", doc, table.FirstRow.Cells[0].CellFormat.Width + table.FirstRow.Cells[1].CellFormat.Width)); table.Rows.Insert(numberIndex, row); table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 5.1 本月项目HSE费用投入统计 var fiveExpenses = BLL.FiveExpenseCService.GetFiveExpenseByMonthReportId(Id); if (fiveExpenses.Count > 0) { isYm = true; whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } numberIndex = 2; foreach (var item in fiveExpenses) { Row row = new Row(doc); row.Cells.Add(CreateCell((numberIndex - 1).ToString(), doc, table.Rows[1].Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.InvestmentProject, doc, table.Rows[1].Cells[1].CellFormat.Width, "", "", "unit")); row.Cells.Add(CreateCell(item.PlanCostMonth.ToString(), doc, table.Rows[1].Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.PlanCostYear.ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.ActualCostMonth.ToString(), doc, table.Rows[1].Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.ActualCostYear.ToString(), doc, table.Rows[1].Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //求和 //创建合计 rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("合计", doc, (table.Rows[1].Cells[0].CellFormat.Width + table.Rows[1].Cells[1].CellFormat.Width))); rowhj.Cells.Add(CreateCell((from x in fiveExpenses select x.PlanCostMonth ?? 0).Sum().ToString(), doc, table.Rows[1].Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in fiveExpenses select x.PlanCostYear ?? 0).Sum().ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in fiveExpenses select x.ActualCostMonth ?? 0).Sum().ToString(), doc, table.Rows[1].Cells[4].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in fiveExpenses select x.ActualCostYear ?? 0).Sum().ToString(), doc, table.Rows[1].Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } else { whileIndex += 1; } #endregion #region 6.1(1) HSE责任事故/事件管理绩效数据统计 var attemptedModel = db.Manager_Attempted.FirstOrDefault(x => x.MonthReportId == Id); if (attemptedModel != null) { bkmark = doc.Range.Bookmarks["WhMonthNum"]; if (bkmark != null) { bkmark.Text = attemptedModel.WhMonthNum.ToString(); } bkmark = doc.Range.Bookmarks["WhYearNum"]; if (bkmark != null) { bkmark.Text = attemptedModel.WhYearNum.ToString(); } bkmark = doc.Range.Bookmarks["FbsMonthNum"]; if (bkmark != null) { bkmark.Text = attemptedModel.FbsMonthNum.ToString(); } bkmark = doc.Range.Bookmarks["FbsYearNum"]; if (bkmark != null) { bkmark.Text = attemptedModel.FbsYearNum.ToString(); } bkmark = doc.Range.Bookmarks["ProNum"]; if (bkmark != null) { bkmark.Text = attemptedModel.ProNum.ToString(); } whileIndex += 1; } #endregion #region 6.1(2)本月伤害事故统计 var injuryAccidents = BLL.InjuryAccidentCService.GetInjuryAccidentCByMonthReportId(Id); if (injuryAccidents.Count > 0) { isYm = true; whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 4) != " 事故") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } numberIndex = 4; foreach (var item in injuryAccidents) { Row row = new Row(doc); row.Cells.Add(CreateCell(item.UnitName, doc, table.Rows[3].Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.FirstAidDressing.ToString(), doc, table.Rows[3].Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.MedicalTreatment.ToString(), doc, table.Rows[3].Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.WorkLimitation.ToString(), doc, table.Rows[3].Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.LossCount.ToString(), doc, table.Rows[3].Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.LossPerson.ToString(), doc, table.Rows[3].Cells[5].CellFormat.Width)); row.Cells.Add(CreateCell(item.LossWorkTime.ToString(), doc, table.Rows[3].Cells[6].CellFormat.Width)); row.Cells.Add(CreateCell(item.LossEconomy.ToString(), doc, table.Rows[3].Cells[7].CellFormat.Width)); row.Cells.Add(CreateCell(item.DeathCount.ToString(), doc, table.Rows[3].Cells[8].CellFormat.Width)); row.Cells.Add(CreateCell(item.DeathPerson.ToString(), doc, table.Rows[3].Cells[9].CellFormat.Width)); row.Cells.Add(CreateCell(item.DeathWorkTime.ToString(), doc, table.Rows[3].Cells[10].CellFormat.Width)); row.Cells.Add(CreateCell(item.DeathEconomy.ToString(), doc, table.Rows[3].Cells[11].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //求和 //创建合计 rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("项目合计", doc, (table.Rows[4].Cells[0].CellFormat.Width))); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.FirstAidDressing ?? 0).Sum().ToString(), doc, table.Rows[4].Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.MedicalTreatment ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.WorkLimitation ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.LossCount ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[4].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.LossPerson ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[5].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.LossWorkTime ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[6].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.LossEconomy ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[7].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.DeathCount ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[8].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.DeathPerson ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[9].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.DeathWorkTime ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[10].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in injuryAccidents select x.DeathEconomy ?? 0).Sum().ToString(), doc, table.Rows[3].Cells[11].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 6.2 HSE责任事故/事件描述 bkmark = doc.Range.Bookmarks["Def"]; if (bkmark != null) { bkmark.Text = model.AccidentDef.ToString(); } #endregion #region 6.3 HSE目标实现情况 bkmark = doc.Range.Bookmarks["Goalach1"]; if (bkmark != null) { bkmark.Text = model.Goalach1.ToString(); } bkmark = doc.Range.Bookmarks["Goalach2"]; if (bkmark != null) { bkmark.Text = model.Goalach2.ToString(); } bkmark = doc.Range.Bookmarks["Goalach3"]; if (bkmark != null) { bkmark.Text = model.Goalach3.ToString(); } whileIndex += 1; #endregion #region 7.1 HSE工作计划 var otherWorkPlanCs = BLL.OtherWorkPlanCService.GetOtherWorkPlanByMonthReportId(Id); isYm = true; whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } if (otherWorkPlanCs.Count > 0) { numberIndex = 1; foreach (var item in otherWorkPlanCs) { Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.WorkContent, doc, table.FirstRow.Cells[1].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } else { numberIndex = 1; Row row = new Row(doc); row.Cells.Add(CreateCell("暂无数据", doc, table.FirstRow.Cells[0].CellFormat.Width + table.FirstRow.Cells[1].CellFormat.Width)); table.Rows.Insert(numberIndex, row); table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 8 HSE合规义务识别与评价 var complianceObligationsCs = (from x in Funs.DB.Manager_Month_ComplianceObligationsC where x.MonthReportId == Id select x).ToList(); isYm = true; whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); //跳过页眉的表头 while (isYm) { if (table.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm = false; } } if (complianceObligationsCs.Count > 0) { numberIndex = 1; foreach (var item in complianceObligationsCs) { Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.InformationContent, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.ResponseMeasures, doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.ImplementationStatus, doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.EvaluationConclusion, doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex++; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } else { numberIndex = 1; Row row = new Row(doc); row.Cells.Add(CreateCell("暂无数据", doc, table.FirstRow.Cells[0].CellFormat.Width + table.FirstRow.Cells[1].CellFormat.Width + table.FirstRow.Cells[2].CellFormat.Width + table.FirstRow.Cells[3].CellFormat.Width + table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 9 需协调解决的主要问题 bkmark = doc.Range.Bookmarks["Question"]; if (bkmark != null) { bkmark.Text = model.Question.ToString(); } #endregion #region 10 项目现场HSE影像照片 var txtReportList = Funs.DB.Report_TextBoxContent.Where(x => x.ReportId == Id).ToList(); string imageUrl = "res/images/R-C.png"; var imageUrl1 = txtReportList.FirstOrDefault(x => x.ContentType == "10-1").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl1) && imageUrl1 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl1; builder.MoveToBookmark("ImageUrl1"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl1, out JpgSize, out Wpx, out Hpx); if (File.Exists(url)) { builder.InsertImage(url, 200, 150); } } } var imageUrl2 = txtReportList.FirstOrDefault(x => x.ContentType == "10-2").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl2) && imageUrl2 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl2; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl2"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl2, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl3 = txtReportList.FirstOrDefault(x => x.ContentType == "10-3").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl3) && imageUrl3 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl3; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl3"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl3, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl4 = txtReportList.FirstOrDefault(x => x.ContentType == "10-4").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl4) && imageUrl4 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl4; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl4"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl4, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl5 = txtReportList.FirstOrDefault(x => x.ContentType == "10-5").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl5) && imageUrl5 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl5; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl5"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl5, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl6 = txtReportList.FirstOrDefault(x => x.ContentType == "10-6").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl6) && imageUrl6 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl6; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl6"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl6, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl7 = txtReportList.FirstOrDefault(x => x.ContentType == "10-7").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl7) && imageUrl7 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl7; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl7"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl7, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl8 = txtReportList.FirstOrDefault(x => x.ContentType == "10-8").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl8) && imageUrl8 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl8; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl8"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl8, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl9 = txtReportList.FirstOrDefault(x => x.ContentType == "10-9").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl9) && imageUrl9 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl9; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl9"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl9, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl10 = txtReportList.FirstOrDefault(x => x.ContentType == "10-10").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl10) && imageUrl10 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl10; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl10"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl10, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl11 = txtReportList.FirstOrDefault(x => x.ContentType == "10-11").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl11) && imageUrl11 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl11; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl11"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl11, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } var imageUrl12 = txtReportList.FirstOrDefault(x => x.ContentType == "10-12").ImageUrl; if (!string.IsNullOrWhiteSpace(imageUrl12) && imageUrl12 != imageUrl) { string rootPathUrl = rootPath.Replace("\\", "/"); string url = rootPathUrl + imageUrl12; //DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("ImageUrl12"); if (!string.IsNullOrEmpty(url)) { System.Drawing.Size JpgSize; float Wpx; float Hpx; UploadAttachmentService.getJpgSize(rootPathUrl + imageUrl12, out JpgSize, out Wpx, out Hpx); //double w = 1; //w = JpgSize.Width / 50.0; if (File.Exists(url)) { //builder.InsertImage(url, JpgSize.Width / w, JpgSize.Height / w); builder.InsertImage(url, 200, 150); } } } #region 图片文字备注 bkmark = doc.Range.Bookmarks["ImageContent1"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-1").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent2"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-2").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent3"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-3").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent4"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-4").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent5"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-5").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent6"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-6").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent7"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-7").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent8"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-8").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent9"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-9").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent10"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-10").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent11"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-11").ContentText; } bkmark = doc.Range.Bookmarks["ImageContent12"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "10-12").ContentText; } #endregion #endregion #region 设置页眉上的数据 whileIndex = 1; table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 1, true); if (unitsYz != null) { //业主名称 table.Rows[0].Cells[2].FirstParagraph.Runs[0].Text = unitsYz.UnitName; } //项目号 table.Rows[0].Cells[4].FirstParagraph.Runs[0].Text = pModel.ProjectCode; //项目名称 table.Rows[1].Cells[2].FirstParagraph.Runs[0].Text = pModel.ProjectName; table.Rows[1].Cells[3].FirstParagraph.Runs[0].Text = pModel.ProjectCode + "-RM-HSE-" + model.MonthReportCode; //总页数 table.Rows[2].Cells[7].FirstParagraph.Runs[0].Text = doc.PageCount.ToString(); bkmark = doc.Range.Bookmarks["CountPage"]; if (bkmark != null) { bkmark.Text = doc.PageCount.ToString(); } //页眉是第二个表 //tableIndex—要移动的表的索引。 //rowIndex - 表中行的索引。 //columnIndex—表中列的索引。 //字符在单元格中的索引。目前只能指定0移动到单元格的开头,或指定 - 1移动到单元格的结尾。 //builder.MoveToCell(1,0,2,0); //builder.Write(unitsYz.UnitName); #endregion doc.Save(newUrl); 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); } catch (Exception ex) { Alert.ShowInTop(ex.Message, MessageBoxIcon.Warning); throw; } } #endregion } }