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

240 lines
8.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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<AntiCorrosionTrustDetailOutput>());
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<AntiCorrosionTrustDetailOutput> 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<AntiCorrosionTrustDetailOutput>());
}
}
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<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,
MaterialCode = values.Value<string>("MaterialCode"),
Quantity = GetDecimal(values.Value<string>("Quantity")),
PaintCode = values.Value<string>("PaintCode"),
IsPostWeld = values.Value<bool?>("IsPostWeld") ?? false,
Remark = values.Value<string>("Remark")
});
}
return result;
}
private decimal? GetDecimal(string value)
{
decimal result;
if (decimal.TryParse(value, out result))
{
return result;
}
return null;
}
}
}