xinjiang/SGGL/FineUIPro.Web/BaseInfo/SafetyProblemNatureSave.asp...

132 lines
4.6 KiB
C#

using System;
using System.Linq;
using BLL;
namespace FineUIPro.Web.BaseInfo
{
public partial class SafetyProblemNatureSave : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string NatureId
{
get
{
return (string)ViewState["NatureId"];
}
set
{
ViewState["NatureId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetButtonPower();
btnClose.OnClientClick = ActiveWindow.GetHideReference();
this.NatureId = Request.QueryString["NatureId"];
if (!string.IsNullOrEmpty(NatureId))
{
var q = BLL.SafetyProblemNatureService.GetNatureById(NatureId);
if (q != null)
{
this.txtNatureCode.Text = q.NatureCode;
this.txtNatureName.Text = q.NatureName;
}
}
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
var obj = Funs.DB.Base_SafetyProblemNature.FirstOrDefault(x => x.NatureCode == this.txtNatureCode.Text.Trim() && x.NatureId != this.NatureId);
if (obj != null)
{
ShowNotify("输入的编号已存在!", MessageBoxIcon.Warning);
return;
}
obj = Funs.DB.Base_SafetyProblemNature.FirstOrDefault(x => x.NatureName == this.txtNatureName.Text.Trim() && x.NatureId != this.NatureId);
if (obj != null)
{
ShowNotify("输入的名称已存在!", MessageBoxIcon.Warning);
return;
}
Model.Base_SafetyProblemNature model = new Model.Base_SafetyProblemNature();
model.NatureCode = this.txtNatureCode.Text.Trim();
model.NatureName = this.txtNatureName.Text.Trim();
if (!string.IsNullOrEmpty(this.NatureId))
{
model.NatureId = this.NatureId;
BLL.SafetyProblemNatureService.UpdateNature(model);
}
else
{
this.NatureId = SQLHelper.GetNewID(typeof(Model.Base_SafetyProblemNature));
model.NatureId = this.NatureId;
BLL.SafetyProblemNatureService.AddNature(model);
}
// 2. 关闭本窗体,然后刷新父窗体
// PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
// 2. 关闭本窗体,然后回发父窗体
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
//PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(trainingId) + ActiveWindow.GetHideReference());
}
#endregion
#region
/// <summary>
/// 验证安全问题性质名称是否存在
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
var model = Funs.DB.Base_SafetyProblemNature.FirstOrDefault(x => x.NatureName == this.txtNatureName.Text.Trim() && (x.NatureId != this.NatureId || this.NatureId == null));
if (model != null)
{
ShowNotify("输入的名称已存在!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SafetyProblemNatureMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
}
}
}
#endregion
}
}