using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Linq; using System.IO; using BLL; using Newtonsoft.Json.Linq; namespace FineUIPro.Web.WeldingManage { public partial class PipelineManage : PageBase { //定义变量 /// /// 上传预设的虚拟路径 /// private string initPath = Const.ExcelUrl; /// /// 错误集合 /// public static string errorInfos = string.Empty; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.InitTreeMenu();//加载树 //显示列 Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "Pipeline"); if (c != null) { this.GetShowColumn(c.Columns); } } } protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); } #region 加载树装置-单位-工作区 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); var totalInstallation = from x in Funs.DB.Project_Installation select x; var totalWorkArea = from x in Funs.DB.Project_WorkArea select x; var totalUnit = from x in Funs.DB.Project_Unit select x; ////装置 var pInstallation = (from x in totalInstallation where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList(); ////区域 var pWorkArea = (from x in totalWorkArea where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList(); ////单位 var pUnits = (from x in totalUnit where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList(); if (!string.IsNullOrEmpty(this.txtWorkArea.Text)) { pWorkArea = pWorkArea.Where(x => x.WorkAreaCode.Contains(this.txtWorkArea.Text.Trim())).OrderBy(x => x.WorkAreaCode).ToList(); pInstallation = (from x in pInstallation join y in pWorkArea on x.InstallationId equals y.InstallationId select x).Distinct().ToList(); pUnits = (from x in pUnits join y in pWorkArea on x.UnitId equals y.UnitId select x).Distinct().ToList(); } this.BindNodes(null, pInstallation, pWorkArea, pUnits); } #endregion #region 绑定树节点 /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node, List pInstallation, List pWorkArea, List pUnits) { if (node == null) { List installations = pInstallation; var pUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId); //if (pUnit != null && !pUnit.UnitType.Contains(Const.UnitType_2) && !pUnit.UnitType.Contains(Const.UnitType_1)) if (pUnit != null && pUnit.UnitType.Contains(Const.UnitType_5)) { installations = (from x in pInstallation join y in pWorkArea on x.InstallationId equals y.InstallationId where y.UnitId == this.CurrUser.UnitId orderby x.InstallationId select x).Distinct().ToList(); } foreach (var q in installations) { TreeNode newNode = new TreeNode(); newNode.NodeID = q.InstallationId; newNode.Text = q.InstallationName; newNode.ToolTip = Resources.Lan.InstallationName; newNode.Expanded = true; this.tvControlItem.Nodes.Add(newNode); this.BindNodes(newNode, pInstallation, pWorkArea, pUnits); } } else if (node.ToolTip == Resources.Lan.InstallationName) { List units = null; var pUnitDepth = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId); if (pUnitDepth == null || pUnitDepth.UnitType.Contains(Const.UnitType_2) || pUnitDepth.UnitType.Contains(Const.UnitType_1) || pUnitDepth.UnitType == BLL.Const.UnitType_3 || pUnitDepth.UnitType == BLL.Const.UnitType_4) { units = (from x in pUnits join y in pWorkArea on x.UnitId equals y.UnitId where y.InstallationId == node.NodeID && x.UnitType.Contains(Const.UnitType_5) select x).ToList(); } else { units = (from x in pUnits join y in pWorkArea on x.UnitId equals y.UnitId where y.InstallationId == node.NodeID && x.UnitType.Contains(Const.UnitType_5) && x.UnitId == this.CurrUser.UnitId select x).ToList(); } units = units.OrderBy(x => x.InTime).Distinct().ToList(); foreach (var q in units) { var unit = BLL.Base_UnitService.GetUnit(q.UnitId); if (unit != null) { TreeNode newNode = new TreeNode(); newNode.Text = unit.UnitName; newNode.NodeID = q.UnitId + "|" + node.NodeID; newNode.ToolTip = Resources.Lan.CompanyName; node.Nodes.Add(newNode); this.BindNodes(newNode, pInstallation, pWorkArea, pUnits); } } } else if (node.ToolTip == Resources.Lan.CompanyName) { var workAreas = (from x in pWorkArea where x.InstallationId == node.ParentNode.NodeID && x.UnitId == node.NodeID.Split('|')[0] select x); workAreas = workAreas.OrderByDescending(x => x.WorkAreaCode); var pipelines = from x in Funs.DB.Pipeline_Pipeline select x; foreach (var q in workAreas) { int a = (from x in pipelines where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitId == node.NodeID.Split('|')[0] && x.WorkAreaId == q.WorkAreaId select x).Count(); TreeNode newNode = new TreeNode(); newNode.Text = q.WorkAreaCode + "【" + a.ToString() + "】" + Resources.Lan.Pipeline; newNode.NodeID = q.WorkAreaId; newNode.EnableClickEvent = true; newNode.ToolTip = Resources.Lan.Area; node.Nodes.Add(newNode); } } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.BindGrid(); } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { string strSql = @"SELECT ProjectId,WorkAreaId,PipelineId,PipelineCode,UnitName,MediumCode,PipingClassCode,PIPClassCode, SystemNumber,WorkAreaCode,WorkPackageCode,SingleNumber,SubSystemNumber,Sheet, PipeSegment,DrawingsNum,MaterialCode,Specification,DesignTemperature,TestPressure, DesignPressure,IfPicklingStr,DetectionRateCode,Remark,TotalDin,JointCount,IsBuilt FROM View_Pipeline_Pipeline WHERE ProjectId= @ProjectId"; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); strSql += " AND WorkAreaId =@WorkAreaId"; listStr.Add(new SqlParameter("@WorkAreaId", this.tvControlItem.SelectedNodeID)); if (!string.IsNullOrEmpty(this.txtPipelineCode.Text.Trim())) { strSql += " AND PipelineCode LIKE @PipelineCode"; listStr.Add(new SqlParameter("@PipelineCode", "%" + this.txtPipelineCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtSingleNumber.Text.Trim())) { strSql += " AND SingleNumber LIKE @SingleNumber"; listStr.Add(new SqlParameter("@SingleNumber", "%" + this.txtSingleNumber.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtWorkAreaCode.Text.Trim())) { strSql += " AND WorkAreaCode LIKE @WorkAreaCode"; listStr.Add(new SqlParameter("@WorkAreaCode", "%" + this.txtWorkAreaCode.Text.Trim() + "%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); this.OutputSummaryData(tb); ///取合计值 Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 计算合计 /// /// 计算合计 /// private void OutputSummaryData(DataTable tb) { decimal count2 = 0;//总达因数 int count3 = 0;//总焊口数 for (int i = 0; i < tb.Rows.Count; i++) { count2 += Funs.GetNewDecimalOrZero(tb.Rows[i]["TotalDin"].ToString()); count3 += Funs.GetNewIntOrZero(tb.Rows[i]["JointCount"].ToString()); } JObject summary = new JObject(); summary.Add("PipelineCode", Resources.Lan.Total); summary.Add("TotalDin", count2); summary.Add("JointCount", count3); Grid1.SummaryData = summary; } #endregion #region 分页排序 #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #endregion #region 管线信息 维护事件 /// /// Grid双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_PipelineManageMenuId, BLL.Const.BtnModify)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineManageEdit.aspx?PipelineId={0}", Grid1.SelectedRowID, "编辑 - "))); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } /// /// 增加管线信息 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PipelineManageMenuId, Const.BtnAdd)) { var workArea = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(tvControlItem.SelectedNodeID); if (workArea != null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineManageEdit.aspx?workAreaId={0}", this.tvControlItem.SelectedNodeID, "新增 - "))); } else { ShowNotify(Resources.Lan.PleaseSelectAreaFirst, MessageBoxIcon.Warning); } } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } /// /// 管线信息编辑 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_PipelineManageMenuId, BLL.Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineManageEdit.aspx?PipelineId={0}", Grid1.SelectedRowID, "维护 - "))); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } /// /// 删除按钮 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PipelineManageMenuId, Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning); return; } bool isShow = true; if (Grid1.SelectedRowIndexArray.Length > 1) { isShow = false; } foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); if (judgementDelete(rowID, isShow)) { BLL.Pipeline_PipelineService.DeletePipeline(rowID); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PipelineManageMenuId, Const.BtnDelete, rowID); ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success); } } this.BindGrid(); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } #endregion /// /// 生成点口随机数 /// /// /// protected void btnBuildPointNo_Click(object sender, EventArgs e) { //if (!string.IsNullOrEmpty(Grid1.SelectedRowID)) //{ // var pipe = Funs.DB.View_Pipeline_Random.FirstOrDefault(x => x.PipelineId == Grid1.SelectedRowID); // if (pipe != null && pipe.DetectionRateValue != null) // { // int totalJotNum = Convert.ToInt32(pipe.JointCount); // int weldingJotNum = Convert.ToInt32(pipe.WeldingCount); // int pointNum = Convert.ToInt32(pipe.PointCount); // int minValue = weldingJotNum + 1; // int maxValue = totalJotNum; // int rate = Convert.ToInt32(pipe.DetectionRateValue); // int pointTotalNum = Convert.ToInt32(Math.Ceiling((double)(totalJotNum * rate) / (double)100)); // int num = pointTotalNum - pointNum; // if (num > 0) // { // int[] r = Funs.GetRandomNum(num, minValue, maxValue); // var q = from x in r orderby x select x; // string random = string.Empty; // foreach (int i in q) // { // if (i <= maxValue) // { // random = random + i.ToString() + ","; // } // } // if (random.Length > 0) // { // string randomNum = random.Substring(0, random.Length - 1); // Pipeline_PipelineService.UpdatePipelineRandom(Grid1.SelectedRowID, randomNum); // ShowNotify("已生成随机点口序号", MessageBoxIcon.Success); // BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, "生成随机点口序号", Grid1.SelectedRowID); // } // } // else // { // Alert.ShowInTop("按比例已达到点口数了!", MessageBoxIcon.Error); // } // } // else // { // Alert.ShowInTop("请设置探伤比例!", MessageBoxIcon.Error); // } //} //else //{ // Alert.ShowInTop("请选择管线!", MessageBoxIcon.Error); //} } #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); } /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; string jotInfo = string.Empty; var q = from x in Funs.DB.Pipeline_WeldJoint where x.PipelineId == id && x.WeldingDailyId != null select x; if (q.Count() > 0) { foreach (var item in q) { jotInfo += Resources.Lan.WeldingJointNumber + ":" + item.WeldJointCode; var dr = Funs.DB.Pipeline_WeldingDaily.FirstOrDefault(x => x.WeldingDailyId == item.WeldingDailyId); if (dr != null) { jotInfo += ";" + Resources.Lan.DailyWeldingReportNumber + ":" + dr.WeldingDailyCode; } } content = Resources.Lan.WeldingJointOfThePipeline + ":" + jotInfo; } if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content, MessageBoxIcon.Error); } return false; } } #endregion #region 选择要显示列 /// /// 选择显示列 /// /// /// protected void btnSelectColumn_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("PipelineShowColumn.aspx", "显示列 - "))); } #endregion protected void Window2_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); //显示列 Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "Pipeline"); if (c != null) { this.GetShowColumn(c.Columns); } } #region 显示的列 /// /// 显示的列 /// /// private void GetShowColumn(string column) { if (!string.IsNullOrEmpty(column)) { this.Grid1.Columns[1].Hidden = true; this.Grid1.Columns[2].Hidden = true; this.Grid1.Columns[3].Hidden = true; this.Grid1.Columns[4].Hidden = true; this.Grid1.Columns[5].Hidden = true; this.Grid1.Columns[6].Hidden = true; this.Grid1.Columns[7].Hidden = true; this.Grid1.Columns[8].Hidden = true; this.Grid1.Columns[9].Hidden = true; this.Grid1.Columns[10].Hidden = true; this.Grid1.Columns[11].Hidden = true; this.Grid1.Columns[12].Hidden = true; this.Grid1.Columns[13].Hidden = true; this.Grid1.Columns[14].Hidden = true; this.Grid1.Columns[15].Hidden = true; this.Grid1.Columns[16].Hidden = true; this.Grid1.Columns[17].Hidden = true; this.Grid1.Columns[18].Hidden = true; this.Grid1.Columns[19].Hidden = true; this.Grid1.Columns[20].Hidden = true; this.Grid1.Columns[21].Hidden = true; this.Grid1.Columns[22].Hidden = true; List columns = column.Split(',').ToList(); foreach (var item in columns) { this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false; } } } #endregion #region 模板下载 /// /// 模板下载 /// /// /// protected void btnDownLoad_Click(object sender, EventArgs e) { string rootPath = Server.MapPath("~/"); string uploadfilepath = rootPath + Const.HJGL_DataInTemplateUrl; string filePath = Const.HJGL_DataInTemplateUrl; 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 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 select x;//单位 var workAreas = from x in Funs.DB.Project_WorkArea where x.ProjectId == this.CurrUser.LoginProjectId select x;//区域 var materials = from x in Funs.DB.Base_Material select x;//材质 var mediums = from x in Funs.DB.Base_Medium select x;//介质 var pipelineClasss = from x in Funs.DB.Base_PipingClass select x;//管道等级 var weldTypes = from x in Funs.DB.Base_WeldType select x;//焊缝类型 var weldingMethods = from x in Funs.DB.Base_WeldingMethod select x;//焊接方法 var grooveTypes = from x in Funs.DB.Base_GrooveType select x;//坡口类型 var componentss = from x in Funs.DB.Base_Components select x;//安装组件 var consumabless = from x in Funs.DB.Base_Consumables select x;//焊接耗材(焊丝、焊条) var weldingLocation = from x in Funs.DB.Base_WeldingLocation select x; //焊接位置 var ndtRate = from x in Funs.DB.Base_DetectionRate select x; List pipelineList = new List(); List weldJointList = new List(); List updatePipelineList = new List(); List updateWeldJointList = new List(); DataTable dt = ds.Tables[0]; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { var isExitJoint = Funs.DB.View_WeldJointAndPipeline.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.UnitCode == ds.Tables[0].Rows[i]["单位代码"].ToString().Trim() && x.WorkAreaCode == ds.Tables[0].Rows[i]["区域编号"].ToString().Trim() && x.PipelineCode == ds.Tables[0].Rows[i]["管线号"].ToString().Trim() && x.WeldJointCode == ds.Tables[0].Rows[i]["焊口号"].ToString().Trim()); string error = string.Empty; #region 数据验证 全新导入 if (isExitJoint == null) { Model.Pipeline_Pipeline pipeline = new Model.Pipeline_Pipeline(); Model.Pipeline_WeldJoint weldJoint = new Model.Pipeline_WeldJoint(); if (ds.Tables[0].Rows[i]["单位代码"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["单位代码"].ToString())) { var unit = units.FirstOrDefault(x => x.UnitCode == ds.Tables[0].Rows[i]["单位代码"].ToString().Trim()); if (unit == null) { error += "单位代码不存在!"; } else { pipeline.UnitId = unit.UnitId; } } else { error += "单位代码不能为空!"; } if (ds.Tables[0].Rows[i]["区域编号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["区域编号"].ToString())) { var area = workAreas.FirstOrDefault(x => x.WorkAreaCode == ds.Tables[0].Rows[i]["区域编号"].ToString().Trim()); if (area == null) { error += "区域编号不存在!"; } else { pipeline.WorkAreaId = area.WorkAreaId; pipeline.InstallationId = area.InstallationId; } } else { error += "区域编号不能为空!"; } string pipelineId = string.Empty; if (ds.Tables[0].Rows[i]["管线号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["管线号"].ToString())) { var isExitPipeline = Funs.DB.View_WeldJointAndPipeline.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.UnitCode == ds.Tables[0].Rows[i]["单位代码"].ToString().Trim() && x.WorkAreaCode == ds.Tables[0].Rows[i]["区域编号"].ToString().Trim() && x.PipelineCode == ds.Tables[0].Rows[i]["管线号"].ToString().Trim()); if (isExitPipeline == null) { var cc = from x in pipelineList where x.PipelineCode== ds.Tables[0].Rows[i]["管线号"].ToString().Trim() select x; if (cc.Count() == 0) { pipelineId = SQLHelper.GetNewID(typeof(Model.Pipeline_Pipeline)); pipeline.PipelineId = pipelineId; pipeline.PipelineCode = ds.Tables[0].Rows[i]["管线号"].ToString(); } else { pipeline.PipelineId = ""; pipelineId = cc.First().PipelineId; } } else { pipeline.PipelineId = ""; pipelineId = isExitPipeline.PipelineId; } } else { error += "管线号不能为空!"; } if (ds.Tables[0].Rows[i]["焊口号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊口号"].ToString())) { weldJoint.PipelineId = pipelineId; weldJoint.WeldJointId = SQLHelper.GetNewID(typeof(Model.Pipeline_WeldJoint)); weldJoint.WeldJointCode = ds.Tables[0].Rows[i]["焊口号"].ToString(); } else { error += "焊口号不能为空!"; } if (ds.Tables[0].Rows[i]["材质1"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["材质1"].ToString())) { var steel = materials.FirstOrDefault(x => x.MaterialCode == ds.Tables[0].Rows[i]["材质1"].ToString().Trim()); if (steel == null) { error += "材质1不存在!"; } else { pipeline.MainMaterialId = steel.MaterialId; weldJoint.Material1Id = steel.MaterialId; } } else { error += "材质1不能为空!"; } if (ds.Tables[0].Rows[i]["材质2"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["材质2"].ToString())) { var steel = materials.FirstOrDefault(x => x.MaterialCode == ds.Tables[0].Rows[i]["材质2"].ToString().Trim()); if (steel == null) { error += "材质2不存在!"; } else { weldJoint.Material2Id = steel.MaterialId; } } if (ds.Tables[0].Rows[i]["管道等级"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["管道等级"].ToString())) { var pipelineClass = pipelineClasss.FirstOrDefault(x => x.PipingClassCode == ds.Tables[0].Rows[i]["管道等级"].ToString().Trim()); if (pipelineClass == null) { error += "管道等级不存在!"; } else { pipeline.PipingClassId = pipelineClass.PipingClassId; weldJoint.PipingClassId = pipelineClass.PipingClassId; } } else { error += "管道等级不能为空!"; } if (ds.Tables[0].Rows[i]["介质代号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["介质代号"].ToString())) { var medium = mediums.FirstOrDefault(x => x.MediumCode == ds.Tables[0].Rows[i]["介质代号"].ToString().Trim()); if (medium == null) { error += "介质代号不存在!"; } else { pipeline.MediumId = medium.MediumId; } } else { error += "介质代号不能为空!"; } pipeline.Specification = ds.Tables[0].Rows[i]["管线规格"].ToString().Trim(); pipeline.SingleNumber = ds.Tables[0].Rows[i]["单线图号"].ToString().Trim(); pipeline.WorkPackageCode = ds.Tables[0].Rows[i]["工作包号"].ToString().Trim(); pipeline.SystemNumber = ds.Tables[0].Rows[i]["系统号"].ToString(); pipeline.SubSystemNumber = ds.Tables[0].Rows[i]["分系统号"].ToString().Trim(); if (!string.IsNullOrEmpty(ds.Tables[0].Rows[i]["总管段数"].ToString().Trim())) { try { int pipeSegment = Convert.ToInt32(ds.Tables[0].Rows[i]["总管段数"].ToString()); pipeline.PipeSegment = pipeSegment; } catch (Exception) { error += "总管段数为整数型!"; } } pipeline.Sheet = ds.Tables[0].Rows[i]["页数"].ToString().Trim(); pipeline.DrawingsNum = ds.Tables[0].Rows[i]["图纸版次"].ToString().Trim(); pipeline.DesignTemperature = ds.Tables[0].Rows[i]["设计温度"].ToString().Trim(); pipeline.TestPressure = ds.Tables[0].Rows[i]["试验压力"].ToString().Trim(); pipeline.DesignPressure = ds.Tables[0].Rows[i]["设计压力"].ToString().Trim(); if (ds.Tables[0].Rows[i]["焊缝类型"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊缝类型"].ToString())) { var weldType = weldTypes.FirstOrDefault(x => x.WeldTypeCode == ds.Tables[0].Rows[i]["焊缝类型"].ToString().Trim()); if (weldType == null) { error += "焊缝类型不存在!"; } else { weldJoint.WeldTypeId = weldType.WeldTypeId; } } else { error += "焊缝类型不能为空!"; } if (ds.Tables[0].Rows[i]["寸径"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["寸径"].ToString())) { try { decimal size = Convert.ToDecimal(ds.Tables[0].Rows[i]["寸径"].ToString().Trim()); weldJoint.Size = size; } catch (Exception) { error += "寸径为数字型!"; } } else { error += "寸径不能为空!"; } string weldDia = string.Empty; if (ds.Tables[0].Rows[i]["外径"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["外径"].ToString())) { try { decimal dia = Convert.ToDecimal(ds.Tables[0].Rows[i]["外径"].ToString().Trim()); weldJoint.Dia = dia; weldDia = dia.ToString(); } catch (Exception) { error += "外径为数字型!"; } } else { error += "外径不能为空!"; } string weldThickness = string.Empty; if (ds.Tables[0].Rows[i]["壁厚"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["壁厚"].ToString())) { try { decimal thickness = Convert.ToDecimal(ds.Tables[0].Rows[i]["壁厚"].ToString().Trim()); weldJoint.Thickness = thickness; weldThickness = thickness.ToString(); } catch (Exception) { error += "壁厚为数字型!"; } } else { error += "壁厚不能为空!"; } if (ds.Tables[0].Rows[i]["焊接方法"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊接方法"].ToString())) { var weldMethod = weldingMethods.FirstOrDefault(x => x.WeldingMethodCode == ds.Tables[0].Rows[i]["焊接方法"].ToString().Trim()); if (weldMethod == null) { error += "焊接方法不存在!"; } else { weldJoint.WeldingMethodId = weldMethod.WeldingMethodId; } } else { error += "焊接方法不能为空!"; } weldJoint.HeartNo1 = ds.Tables[0].Rows[i]["炉批号1"].ToString(); weldJoint.HeartNo2 = ds.Tables[0].Rows[i]["炉批号2"].ToString(); if (ds.Tables[0].Rows[i]["坡口类型"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["坡口类型"].ToString())) { var grooveType = grooveTypes.FirstOrDefault(x => x.GrooveTypeCode == ds.Tables[0].Rows[i]["坡口类型"].ToString().Trim()); if (grooveType == null) { error += "坡口类型不存在!"; } else { weldJoint.GrooveTypeId = grooveType.GrooveTypeId; } } else { error += "坡口类型不能为空!"; } if (ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"].ToString())) { if (ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"].ToString().Trim() != "S" && ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"].ToString().Trim() != "F") { error += "焊口属性值为:S或F!"; } else { if (ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"].ToString() == "S") { weldJoint.JointAttribute = "活动S"; weldJoint.JointArea = "S"; } else { weldJoint.JointAttribute = "固定F"; weldJoint.JointArea = "F"; } } } else { error += "焊口属性不能为空!"; } if (ds.Tables[0].Rows[i]["组件1号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["组件1号"].ToString())) { var com = componentss.FirstOrDefault(x => x.ComponentsCode == ds.Tables[0].Rows[i]["组件1号"].ToString().Trim()); if (com == null) { error += "组件1号不存在!"; } else { weldJoint.PipeAssembly1Id = com.ComponentsId; } } if (ds.Tables[0].Rows[i]["组件2号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["组件2号"].ToString())) { var com = componentss.FirstOrDefault(x => x.ComponentsCode == ds.Tables[0].Rows[i]["组件2号"].ToString().Trim()); if (com == null) { error += "组件2号不存在!"; } else { weldJoint.PipeAssembly2Id = com.ComponentsId; } } if (ds.Tables[0].Rows[i]["焊丝"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊丝"].ToString())) { var weldSilk = consumabless.FirstOrDefault(x => x.ConsumablesCode == ds.Tables[0].Rows[i]["焊丝"].ToString().Trim() && x.ConsumablesType == "1"); if (weldSilk == null) { error += "焊丝不存在!"; } else { weldJoint.WeldSilkId = weldSilk.ConsumablesId; } } if (ds.Tables[0].Rows[i]["焊条"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊条"].ToString())) { var weldMat = consumabless.FirstOrDefault(x => x.ConsumablesCode == ds.Tables[0].Rows[i]["焊条"].ToString().Trim() && x.ConsumablesType == "2"); if (weldMat == null) { error += "焊条不存在!"; } else { weldJoint.WeldMatId = weldMat.ConsumablesId; } } if (ds.Tables[0].Rows[i]["是否热处理(是、否)"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["是否热处理(是、否)"].ToString())) { if (ds.Tables[0].Rows[i]["是否热处理(是、否)"].ToString() == "是") { weldJoint.IsHotProess = true; } else if (ds.Tables[0].Rows[i]["是否热处理(是、否)"].ToString() == "否") { weldJoint.IsHotProess = false; } } if (ds.Tables[0].Rows[i]["是否酸洗(是、否)"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["是否酸洗(是、否)"].ToString())) { if (ds.Tables[0].Rows[i]["是否酸洗(是、否)"].ToString() == "是") { pipeline.IfPickling = true; } else if (ds.Tables[0].Rows[i]["是否酸洗(是、否)"].ToString() == "否") { pipeline.IfPickling = false; } } if (ds.Tables[0].Rows[i]["焊接位置"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊接位置"].ToString())) { var loc = weldingLocation.FirstOrDefault(x => x.WeldingLocationCode == ds.Tables[0].Rows[i]["焊接位置"].ToString().Trim()); if (loc == null) { error += "焊接位置不存在!"; } else { weldJoint.WeldingLocationId = loc.WeldingLocationId; } } if (ds.Tables[0].Rows[i]["检测比例"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["检测比例"].ToString())) { var rate = ndtRate.FirstOrDefault(x => x.DetectionRateCode == ds.Tables[0].Rows[i]["检测比例"].ToString().Trim()); if (rate == null) { error += "检测比例不存在!"; } else { pipeline.DetectionRateId = rate.DetectionRateId; } } else { error += "检测比例不能为空!"; } if (!string.IsNullOrEmpty(weldDia) && !string.IsNullOrEmpty(weldThickness)) { weldJoint.Specification = "Φ" + weldDia + "*" + weldThickness; } pipeline.ProjectId = this.CurrUser.LoginProjectId; weldJoint.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(error)) { errorInfos += "第" + (i + 2) + "行:" + error + "
"; } pipelineList.Add(pipeline); weldJointList.Add(weldJoint); } #endregion #region 数据验证 更新导入 if (isExitJoint != null) { Model.Pipeline_Pipeline updatePipeline = new Model.Pipeline_Pipeline(); Model.Pipeline_WeldJoint updateWeldJoint = new Model.Pipeline_WeldJoint(); if (isExitJoint.WeldingDailyId != null) { error += "已焊接,不能更新!"; } if (ds.Tables[0].Rows[i]["单位代码"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["单位代码"].ToString())) { var unit = units.FirstOrDefault(x => x.UnitCode == ds.Tables[0].Rows[i]["单位代码"].ToString().Trim()); if (unit == null) { error += "单位代码不存在!"; } else { updatePipeline.UnitId = unit.UnitId; } } else { error += "单位代码不能为空!"; } if (ds.Tables[0].Rows[i]["区域编号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["区域编号"].ToString())) { var area = workAreas.FirstOrDefault(x => x.WorkAreaCode == ds.Tables[0].Rows[i]["区域编号"].ToString().Trim()); if (area == null) { error += "区域编号不存在!"; } else { updatePipeline.WorkAreaId = area.WorkAreaId; updatePipeline.InstallationId = area.InstallationId; } } else { error += "区域编号不能为空!"; } if (ds.Tables[0].Rows[i]["管线号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["管线号"].ToString())) { var isExitPipeline = Funs.DB.View_WeldJointAndPipeline.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.UnitCode == ds.Tables[0].Rows[i]["单位代码"].ToString().Trim() && x.WorkAreaCode == ds.Tables[0].Rows[i]["区域编号"].ToString().Trim() && x.PipelineCode == ds.Tables[0].Rows[i]["管线号"].ToString().Trim()); updatePipeline.PipelineId = isExitPipeline.PipelineId; updatePipeline.PipelineCode = ds.Tables[0].Rows[i]["管线号"].ToString(); } else { error += "管线号不能为空!"; } if (ds.Tables[0].Rows[i]["焊口号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊口号"].ToString())) { updateWeldJoint.PipelineId = updatePipeline.PipelineId; updateWeldJoint.WeldJointCode = ds.Tables[0].Rows[i]["焊口号"].ToString().Trim(); } else { error += "焊口号不能为空!"; } if (ds.Tables[0].Rows[i]["材质1"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["材质1"].ToString())) { var steel = materials.FirstOrDefault(x => x.MaterialCode == ds.Tables[0].Rows[i]["材质1"].ToString().Trim()); if (steel == null) { error += "材质1不存在!"; } else { updatePipeline.MainMaterialId = steel.MaterialId; updateWeldJoint.Material1Id = steel.MaterialId; } } else { error += "材质1不能为空!"; } if (ds.Tables[0].Rows[i]["材质2"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["材质2"].ToString())) { var steel = materials.FirstOrDefault(x => x.MaterialCode == ds.Tables[0].Rows[i]["材质2"].ToString().Trim()); if (steel == null) { error += "材质2不存在!"; } else { updateWeldJoint.Material2Id = steel.MaterialId; } } if (ds.Tables[0].Rows[i]["管道等级"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["管道等级"].ToString())) { var pipelineClass = pipelineClasss.FirstOrDefault(x => x.PipingClassCode == ds.Tables[0].Rows[i]["管道等级"].ToString().Trim()); if (pipelineClass == null) { error += "管道等级不存在!"; } else { updatePipeline.PipingClassId = pipelineClass.PipingClassId; updateWeldJoint.PipingClassId = pipelineClass.PipingClassId; } } else { error += "管道等级不能为空!"; } if (ds.Tables[0].Rows[i]["介质代号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["介质代号"].ToString())) { var medium = mediums.FirstOrDefault(x => x.MediumCode == ds.Tables[0].Rows[i]["介质代号"].ToString().Trim()); if (medium == null) { error += "介质代号不存在!"; } else { updatePipeline.MediumId = medium.MediumId; } } else { error += "介质代号不能为空!"; } updatePipeline.Specification = ds.Tables[0].Rows[i]["管线规格"].ToString().Trim(); updatePipeline.SingleNumber = ds.Tables[0].Rows[i]["单线图号"].ToString().Trim(); updatePipeline.WorkPackageCode = ds.Tables[0].Rows[i]["工作包号"].ToString().Trim(); updatePipeline.SystemNumber = ds.Tables[0].Rows[i]["系统号"].ToString().Trim(); updatePipeline.SubSystemNumber = ds.Tables[0].Rows[i]["分系统号"].ToString().Trim(); if (!string.IsNullOrEmpty(ds.Tables[0].Rows[i]["总管段数"].ToString().Trim())) { try { int pipeSegment = Convert.ToInt32(ds.Tables[0].Rows[i]["总管段数"].ToString().Trim()); updatePipeline.PipeSegment = pipeSegment; } catch (Exception) { error += "总管段数为整数型!"; } } updatePipeline.Sheet = ds.Tables[0].Rows[i]["页数"].ToString().Trim(); updatePipeline.DrawingsNum = ds.Tables[0].Rows[i]["图纸版次"].ToString().Trim(); updatePipeline.DesignTemperature = ds.Tables[0].Rows[i]["设计温度"].ToString().Trim(); updatePipeline.TestPressure = ds.Tables[0].Rows[i]["试验压力"].ToString().Trim(); updatePipeline.DesignPressure = ds.Tables[0].Rows[i]["设计压力"].ToString().Trim(); if (ds.Tables[0].Rows[i]["焊缝类型"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊缝类型"].ToString())) { var weldType = weldTypes.FirstOrDefault(x => x.WeldTypeCode == ds.Tables[0].Rows[i]["焊缝类型"].ToString().Trim()); if (weldType == null) { error += "焊缝类型不存在!"; } else { updateWeldJoint.WeldTypeId = weldType.WeldTypeId; } } else { error += "焊缝类型不能为空!"; } if (ds.Tables[0].Rows[i]["寸径"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["寸径"].ToString())) { try { decimal size = Convert.ToDecimal(ds.Tables[0].Rows[i]["寸径"].ToString().Trim()); updateWeldJoint.Size = size; } catch (Exception) { error += "寸径为数字型!"; } } else { error += "寸径不能为空!"; } string weldDia = string.Empty; if (ds.Tables[0].Rows[i]["外径"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["外径"].ToString())) { try { decimal dia = Convert.ToDecimal(ds.Tables[0].Rows[i]["外径"].ToString().Trim()); updateWeldJoint.Dia = dia; weldDia = dia.ToString(); } catch (Exception) { error += "外径为数字型!"; } } else { error += "外径不能为空!"; } string weldThickness = string.Empty; if (ds.Tables[0].Rows[i]["壁厚"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["壁厚"].ToString())) { try { decimal thickness = Convert.ToDecimal(ds.Tables[0].Rows[i]["壁厚"].ToString().Trim()); updateWeldJoint.Thickness = thickness; weldThickness = thickness.ToString(); } catch (Exception) { error += "壁厚为数字型!"; } } else { error += "壁厚不能为空!"; } if (ds.Tables[0].Rows[i]["焊接方法"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊接方法"].ToString())) { var weldMethod = weldingMethods.FirstOrDefault(x => x.WeldingMethodCode == ds.Tables[0].Rows[i]["焊接方法"].ToString().Trim()); if (weldMethod == null) { error += "焊接方法不存在!"; } else { updateWeldJoint.WeldingMethodId = weldMethod.WeldingMethodId; } } else { error += "焊接方法不能为空!"; } updateWeldJoint.HeartNo1 = ds.Tables[0].Rows[i]["炉批号1"].ToString(); updateWeldJoint.HeartNo2 = ds.Tables[0].Rows[i]["炉批号2"].ToString(); if (ds.Tables[0].Rows[i]["坡口类型"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["坡口类型"].ToString().Trim())) { var grooveType = grooveTypes.FirstOrDefault(x => x.GrooveTypeCode == ds.Tables[0].Rows[i]["坡口类型"].ToString().Trim()); if (grooveType == null) { error += "坡口类型不存在!"; } else { updateWeldJoint.GrooveTypeId = grooveType.GrooveTypeId; } } else { error += "坡口类型不能为空!"; } if (ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"].ToString())) { if (ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"].ToString() != "S" && ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"].ToString() != "F") { error += "焊口属性值为:S或F!"; } else { if (ds.Tables[0].Rows[i]["焊口属性(活动S、固定F)"].ToString() == "S") { updateWeldJoint.JointAttribute = "活动S"; updateWeldJoint.JointArea = "S"; } else { updateWeldJoint.JointAttribute = "固定F"; updateWeldJoint.JointArea = "F"; } } } else { error += "焊口属性不能为空!"; } if (ds.Tables[0].Rows[i]["组件1号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["组件1号"].ToString())) { var com = componentss.FirstOrDefault(x => x.ComponentsCode == ds.Tables[0].Rows[i]["组件1号"].ToString()); if (com == null) { error += "组件1号不存在!"; } else { updateWeldJoint.PipeAssembly1Id = com.ComponentsId; } } if (ds.Tables[0].Rows[i]["组件2号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["组件2号"].ToString())) { var com = componentss.FirstOrDefault(x => x.ComponentsCode == ds.Tables[0].Rows[i]["组件2号"].ToString()); if (com == null) { error += "组件2号不存在!"; } else { updateWeldJoint.PipeAssembly2Id = com.ComponentsId; } } if (ds.Tables[0].Rows[i]["焊丝"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊丝"].ToString())) { var weldSilk = consumabless.FirstOrDefault(x => x.ConsumablesCode == ds.Tables[0].Rows[i]["焊丝"].ToString() && x.ConsumablesType == "1"); if (weldSilk == null) { error += "焊丝不存在!"; } else { updateWeldJoint.WeldSilkId = weldSilk.ConsumablesId; } } if (ds.Tables[0].Rows[i]["焊条"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊条"].ToString())) { var weldMat = consumabless.FirstOrDefault(x => x.ConsumablesCode == ds.Tables[0].Rows[i]["焊条"].ToString() && x.ConsumablesType == "2"); if (weldMat == null) { error += "焊条不存在!"; } else { updateWeldJoint.WeldMatId = weldMat.ConsumablesId; } } if (ds.Tables[0].Rows[i]["是否热处理(是、否)"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["是否热处理(是、否)"].ToString())) { if (ds.Tables[0].Rows[i]["是否热处理(是、否)"].ToString() == "是") { updateWeldJoint.IsHotProess = true; } else if (ds.Tables[0].Rows[i]["是否热处理(是、否)"].ToString() == "否") { updateWeldJoint.IsHotProess = false; } } if (ds.Tables[0].Rows[i]["是否酸洗(是、否)"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["是否酸洗(是、否)"].ToString())) { if (ds.Tables[0].Rows[i]["是否酸洗(是、否)"].ToString() == "是") { updatePipeline.IfPickling = true; } else if (ds.Tables[0].Rows[i]["是否酸洗(是、否)"].ToString() == "否") { updatePipeline.IfPickling = false; } } if (ds.Tables[0].Rows[i]["焊接位置"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊接位置"].ToString())) { var loc = weldingLocation.FirstOrDefault(x => x.WeldingLocationCode == ds.Tables[0].Rows[i]["焊接位置"].ToString().Trim()); if (loc == null) { error += "焊接位置不存在!"; } else { updateWeldJoint.WeldingLocationId = loc.WeldingLocationId; } } if (ds.Tables[0].Rows[i]["检测比例"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["检测比例"].ToString())) { var rate = ndtRate.FirstOrDefault(x => x.DetectionRateCode == ds.Tables[0].Rows[i]["检测比例"].ToString().Trim()); if (rate == null) { error += "检测比例不存在!"; } else { updatePipeline.DetectionRateId = rate.DetectionRateId; } } else { error += "检测比例不能为空!"; } if (!string.IsNullOrEmpty(weldDia) && !string.IsNullOrEmpty(weldThickness)) { updateWeldJoint.Specification = "Φ" + weldDia + "*" + weldThickness; } updatePipeline.ProjectId = this.CurrUser.LoginProjectId; updateWeldJoint.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(error)) { errorInfos += "第" + (i + 2) + "行:" + error + "
"; } updatePipelineList.Add(updatePipeline); updateWeldJointList.Add(updateWeldJoint); } #endregion } // 数据验证错误,返回 if (!string.IsNullOrEmpty(errorInfos)) { ShowNotify(errorInfos, MessageBoxIcon.Warning, 30000); return; } else { // 不更新,新数据插入 if (weldJointList.Count > 0 && pipelineList.Count() > 0) { var newPipeLineList = from x in pipelineList where x.PipelineId != "" select x; Funs.DB.Pipeline_Pipeline.InsertAllOnSubmit(newPipeLineList); Funs.DB.Pipeline_WeldJoint.InsertAllOnSubmit(weldJointList); Funs.DB.SubmitChanges(); } // 更新插入 if (updateWeldJointList.Count() > 0 && updatePipelineList.Count() > 0) { var pipeList = updatePipelineList.Distinct(); foreach (var q in pipeList) { BLL.Pipeline_PipelineService.UpdatePipeline(q); } foreach (var j in updateWeldJointList) { BLL.Pipeline_WeldJointService.UpdateWeldJoint(j); } } ShowNotify("管道信息导入成功!", MessageBoxIcon.Success); this.BindGrid(); } } else { ShowAlert("没有数据!", MessageBoxIcon.Warning); return; } } catch (Exception ex) { ShowAlert("'" + ex.Message + "'", MessageBoxIcon.Warning); } } } }