CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/HSSE/Hazard/OtherHazardEdit.aspx.cs

150 lines
5.8 KiB
C#

using BLL;
using System;
namespace FineUIPro.Web.HSSE.Hazard
{
public partial class OtherHazardEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string OtherHazardId
{
get
{
return (string)ViewState["OtherHazardId"];
}
set
{
ViewState["OtherHazardId"] = value;
}
}
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ProjectId = this.CurrUser.LoginProjectId;
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
this.OtherHazardId = Request.Params["OtherHazardId"];
var otherHazard = BLL.Hazard_OtherHazardService.GetOtherHazardByOtherHazardId(this.OtherHazardId);
if (otherHazard != null)
{
this.ProjectId = otherHazard.ProjectId;
this.txtOtherHazardCode.Text = BLL.CodeRecordsService.ReturnCodeByDataId(this.OtherHazardId);
this.txtOtherHazardName.Text = otherHazard.OtherHazardName;
this.txtCompileMan.Text = BLL.UserService.GetUserNameByUserId(otherHazard.CompileMan);
this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", otherHazard.CompileDate);
}
else
{
////自动生成编码
this.txtOtherHazardCode.Text = BLL.CodeRecordsService.ReturnCodeByMenuIdProjectId(BLL.Const.OtherHazardMenuId, this.ProjectId, this.CurrUser.UnitId);
this.txtCompileMan.Text = this.CurrUser.UserName;
this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
this.SaveData(BLL.Const.BtnSave);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
/// <summary>
/// 保存数据
/// </summary>
/// <param name="type"></param>
private void SaveData(string type)
{
Model.Hazard_OtherHazard otherHazard = new Model.Hazard_OtherHazard
{
OtherHazardCode = this.txtOtherHazardCode.Text.Trim(),
OtherHazardName = this.txtOtherHazardName.Text.Trim(),
CompileDate = Funs.GetNewDateTime(this.txtCompileDate.Text.Trim()),
ProjectId = this.ProjectId,
////单据状态
States = BLL.Const.State_2
};
if (!string.IsNullOrEmpty(this.OtherHazardId))
{
otherHazard.OtherHazardId = this.OtherHazardId;
BLL.Hazard_OtherHazardService.UpdateOtherHazard(otherHazard);
BLL.LogService.AddSys_Log(this.CurrUser, otherHazard.OtherHazardCode, otherHazard.OtherHazardId, BLL.Const.OtherHazardMenuId, BLL.Const.BtnModify);
}
else
{
otherHazard.OtherHazardId = SQLHelper.GetNewID(typeof(Model.Hazard_OtherHazard));
otherHazard.CompileMan = this.CurrUser.UserId;
this.OtherHazardId = otherHazard.OtherHazardId;
BLL.Hazard_OtherHazardService.AddOtherHazard(otherHazard);
BLL.LogService.AddSys_Log(this.CurrUser, otherHazard.OtherHazardCode, otherHazard.OtherHazardId, BLL.Const.OtherHazardMenuId, BLL.Const.BtnAdd);
}
}
private void SaveNew()
{
Model.Hazard_OtherHazard otherHazard = new Model.Hazard_OtherHazard
{
OtherHazardCode = this.txtOtherHazardCode.Text.Trim(),
OtherHazardName = this.txtOtherHazardName.Text.Trim(),
CompileDate = Funs.GetNewDateTime(this.txtCompileDate.Text.Trim()),
ProjectId = this.ProjectId,
////单据状态
States = BLL.Const.State_0,
OtherHazardId = SQLHelper.GetNewID(typeof(Model.Hazard_OtherHazard)),
CompileMan = this.CurrUser.UserId
};
this.OtherHazardId = otherHazard.OtherHazardId;
BLL.Hazard_OtherHazardService.AddOtherHazard(otherHazard);
BLL.LogService.AddSys_Log(this.CurrUser, otherHazard.OtherHazardCode, otherHazard.OtherHazardId, BLL.Const.OtherHazardMenuId, BLL.Const.BtnAdd);
}
#endregion
#region
/// <summary>
/// 上传附件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.OtherHazardId))
{
SaveNew();
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/OtherHazard&menuId={1}", this.OtherHazardId, BLL.Const.OtherHazardMenuId)));
}
#endregion
}
}