diff --git a/HJGL_DS/FineUIPro.Web/File/Fastreport/JGZL/管道系统泄漏性、真空试验条件确认与试验记录.frx b/HJGL_DS/FineUIPro.Web/File/Fastreport/JGZL/管道系统泄漏性、真空试验条件确认与试验记录.frx index 880f831..9436882 100644 --- a/HJGL_DS/FineUIPro.Web/File/Fastreport/JGZL/管道系统泄漏性、真空试验条件确认与试验记录.frx +++ b/HJGL_DS/FineUIPro.Web/File/Fastreport/JGZL/管道系统泄漏性、真空试验条件确认与试验记录.frx @@ -1,5 +1,5 @@  - + using System; using System.Collections; using System.Collections.Generic; @@ -42,7 +42,7 @@ namespace FastReport } - + diff --git a/HJGL_DS/FineUIPro.Web/File/Word/JGZL/管道系统泄漏性试验记录导出模板.docx b/HJGL_DS/FineUIPro.Web/File/Word/JGZL/管道系统泄漏性试验记录导出模板.docx index 16286c1..69f35f5 100644 Binary files a/HJGL_DS/FineUIPro.Web/File/Word/JGZL/管道系统泄漏性试验记录导出模板.docx and b/HJGL_DS/FineUIPro.Web/File/Word/JGZL/管道系统泄漏性试验记录导出模板.docx differ diff --git a/HJGL_DS/FineUIPro.Web/JGZL/LeakageVacuum.aspx b/HJGL_DS/FineUIPro.Web/JGZL/LeakageVacuum.aspx index 04be9f9..e83cbd7 100644 --- a/HJGL_DS/FineUIPro.Web/JGZL/LeakageVacuum.aspx +++ b/HJGL_DS/FineUIPro.Web/JGZL/LeakageVacuum.aspx @@ -45,7 +45,7 @@ @@ -62,62 +62,74 @@ - - - <%-- - - - --%> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <%-- - - - --%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0) { @@ -143,7 +143,7 @@ namespace FineUIPro.Web.JGZL } } else - { + { foreach (var item in isoInfos) { Model.JGZL_LeakageVacuumTestRecord newItem = new JGZL_LeakageVacuumTestRecord(); @@ -156,9 +156,23 @@ namespace FineUIPro.Web.JGZL itemLists.Add(newItem); } } - this.Grid1.DataSource = itemLists; - this.Grid1.DataBind(); } + else + { + foreach (var item in isoInfos) + { + Model.JGZL_LeakageVacuumTestRecord newItem = new JGZL_LeakageVacuumTestRecord(); + newItem.LeakageVacuumTestRecordId = SQLHelper.GetNewID(typeof(Model.JGZL_LeakageVacuumTestRecord)); + newItem.PipelineId = item.ISO_ID; + newItem.PipelineCode = item.ISO_IsoNo; + newItem.DesignPressure = item.ISO_DesignPress.HasValue ? item.ISO_DesignPress.Value.ToString("0.##########") : ""; + newItem.DesignTem = item.ISO_DesignTemperature.HasValue ? item.ISO_DesignTemperature.Value.ToString("0.##########") : ""; + newItem.LeakPressure = item.LeakageTest.ToString(); + itemLists.Add(newItem); + } + } + this.Grid1.DataSource = itemLists; + this.Grid1.DataBind(); } } #endregion @@ -579,192 +593,163 @@ namespace FineUIPro.Web.JGZL protected void btnOut_Click(object sender, EventArgs e) { string rootPath = Server.MapPath("~/"); - string initTemplatePath = string.Empty; - string uploadfilepath = string.Empty; - string newUrl = string.Empty; - string filePath = string.Empty; - - //每页显示的固定数据行数 - int rowsPerPage = 8; - + string initTemplatePath = Const.JGZL_LeakageVacuumUrl; string projectId = this.tvControlItem.SelectedNodeID; - if (!string.IsNullOrEmpty(projectId)) - { - var report = BLL.LeakageVacuumService.GetLeakageVacuumByProjectId(projectId); - if (report != null) - { - initTemplatePath = Const.JGZL_LeakageVacuumUrl; - uploadfilepath = rootPath + initTemplatePath; - newUrl = uploadfilepath.Replace("管道系统泄漏性试验记录导出模板", "管道系统泄漏性试验记录"); - if (File.Exists(newUrl)) - { - File.Delete(newUrl); - } - File.Copy(uploadfilepath, newUrl); - //更新书签内容 - Document doc = new Aspose.Words.Document(newUrl); - DocumentBuilder builder = new DocumentBuilder(doc); - - Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true); - - Bookmark projectName = doc.Range.Bookmarks["ProjectName"]; - if (projectName != null) - { - projectName.Text = BLL.Base_ProjectService.GetProjectByProjectId(report.ProjectId).ProjectName; - } - Bookmark systemName = doc.Range.Bookmarks["SystemName"]; - if (systemName != null) - { - systemName.Text = report.SystemName; - } - Bookmark systemCode = doc.Range.Bookmarks["SystemCode"]; - if (systemCode != null) - { - systemCode.Text = report.SystemCode; - } - Bookmark checkItemResult1 = doc.Range.Bookmarks["CheckItemResult1"]; - if (checkItemResult1 != null) - { - checkItemResult1.Text = report.CheckItemResult1; - } - Bookmark checkItemResult2 = doc.Range.Bookmarks["CheckItemResult2"]; - if (checkItemResult2 != null) - { - checkItemResult2.Text = report.CheckItemResult2; - } - Bookmark checkItemResult3 = doc.Range.Bookmarks["CheckItemResult3"]; - if (checkItemResult3 != null) - { - checkItemResult3.Text = report.CheckItemResult3; - } - Bookmark checkItemResult4 = doc.Range.Bookmarks["CheckItemResult4"]; - if (checkItemResult4 != null) - { - checkItemResult4.Text = report.CheckItemResult4; - } - Bookmark checkItemResult5 = doc.Range.Bookmarks["CheckItemResult5"]; - if (checkItemResult5 != null) - { - checkItemResult5.Text = report.CheckItemResult5; - } - - // 设置表头行重复显示 - table.Rows[0].RowFormat.HeadingFormat = true; - table.Rows[1].RowFormat.HeadingFormat = true; - table.Rows[2].RowFormat.HeadingFormat = true; - table.Rows[3].RowFormat.HeadingFormat = true; - table.Rows[4].RowFormat.HeadingFormat = true; - table.Rows[5].RowFormat.HeadingFormat = true; - table.Rows[6].RowFormat.HeadingFormat = true; - table.Rows[7].RowFormat.HeadingFormat = true; - table.Rows[8].RowFormat.HeadingFormat = true; - table.Rows[9].RowFormat.HeadingFormat = true; - table.Rows[10].RowFormat.HeadingFormat = true; - - // ====固定表格布局===== - table.AutoFit(AutoFitBehavior.FixedColumnWidths); - table.AllowAutoFit = false; - table.Alignment = TableAlignment.Center; - - // 先记录页尾行,并从表格中移除 - //Row footerRow = table.Rows[table.Rows.Count - 1]; - //table.Rows.RemoveAt(table.Rows.Count - 1); - - var recordLists = BLL.LeakageVacuumTestRecordServic.GetLeakageVacuumTestRecordByLeakageVacuumId(report.LeakageVacuumId); - if (recordLists.Count == Grid1.GetMergedData().Count) - { - int i = 0; - foreach (var item in recordLists) - { - //创建行 - Aspose.Words.Tables.Row row = new Aspose.Words.Tables.Row(doc); - row.Cells.Add(CreateCell(item.PipelineCode, doc, 128.42, "", ""));//管道编号/单线号 - row.Cells.Add(CreateCell(item.DesignPressure, doc, 35.72, "", ""));//设计压力 - row.Cells.Add(CreateCell(item.DesignTem, doc, 41.96, "", ""));//设计温度 - row.Cells.Add(CreateCell(item.TestAmbientTemp, doc, 52.73, "", ""));//试验环境温度℃ - row.Cells.Add(CreateCell(item.TestMediumTemp, doc, 41.96, "", ""));//试验介质温度℃ - row.Cells.Add(CreateCell(item.LeakPressure, doc, 39.4, "", ""));//泄漏性试验-压力 - row.Cells.Add(CreateCell(item.LeakMedium, doc, 41.96, "", ""));//泄漏性试验-介质 - row.Cells.Add(CreateCell(item.VacuumPressure, doc, 45.07, "", ""));//真空试验-压力 - row.Cells.Add(CreateCell(item.VacuumMedium, doc, 41.39, "", ""));//真空试验-介质 - - table.Rows.Insert(i + 11, row); - } - - // 计算并插入空白行,填满整页 - // 计算总数据行数 - int totalDataRows = recordLists.Count; - // 计算需要补充的空白行数量 - int remainder = totalDataRows % rowsPerPage; - int needBlankRows = remainder == 0 ? 0 : rowsPerPage - remainder; - - // 插入空白行(和数据行格式保持一致,仅内容为空) - //for (int i = 0; i < needBlankRows - 1; i++) - //{ - // Aspose.Words.Tables.Row blankRow = new Aspose.Words.Tables.Row(doc); - // 空白行的单元格宽度和数据行保持一致 - //blankRow.Cells.Add(CreateCell("", doc, 22.68, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 65.49, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 37.14, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 27.78, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 28.06, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 28, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 34.87, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 43.66, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 59.82, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 34.58, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 33.74, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 27, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 45.93, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 37.14, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 30.62, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 48.76, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 25.23, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 28.92, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 48.76, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 26.08, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 56.7, "", "")); - //blankRow.Cells.Add(CreateCell("", doc, 22.11, "", "")); - // 插入到表格最后一行 - // table.Rows.Add(blankRow); - //} - //把页尾行重新加回表格最后 - //table.Rows.Add(footerRow); - - doc.Save(newUrl); - } - else - { - Alert.ShowInTop("请先保存数据!", MessageBoxIcon.Warning); - return; - } - - string fileName = Path.GetFileName(newUrl); - FileInfo info = new FileInfo(newUrl); - long fileSize = info.Length; - Response.Clear(); - Response.ContentType = "application/x-zip-compressed"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); - Response.AddHeader("Content-Length", fileSize.ToString()); - Response.TransmitFile(newUrl, 0, fileSize); - Response.Flush(); - Response.Close(); - File.Delete(newUrl); - } - else - { - Alert.ShowInTop("没有要导出的数据!", MessageBoxIcon.Warning); - return; - } - } - else + if (string.IsNullOrEmpty(projectId)) { Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning); return; } + var report = BLL.LeakageVacuumService.GetLeakageVacuumByProjectId(projectId); + if (report == null) + { + Alert.ShowInTop("请先保存数据!", MessageBoxIcon.Warning); + return; + } + else + { + var lists = BLL.LeakageVacuumTestRecordServic.GetLeakageVacuumTestRecordByLeakageVacuumId(report.LeakageVacuumId); + if (lists.Count != Grid1.GetMergedData().Count) + { + Alert.ShowInTop("请先保存数据!", MessageBoxIcon.Warning); + return; + } + } + string templateFullPath = Path.Combine(rootPath, initTemplatePath); + if (!File.Exists(templateFullPath)) + { + Alert.ShowInTop("导出模板文件不存在!", MessageBoxIcon.Warning); + return; + } + Document doc = new Aspose.Words.Document(templateFullPath); + Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true); + + #region 顶层书签赋值(工程名称、系统、检查项) + SafeSetBookmarkText(doc, "ProjectName", BLL.Base_ProjectService.GetProjectByProjectId(report.ProjectId)?.ProjectName); + SafeSetBookmarkText(doc, "SystemName", report.SystemName); + SafeSetBookmarkText(doc, "SystemCode", report.SystemCode); + SafeSetBookmarkText(doc, "CheckItemResult1", report.CheckItemResult1); + SafeSetBookmarkText(doc, "CheckItemResult2", report.CheckItemResult2); + SafeSetBookmarkText(doc, "CheckItemResult3", report.CheckItemResult3); + SafeSetBookmarkText(doc, "CheckItemResult4", report.CheckItemResult4); + SafeSetBookmarkText(doc, "CheckItemResult5", report.CheckItemResult5); + #endregion + + #region 表头跨页重复设置 + for (int r = 0; r <= 10; r++) + { + table.Rows[r].RowFormat.HeadingFormat = true; + } + table.AutoFit(AutoFitBehavior.FixedColumnWidths); + table.AllowAutoFit = false; + table.Alignment = TableAlignment.Center; + #endregion + + var recordLists = BLL.LeakageVacuumTestRecordServic.GetLeakageVacuumTestRecordByLeakageVacuumId(report.LeakageVacuumId); + Aspose.Words.Tables.Row templateDataRow = table.Rows[11]; + + if (recordLists.Count > 0) + { + foreach (var item in recordLists) + { + Aspose.Words.Tables.Row newDataRow = (Aspose.Words.Tables.Row)templateDataRow.Clone(true); + + SafeSetRowBookmarkText(newDataRow, "Bk_PipelineCode", item.PipelineCode); + SafeSetRowBookmarkText(newDataRow, "Bk_DesignPressure", item.DesignPressure); + SafeSetRowBookmarkText(newDataRow, "Bk_DesignTem", item.DesignTem); + SafeSetRowBookmarkText(newDataRow, "Bk_TestAmbientTemp", item.TestAmbientTemp); + SafeSetRowBookmarkText(newDataRow, "Bk_TestMediumTemp", item.TestMediumTemp); + SafeSetRowBookmarkText(newDataRow, "Bk_LeakPressure", item.LeakPressure); + SafeSetRowBookmarkText(newDataRow, "Bk_LeakMedium", item.LeakMedium); + SafeSetRowBookmarkText(newDataRow, "Bk_VacuumPressure", item.VacuumPressure); + SafeSetRowBookmarkText(newDataRow, "Bk_VacuumMedium", item.VacuumMedium); + + table.InsertBefore(newDataRow, templateDataRow); + } + } + + #region 补充空白行填满每页8行 + int rowsPerPage = 8; + int totalDataRows = recordLists.Count; + int remainder = totalDataRows % rowsPerPage; + int needBlankRows = remainder == 0 ? 0 : rowsPerPage - remainder; + + for (int i = 0; i < needBlankRows; i++) + { + Aspose.Words.Tables.Row blankRow = (Aspose.Words.Tables.Row)templateDataRow.Clone(true); + SafeSetRowBookmarkText(blankRow, "Bk_PipelineCode", ""); + SafeSetRowBookmarkText(blankRow, "Bk_DesignPressure", ""); + SafeSetRowBookmarkText(blankRow, "Bk_DesignTem", ""); + SafeSetRowBookmarkText(blankRow, "Bk_TestAmbientTemp", ""); + SafeSetRowBookmarkText(blankRow, "Bk_TestMediumTemp", ""); + SafeSetRowBookmarkText(blankRow, "Bk_LeakPressure", ""); + SafeSetRowBookmarkText(blankRow, "Bk_LeakMedium", ""); + SafeSetRowBookmarkText(blankRow, "Bk_VacuumPressure", ""); + SafeSetRowBookmarkText(blankRow, "Bk_VacuumMedium", ""); + + table.InsertBefore(blankRow, templateDataRow); + } + #endregion + + templateDataRow.Remove(); + + using (MemoryStream ms = new MemoryStream()) + { + doc.Save(ms, Aspose.Words.SaveFormat.Docx); + ms.Position = 0; + + Response.Clear(); + Response.ContentType = "application/x-zip-compressed"; + string downloadFileName = "管道系统泄漏性试验记录.docx"; + Response.AddHeader("Content-Disposition", $"attachment;filename={System.Web.HttpUtility.UrlEncode(downloadFileName, System.Text.Encoding.UTF8)}"); + Response.BinaryWrite(ms.ToArray()); + Response.Flush(); + Response.End(); + } } + /// + /// 设置文档全局书签文本 + /// + private static void SafeSetBookmarkText(Document doc, string bookmarkName, string text) + { + Bookmark bm = doc.Range.Bookmarks[bookmarkName]; + if (bm == null) return; + bm.Text = text ?? ""; + } + + /// + /// 在指定Row行节点范围内查找书签并赋值 + /// + private static void SafeSetRowBookmarkText(Row row, string bookmarkName, string text) + { + text = text ?? ""; + BookmarkStart bkStart = null; + NodeCollection childNodes = row.GetChildNodes(NodeType.BookmarkStart, true); + foreach (Node childNode in childNodes) + { + BookmarkStart bs = childNode as BookmarkStart; + if (bs != null && bs.Name == bookmarkName) + { + bkStart = bs; + break; + } + } + if (bkStart == null) return; + + Node cur = bkStart.NextSibling; + while (cur != null && cur.NodeType != NodeType.BookmarkEnd) + { + Node next = cur.NextSibling; + cur.Remove(); + cur = next; + } + Run run = new Run(row.Document, text); + bkStart.ParentNode.InsertAfter(run, bkStart); + } + + public static Cell CreateCell(String value, Document doc, double cellWidth, string cellMerge = "", string CenterPage = "", string cellUnitLeft = "") { Cell cell = new Cell(doc); diff --git a/HJGL_DS/FineUIPro.Web/JGZL/LeakageVacuum.aspx.designer.cs b/HJGL_DS/FineUIPro.Web/JGZL/LeakageVacuum.aspx.designer.cs index 16b8b8a..1c5565d 100644 --- a/HJGL_DS/FineUIPro.Web/JGZL/LeakageVacuum.aspx.designer.cs +++ b/HJGL_DS/FineUIPro.Web/JGZL/LeakageVacuum.aspx.designer.cs @@ -167,6 +167,24 @@ namespace FineUIPro.Web.JGZL /// protected global::FineUIPro.TextBox txtSystemCode; + /// + /// SimpleForm2 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::FineUIPro.SimpleForm SimpleForm2; + + /// + /// Form2 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::FineUIPro.Form Form2; + /// /// drpCheckResult1 控件。 ///