using BLL; using System; using System.Collections.Generic; using System.Data; using System.Linq; namespace FineUIPro.Web.Transfer { public partial class ElectricalEdit : PageBase { #region 定义项 /// /// 主键 /// private string Id { get { return (string)ViewState["Id"]; } set { ViewState["Id"] = value; } } /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Id = Request.Params["Id"]; ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(Id)) { var model = Funs.DB.Transfer_Electrical.FirstOrDefault(x => x.Id == Id); if (model != null) { txtELECTRICAL.Text = model.ELECTRICAL; txtSystemName.Text = model.SystemName; txtSubsystem.Text = model.Subsystem; txtTest_Package.Text = model.Test_Package; ddlInstallation.SelectedValue = model.Installation; ddlCommunicationtest.SelectedValue = model.Communicationtest; ddlCableLaying.SelectedValue = model.CableLaying; ddlLoopTest.SelectedValue = model.LoopTest; txtDescriptions.Text = model.Descriptions; } } } } protected void btnSave_Click(object sender, EventArgs e) { var model = new Model.Transfer_Electrical { ProjectId = ProjectId, ELECTRICAL = txtELECTRICAL.Text, SystemName = txtSystemName.Text, Subsystem = txtSubsystem.Text, Test_Package = txtTest_Package.Text, Installation = ddlInstallation.SelectedValue, Communicationtest = ddlCommunicationtest.SelectedValue, CableLaying = ddlCableLaying.SelectedValue, LoopTest = ddlLoopTest.SelectedValue, Descriptions= txtDescriptions.Text }; #region 判断状态 var listObj = new List(); listObj.Add(model.Installation); listObj.Add(model.Communicationtest); listObj.Add(model.CableLaying); listObj.Add(model.LoopTest); //全是NA或Completed 状态是Completed if (listObj.Where(x => x == "NA" || x == "Completed").ToList().Count == 4) { model.FINAL_Status = "Completed"; } //如果全是Not Start 就是 Not Start else if (listObj.Where(x => x == "Not Start").ToList().Count == 4) { model.FINAL_Status = "Not Start"; } //如果其中有一项是In progress 或Not Start 是 In progress else if (listObj.Where(x => x == "In progress" || x == "Not Start").ToList().Count >= 1) { model.FINAL_Status = "In progress"; } #endregion if (!string.IsNullOrEmpty(Id)) { var newModel = Funs.DB.Transfer_Electrical.FirstOrDefault(x => x.Id == Id); if (newModel != null) { newModel.ELECTRICAL = txtELECTRICAL.Text; newModel.SystemName = txtSystemName.Text; newModel.Subsystem = txtSubsystem.Text; newModel.Test_Package = txtTest_Package.Text; newModel.Installation = ddlInstallation.SelectedValue; newModel.Communicationtest = ddlCommunicationtest.SelectedValue; newModel.CableLaying = ddlCommunicationtest.SelectedValue; newModel.LoopTest = ddlLoopTest.SelectedValue; newModel.FINAL_Status = model.FINAL_Status; newModel.Descriptions = txtDescriptions.Text; } } else { model.Id = Id = Guid.NewGuid().ToString(); Funs.DB.Transfer_Electrical.InsertOnSubmit(model); } Funs.DB.SubmitChanges(); ShowNotify("保存成功", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } }