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 + "项目安全月报(" + 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 = weekModel.CreateDate.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-PQM-顺序号 if (bkmark != null) { bkmark.Text = pModel.ProjectCode + "-RM-PQM-" + 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")); 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)); 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().ToString(), doc, table.Rows[1].Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell((from x in sorts select x.SumOutPersonNum ?? 0).Sum().ToString(), doc, 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); } #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); } #endregion #region 4.4项目作业许可管理数据 #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-PQM-" + 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 } }