using BLL; using System; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.HSSE.Technique { public partial class AwardStandardsEdit : PageBase { #region 定义变量 /// /// 防护标准ID /// public string AwardStandardsId { get { return (string)ViewState["AwardStandardsId"]; } set { ViewState["AwardStandardsId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// 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.AwardStandardsId = Request.Params["AwardStandardsId"]; if (!string.IsNullOrEmpty(this.AwardStandardsId)) { var AwardStandards = BLL.AwardStandardsService.GetAwardStandardsListById(this.AwardStandardsId); if (AwardStandards != null) { this.txtAwardStandardsCode.Text = AwardStandards.AwardStandardsCode; this.txtAwardStandardsName.Text = AwardStandards.AwardStandardsName; this.txtRemark.Text = AwardStandards.Remark; this.dpkCompileDate.Text = string.Format("{0:yyyy-MM-dd}", AwardStandards.CompileDate); if (!string.IsNullOrEmpty(AwardStandards.CompileMan)) { this.ddlCompileMan.SelectedItem.Text = AwardStandards.CompileMan; } } } } } #endregion #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { SaveData(); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } /// /// 保存数据 /// private void SaveData() { Model.Technique_AwardStandards AwardStandards = new Model.Technique_AwardStandards(); if (!string.IsNullOrEmpty(this.txtAwardStandardsCode.Text.Trim())) { AwardStandards.AwardStandardsCode = this.txtAwardStandardsCode.Text.Trim(); } else { ShowNotify("请输入编号", MessageBoxIcon.Warning); return; } if (!string.IsNullOrEmpty(this.txtAwardStandardsName.Text.Trim())) { AwardStandards.AwardStandardsName = this.txtAwardStandardsName.Text.Trim(); } else { ShowNotify("请输入名称", MessageBoxIcon.Warning); return; } if (this.ddlCompileMan.SelectedValue != null) { AwardStandards.CompileMan = this.ddlCompileMan.SelectedItem.Text; } else { AwardStandards.CompileMan = this.CurrUser.UserName; } if (!string.IsNullOrEmpty(this.dpkCompileDate.Text)) { AwardStandards.CompileDate = Convert.ToDateTime(this.dpkCompileDate.Text); } else { AwardStandards.CompileDate = DateTime.Now; } if (txtRemark.Text.Trim() != string.Empty) { AwardStandards.Remark = txtRemark.Text.Trim(); } if (string.IsNullOrEmpty(this.AwardStandardsId)) { AwardStandards.IsPass = true; this.AwardStandardsId = AwardStandards.AwardStandardsId = SQLHelper.GetNewID(typeof(Model.Technique_AwardStandards)); BLL.AwardStandardsService.AddAwardStandardsList(AwardStandards); BLL.LogService.AddSys_Log(this.CurrUser, AwardStandards.AwardStandardsCode, AwardStandards.AwardStandardsId, BLL.Const.AwardStandardsMenuId, Const.BtnAdd); } else { AwardStandards.AwardStandardsId = this.AwardStandardsId; BLL.AwardStandardsService.UpdateAwardStandardsList(AwardStandards); BLL.LogService.AddSys_Log(this.CurrUser, AwardStandards.AwardStandardsCode, AwardStandards.AwardStandardsId, BLL.Const.AwardStandardsMenuId, Const.BtnModify); } } #endregion #region 附件上传 /// /// 上传附件资源 /// /// /// 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/AwardStandards&type=-1", this.AwardStandardsId))); } else { if (string.IsNullOrEmpty(this.txtAwardStandardsCode.Text.Trim())) { ShowNotify("请输入方案编号", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.txtAwardStandardsName.Text.Trim())) { ShowNotify("请输入方案名称", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.AwardStandardsId)) { SaveData(); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/AwardStandards&menuId={1}", this.AwardStandardsId, BLL.Const.AwardStandardsMenuId))); } } #endregion #region 验证方案编号、名称是否存在 /// /// 验证方案编号、名称是否存在 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { var q = Funs.DB.Technique_AwardStandards.FirstOrDefault(x => x.IsPass == true && x.AwardStandardsCode == this.txtAwardStandardsCode.Text.Trim() && (x.AwardStandardsId != this.AwardStandardsId || (this.AwardStandardsId == null && x.AwardStandardsId != null))); if (q != null) { ShowNotify("输入的方案编号已存在!", MessageBoxIcon.Warning); } var q2 = Funs.DB.Technique_AwardStandards.FirstOrDefault(x => x.IsPass == true && x.AwardStandardsName == this.txtAwardStandardsName.Text.Trim() && (x.AwardStandardsId != this.AwardStandardsId || (this.AwardStandardsId == null && x.AwardStandardsId != null))); if (q2 != null) { ShowNotify("输入的方案名称已存在!", MessageBoxIcon.Warning); } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.AwardStandardsMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion } }