Files
SGGL_SHJ/SGGL/FineUIPro.Web/HJGL/DataImport/MaterialInformationEdit.aspx.cs
T
2026-07-26 17:52:46 +08:00

126 lines
4.6 KiB
C#

using BLL;
using System;
using System.Linq;
namespace FineUIPro.Web.HJGL.DataImport
{
public partial class MaterialInformationEdit : PageBase
{
/// <summary>
/// 管线材料ID。
/// </summary>
public string PipeLineMatId
{
get
{
return (string)ViewState["PipeLineMatId"];
}
set
{
ViewState["PipeLineMatId"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
this.txtHeatNo.Readonly = true;
this.txtBatchNo.Readonly = true;
if (!IsPostBack)
{
btnClose.OnClientClick = ActiveWindow.GetHideReference();
this.PipeLineMatId = Request.Params["PipeLineMatId"];
BindMainMaterialCodes();
Model.HJGL_PipeLineMat pipeLineMat = PipelineMatService.GetPipeLineMat(this.PipeLineMatId);
if (pipeLineMat == null)
{
Alert.ShowInTop("未找到材料记录!", MessageBoxIcon.Warning);
return;
}
this.drpMainMaterialCode.SelectedValue = string.IsNullOrEmpty(pipeLineMat.MaterialCode)
? Const._Null
: pipeLineMat.MaterialCode;
this.txtMaterialCode.Text = pipeLineMat.MaterialCode2;
BindMaterialDetails(pipeLineMat.MaterialCode, false);
}
}
/// <summary>
/// 绑定材料主编码,下拉框保留空选项以支持解除材料主数据关联。
/// </summary>
private void BindMainMaterialCodes()
{
this.drpMainMaterialCode.DataTextField = "MaterialCode";
this.drpMainMaterialCode.DataValueField = "MaterialCode";
this.drpMainMaterialCode.DataSource = MaterialCodeLibService.GetMaterialCodeLibList()
.OrderBy(x => x.MaterialCode)
.ToList();
this.drpMainMaterialCode.DataBind();
Funs.FineUIPleaseSelect(this.drpMainMaterialCode, "-请选择-");
}
/// <summary>
/// 材料主编码变化后同步其材料编码、炉号和批号。
/// </summary>
protected void drpMainMaterialCode_SelectedIndexChanged(object sender, EventArgs e)
{
BindMaterialDetails(GetMainMaterialCode(), true);
}
/// <summary>
/// 按材料主编码填充关联信息;清空选择时同步清空联动字段。
/// </summary>
private void BindMaterialDetails(string mainMaterialCode, bool updateMaterialCode)
{
Model.HJGL_MaterialCodeLib material = string.IsNullOrEmpty(mainMaterialCode)
? null
: MaterialCodeLibService.GetMaterialCodeLib(mainMaterialCode);
if (updateMaterialCode)
{
this.txtMaterialCode.Text = material == null ? string.Empty : material.Code;
}
this.txtHeatNo.Text = material == null ? string.Empty : material.HeatNo;
this.txtBatchNo.Text = material == null ? string.Empty : material.BatchNo;
}
/// <summary>
/// 将下拉框的“请选择”值转换为数据库可保存的空值。
/// </summary>
private string GetMainMaterialCode()
{
string value = this.drpMainMaterialCode.SelectedValue;
return string.IsNullOrEmpty(value) || value == Const._Null ? null : value.Trim();
}
/// <summary>
/// 保存材料主编码和材料编码。
/// </summary>
protected void btnSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.PipeLineMatId))
{
Alert.ShowInTop("未找到材料记录!", MessageBoxIcon.Warning);
return;
}
string mainMaterialCode = GetMainMaterialCode();
if (!string.IsNullOrEmpty(mainMaterialCode) && MaterialCodeLibService.GetMaterialCodeLib(mainMaterialCode) == null)
{
Alert.ShowInTop("所选材料主编码不存在,请重新选择!", MessageBoxIcon.Warning);
return;
}
PipelineMatService.UpdateMaterialCodes(
this.PipeLineMatId,
mainMaterialCode,
this.txtMaterialCode.Text.Trim());
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
}
}