269 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			269 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using BLL; | |||
|  | using Model; | |||
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.Linq; | |||
|  | using System.Web; | |||
|  | using System.Web.UI; | |||
|  | using System.Web.UI.WebControls; | |||
|  | 
 | |||
|  | namespace FineUIPro.Web.TestRun.TestRunManage | |||
|  | { | |||
|  |     public partial class DeviceRunEdit : PageBase | |||
|  |     { | |||
|  |         /// <summary> | |||
|  |         /// 上级主键 | |||
|  |         /// </summary> | |||
|  |         public string ParentId | |||
|  |         { | |||
|  |             get { return (string)ViewState["ParentId"]; } | |||
|  |             set { ViewState["ParentId"] = value; } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 主键 | |||
|  |         /// </summary> | |||
|  |         public string RunId | |||
|  |         { | |||
|  |             get { return (string)ViewState["RunId"]; } | |||
|  |             set { ViewState["RunId"] = value; } | |||
|  |         } | |||
|  | 
 | |||
|  |         protected void Page_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (!IsPostBack) | |||
|  |             { | |||
|  |                 this.RunId = Request.Params["RunId"]; | |||
|  |                 this.ParentId = Request.Params["ParentId"]; | |||
|  |                 //绑定数据 | |||
|  |                 PageIn(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 绑定数据 | |||
|  |         /// </summary> | |||
|  |         /// <param name="runId">主键</param> | |||
|  |         /// <param name="parentId">上级主键</param> | |||
|  |         public void PageIn() | |||
|  |         { | |||
|  |             var num = 0; | |||
|  |             if (!string.IsNullOrWhiteSpace(this.ParentId)) | |||
|  |             { | |||
|  |                 var parenLs = GetAllDevices(this.ParentId); | |||
|  |                 if (parenLs.Count > 0) | |||
|  |                 { | |||
|  |                     var itemModel = parenLs.FirstOrDefault(p => p.PreRunId == this.ParentId); | |||
|  |                     if (itemModel != null) | |||
|  |                     { | |||
|  |                         if (itemModel.PreRunLevel == 1) | |||
|  |                         { | |||
|  |                             zz.Hidden = false; | |||
|  |                             var oneModel = parenLs.FirstOrDefault(p => p.PreRunLevel == 1); | |||
|  |                             if (oneModel != null) | |||
|  |                             { | |||
|  |                                 lblzzmc.Text = oneModel.PreRunName; | |||
|  |                                 lblzzbm.Text = oneModel.PreRunCode; | |||
|  |                                 if (string.IsNullOrWhiteSpace(this.RunId)) | |||
|  |                                 { | |||
|  |                                     num = Funs.DB.PreRun_SysDevice.Count(p => p.ProjectId == this.CurrUser.LoginProjectId && p.PreRunLevel == 2) + 1; | |||
|  |                                     txtRunCode.Text = string.Format("PA{0}", string.Format("{0:d2}", num)); | |||
|  |                                     txtSort.Text = num.ToString(); | |||
|  |                                 } | |||
|  |                                 txtRunName.Label = "工序名称"; | |||
|  |                                 txtRunCode.Label = "工序编码"; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         else if (itemModel.PreRunLevel == 2) | |||
|  |                         { | |||
|  |                             zz.Hidden = false; | |||
|  |                             gx.Hidden = false; | |||
|  |                             var oneModel = parenLs.FirstOrDefault(p => p.PreRunLevel == 1); | |||
|  |                             if (oneModel != null) | |||
|  |                             { | |||
|  |                                 lblzzmc.Text = oneModel.PreRunName; | |||
|  |                                 lblzzbm.Text = oneModel.PreRunCode; | |||
|  |                             } | |||
|  |                             var twoModel = parenLs.FirstOrDefault(p => p.PreRunLevel == 2); | |||
|  |                             if (twoModel != null) | |||
|  |                             { | |||
|  |                                 lblgxmc.Text = twoModel.PreRunName; | |||
|  |                                 lblgxbm.Text = twoModel.PreRunCode; | |||
|  |                             } | |||
|  |                             if (string.IsNullOrWhiteSpace(this.RunId)) | |||
|  |                             { | |||
|  |                                 num = Funs.DB.PreRun_SysDevice.Count(p => p.ProjectId == this.CurrUser.LoginProjectId && p.PreRunLevel == 3) + 1; | |||
|  |                                 txtRunCode.Text = string.Format("S{0}", string.Format("{0:d2}", num)); | |||
|  |                                 txtSort.Text = num.ToString(); | |||
|  |                             } | |||
|  |                             txtRunName.Label = "S系统名称"; | |||
|  |                             txtRunCode.Label = "S系统编码"; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 if (string.IsNullOrWhiteSpace(this.RunId)) | |||
|  |                 { | |||
|  |                     txtRunName.Label = "装置名称"; | |||
|  |                     txtRunCode.Label = "装置编码"; | |||
|  |                     num = Funs.DB.PreRun_SysDevice.Count(p => p.ProjectId == this.CurrUser.LoginProjectId && p.PreRunLevel == 1) + 1; | |||
|  |                     txtRunCode.Text = string.Format("P{0}", string.Format("{0:d2}", num)); | |||
|  |                     txtSort.Text = num.ToString(); | |||
|  |                 } | |||
|  |             } | |||
|  |             if (!string.IsNullOrWhiteSpace(this.RunId)) | |||
|  |             { | |||
|  |                 var deviceModel = Funs.DB.PreRun_SysDevice.FirstOrDefault(p => p.PreRunId == this.RunId); | |||
|  |                 if (deviceModel != null) | |||
|  |                 { | |||
|  |                     txtRunCode.Text = deviceModel.PreRunCode; | |||
|  |                     txtRunName.Text = deviceModel.PreRunName; | |||
|  |                     txtRemark.Text = deviceModel.Remark; | |||
|  |                     txtSort.Text = deviceModel.Sort.ToString(); | |||
|  | 
 | |||
|  |                     if (deviceModel.PreRunLevel == 1) | |||
|  |                     { | |||
|  |                         txtRunName.Label = "装置名称"; | |||
|  |                         txtRunCode.Label = "装置编码"; | |||
|  |                     } | |||
|  |                     else if (deviceModel.PreRunLevel == 2) | |||
|  |                     { | |||
|  |                         txtRunName.Label = "工序名称"; | |||
|  |                         txtRunCode.Label = "工序编码"; | |||
|  |                     } | |||
|  |                     else if (deviceModel.PreRunLevel == 3) | |||
|  |                     { | |||
|  |                         txtRunName.Label = "S系统名称"; | |||
|  |                         txtRunCode.Label = "S系统编码"; | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         txtRunName.Label = "装置名称"; | |||
|  |                         txtRunCode.Label = "装置编码"; | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 保存 | |||
|  |         /// </summary> | |||
|  |         protected void btnSave_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             var model = new PreRun_SysDevice(); | |||
|  |             model.PreRunId = Guid.NewGuid().ToString(); | |||
|  |             var deviceId = string.Empty; | |||
|  |             var processesId = string.Empty; | |||
|  |             var systemIdId = string.Empty; | |||
|  |             if (!string.IsNullOrWhiteSpace(this.RunId)) | |||
|  |             { | |||
|  |                 model = Funs.DB.PreRun_SysDevice.FirstOrDefault(p => p.PreRunId == this.RunId); | |||
|  |             } | |||
|  |             if (model == null) | |||
|  |             { | |||
|  |                 ShowNotify("传递参数错误!", MessageBoxIcon.Error); | |||
|  |                 return; | |||
|  |             } | |||
|  |             model.ProjectId = CurrUser.LoginProjectId; | |||
|  |             if (!string.IsNullOrWhiteSpace(this.ParentId)) | |||
|  |             { | |||
|  |                 var parenLs = GetAllDevices(this.ParentId); | |||
|  |                 if (parenLs.Count > 0) | |||
|  |                 { | |||
|  |                     var oneModel = parenLs.FirstOrDefault(p => p.PreRunLevel == 1); | |||
|  |                     if (oneModel != null) | |||
|  |                     { | |||
|  |                         model.InstallationId = oneModel.PreRunId; | |||
|  |                         model.ParentId = oneModel.PreRunId; | |||
|  |                         model.ProcessesId = model.PreRunId; | |||
|  |                         model.PreRunLevel = 2; | |||
|  |                     } | |||
|  |                     var twoModel = parenLs.FirstOrDefault(p => p.PreRunLevel == 2); | |||
|  |                     if (twoModel != null) | |||
|  |                     { | |||
|  |                         model.ProcessesId = twoModel.PreRunId; | |||
|  |                         model.ParentId = twoModel.PreRunId; | |||
|  |                         model.SystemId = model.PreRunId; | |||
|  |                         model.PreRunLevel = 3; | |||
|  |                     } | |||
|  |                     var threeModel = parenLs.FirstOrDefault(p => p.PreRunLevel == 3); | |||
|  |                     if (threeModel != null) | |||
|  |                     { | |||
|  |                         model.SystemId = threeModel.PreRunId; | |||
|  |                         model.ParentId = threeModel.PreRunId; | |||
|  |                         model.SubsystemId = model.PreRunId; | |||
|  |                         model.PreRunLevel = 4; | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 model.PreRunLevel = 1; | |||
|  |             } | |||
|  |             model.AddUser = CurrUser.Account; | |||
|  |             model.OperateTime = DateTime.Now; | |||
|  |             model.Sort = !string.IsNullOrEmpty(txtSort.Text) ? int.Parse(txtSort.Text) : Funs.DB.PreRun_SysDevice.Count(p => p.ProjectId == CurrUser.LoginProjectId && p.PreRunLevel == model.PreRunLevel) + 1; | |||
|  |             model.PreRunCode = txtRunCode.Text; | |||
|  |             model.PreRunName = txtRunName.Text; | |||
|  |             model.Remark = txtRemark.Text; | |||
|  | 
 | |||
|  |             if (string.IsNullOrWhiteSpace(this.RunId)) | |||
|  |             { | |||
|  |                 if (Funs.DB.PreRun_SysDevice.Count(p => p.PreRunCode == txtRunCode.Text.Trim() && p.ProjectId == this.CurrUser.LoginProjectId) > 0) | |||
|  |                 { | |||
|  |                     ShowNotify($"编码{txtRunCode.Text.Trim()}已存在!", MessageBoxIcon.Error); | |||
|  |                     return; | |||
|  |                 } | |||
|  |                 Funs.DB.PreRun_SysDevice.InsertOnSubmit(model); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 if (Funs.DB.PreRun_SysDevice.Count(p => p.PreRunCode == txtRunCode.Text.Trim() && p.PreRunId != model.PreRunId && p.ProjectId == this.CurrUser.LoginProjectId) > 0) | |||
|  |                 { | |||
|  |                     ShowNotify($"编码{txtRunCode.Text.Trim()}已存在!", MessageBoxIcon.Error); | |||
|  |                     return; | |||
|  |                 } | |||
|  |             } | |||
|  |             Funs.DB.SubmitChanges(); | |||
|  |             ShowNotify("保存成功!", MessageBoxIcon.Success); | |||
|  |             PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); | |||
|  |         } | |||
|  | 
 | |||
|  |         #region 私有方法 | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 根据主键获取所有节点 | |||
|  |         /// </summary> | |||
|  |         /// <returns></returns> | |||
|  |         public List<PreRun_SysDevice> GetAllDevices(string parentId) | |||
|  |         { | |||
|  |             var result = new List<PreRun_SysDevice>(); | |||
|  | 
 | |||
|  |             var ids = new List<string>(); | |||
|  |             var itemDevice = Funs.DB.PreRun_SysDevice.FirstOrDefault(p => p.PreRunId == parentId); | |||
|  |             if (itemDevice != null) | |||
|  |             { | |||
|  |                 ids.Add(itemDevice.PreRunId); | |||
|  |                 if (!string.IsNullOrWhiteSpace(itemDevice.InstallationId)) | |||
|  |                 { | |||
|  |                     ids.Add(itemDevice.InstallationId); | |||
|  |                 } | |||
|  |                 if (!string.IsNullOrWhiteSpace(itemDevice.ProcessesId)) | |||
|  |                 { | |||
|  |                     ids.Add(itemDevice.ProcessesId); | |||
|  |                 } | |||
|  |                 //if (!string.IsNullOrWhiteSpace(itemDevice.SystemId)) | |||
|  |                 //{ | |||
|  |                 //    ids.Add(itemDevice.SystemId); | |||
|  |                 //} | |||
|  |                 result = Funs.DB.PreRun_SysDevice.Where(p => ids.Contains(p.PreRunId)).ToList(); | |||
|  |             } | |||
|  |             return result; | |||
|  |         } | |||
|  | 
 | |||
|  |         #endregion | |||
|  | 
 | |||
|  |     } | |||
|  | } |