SGGL_HBAZ/SGGL/FineUIPro.Web/HSSE/Technique/ProtectionStandardsEdit.asp...

223 lines
8.9 KiB
C#

using BLL;
using System;
using System.Linq;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.Technique
{
public partial class ProtectionStandardsEdit : PageBase
{
#region
/// <summary>
/// 防护标准ID
/// </summary>
public string ProtectionStandardsId
{
get
{
return (string)ViewState["ProtectionStandardsId"];
}
set
{
ViewState["ProtectionStandardsId"] = 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();
//人员
UserService.InitUserDropDownList(this.ddlCompileMan, string.Empty, true);
//加载默认整理人、整理日期
this.ddlCompileMan.SelectedValue = this.CurrUser.UserId;
this.dpkCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
this.ProtectionStandardsId = Request.Params["ProtectionStandardsId"];
if (!string.IsNullOrEmpty(this.ProtectionStandardsId))
{
var ProtectionStandards = BLL.ProtectionStandardsService.GetProtectionStandardsListById(this.ProtectionStandardsId);
if (ProtectionStandards != null)
{
this.txtProtectionStandardsCode.Text = ProtectionStandards.ProtectionStandardsCode;
this.txtProtectionStandardsName.Text = ProtectionStandards.ProtectionStandardsName;
this.txtRemark.Text = ProtectionStandards.Remark;
this.dpkCompileDate.Text = string.Format("{0:yyyy-MM-dd}", ProtectionStandards.CompileDate);
if (!string.IsNullOrEmpty(ProtectionStandards.CompileMan))
{
this.ddlCompileMan.SelectedItem.Text = ProtectionStandards.CompileMan;
}
}
}
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
SaveData();
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
/// <summary>
/// 保存数据
/// </summary>
private void SaveData()
{
Model.Technique_ProtectionStandards ProtectionStandards = new Model.Technique_ProtectionStandards();
if (!string.IsNullOrEmpty(this.txtProtectionStandardsCode.Text.Trim()))
{
ProtectionStandards.ProtectionStandardsCode = this.txtProtectionStandardsCode.Text.Trim();
}
else
{
ShowNotify("请输入编号", MessageBoxIcon.Warning);
return;
}
if (!string.IsNullOrEmpty(this.txtProtectionStandardsName.Text.Trim()))
{
ProtectionStandards.ProtectionStandardsName = this.txtProtectionStandardsName.Text.Trim();
}
else
{
ShowNotify("请输入名称", MessageBoxIcon.Warning);
return;
}
if (this.ddlCompileMan.SelectedValue != null)
{
ProtectionStandards.CompileMan = this.ddlCompileMan.SelectedItem.Text;
}
else
{
ProtectionStandards.CompileMan = this.CurrUser.UserName;
}
if (!string.IsNullOrEmpty(this.dpkCompileDate.Text))
{
ProtectionStandards.CompileDate = Convert.ToDateTime(this.dpkCompileDate.Text);
}
else
{
ProtectionStandards.CompileDate = DateTime.Now;
}
if (txtRemark.Text.Trim() != string.Empty)
{
ProtectionStandards.Remark = txtRemark.Text.Trim();
}
if (string.IsNullOrEmpty(this.ProtectionStandardsId))
{
ProtectionStandards.IsPass = true;
this.ProtectionStandardsId = ProtectionStandards.ProtectionStandardsId = SQLHelper.GetNewID(typeof(Model.Technique_ProtectionStandards));
BLL.ProtectionStandardsService.AddProtectionStandardsList(ProtectionStandards);
BLL.LogService.AddSys_Log(this.CurrUser, ProtectionStandards.ProtectionStandardsCode, ProtectionStandards.ProtectionStandardsId, BLL.Const.ProtectionStandardsMenuId, Const.BtnAdd);
}
else
{
ProtectionStandards.ProtectionStandardsId = this.ProtectionStandardsId;
BLL.ProtectionStandardsService.UpdateProtectionStandardsList(ProtectionStandards);
BLL.LogService.AddSys_Log(this.CurrUser, ProtectionStandards.ProtectionStandardsCode, ProtectionStandards.ProtectionStandardsId, BLL.Const.ProtectionStandardsMenuId, Const.BtnModify);
}
}
#endregion
#region
/// <summary>
/// 上传附件资源
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnUploadResources_Click(object sender, EventArgs e)
{
if (this.btnSave.Hidden)
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/ProtectionStandards&type=-1", this.ProtectionStandardsId)));
}
else
{
if (string.IsNullOrEmpty(this.txtProtectionStandardsCode.Text.Trim()))
{
ShowNotify("请输入方案编号", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.txtProtectionStandardsName.Text.Trim()))
{
ShowNotify("请输入方案名称", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.ProtectionStandardsId))
{
SaveData();
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/ProtectionStandards&menuId={1}", this.ProtectionStandardsId, BLL.Const.ProtectionStandardsMenuId)));
}
}
#endregion
#region
/// <summary>
/// 验证方案编号、名称是否存在
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
var q = Funs.DB.Technique_ProtectionStandards.FirstOrDefault(x => x.IsPass == true && x.ProtectionStandardsCode == this.txtProtectionStandardsCode.Text.Trim() && (x.ProtectionStandardsId != this.ProtectionStandardsId || (this.ProtectionStandardsId == null && x.ProtectionStandardsId != null)));
if (q != null)
{
ShowNotify("输入的方案编号已存在!", MessageBoxIcon.Warning);
}
var q2 = Funs.DB.Technique_ProtectionStandards.FirstOrDefault(x => x.IsPass == true && x.ProtectionStandardsName == this.txtProtectionStandardsName.Text.Trim() && (x.ProtectionStandardsId != this.ProtectionStandardsId || (this.ProtectionStandardsId == null && x.ProtectionStandardsId != null)));
if (q2 != null)
{
ShowNotify("输入的方案名称已存在!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ProtectionStandardsMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
}
}
}
#endregion
}
}