SGGL_SHJ/SGGL/FineUIPro.Web/HJGL/BaseInfo/WeldingLocationEdit.aspx.cs

107 lines
4.1 KiB
C#
Raw Normal View History

2022-09-05 16:36:31 +08:00
using BLL;
using System;
using System.Linq;
namespace FineUIPro.Web.HJGL.BaseInfo
{
public partial class WeldingLocationEdit : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtWeldingLocationCode.Focus();
btnClose.OnClientClick = ActiveWindow.GetHideReference();
string WeldingLocationId = Request.Params["WeldingLocationId"];
if (!string.IsNullOrEmpty(WeldingLocationId))
{
Model.Base_WeldingLocation WeldingLocation = BLL.Base_WeldingLocationServie.GetWeldingLocationById(WeldingLocationId);
if (WeldingLocation != null)
{
this.txtWeldingLocationCode.Text = WeldingLocation.WeldingLocationCode;
this.txtWeldingLocationName.Text = WeldingLocation.WeldingLocationName;
this.txtRemark.Text = WeldingLocation.Remark;
}
}
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
string WeldingLocationId = Request.Params["WeldingLocationId"];
2025-09-24 17:31:28 +08:00
string code = this.txtWeldingLocationCode.Text.Trim();
string name = this.txtWeldingLocationName.Text.Trim();
// 判断是否为编辑场景id 不为空)
if (!string.IsNullOrEmpty(WeldingLocationId))
2022-09-05 16:36:31 +08:00
{
2025-09-24 17:31:28 +08:00
var q = Funs.DB.Base_WeldingLocation.FirstOrDefault(x => x.WeldingLocationCode == code && x.WeldingLocationId != WeldingLocationId);
if (q != null)
{
Alert.ShowInTop("此位置代号已存在!", MessageBoxIcon.Warning);
return;
}
2022-09-05 16:36:31 +08:00
2025-09-24 17:31:28 +08:00
var q2 = Funs.DB.Base_WeldingLocation.FirstOrDefault(x => x.WeldingLocationName == name && x.WeldingLocationId != WeldingLocationId);
if (q2 != null)
{
Alert.ShowInTop("此位置名称已存在!", MessageBoxIcon.Warning);
return;
}
}
else
2022-09-05 16:36:31 +08:00
{
2025-09-24 17:31:28 +08:00
// 新增场景:只需判断是否存在相同的 code 或 name
var q = Funs.DB.Base_WeldingLocation.FirstOrDefault(x => x.WeldingLocationCode == code);
if (q != null)
{
Alert.ShowInTop("此位置代号已存在!", MessageBoxIcon.Warning);
return;
}
var q2 = Funs.DB.Base_WeldingLocation.FirstOrDefault(x => x.WeldingLocationName == name);
if (q2 != null)
{
Alert.ShowInTop("此位置名称已存在!", MessageBoxIcon.Warning);
return;
}
2022-09-05 16:36:31 +08:00
}
Model.Base_WeldingLocation newWeldingLocation = new Model.Base_WeldingLocation
{
2025-09-24 17:31:28 +08:00
WeldingLocationCode = code,
WeldingLocationName = name,
2022-09-05 16:36:31 +08:00
Remark = this.txtRemark.Text.Trim()
};
if (!string.IsNullOrEmpty(WeldingLocationId))
{
newWeldingLocation.WeldingLocationId = WeldingLocationId;
BLL.Base_WeldingLocationServie.UpdateWeldingLocation(newWeldingLocation);
}
else
{
newWeldingLocation.WeldingLocationId = SQLHelper.GetNewID(typeof(Model.Base_WeldingLocation));
BLL.Base_WeldingLocationServie.AddWeldingLocation(newWeldingLocation);
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
}
}