Files
HJGL_DS/HJGL_DS/FineUIPro.Web/JGZL/LeakageVacuum.aspx.cs
T

802 lines
34 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Aspose.Words;
using Aspose.Words.Tables;
using BLL;
using FastReport.DevComponents.DotNetBar;
using Model;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.DirectoryServices.ActiveDirectory;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.JGZL
{
public partial class LeakageVacuum : PageBase
{
#region 定义项
/// <summary>
/// 主键
/// </summary>
private string LeakageVacuumTestRecordId
{
get
{
return (string)ViewState["LeakageVacuumTestRecordId"];
}
set
{
ViewState["LeakageVacuumTestRecordId"] = value;
}
}
/// <summary>
/// 项目Id
/// </summary>
private string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
/// <summary>
/// 外键—LeakageVacuumId
/// </summary>
public string LeakageVacuumId
{
get
{
return (string)ViewState["LeakageVacuumId"];
}
set
{
ViewState["LeakageVacuumId"] = value;
}
}
/// <summary>
/// 定义集合
/// </summary>
private static List<Model.JGZL_LeakageVacuumTestRecord> itemLists = new List<JGZL_LeakageVacuumTestRecord>();
#endregion
#region 加载页面
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.drpProjectId.DataTextField = "ProjectCode";
this.drpProjectId.DataValueField = "ProjectId";
this.drpProjectId.DataSource = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
this.drpProjectId.DataBind();
Funs.FineUIPleaseSelect(this.drpProjectId);
this.drpProjectId.SelectedValue = this.CurrUser.LoginProjectId;
this.InitTreeMenu();//加载树
this.tvControlItem.SelectedNodeID = this.drpProjectId.SelectedValue;
this.ProjectId = this.tvControlItem.SelectedNodeID;
DataIsoInfo();
}
}
private void DataIsoInfo()
{
this.txtSystemCode.Text = string.Empty;
this.txtSystemName.Text = string.Empty;
this.drpCheckResult1.SelectedValue = "合格";
this.drpCheckResult2.SelectedValue = "合格";
this.drpCheckResult3.SelectedValue = "合格";
this.drpCheckResult4.SelectedValue = "合格";
this.drpCheckResult5.SelectedValue = "合格";
itemLists.Clear();
if (!string.IsNullOrEmpty(this.ProjectId))
{
var isoInfos = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByProjectId(this.ProjectId);
var record = BLL.LeakageVacuumService.GetLeakageVacuumByProjectId(this.ProjectId);
if (record != null)
{
this.LeakageVacuumId = record.LeakageVacuumId;
this.txtSystemCode.Text = record.SystemCode;
this.txtSystemName.Text = record.SystemName;
this.drpCheckResult1.SelectedValue = record.CheckItemResult1;
this.drpCheckResult2.SelectedValue = record.CheckItemResult2;
this.drpCheckResult3.SelectedValue = record.CheckItemResult3;
this.drpCheckResult4.SelectedValue = record.CheckItemResult4;
this.drpCheckResult5.SelectedValue = record.CheckItemResult5;
itemLists = BLL.LeakageVacuumTestRecordServic.GetLeakageVacuumTestRecordByLeakageVacuumId(this.LeakageVacuumId);
if (itemLists.Count > 0)
{
foreach (var item in isoInfos)
{
var iso = itemLists.Where(x => x.PipelineId != null && !string.IsNullOrEmpty(x.PipelineId) && x.PipelineId == item.ISO_ID).FirstOrDefault();
if (iso == null)
{
Model.JGZL_LeakageVacuumTestRecord newIso = new JGZL_LeakageVacuumTestRecord();
newIso.LeakageVacuumTestRecordId = SQLHelper.GetNewID(typeof(Model.JGZL_LeakageVacuumTestRecord));
newIso.PipelineId = item.ISO_ID;
newIso.PipelineCode = item.ISO_IsoNo;
newIso.DesignPressure = item.ISO_DesignPress.HasValue ? item.ISO_DesignPress.Value.ToString("0.##########") : "";
newIso.DesignTem = item.ISO_DesignTemperature.HasValue ? item.ISO_DesignTemperature.Value.ToString("0.##########") : "";
newIso.LeakPressure = item.LeakageTest.ToString();
itemLists.Add(newIso);
}
}
}
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);
}
}
}
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
#region 加载树项目
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "项目";
rootNode.ToolTip = "项目";
rootNode.NodeID = "0";
rootNode.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode);
List<Model.Base_Project> projects = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
{
projects = projects.Where(e => e.ProjectId == this.drpProjectId.SelectedValue).ToList();
}
foreach (var item in projects)
{
TreeNode rootProjectNode = new TreeNode();//定义根节点
rootProjectNode.Text = item.ProjectCode;
rootProjectNode.NodeID = item.ProjectId;
rootProjectNode.EnableClickEvent = true;
rootProjectNode.Expanded = true;
rootProjectNode.ToolTip = item.ProjectName;
rootProjectNode.CommandName = "项目名称";
rootNode.Nodes.Add(rootProjectNode);
}
}
#endregion
#region 点击TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
if (this.tvControlItem.SelectedNodeID != "0")
{
this.BindGrid();
}
}
#endregion
#region 数据绑定
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
//string projectIds = BLL.Base_ProjectService.GetStrOnProjectIds(this.CurrUser.UserId, "1");
string strSql = @"SELECT * from JGZL_LeakageVacuumTestRecord m left join JGZL_LeakageVacuum b on b.LeakageVacuumId = m.LeakageVacuumId where 1=1";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
strSql += " AND b.ProjectId = @ProjectId";
listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID));
}
//else
//{
// strSql += " AND CHARINDEX(ProjectId,@ProjectId)>0 ";
// listStr.Add(new SqlParameter("@ProjectId", projectIds));
//}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region 分页排序
#region 页索引改变事件
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
#endregion
#region 排序
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region 分页选择下拉改变事件
/// <summary>
/// 分页选择下拉改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
#endregion
#region 查询
///<summary>
///查询
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
{
this.tvControlItem.SelectedNodeID = this.drpProjectId.SelectedValue;
this.ProjectId = this.tvControlItem.SelectedNodeID;
this.InitTreeMenu();
DataIsoInfo();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region 维护
/// <summary>
/// 增加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
JArray teamGroupData = Grid1.GetMergedData();
List<JObject> list = new List<JObject>();
foreach (JObject teamGroupRow in teamGroupData)
{
JObject values = teamGroupRow.Value<JObject>("values");
list.Add(values);
}
JObject defaultObj = new JObject
{
{ "LeakageVacuumTestRecordId", Guid.NewGuid() },
{ "LeakageVacuumId", this.LeakageVacuumId },
{ "PipelineId", "" },
{ "PipelineCode", "" },
{ "DesignPressure", "" },
{ "DesignTem", "" },
{ "TestAmbientTemp", "" },
{ "TestMediumTemp", "" },
{ "LeakPressure", "" },
{ "LeakMedium", "" },
{ "VacuumPressure", "" },
{ "VacuumMedium", "" },
{
"Delete3",
String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>",
GetDeleteScriptGrid1(), IconHelper.GetResolvedIconUrl(Icon.Delete))
}
};
list.Add(defaultObj);
Grid1.DataSource = list;
Grid1.DataBind();
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PressureTestOfPipelineSystemRecordEdit.aspx?projectId={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
}
else
{
Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
return;
}
}
protected void Grid1_PreDataBound(object sender, EventArgs e)
{
// 设置LinkButtonField的点击客户端事件
LinkButtonField deleteField = Grid1.FindColumn("Delete3") as LinkButtonField;
deleteField.OnClientClick = GetDeleteScriptGrid1();
}
/// <summary>
/// 删除提示
/// </summary>
/// <returns></returns>
private string GetDeleteScriptGrid1()
{
return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question,
Grid1.GetDeleteSelectedRowsReference(), String.Empty);
}
#endregion
#region 保存
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId,
Const.JGZL_LeakageVacuumMenuId, Const.BtnSave))
{
Model.JGZL_LeakageVacuum newRecord = new JGZL_LeakageVacuum();
newRecord.SystemCode = this.txtSystemCode.Text;
newRecord.SystemName = this.txtSystemName.Text;
newRecord.CheckItemResult1 = this.drpCheckResult1.SelectedValue;
newRecord.CheckItemResult2 = this.drpCheckResult2.SelectedValue;
newRecord.CheckItemResult3 = this.drpCheckResult3.SelectedValue;
newRecord.CheckItemResult4 = this.drpCheckResult4.SelectedValue;
newRecord.CheckItemResult5 = this.drpCheckResult5.SelectedValue;
if (!string.IsNullOrEmpty(this.LeakageVacuumId))
{
newRecord.LeakageVacuumId = this.LeakageVacuumId;
BLL.LeakageVacuumService.UpdateLeakageVacuum(newRecord);
}
else
{
newRecord.ProjectId = this.tvControlItem.SelectedNodeID;
newRecord.LeakageVacuumId = SQLHelper.GetNewID(typeof(Model.JGZL_LeakageVacuum));
this.LeakageVacuumId = newRecord.LeakageVacuumId;
BLL.LeakageVacuumService.AddLeakageVacuum(newRecord);
}
saveItem();
BindGrid();
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
void saveItem()
{
itemLists.Clear();
BLL.LeakageVacuumTestRecordServic.DeleteLeakageVacuumTestRecordByLeakageVacuumId(this.LeakageVacuumId);
JArray teamGroupData = Grid1.GetMergedData();
foreach (JObject teamGroupRow in teamGroupData)
{
JObject values = teamGroupRow.Value<JObject>("values");
int rowIndex = teamGroupRow.Value<int>("index");
Model.JGZL_LeakageVacuumTestRecord newDetail = new Model.JGZL_LeakageVacuumTestRecord
{
LeakageVacuumTestRecordId = values.Value<string>("LeakageVacuumTestRecordId"),
LeakageVacuumId = this.LeakageVacuumId,
PipelineId = values.Value<string>("PipelineId"),
PipelineCode = values.Value<string>("PipelineCode"),
DesignPressure = values.Value<string>("DesignPressure"),
DesignTem = values.Value<string>("DesignTem"),
TestAmbientTemp = values.Value<string>("TestAmbientTemp"),
TestMediumTemp = values.Value<string>("TestMediumTemp"),
LeakPressure = values.Value<string>("LeakPressure"),
LeakMedium = values.Value<string>("LeakMedium"),
VacuumPressure = values.Value<string>("VacuumPressure"),
VacuumMedium = values.Value<string>("VacuumMedium"),
};
itemLists.Add(newDetail);
}
try
{
if (itemLists.Count > 0)
{
Funs.DB.JGZL_LeakageVacuumTestRecord.InsertAllOnSubmit(itemLists);
}
Funs.DB.SubmitChanges();
}
catch (Exception)
{
return;
}
}
#endregion
#region 打印
/// <summary>
/// 打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrint_Click(object sender, EventArgs e)
{
string projectId = this.tvControlItem.SelectedNodeID;
if (projectId != null)
{
string initTemplatePath = "";
string rootPath = Server.MapPath("~/");
BLL.Common.FastReportService.ResetData();
var report = BLL.LeakageVacuumService.GetLeakageVacuumByProjectId(projectId);
if (report != null)
{
DataTable dt = new DataTable();
dt.TableName = "MainData";
dt.Columns.Add("ProjectName");
dt.Columns.Add("SystemName");
dt.Columns.Add("SystemCode");
dt.Columns.Add("CheckItemResult1");
dt.Columns.Add("CheckItemResult2");
dt.Columns.Add("CheckItemResult3");
dt.Columns.Add("CheckItemResult4");
dt.Columns.Add("CheckItemResult5");
dt.Columns.Add("Conclusion");
var newRow = dt.NewRow();
newRow["ProjectName"] = BLL.Base_ProjectService.GetProjectByProjectId(report.ProjectId).ProjectName;
newRow["SystemName"] = this.txtSystemName.Text.Trim();
newRow["SystemCode"] = this.txtSystemCode.Text.Trim();
newRow["CheckItemResult1"] = report.CheckItemResult1;
newRow["CheckItemResult2"] = report.CheckItemResult2;
newRow["CheckItemResult3"] = report.CheckItemResult3;
newRow["CheckItemResult4"] = report.CheckItemResult4;
newRow["CheckItemResult5"] = report.CheckItemResult5;
newRow["Conclusion"] = report.Conclusion;
dt.Rows.Add(newRow);
BLL.Common.FastReportService.AddFastreportTable(dt);
var recordLists = BLL.LeakageVacuumTestRecordServic.GetLeakageVacuumTestRecordByLeakageVacuumId(report.LeakageVacuumId);
if (recordLists.Count == Grid1.GetMergedData().Count)
{
DataTable itemdt = new DataTable();
itemdt.TableName = "Data";
itemdt.Columns.Add("PipelineNo");
itemdt.Columns.Add("DesignPressure");
itemdt.Columns.Add("DesignTem");
itemdt.Columns.Add("TestAmbientTemp");
itemdt.Columns.Add("TestMediumTemp");
itemdt.Columns.Add("LeakPressure");
itemdt.Columns.Add("LeakMedium");
itemdt.Columns.Add("VacuumPressure");
itemdt.Columns.Add("VacuumMedium");
foreach (var item in recordLists)
{
var newRow2 = itemdt.NewRow();
newRow2["PipelineNo"] = item.PipelineCode;
newRow2["DesignPressure"] = item.DesignPressure;
newRow2["DesignTem"] = item.DesignTem;
newRow2["TestAmbientTemp"] = item.TestAmbientTemp;
newRow2["TestMediumTemp"] = item.TestMediumTemp;
newRow2["LeakPressure"] = item.LeakPressure;
newRow2["LeakMedium"] = item.LeakMedium;
newRow2["VacuumPressure"] = item.VacuumPressure;
newRow2["VacuumMedium"] = item.VacuumMedium;
itemdt.Rows.Add(newRow2);
}
BLL.Common.FastReportService.AddFastreportTable(itemdt);
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
//keyValuePairs.Add("ProjectName", BLL.Base_ProjectService.GetProjectByProjectId(projectId).ProjectName);
BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs);
initTemplatePath = "File\\Fastreport\\JGZL\\管道系统泄漏性、真空试验条件确认与试验记录.frx";
if (File.Exists(rootPath + initTemplatePath))
{
PageContext.RegisterStartupScript(WindowPrint.GetShowReference(String.Format("../common/ReportPrint/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
}
}
else
{
Alert.ShowInTop("请先保存数据!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("请先保存数据!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region 导出按钮
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string initTemplatePath = Const.JGZL_LeakageVacuumUrl;
string projectId = this.tvControlItem.SelectedNodeID;
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();
}
}
/// <summary>
/// 设置文档全局书签文本
/// </summary>
private static void SafeSetBookmarkText(Document doc, string bookmarkName, string text)
{
Bookmark bm = doc.Range.Bookmarks[bookmarkName];
if (bm == null) return;
bm.Text = text ?? "";
}
/// <summary>
/// 在指定Row行节点范围内查找书签并赋值
/// </summary>
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);
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.75;
cell.AppendChild(p);
return cell;
}
#endregion
}
}