using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Aspose.Words; using Aspose.Words.Tables; using BLL; namespace FineUIPro.Web.CQMS.ManageReportNew { public partial class MonthReport : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); GetButtonPower(); } } public void BindGrid() { string strSql = @"select Id, Sortid, StartDate, EndDate, ProjectId from Report_WeekAndMonthReport_New C where C.ProjectId = @ProjectId"; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 格式化字符串 /// /// /// protected static string ConvertDate(object reportId) { string date = string.Empty; if (reportId != null) { var r = BLL.WeekAndMonthReportNewService.Detail(reportId.ToString()); if (r != null) { date = string.Format("{0:yyyy-MM-dd}", r.StartDate) + " 至 " + string.Format("{0:yyyy-MM-dd}", r.EndDate); } } return date; } /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportEdit.aspx?reportId=" + Grid1.SelectedRowID, "添加 - "))); } protected void btnNew_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportEdit.aspx", "添加 - "))); } protected void btnMenuModify_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportEdit.aspx?reportId=" + Grid1.SelectedRowID, "添加 - "))); } protected void btnMenuView_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportEdit.aspx?view=view&reportId=" + Grid1.SelectedRowID, "查看 - "))); } 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(); //本月质量目标管理情况 CqmsTargetService.Delete(rowID); TextBoxContentService.Delete(rowID); Report_CQMS_MonthReportItemService.DeleteReportItemByReportId(rowID); WeekAndMonthReportNewService.Delete(rowID); } BindGrid(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == BLL.Const._Null) { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CQWeekReportNewMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuModify.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDel.Hidden = false; } } } #endregion #region 导出 /** * 创建列值 * @param value 要插入的值 * @param doc Document对象 * @return */ public static Cell CreateCell(String value, Document doc, double cellWidth) { Cell cell = new Cell(doc); Paragraph p = new Paragraph(doc); p.AppendChild(new Run(doc, value)); cell.CellFormat.Width = cellWidth; cell.AppendChild(p); return cell; } protected void btnPrinter_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.MonthReportNewTemplateUrl; uploadfilepath = rootPath + initTemplatePath; newUrl = uploadfilepath.Replace(".doc", "(" + Funs.GetNewFileName() + ")" + ".doc"); if (File.Exists(newUrl)) { File.Delete(newUrl); } File.Copy(uploadfilepath, newUrl); //更新书签内容 Document doc = new Aspose.Words.Document(newUrl); DocumentBuilder builder = new DocumentBuilder(doc); //根据id获取质量月报主表数据 var weekModel= db.Report_WeekAndMonthReport_New.FirstOrDefault(x => x.Id == Id); var startDate = Convert.ToDateTime(weekModel.StartDate); var endDate = Convert.ToDateTime(weekModel.EndDate); //获取project var pModel = db.Base_Project.FirstOrDefault(x => x.ProjectId == weekModel.ProjectId); #region 头部静态列 Bookmark bkmark = doc.Range.Bookmarks["username"]; if (bkmark != null) { 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+"("+ pModel.ProjectCode + ")"; } bkmark = doc.Range.Bookmarks["quamanagername"]; if (bkmark != null) { var zlName = ""; //根据项目获取质量经理 var puserList = db.Project_ProjectUser.Where(x => x.ProjectId == weekModel.ProjectId && x.RoleId.Contains(BLL.Const.QAManager)).ToList(); foreach (var item in puserList) { zlName+= db.Sys_User.FirstOrDefault(x => x.UserId == item.UserId).UserName+","; } bkmark.Text = zlName; } bkmark = doc.Range.Bookmarks["reportAlldate"]; //20XX年XX月XX日至20XX年XX月XX日 if (bkmark != null) { var sdate = Convert.ToDateTime(weekModel.StartDate); var edate = Convert.ToDateTime(weekModel.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 = weekModel.SortId; } bkmark = doc.Range.Bookmarks["fromcode"]; //fromcode,项目号-RM-PQM-顺序号 if (bkmark!=null) { bkmark.Text = pModel.ProjectCode + "-RM-PQM-" + weekModel.SortId; } #endregion #region 本月质量目标管理情况 //获取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 cqrmTargetList = db.Report_CqmsTarget.Where(x => x.ReportId == Id).OrderBy(x => x.SortId); int numberIndex = 1; foreach (var item in cqrmTargetList) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProStage, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProDescribe, doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.TargetValue, doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.MonthPer, doc, table.FirstRow.Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); #endregion #region 本月主要工作内容 var txtReportList = Funs.DB.Report_TextBoxContent.Where(x => x.ReportId == Id).ToList(); bkmark = doc.Range.Bookmarks["Content1"]; if (bkmark != null) { bkmark.Text= txtReportList.FirstOrDefault(x => x.ContentType == "0").ContentText; } bkmark = doc.Range.Bookmarks["Content2"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "1").ContentText; } bkmark = doc.Range.Bookmarks["Content3"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "2").ContentText; } #endregion var ContuructionAllList = db.Report_Construction_Plan.Where(x => x.ReportId == Id).OrderBy(x=>x.UnitOrMajor).ToList(); #region 3.施工方案及检验试验计划审批情况 #region 一般施工方案审批情况 var ybsgfaList = ContuructionAllList.Where(x => x.ReType == "0").ToList(); if (ybsgfaList.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; int? num1 = 0, num2 = 0; foreach (var item in ybsgfaList) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.UnitOrMajor, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); num1 += item.Quantity1; num2 += item.Quantity2; numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 危大工程方案审批情况 var wdsgfaList = ContuructionAllList.Where(x => x.ReType == "1").ToList(); if (wdsgfaList.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; int? num1 = 0, num2 = 0, num3=0; foreach (var item in wdsgfaList) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.UnitOrMajor, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity3.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, row); num1 += item.Quantity1; num2 += item.Quantity2; num3+= item.Quantity3; numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 //创建行 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num3.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 质量控制点或检验试验计划(ITP)情况 var itpList = ContuructionAllList.Where(x => x.ReType == "2").ToList(); if (itpList.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; int? num1 = 0, num2 = 0; foreach (var item in itpList) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.UnitOrMajor, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); num1 += item.Quantity1; num2 += item.Quantity2; numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 //创建行 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #endregion #region 设计交底管理情况 var sjjdList = ContuructionAllList.Where(x => x.ReType == "3").ToList(); if (sjjdList.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; int? num1 = 0, num2 = 0; foreach (var item in sjjdList) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.UnitOrMajor, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); num1 += item.Quantity1; num2 += item.Quantity2; numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 //创建行 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 图纸会审管理情况 var tzhsList = ContuructionAllList.Where(x => x.ReType == "4").ToList(); if (tzhsList.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; int? num1 = 0, num2 = 0; foreach (var item in tzhsList) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.UnitOrMajor, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); num1 += item.Quantity1; num2 += item.Quantity2; numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 //创建行 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 6.设计变更管理情况 int Quantity1Sum = 0, Quantity2Sum = 0, Quantity3Sum = 0, Quantity4Sum = 0, Quantity5Sum = 0, Quantity6Sum = 0; DateTime projectStartDate = Convert.ToDateTime("2015-01-01"); List StatisticsList = new List(); Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId); if (project != null) { if (project.StartDate != null) { projectStartDate = Convert.ToDateTime(project.StartDate); } } int i = 1; var cNProfessionals = from x in Funs.DB.Base_CNProfessional orderby x.SortIndex select x; foreach (var item in cNProfessionals) { //专业下所有集合 List totalManagementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, item.CNProfessionalId, projectStartDate, DateTime.Now); //专业下当期集合 List managementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, item.CNProfessionalId, startDate, endDate); Model.CheckStatisc checkStatisc = new Model.CheckStatisc(); checkStatisc.Num = i; checkStatisc.WorkName = item.ProfessionalName; checkStatisc.CheckNum = managementList.Count(); checkStatisc.TotalCheckNum = totalManagementList.Count(); checkStatisc.OKNum = managementList.Count(x => x.ApprovalDate != null); checkStatisc.TotalOKNum = totalManagementList.Count(x => x.ApprovalDate != null); checkStatisc.OneOKRate = managementList.Count(x => x.Status == "3").ToString(); //当期完成数 checkStatisc.TotalOneOKRate = totalManagementList.Count(x => x.Status == "3").ToString(); //累计完成数 StatisticsList.Add(checkStatisc); Quantity1Sum += checkStatisc.CheckNum; Quantity2Sum += checkStatisc.TotalCheckNum; Quantity3Sum += checkStatisc.OKNum; Quantity4Sum += checkStatisc.TotalOKNum; Quantity5Sum += Convert.ToInt32(checkStatisc.OneOKRate); Quantity6Sum += Convert.ToInt32(checkStatisc.TotalOneOKRate); } if (StatisticsList.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; //需要插入的table foreach (var item in StatisticsList) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell((numberIndex-1).ToString(), doc, table.Rows[0].Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.WorkName, doc, table.Rows[0].Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.CheckNum.ToString(), doc, table.Rows[1].Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.TotalCheckNum.ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.OKNum.ToString(), doc, table.Rows[1].Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.TotalOKNum.ToString(), doc, table.Rows[1].Cells[5].CellFormat.Width)); row.Cells.Add(CreateCell(item.OneOKRate.ToString(), doc, table.Rows[1].Cells[6].CellFormat.Width)); row.Cells.Add(CreateCell(item.TotalOneOKRate.ToString(), doc, table.Rows[1].Cells[7].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 //创建行 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.Rows[0].Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.Rows[0].Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity1Sum.ToString(), doc, table.Rows[1].Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity2Sum.ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity3Sum.ToString(), doc, table.Rows[1].Cells[4].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity4Sum.ToString(), doc, table.Rows[1].Cells[5].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity5Sum.ToString(), doc, table.Rows[1].Cells[6].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity6Sum.ToString(), doc, table.Rows[1].Cells[7].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 7.1合格焊工管理情况 Quantity1Sum = 0; Quantity2Sum = 0; Quantity3Sum = 0; Quantity4Sum = 0; Quantity5Sum = 0; Quantity6Sum = 0; int Quantity7Sum = 0, Quantity8Sum = 0; List PassWelderList = new List(); if (project != null) { if (project.StartDate != null) { projectStartDate = Convert.ToDateTime(project.StartDate); } } i = 1; var units = from x in Funs.DB.Project_ProjectUnit join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitType == BLL.Const.ProjectUnitType_2 orderby y.UnitCode select new { x.UnitId, y.UnitName }; foreach (var item in units) { var query = from c in db.Comprehensive_InspectionPerson join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin from u in unitJoin.DefaultIfEmpty() join cn in db.Base_CNProfessional on c.CNProfessionalId equals cn.CNProfessionalId into cnJoin from cn in cnJoin.DefaultIfEmpty() join p in db.Base_Post on c.PostId equals p.PostId into postJoin from p in postJoin.DefaultIfEmpty() where c.ProjectId == this.CurrUser.LoginProjectId && c.UnitId == item.UnitId select new { c.InspectionPersonId, c.ProjectId, u.UnitId, u.UnitName, c.PersonName, c.ApprovalTime, cn.ProfessionalName, p.PostName }; //单位下所有集合 // List totalWelderList = BLL.PersonManageService.GetWelderListByUnitId(this.CurrUser.LoginProjectId, item.UnitId); //List welderList = BLL.PersonManageService.GetWelderListByUnitIdAndDate(this.CurrUser.LoginProjectId, item.UnitId, startDate, endDate); var totalWelderList = query.ToList(); var welderList = query .Where(x => (x.ApprovalTime >= Convert.ToDateTime(startDate) && x.ApprovalTime <= Convert.ToDateTime(endDate))); Model.PassWelderStatisc passWelderStatisc = new Model.PassWelderStatisc(); passWelderStatisc.Num = i; passWelderStatisc.UnitName = item.UnitName; passWelderStatisc.PipeMountGuard = welderList.Count(x => x.ProfessionalName == "管道" && x.PostName == "焊工"); passWelderStatisc.PipeTotal = totalWelderList.Count(x => x.ProfessionalName == "管道" && x.PostName == "焊工"); passWelderStatisc.SteelStructureMountGuard = welderList.Count(x => x.ProfessionalName == "土建" && x.PostName == "焊工"); passWelderStatisc.SteelStructureTotal = totalWelderList.Count(x => x.ProfessionalName == "土建" && x.PostName == "焊工"); passWelderStatisc.EquipmentMountGuard = welderList.Count(x => x.ProfessionalName == "设备" && x.PostName == "焊工"); passWelderStatisc.EquipmentTotal = totalWelderList.Count(x => x.ProfessionalName == "设备" && x.PostName == "焊工"); passWelderStatisc.OtherMountGuard = welderList.Count(x => x.ProfessionalName != "管道" && x.ProfessionalName != "土建" && x.ProfessionalName != "设备" && x.PostName == "焊工"); passWelderStatisc.OtherTotal = totalWelderList.Count(x => x.ProfessionalName != "管道" && x.ProfessionalName != "土建" && x.ProfessionalName != "设备" && x.PostName == "焊工"); PassWelderList.Add(passWelderStatisc); i++; Quantity1Sum += passWelderStatisc.PipeMountGuard; Quantity2Sum += passWelderStatisc.PipeTotal; Quantity3Sum += passWelderStatisc.SteelStructureMountGuard; Quantity4Sum += passWelderStatisc.SteelStructureTotal; Quantity5Sum += passWelderStatisc.EquipmentMountGuard; Quantity6Sum += passWelderStatisc.EquipmentTotal; Quantity7Sum += passWelderStatisc.OtherMountGuard; Quantity8Sum += passWelderStatisc.OtherTotal; } if (PassWelderList.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; //需要插入的table foreach (var item in PassWelderList) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell((numberIndex - 1).ToString(), doc, table.Rows[0].Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.UnitName, doc, table.Rows[0].Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.PipeMountGuard.ToString(), doc, table.Rows[1].Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.PipeTotal.ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.SteelStructureMountGuard.ToString(), doc, table.Rows[1].Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.SteelStructureTotal.ToString(), doc, table.Rows[1].Cells[5].CellFormat.Width)); row.Cells.Add(CreateCell(item.EquipmentMountGuard.ToString(), doc, table.Rows[1].Cells[6].CellFormat.Width)); row.Cells.Add(CreateCell(item.EquipmentTotal.ToString(), doc, table.Rows[1].Cells[7].CellFormat.Width)); row.Cells.Add(CreateCell(item.OtherMountGuard.ToString(), doc, table.Rows[1].Cells[8].CellFormat.Width)); row.Cells.Add(CreateCell(item.OtherTotal.ToString(), doc, table.Rows[1].Cells[9].CellFormat.Width)); table.Rows.Insert(numberIndex, row); numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 //创建行 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.Rows[0].Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.Rows[0].Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity1Sum.ToString(), doc, table.Rows[1].Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity2Sum.ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity3Sum.ToString(), doc, table.Rows[1].Cells[4].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity4Sum.ToString(), doc, table.Rows[1].Cells[5].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity5Sum.ToString(), doc, table.Rows[1].Cells[6].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity6Sum.ToString(), doc, table.Rows[1].Cells[7].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity7Sum.ToString(), doc, table.Rows[1].Cells[8].CellFormat.Width)); rowhj.Cells.Add(CreateCell(Quantity8Sum.ToString(), doc, table.Rows[1].Cells[9].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 7.2PQR/WPS报验情况 var pqrList = ContuructionAllList.Where(x => x.ReType == "5").ToList(); if (pqrList.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; int? num1 = 0, num2 = 0; foreach (var item in pqrList) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.UnitOrMajor, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.Quantity2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); num1 += item.Quantity1; num2 += item.Quantity2; numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 //创建行 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion var reportItem = db.Report_CQMS_MonthReportItem.Where(x => x.ReportId == Id).OrderBy(x => x.ContentName).ToList(); #region 9.计量器具报验管理情况 #endregion #region 10.现场质量共检数据 #endregion #region 11.压力管道监检情况 #endregion #region 12.管道试压包管理情况 #endregion #region 13.特种设备监检情况 #endregion #region 14.NCR管理情况 #endregion #region 15.质量巡检情况 var qualityInspections = reportItem.Where(x => x.ReType == "1").ToList(); if (qualityInspections.Count > 0) { isYm = true; //whileIndex += 1; whileIndex = 26; 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; int? num1 = 0, num2 = 0; foreach (var item in qualityInspections) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.ContentName, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.MonthsCount.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProjectCount.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.RectificationRate, doc, table.FirstRow.Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, row); num1 += item.MonthsCount; num2 += item.ProjectCount; numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[4].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 16.质量专项检查情况 var specialChecks = reportItem.Where(x => x.ReType == "2").ToList(); if (specialChecks.Count > 0) { isYm = true; //whileIndex += 1; whileIndex = 27; 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; int? num1 = 0, num2 = 0; foreach (var item in specialChecks) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.ContentName, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.MonthsCount.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProjectCount.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remarks, doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, row); num1 += item.MonthsCount; num2 += item.ProjectCount; numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[4].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 17.质量文件上报情况 var fileReports = reportItem.Where(x => x.ReType == "3").ToList(); if (fileReports.Count > 0) { isYm = true; //whileIndex += 1; whileIndex = 28; 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; int? num1 = 0, num2 = 0, num3 = 0, num4 = 0; foreach (var item in fileReports) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.ContentName, doc, table.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.MonthsCount.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProjectCount.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.MonthsBackCount.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.TotalNoBackCount.ToString(), doc, table.FirstRow.Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, row); num1 += item.MonthsCount; num2 += item.ProjectCount; num3 += item.MonthsBackCount; num4 += item.TotalNoBackCount; numberIndex += 1; } //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); //创建合计 Row rowhj = new Row(doc); rowhj.Cells.Add(CreateCell("", doc, table.FirstRow.Cells[0].CellFormat.Width)); rowhj.Cells.Add(CreateCell("合计", doc, table.FirstRow.Cells[1].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num1.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num2.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num3.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width)); rowhj.Cells.Add(CreateCell(num4.ToString(), doc, table.FirstRow.Cells[5].CellFormat.Width)); table.Rows.Insert(numberIndex, rowhj); //自动设置表格样式 table.AutoFit(AutoFitBehavior.FixedColumnWidths); } #endregion #region 18.本月质量问题处理情况 #region (1)原材料问题 whileIndex = 29; Aspose.Words.Tables.Table table18_1 = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); bool isYm18_1 = true; //跳过页眉的表头 while (isYm18_1) { if (table18_1.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table18_1 = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm18_1 = false; } } var rowMaterialProblems = db.Report_RowMaterialProblem.Where(x => x.ReportId == Id); int numberIndex18_1 = 1; foreach (var item in rowMaterialProblems) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex18_1.ToString(), doc, table18_1.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.UnitId, doc, table18_1.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProblemDesrioption, doc, table18_1.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.TreatmentMeasures, doc, table18_1.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProcessingResults, doc, table18_1.FirstRow.Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remark, doc, table18_1.FirstRow.Cells[5].CellFormat.Width)); table18_1.Rows.Insert(numberIndex18_1, row); numberIndex18_1 += 1; } //自动设置表格样式 table18_1.AutoFit(AutoFitBehavior.FixedColumnWidths); #endregion #region (2)施工过程问题 whileIndex = 30; Aspose.Words.Tables.Table table18_2 = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); bool isYm18_2 = true; //跳过页眉的表头 while (isYm18_2) { if (table18_2.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table18_2 = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm18_2 = false; } } var constructionProblems = db.Report_ConstructionProblems.Where(x => x.ReportId == Id); int numberIndex18_2 = 1; foreach (var item in constructionProblems) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex18_2.ToString(), doc, table18_2.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.UnitId, doc, table18_2.FirstRow.Cells[1].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProblemDesrioption, doc, table18_2.FirstRow.Cells[2].CellFormat.Width)); row.Cells.Add(CreateCell(item.TreatmentMeasures, doc, table18_2.FirstRow.Cells[3].CellFormat.Width)); row.Cells.Add(CreateCell(item.ProcessingResults, doc, table18_2.FirstRow.Cells[4].CellFormat.Width)); row.Cells.Add(CreateCell(item.Remark, doc, table18_2.FirstRow.Cells[5].CellFormat.Width)); table18_2.Rows.Insert(numberIndex18_2, row); numberIndex18_2 += 1; } //自动设置表格样式 table18_2.AutoFit(AutoFitBehavior.FixedColumnWidths); #endregion #endregion #region 19.下月质量控制重点 whileIndex = 31; Aspose.Words.Tables.Table table19 = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); bool isYm19 = true; //跳过页眉的表头 while (isYm19) { if (table19.Range.Text.Substring(0, 2) != "序号") { whileIndex += 1; table19 = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true); } else { isYm19 = false; } } var nextQualityControls = db.Report_NextQualityControl.Where(x => x.ReportId == Id); int numberIndex19 = 1; foreach (var item in nextQualityControls) { //创建行 Row row = new Row(doc); row.Cells.Add(CreateCell(numberIndex19.ToString(), doc, table19.FirstRow.Cells[0].CellFormat.Width)); row.Cells.Add(CreateCell(item.NextQualityControlContent, doc, table19.FirstRow.Cells[1].CellFormat.Width)); table19.Rows.Insert(numberIndex19, row); numberIndex19 += 1; } //自动设置表格样式 table19.AutoFit(AutoFitBehavior.FixedColumnWidths); #endregion #region 20.项目质量体系审核 bkmark = doc.Range.Bookmarks["Content20"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "20").ContentText; } #endregion #region 21.类似项目管理经验教训应对措施及跟踪 bkmark = doc.Range.Bookmarks["Content21"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "21").ContentText; } #endregion #region 22.附件 bkmark = doc.Range.Bookmarks["Content22"]; if (bkmark != null) { bkmark.Text = txtReportList.FirstOrDefault(x => x.ContentType == "22").ContentText; } #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 } }