Files
SGGL_SHJ/SGGL/FineUIPro.Web/CLGL/AntiCorrosionTrustEdit.aspx.cs
T

240 lines
8.8 KiB
C#
Raw Normal View History

2026-06-15 18:06:19 +08:00
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; }
}
2026-06-15 18:06:19 +08:00
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);
2026-06-15 18:06:19 +08:00
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"]);
2026-06-15 18:06:19 +08:00
BindGrid(new List<AntiCorrosionTrustDetailOutput>());
if (!string.IsNullOrEmpty(Request.Params["TaskCode"]))
{
drpWeldTask.SelectedValue = Request.Params["TaskCode"];
BindGrid(TwAntiCorrosionTrustService.GetDetailsByTaskCode(this.CurrUser.LoginProjectId, Request.Params["TaskCode"]));
}
2026-06-15 18:06:19 +08:00
}
}
private void InitWeldTaskDropDown(string selectedTaskCode)
2026-06-15 18:06:19 +08:00
{
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))
2026-06-15 18:06:19 +08:00
{
drpWeldTask.SelectedValue = selectedTaskCode;
2026-06-15 18:06:19 +08:00
}
}
private void InitPaintCodeEditor()
{
drpPaintCodeEditor.DataTextField = "PaintCode";
drpPaintCodeEditor.DataValueField = "PaintCode";
drpPaintCodeEditor.DataSource = TwAntiCorrosionTrustService.GetPaintCodeList();
drpPaintCodeEditor.DataBind();
Funs.FineUIPleaseSelect(drpPaintCodeEditor);
}
private void BindGrid(List<AntiCorrosionTrustDetailOutput> list)
{
Grid1.DataSource = list;
Grid1.DataBind();
}
protected void drpWeldTask_SelectedIndexChanged(object sender, EventArgs e)
2026-06-15 18:06:19 +08:00
{
if (drpWeldTask.SelectedValue != Const._Null)
2026-06-15 18:06:19 +08:00
{
BindGrid(TwAntiCorrosionTrustService.GetDetailsByTaskCode(this.CurrUser.LoginProjectId, drpWeldTask.SelectedValue));
2026-06-15 18:06:19 +08:00
}
else
{
BindGrid(new List<AntiCorrosionTrustDetailOutput>());
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
var trust = SaveTrust(false);
2026-06-15 18:06:19 +08:00
if (trust == null)
{
return;
}
TrustId = trust.Id;
ShowNotify("保存成功!", MessageBoxIcon.Success);
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
var trust = SaveTrust(true);
2026-06-15 18:06:19 +08:00
if (trust == null)
{
return;
}
TrustId = trust.Id;
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
private AntiCorrosionTrustOutput SaveTrust(bool splitOnSubmit)
2026-06-15 18:06:19 +08:00
{
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)
2026-06-15 18:06:19 +08:00
{
ShowNotify("请选择焊接任务单!", MessageBoxIcon.Warning);
2026-06-15 18:06:19 +08:00
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,
2026-06-15 18:06:19 +08:00
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;
}
2026-06-15 18:06:19 +08:00
}
private List<AntiCorrosionTrustDetailOutput> CollectGridDetailInfo()
{
var result = new List<AntiCorrosionTrustDetailOutput>();
int sortIndex = 0;
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
JObject values = mergedRow.Value<JObject>("values");
sortIndex++;
result.Add(new AntiCorrosionTrustDetailOutput
{
Id = values.Value<string>("Id"),
SortIndex = values.Value<int?>("SortIndex") ?? sortIndex,
2026-06-15 18:06:19 +08:00
MaterialCode = values.Value<string>("MaterialCode"),
Quantity = GetDecimal(values.Value<string>("Quantity")),
PaintCode = values.Value<string>("PaintCode"),
IsPostWeld = values.Value<bool?>("IsPostWeld") ?? false,
2026-06-15 18:06:19 +08:00
Remark = values.Value<string>("Remark")
});
}
return result;
}
private decimal? GetDecimal(string value)
{
decimal result;
if (decimal.TryParse(value, out result))
{
return result;
}
return null;
}
}
}