using BLL; using Model; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; namespace FineUIPro.Web.CLGL { public partial class AntiCorrosionTrustEdit : PageBase { public string TrustId { get { return (string)ViewState["TrustId"]; } set { ViewState["TrustId"] = value; } } public string UnitWorkId { get { return (string)ViewState["UnitWorkId"]; } set { ViewState["UnitWorkId"] = value; } } public string HotProessTrustId { get { return (string)ViewState["HotProessTrustId"]; } set { ViewState["HotProessTrustId"] = value; } } public string PaintCodeJson { get { var list = TwAntiCorrosionTrustService.GetPaintCodeList(); return JsonConvert.SerializeObject(list); } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { TrustId = Request.Params["Id"]; InitPaintCodeEditor(); PageInfoLoad(); } } private void PageInfoLoad() { var trust = TwAntiCorrosionTrustService.GetById(TrustId); if (trust != null) { UnitWorkId = trust.UnitWorkId; txtUnitWorkName.Text = trust.UnitWorkName; txtConstructionPart.Text = trust.ConstructionPart; txtConstructionProfessional.Text = trust.ConstructionProfessional; txtTrustCode.Text = trust.TrustCode; txtDemandDate.Text = string.Format("{0:yyyy-MM-dd}", trust.DemandDate); txtCompleteDate.Text = string.Format("{0:yyyy-MM-dd}", trust.CompleteDate); txtRemark.Text = trust.Remark; HotProessTrustId = trust.HotProessTrustId; InitWeldTaskDropDown(trust.WeldTaskCode); BindGrid(TwAntiCorrosionTrustService.GetDetailList(TrustId)); } else { UnitWorkId = Request.Params["UnitWorkId"]; var unitWork = UnitWorkService.GetUnitWorkByUnitWorkId(UnitWorkId); if (unitWork != null) { txtUnitWorkName.Text = unitWork.UnitWorkName; } txtTrustCode.Text = TwAntiCorrosionTrustService.GenerateTrustCode(UnitWorkId); InitWeldTaskDropDown(Request.Params["TaskCode"]); BindGrid(new List()); if (!string.IsNullOrEmpty(Request.Params["TaskCode"])) { drpWeldTask.SelectedValue = Request.Params["TaskCode"]; BindGrid(TwAntiCorrosionTrustService.GetDetailsByTaskCode(this.CurrUser.LoginProjectId, Request.Params["TaskCode"])); } } } private void InitWeldTaskDropDown(string selectedTaskCode) { drpWeldTask.DataTextField = "Text"; drpWeldTask.DataValueField = "TaskCode"; var list = TwAntiCorrosionTrustService.GetAvailableWeldTasks(this.CurrUser.LoginProjectId, UnitWorkId, TrustId) .Select(x => new { x.TaskCode, Text = x.TaskCode + "(" + x.TeamGroupName + ")" }).ToList(); drpWeldTask.DataSource = list; drpWeldTask.DataBind(); Funs.FineUIPleaseSelect(drpWeldTask); if (!string.IsNullOrEmpty(selectedTaskCode)) { drpWeldTask.SelectedValue = selectedTaskCode; } } private void InitPaintCodeEditor() { drpPaintCodeEditor.DataTextField = "PaintCode"; drpPaintCodeEditor.DataValueField = "PaintCode"; drpPaintCodeEditor.DataSource = TwAntiCorrosionTrustService.GetPaintCodeList(); drpPaintCodeEditor.DataBind(); Funs.FineUIPleaseSelect(drpPaintCodeEditor); } private void BindGrid(List list) { Grid1.DataSource = list; Grid1.DataBind(); } protected void drpWeldTask_SelectedIndexChanged(object sender, EventArgs e) { if (drpWeldTask.SelectedValue != Const._Null) { BindGrid(TwAntiCorrosionTrustService.GetDetailsByTaskCode(this.CurrUser.LoginProjectId, drpWeldTask.SelectedValue)); } else { BindGrid(new List()); } } protected void btnSave_Click(object sender, EventArgs e) { var trust = SaveTrust(false); if (trust == null) { return; } TrustId = trust.Id; ShowNotify("保存成功!", MessageBoxIcon.Success); } protected void btnSubmit_Click(object sender, EventArgs e) { var trust = SaveTrust(true); if (trust == null) { return; } TrustId = trust.Id; PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } private AntiCorrosionTrustOutput SaveTrust(bool splitOnSubmit) { if (!CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.Tw_AntiCorrosionTrustMenuId, Const.BtnSave)) { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return null; } if (string.IsNullOrEmpty(TrustId) && string.IsNullOrEmpty(HotProessTrustId) && drpWeldTask.SelectedValue == Const._Null) { ShowNotify("请选择焊接任务单!", MessageBoxIcon.Warning); return null; } if (TwAntiCorrosionTrustService.IsExistTrustCode(txtTrustCode.Text.Trim(), TrustId, this.CurrUser.LoginProjectId)) { ShowNotify("委托单编号已存在,请重新生成!", MessageBoxIcon.Warning); return null; } var trust = new AntiCorrosionTrustOutput { Id = TrustId, ProjectId = this.CurrUser.LoginProjectId, UnitWorkId = UnitWorkId, ConstructionPart = txtConstructionPart.Text.Trim(), ConstructionProfessional = txtConstructionProfessional.Text.Trim(), TrustCode = txtTrustCode.Text.Trim(), WeldTaskCode = drpWeldTask.SelectedValue == Const._Null ? null : drpWeldTask.SelectedValue, HotProessTrustId = HotProessTrustId, DemandDate = Funs.GetNewDateTime(txtDemandDate.Text.Trim()), CompleteDate = Funs.GetNewDateTime(txtCompleteDate.Text.Trim()), CreateMan = this.CurrUser.PersonId, Remark = txtRemark.Text.Trim() }; var details = CollectGridDetailInfo(); if (details.Count == 0) { ShowNotify("防腐委托单明细不能为空!", MessageBoxIcon.Warning); return null; } try { TwAntiCorrosionTrustService.Save(trust, details, splitOnSubmit); return trust; } catch (ArgumentException ex) { ShowNotify(ex.Message, MessageBoxIcon.Warning); return null; } } private List CollectGridDetailInfo() { var result = new List(); int sortIndex = 0; JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { JObject values = mergedRow.Value("values"); sortIndex++; result.Add(new AntiCorrosionTrustDetailOutput { Id = values.Value("Id"), SortIndex = values.Value("SortIndex") ?? sortIndex, MaterialCode = values.Value("MaterialCode"), Quantity = GetDecimal(values.Value("Quantity")), PaintCode = values.Value("PaintCode"), IsPostWeld = values.Value("IsPostWeld") ?? false, Remark = values.Value("Remark") }); } return result; } private decimal? GetDecimal(string value) { decimal result; if (decimal.TryParse(value, out result)) { return result; } return null; } } }