using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.IO; using System.Web; using BLL; using Newtonsoft.Json.Linq; using Model; using NPOI.HSSF.EventUserModel; namespace FineUIPro.Web.WeldingProcess.TestPackageManage { public partial class TestPackageManageEdit : PageBase { #region 定义项 /// /// 试压包主键 /// public string PTP_ID { get { return (string)ViewState["PTP_ID"]; } set { ViewState["PTP_ID"] = value; } } #endregion //定义变量 /// /// 上传预设的虚拟路径 /// private string initPath = Const.ExcelUrl; /// /// 错误集合 /// public static string errorInfos = string.Empty; #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.PTP_ID = string.Empty; this.txtSearchDate.Text = string.Format("{0:yyyy-MM}", System.DateTime.Now); this.InitTreeMenu();//加载树 } } #endregion #region 加载树装置-单位-工作区 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "单位-装置-月份"; rootNode.NodeID = "0"; rootNode.Expanded = true; this.tvControlItem.Nodes.Add(rootNode); DateTime startTime = Convert.ToDateTime(this.txtSearchDate.Text.Trim() + "-01"); DateTime endTime = startTime.AddMonths(1); List units = new List(); ///单位 var pUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId); if (pUnit == null || pUnit.UnitType == BLL.Const.UnitType_1 || pUnit.UnitType == BLL.Const.UnitType_2 || pUnit.UnitType == BLL.Const.UnitType_3 || pUnit.UnitType == BLL.Const.UnitType_4) { units = (from x in Funs.DB.Base_Unit join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId where y.ProjectId == this.CurrUser.LoginProjectId && y.UnitType.Contains(BLL.Const.UnitType_5) select x).ToList(); } else { units.Add(BLL.Base_UnitService.GetUnit(this.CurrUser.UnitId)); } List testPackageLists = (from x in Funs.DB.PTP_TestPackage where x.ProjectId == this.CurrUser.LoginProjectId && x.TableDate >= startTime && x.TableDate < endTime select x).ToList(); if (units != null) { foreach (var unit in units) { TreeNode rootUnitNode = new TreeNode();//定义根节点 rootUnitNode.Text = unit.UnitName; rootUnitNode.NodeID = unit.UnitId; rootUnitNode.Expanded = true; rootUnitNode.ToolTip = "施工单位"; rootNode.Nodes.Add(rootUnitNode); var testPackageUnitList = testPackageLists.Where(x => x.UnitId == unit.UnitId).ToList(); this.BindNodes(rootUnitNode, testPackageUnitList); } } else { ShowNotify("请先增加施工单位!", MessageBoxIcon.Warning); return; } } #endregion #region 绑定树节点 /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node, List testPackageUnitList) { if (node.ToolTip == "施工单位") { var installId = (from x in testPackageUnitList where x.UnitId == node.NodeID select x.InstallationId).Distinct(); if (installId.Count() > 0) { var install = from x in Funs.DB.Project_Installation where installId.Contains(x.InstallationId) orderby x.InstallationCode select x; foreach (var q in install) { TreeNode newNode = new TreeNode(); newNode.Text = q.InstallationName; newNode.NodeID = q.InstallationId + "|" + node.NodeID; newNode.ToolTip = "装置"; newNode.Expanded = true; node.Nodes.Add(newNode); this.BindNodes(newNode, testPackageUnitList); } } } else if (node.ToolTip == "装置") { string installationId = Funs.GetStrListByStr(node.NodeID, '|')[0]; var pointListMonth = (from x in testPackageUnitList where x.InstallationId == installationId select string.Format("{0:yyyy-MM}", x.TableDate)).Distinct(); foreach (var item in pointListMonth) { TreeNode newNode = new TreeNode(); newNode.Text = item; newNode.NodeID = item + "|" + node.NodeID; newNode.ToolTip = "月份"; node.Nodes.Add(newNode); this.BindNodes(newNode, testPackageUnitList); } } //else if (node.ToolTip == "月份") //{ // string installationId = Funs.GetStrListByStr(node.ParentNode.NodeID, '|')[0]; // var days = (from x in testPackageUnitList // where x.InstallationId == installationId // orderby x.TableDate descending // select x.TableDate).Distinct(); // foreach (var item in days) // { // TreeNode newNode = new TreeNode(); // newNode.Text = string.Format("{0:yyyy-MM-dd}", item); // newNode.NodeID = item.ToString() + "|" + node.NodeID; // newNode.ToolTip = "日期"; // node.Nodes.Add(newNode); // this.BindNodes(newNode, testPackageUnitList); // } //} else if (node.ToolTip == "月份") { DateTime startTime = Convert.ToDateTime(this.txtSearchDate.Text.Trim() + "-01"); DateTime endTime = startTime.AddMonths(1); string installationId = Funs.GetStrListByStr(node.ParentNode.NodeID, '|')[0]; var dReports = from x in testPackageUnitList where x.InstallationId == installationId && x.TableDate >= startTime && x.TableDate < endTime orderby x.TestPackageNo descending select x; foreach (var item in dReports) { TreeNode newNode = new TreeNode(); if (!string.IsNullOrEmpty(item.TestPackageNo)) { newNode.Text = item.TestPackageNo; } else { newNode.Text = "未知"; } if (!item.AduditDate.HasValue || string.IsNullOrEmpty(item.Auditer)) { newNode.Text = "" + newNode.Text + ""; node.Text = "" + node.Text + ""; node.ParentNode.Text = "" + node.ParentNode.Text + ""; } newNode.NodeID = item.PTP_ID; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.PTP_ID = tvControlItem.SelectedNodeID; this.BindGrid(); } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { this.SetTextTemp(); this.PageInfoLoad(); ///页面输入保存信息 string strSql = @"SELECT ptp.ProjectId, ptp.PTP_ID,ptpPipe.PT_PipeId, WorkArea.WorkAreaCode,IsoInfo.PipelineCode, IsoInfo.DesignPressure,IsoInfo.DesignTemperature,ser.MediumName, ptpPipe.isAll,(case when (isnull(ptpPipe.WeldJonintCode,'')='') then '全部' else ptpPipe.WeldJonintCode end) as WeldJonintCode FROM dbo.PTP_TestPackage AS ptp LEFT JOIN dbo.PTP_PipelineList AS ptpPipe ON ptp.PTP_ID=ptpPipe.PTP_ID LEFT JOIN dbo.Pipeline_Pipeline AS IsoInfo ON IsoInfo.PipelineId = ptpPipe.PipelineId LEFT JOIN Project_WorkArea AS WorkArea ON IsoInfo.WorkAreaId=WorkArea.WorkAreaId LEFT JOIN dbo.Base_Medium AS ser ON ser.MediumId = IsoInfo.MediumId WHERE ptp.ProjectId= @ProjectId AND ptp.PTP_ID=@PTP_ID"; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); listStr.Add(new SqlParameter("@PTP_ID", this.PTP_ID)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #region 加载页面输入保存信息 /// /// 加载页面输入保存信息 /// private void PageInfoLoad() { this.btnEdit.Hidden = true; this.btnDelete.Hidden = true; //this.btnPrint.Hidden = true; var testPackageManage = BLL.TestPackageManageEditService.GetTestPackageByID(this.PTP_ID); if (testPackageManage != null) { this.txtTestPackageNo.Text = testPackageManage.TestPackageNo; //if (!string.IsNullOrEmpty(testPackageManage.UnitId)) //{ // var unit = BLL.Base_UnitService.GetUnit(testPackageManage.UnitId); // if (unit != null) // { // this.drpUnit.Text = unit.UnitName; // } //} if (!string.IsNullOrEmpty(testPackageManage.InstallationId)) { var install = BLL.Project_InstallationService.GetProject_InstallationByInstallationId(testPackageManage.InstallationId); if (install != null) { this.drpInstallation.Text = install.InstallationName; } } this.txtTestPackageName.Text = testPackageManage.TestPackageName; //this.txtTestPackageCode.Text = testPackageManage.TestPackageCode; if (!string.IsNullOrEmpty(testPackageManage.TestType)) { var testType = BLL.Base_PressureService.GetPressureByPressureId(testPackageManage.TestType); if (testType != null) { this.drpTestType.Text = testType.PressureName; } } this.txtTestService.Text = testPackageManage.TestService; this.txtTestHeat.Text = testPackageManage.TestHeat; this.txtTestAmbientTemp.Text = testPackageManage.TestAmbientTemp; this.txtTestMediumTemp.Text = testPackageManage.TestMediumTemp; this.txtVacuumTestService.Text = testPackageManage.VacuumTestService; this.txtVacuumTestPressure.Text = testPackageManage.VacuumTestPressure; this.txtTightnessTestTime.Text = testPackageManage.TightnessTestTime; this.txtTightnessTestTemp.Text = testPackageManage.TightnessTestTemp; this.txtTightnessTest.Text = testPackageManage.TightnessTest; this.txtTestPressure.Text = testPackageManage.TestPressure; this.txtTestPressureTemp.Text = testPackageManage.TestPressureTemp; this.txtTestPressureTime.Text = testPackageManage.TestPressureTime; this.txtOperationMedium.Text = testPackageManage.OperationMedium; this.txtPurgingMedium.Text = testPackageManage.PurgingMedium; this.txtCleaningMedium.Text = testPackageManage.CleaningMedium; this.txtLeakageTestService.Text = testPackageManage.LeakageTestService; this.txtLeakageTestPressure.Text = testPackageManage.LeakageTestPressure; this.txtAllowSeepage.Text = testPackageManage.AllowSeepage; this.txtFactSeepage.Text = testPackageManage.FactSeepage; this.txtModifyDate.Text = string.Format("{0:yyyy-MM-dd}", testPackageManage.ModifyDate); if (!string.IsNullOrEmpty(testPackageManage.Modifier)) { var users = BLL.Sys_UserService.GetUsersByUserId(testPackageManage.Modifier); if (users != null) { this.drpModifier.Text = users.UserName; } } this.txtTableDate.Text = string.Format("{0:yyyy-MM-dd}", testPackageManage.TableDate); if (!string.IsNullOrEmpty(testPackageManage.Tabler)) { var users = BLL.Sys_UserService.GetUsersByUserId(testPackageManage.Tabler); if (users != null) { this.drpTabler.Text = users.UserName; } } this.txtRemark.Text = testPackageManage.Remark; this.txtAduditDate.Text = string.Format("{0:yyyy-MM-dd}", testPackageManage.AduditDate); if (!string.IsNullOrEmpty(testPackageManage.Auditer)) { var users = BLL.Sys_UserService.GetUsersByUserId(testPackageManage.Auditer); if (users != null) { this.drpAuditer.Text = users.UserName; } } if (string.IsNullOrEmpty(testPackageManage.Auditer) || !testPackageManage.AduditDate.HasValue) { this.btnEdit.Hidden = false; this.btnDelete.Hidden = false; //this.btnPrint.Hidden = false; } } } #endregion #region 清空页面输入信息 /// /// 清空页面输入信息 /// private void SetTextTemp() { this.txtTestPackageNo.Text = string.Empty; //this.drpUnit.Text = string.Empty; this.drpInstallation.Text = string.Empty; this.txtTestPackageName.Text = string.Empty; //this.txtTestPackageCode.Text = string.Empty; this.drpTestType.Text = string.Empty; this.txtTestService.Text = string.Empty; this.txtTestHeat.Text = string.Empty; this.txtTestAmbientTemp.Text = string.Empty; this.txtTestMediumTemp.Text = string.Empty; this.txtVacuumTestService.Text = string.Empty; this.txtVacuumTestPressure.Text = string.Empty; this.txtTightnessTestTime.Text = string.Empty; this.txtTightnessTestTemp.Text = string.Empty; this.txtTightnessTest.Text = string.Empty; this.txtTestPressure.Text = string.Empty; this.txtTestPressureTemp.Text = string.Empty; this.txtTestPressureTime.Text = string.Empty; this.txtOperationMedium.Text = string.Empty; this.txtPurgingMedium.Text = string.Empty; this.txtCleaningMedium.Text = string.Empty; this.txtLeakageTestService.Text = string.Empty; this.txtLeakageTestPressure.Text = string.Empty; this.txtAllowSeepage.Text = string.Empty; this.txtFactSeepage.Text = string.Empty; this.drpModifier.Text = string.Empty; this.txtModifyDate.Text = string.Empty; this.drpTabler.Text = string.Empty; this.txtTableDate.Text = string.Empty; this.txtRemark.Text = string.Empty; this.drpAuditer.Text = string.Empty; this.txtAduditDate.Text = string.Empty; } #endregion #endregion #region 分页排序 #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #endregion #region 试压包 维护事件 /// /// 增加试压包 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.TestPackageManageEditMenuId, Const.BtnAdd)) { this.SetTextTemp(); string window = String.Format("TestPackageManageItemEdit.aspx?PTP_ID={0}", string.Empty, "新增 - "); PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdPTP_ID.ClientID) + Window1.GetShowReference(window)); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #region 编辑试压包 /// /// 编辑试压包 /// /// /// protected void btnEdit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.TestPackageManageEditMenuId, Const.BtnSave)) { var testPackageManage = BLL.TestPackageManageEditService.GetTestPackageByID(this.PTP_ID); if (testPackageManage != null) { if (testPackageManage.AduditDate.HasValue) { Alert.ShowInTop("此试压单已审核!", MessageBoxIcon.Warning); return; } string window = String.Format("TestPackageManageItemEdit.aspx?PTP_ID={0}", this.PTP_ID, "编辑 - "); PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdPTP_ID.ClientID) + Window1.GetShowReference(window)); } else { ShowNotify("请选择要修改的试压包记录!", MessageBoxIcon.Warning); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 删除试压包 /// /// 删除试压包 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.TestPackageManageEditMenuId, Const.BtnDelete)) { var testPackageManage = BLL.TestPackageManageEditService.GetTestPackageByID(this.PTP_ID); if (testPackageManage != null) { if (testPackageManage.AduditDate.HasValue) { Alert.ShowInTop("此试压单已审核!", MessageBoxIcon.Warning); return; } BLL.TestPackageManageEditService.DeletePipelineListByPTP_ID(this.PTP_ID); BLL.TestPackageManageEditService.DeleteTestPackage(this.PTP_ID); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.TestPackageManageEditMenuId, Const.BtnDelete, this.PTP_ID); Alert.ShowInTop("删除成功!", MessageBoxIcon.Success); this.InitTreeMenu(); this.BindGrid(); } else { ShowNotify("请选择要删除的试压包记录!", MessageBoxIcon.Warning); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #endregion #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.PTP_ID = this.hdPTP_ID.Text; this.BindGrid(); this.InitTreeMenu(); this.hdPTP_ID.Text = string.Empty; } /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion protected void btnPrint_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.PTP_ID)) { var project = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId); var pip = BLL.TestPackageManageEditService.GetTestPackageByID(this.PTP_ID); var ins = BLL.Project_InstallationService.GetProject_InstallationByInstallationId(pip.InstallationId); string unitName = BLL.Base_UnitService.GetUnitNameByUnitId(pip.UnitId); var pipe = BLL.TestPackageManageEditService.GetPipeLineListByPTP_ID(this.PTP_ID); string varValue = string.Empty; if (project != null) { varValue = "工程名称:" + project.ProjectName; string insName = string.Empty; if (ins != null) { insName = "单位工程名称:" + ins.InstallationName.ToString() + "(" + ins.InstallationCode + ")"; } else { insName = "单位工程名称:"; } varValue = varValue + "|" + insName; } if (drpPrintTypeList.SelectedValue == "1") { Window2.Title = "焊接工作记录打印"; Window3.Title = "焊接工作记录打印(续)"; string isoIds = string.Join(",", pipe.Select(p => p.PipelineId)); List listStr = new List(); listStr.Add(new SqlParameter("@IsoIds", isoIds)); listStr.Add(new SqlParameter("@Flag", "0")); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = BLL.SQLHelper.GetDataTableRunProc("HJGL_spJointWorkRecordNew", parameter); string page = Funs.GetPagesCountByPageSize(11, 16, tb.Rows.Count).ToString(); varValue = varValue + "|" + page; if (!string.IsNullOrEmpty(varValue)) { varValue = HttpUtility.UrlEncodeUnicode(varValue); } if (tb.Rows.Count <= 11) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.WeldingRecordReport1, isoIds, varValue))); } else { PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.WeldingRecordReport2, isoIds, varValue))); PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.WeldingRecordReport1, isoIds, varValue))); } } if (drpPrintTypeList.SelectedValue == "2") { Window2.Title = "管道无损检测结果汇总表"; Window3.Title = "管道无损检测结果汇总表(续)"; List listStr = new List(); listStr.Add(new SqlParameter("@PTP_ID", this.PTP_ID)); listStr.Add(new SqlParameter("@Flag", "0")); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = BLL.SQLHelper.GetDataTableRunProc("Sp_CheckResultSummary", parameter); string pageNum = Funs.GetPagesCountByPageSize(5, 14, tb.Rows.Count).ToString(); string supervisorUnit = "NULL"; string insCode = "NULL"; if (ins != null) { supervisorUnit = BLL.Base_UnitService.GetUnitNameByUnitId(ins.SupervisorUnitId); insCode = ins.InstallationCode; } else { supervisorUnit = "NULL"; } string cunit = BLL.Base_UnitService.GetUnitNameByUnitId(pip.UnitId); string checkStan = "NB/T47013-2015"; string pipeClass = "NULL"; if (pipe.Count() > 0) { var pc = BLL.Base_PipingClassService.GetPipingClassByPipingClassId(pipe.First().PipingClassId); if (pc != null) { pipeClass = pc.PipingClassCode; } } var qq = from x in Funs.DB.View_CheckResultSummary where x.PTP_ID == this.PTP_ID select x; // 合格 var rt = qq.Where(x => x.DetectionTypeCode == "RT" && x.CheckResult == "合格"); string bRt = "/"; if (rt.Count() > 0) { bRt = rt.Count().ToString() + "/" + rt.Sum(x => x.TotalFilm).ToString(); } var jpt = qq.Where(x => x.DetectionTypeCode == "PT" && x.CheckResult == "合格" && x.WeldType == "2"); string ptj = "/"; if (jpt.Count() > 0) { ptj = jpt.Count().ToString(); } var zpt = qq.Where(x => x.DetectionTypeCode == "PT" && x.CheckResult == "合格" && x.WeldType == "3"); string ptz = "/"; if (zpt.Count() > 0) { ptz = zpt.Count().ToString(); } // 不合格 var nrt = qq.Where(x => x.DetectionTypeCode == "RT" && x.CheckResult == "不合格"); string nbRt = "/"; if (nrt.Count() > 0) { nbRt = nrt.Count().ToString() + "/" + nrt.Sum(x => x.TotalFilm).ToString(); } var njpt = qq.Where(x => x.DetectionTypeCode == "PT" && x.CheckResult == "不合格" && x.WeldType == "2"); string nptj = "/"; if (njpt.Count() > 0) { nptj = njpt.Count().ToString(); } var nzpt = qq.Where(x => x.DetectionTypeCode == "PT" && x.CheckResult == "不合格" && x.WeldType == "3"); string nptz = "/"; if (nzpt.Count() > 0) { nptz = nzpt.Count().ToString(); } varValue = pageNum + "|" + varValue + "|" + supervisorUnit + "|" + cunit + "|" + checkStan + "|" + pipeClass + "|" + insCode + "|" + bRt + "|" + ptj + "|" + ptz + "|" + nbRt + "|" + nptj + "|" + nptz; if (!string.IsNullOrEmpty(varValue)) { varValue = HttpUtility.UrlEncodeUnicode(varValue); } if (tb.Rows.Count <= 5) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.NdtTotalReport1, this.PTP_ID, varValue))); } else { PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.NdtTotalReport2, this.PTP_ID, varValue))); PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.NdtTotalReport1, this.PTP_ID, varValue))); } } if (drpPrintTypeList.SelectedValue == "3") { Window2.Title = "管道无损检测比例统计表"; varValue = varValue + "|" + "试压包号:" + pip.TestPackageNo.Trim(); if (!string.IsNullOrEmpty(unitName)) { varValue = varValue + "|" + unitName; } else { varValue = varValue + "|" + "NULL"; } if (!string.IsNullOrEmpty(varValue)) { varValue = HttpUtility.UrlEncodeUnicode(varValue); } PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.NdtRateReport1, this.PTP_ID, varValue))); } } else { ShowNotify("请选择试压包记录!", MessageBoxIcon.Warning); return; } } #region 模板下载 /// /// 模板下载 /// /// /// protected void btnDownLoad_Click(object sender, EventArgs e) { string rootPath = Server.MapPath("~/"); string uploadfilepath = rootPath + Const.HJGL_TestTemplateUrl; string filePath = Const.HJGL_TestTemplateUrl; string fileName = Path.GetFileName(filePath); FileInfo info = new FileInfo(uploadfilepath); long fileSize = info.Length; Response.ClearContent(); Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.ContentType = "excel/plain"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.AddHeader("Content-Length", fileSize.ToString().Trim()); Response.TransmitFile(uploadfilepath, 0, fileSize); Response.End(); //PageContext.RegisterStartupScript(Confirm.GetShowReference("确定要下载焊工信息导入模板?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel"))); } #endregion protected void btnImport_Click(object sender, EventArgs e) { string message = string.Empty; errorInfos = string.Empty; try { if (this.fileUpload.HasFile == false) { ShowNotify("请选择Excel文件!", MessageBoxIcon.Warning); return; } string IsXls = Path.GetExtension(this.fileUpload.FileName).ToString().Trim().ToLower(); if (IsXls != ".xls" && IsXls != ".xlsx") { ShowNotify("只能选择Excel文件!", MessageBoxIcon.Warning); return; } string rootPath = Server.MapPath("~/"); string initFullPath = rootPath + initPath; if (!Directory.Exists(initFullPath)) { Directory.CreateDirectory(initFullPath); } //指定上传文件名称 this.hidFileName.Text = BLL.Funs.GetNewFileName() + IsXls; //上传文件路径 string filePath = initFullPath + this.hidFileName.Text; //文件上传服务器 this.fileUpload.PostedFile.SaveAs(filePath); //文件上传服务器后的名称 string fileName = rootPath + initPath + this.hidFileName.Text; //读取Excel DataSet ds = NPOIHelper.ExcelToDataSet(fileName, out errorInfos, true); //验证Excel读取是否有误 if (!string.IsNullOrEmpty(errorInfos)) { ShowNotify(errorInfos, MessageBoxIcon.Warning); return; } if (ds.Tables.Count > 0) { //定义错误集合实体类 var data = ValidateFieldsExcelData(ds.Tables[0]); Funs.DB.PTP_TestPackage_ImportErrorLog.InsertAllOnSubmit(data.Item2); Funs.DB.SubmitChanges(); //验证错误集合 if (data.Item1) { string batchNo = data.Item2.Select(t => t.BatchNo).Distinct().First(); PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("ImportError.aspx?batchNo={0}", batchNo),"试压包导入错误日志")); return; } //导入数据 List listPtpPackgeData = new List(); List listDetailData = new List(); foreach (var item in data.Item2) { if (!listPtpPackgeData.Any(t => t.TestPackageNo == item.TestPackageNo)) { List ptpItemListData = new List(); Model.PTP_TestPackage model = new PTP_TestPackage(); model.PTP_ID = SQLHelper.GetNewID(typeof(PTP_TestPackage)); model.TestPackageNo = item.TestPackageNo; model.UnitId = item.UnitId; model.ProjectId = item.ProjectId; model.InstallationId = item.InstallId; model.TableDate = DateTime.Now; model.Tabler = this.CurrUser.UserId; listPtpPackgeData.Add(model); var itemData=data.Item2.Where(t=>t.TestPackageNo==item.TestPackageNo).ToList(); foreach (var item2 in itemData) { var model2=new PTP_PipelineList(); model2.PTP_ID = model.PTP_ID; model2.PipelineId = item2.PipelineId; model2.WorkAreaId = item2.WorkAreaId; model2.WeldJonintCode = item2.JointCode; model2.PT_PipeId = SQLHelper.GetNewID(typeof(PTP_PipelineList)); model2.IsAll= item2.IsAll == "是" ? true : false; listDetailData.Add(model2); } } } Funs.DB.PTP_TestPackage.InsertAllOnSubmit(listPtpPackgeData); Funs.DB.PTP_PipelineList.InsertAllOnSubmit(listDetailData); //绑定表格 Funs.DB.SubmitChanges(); this.BindGrid(); ShowNotify("导入成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(this.PTP_ID)+ ActiveWindow.GetHidePostBackReference()); } else { ShowAlert("没有数据!", MessageBoxIcon.Warning); return; } } catch (Exception ex) { ShowAlert("'" + ex.Message + "'", MessageBoxIcon.Warning); } } /// /// 验证Excle中的数据列是否符合要求 /// private (bool, List) ValidateFieldsExcelData(DataTable dt) { var listData = new List(); bool flag = false; int k = 0; string batchNo = DateTime.Now.ToString("yyyyMMddHHmmss"); foreach (DataRow dr in dt.Rows) { var model = new PTP_TestPackage_ImportErrorLog(); k++; string testpackNo = dr[0].ToString(); //试压包编号 string untiCode = dr[1].ToString(); //单位编号 string installCode = dr[2].ToString(); //装置编号 string areaCode = dr[3].ToString(); //区域编号 string pipelineCode = dr[4].ToString(); //管线编号 string isALL = dr[5].ToString(); //是否全部焊口 string jointCode = dr[6].ToString(); //焊口列表逗号 model.Id = SQLHelper.GetNewID(typeof(PTP_TestPackage_ImportErrorLog)); model.TestPackageNo = testpackNo; model.UnitCode = untiCode; model.InstallCode = installCode; model.AreaCode = areaCode; model.PiplineCode = pipelineCode; model.IsAll = isALL; model.JointCode = jointCode; model.CreatedTime = DateTime.Now; model.RowId = k; model.UnitId = string.Empty; model.InstallId = string.Empty; model.WorkAreaId = string.Empty; model.ProjectId = this.CurrUser.LoginProjectId; model.PipelineId=string.Empty; model.BatchNo = batchNo; string errorMsg = string.Empty; //验证是否为空 if (string.IsNullOrEmpty(model.TestPackageNo)) { errorMsg += "试压包编号未填写 |"; } if (string.IsNullOrEmpty(model.UnitCode)) { errorMsg += "试单位编号未填写 | "; } if (string.IsNullOrEmpty(installCode)) { errorMsg += "装置编号未填写 | "; } if (string.IsNullOrEmpty(areaCode)) { errorMsg += "区域编号未填写 | "; } if (string.IsNullOrEmpty(pipelineCode)) { errorMsg += "管线号未填写 | "; } if (string.IsNullOrEmpty(isALL)) { errorMsg += "是否全部焊口未填写 | "; } //检查单位编号是否存在 var unitInfo = Funs.DB.Base_Unit.FirstOrDefault(t => t.UnitCode == model.UnitCode); if (unitInfo == null) { errorMsg += "未知的单位编号 | "; } var installInfo = Funs.DB.Project_Installation.FirstOrDefault(t => t.InstallationCode == model.InstallCode); if (installInfo == null) { errorMsg += "未知的装置编号 | "; } var areaInfo = Funs.DB.Project_WorkArea.FirstOrDefault(t => t.WorkAreaCode == model.AreaCode); if (areaInfo == null) { errorMsg += "未知的区域编号 | "; } var isAnypipeline = Funs.DB.Pipeline_Pipeline.Any(t => t.PipelineCode == model.PiplineCode); if (!isAnypipeline) { errorMsg += "未知的管线号 | "; } if (isALL != "是" && isALL != "否") { errorMsg += "是否部分焊口值不正确,只能为是或否 | "; } if (isALL == "否" && string.IsNullOrEmpty(model.JointCode)) { errorMsg += "部分焊口请填写焊口编号 | "; } var isPackNoAny = Funs.DB.PTP_TestPackage.Any(t => t.TestPackageCode == model.TestPackageNo); if (isPackNoAny) { errorMsg += "该试压包编号已存在 | "; } if (unitInfo != null && installInfo != null && areaInfo != null ) { model.UnitId = unitInfo.UnitId; model.WorkAreaId = areaInfo.WorkAreaId; model.InstallId = installInfo.InstallationId; var newPipelineInfo = Funs.DB.Pipeline_Pipeline.FirstOrDefault(t => t.UnitId == unitInfo.UnitId && t.InstallationId == installInfo.InstallationId && t.WorkAreaId == areaInfo.WorkAreaId && t.PipelineCode==model.PiplineCode); if (newPipelineInfo == null) { errorMsg += "当前区域下不存在此管线号 | "; model.PipelineId = string.Empty; } else { model.PipelineId = newPipelineInfo.PipelineId; var ptpDetailList = Funs.DB.PTP_PipelineList .Where(t => t.PipelineId == newPipelineInfo.PipelineId); var isExcelPipline = listData.Where(t => t.PipelineId == newPipelineInfo.PipelineId).Any(); if (isExcelPipline) { errorMsg += "该管线已被使用 | "; } //查询当前的管线是否被使用了 if (isALL == "是") { var isAnyPipeline = ptpDetailList.Where(t => t.IsAll == true).Any(); if (isAnyPipeline) { errorMsg += "该管线已被使用 | "; } } //查询当前的焊口是否被使用了 if (isALL == "否") { var baseDict = GetJointCodeByPipelineIdDic(newPipelineInfo.PipelineId); var dict = GetJointCodeDic(newPipelineInfo.PipelineId); string[] modelCodes = model.JointCode.Split(','); for (int i = 0; i < modelCodes.Length; i++) { if (dict.ContainsKey(modelCodes[i])) { errorMsg += $"焊口【{modelCodes[i]}】已被使用 | "; } if (!baseDict.ContainsValue(modelCodes[i])) { errorMsg += $"未知的焊口【{modelCodes[i]}】| "; } } int baseCount = BLL.TestPackageManageEditService.countBaseWeldJointCode(newPipelineInfo.PipelineId); if (dict.Count == baseCount) { errorMsg += $"当前管线【{newPipelineInfo.PipelineId}】已被使用 | "; } } } } model.Remark = errorMsg; if (!string.IsNullOrEmpty(model.Remark)) flag = true; listData.Add(model); } return (flag, listData); } private Dictionary GetJointCodeDic(string piplineId) { var dict = new Dictionary(); var dataList = Funs.DB.PTP_PipelineList.Where(t => t.PipelineId == piplineId && t.IsAll == false) .Select(t => t.WeldJonintCode).ToList(); int k = 0; foreach (var item in dataList) { k++; if (!string.IsNullOrEmpty(item)) { string[] arr = item.Split(','); for (int i = 0; i < arr.Length; i++) { if (!dict.ContainsKey(arr[i])) { dict.Add(arr[i], k); } } } } return dict; } private Dictionary GetJointCodeByPipelineIdDic(string piplineId) { var dict = Funs.DB.Pipeline_WeldJoint.Where(t => t.PipelineId == piplineId) .ToDictionary(t => t.WeldJointId, t => t.WeldJointCode); return dict; } } }