using System; using System.Linq; using Model; using BLL; using System.Collections.Generic; using Microsoft.Office.Interop.Excel; namespace FineUIPro.Web.BaseInfo { public partial class SafetyProblemClassifyItemSave : PageBase { #region 定义变量 /// /// 主键 /// public string ClassifyItemId { get { return (string)ViewState["ClassifyItemId"]; } set { ViewState["ClassifyItemId"] = value; } } /// /// 主表主键 /// public string ClassifyId { get { return (string)ViewState["ClassifyId"]; } set { ViewState["ClassifyId"] = value; } } #endregion #region 加载页面 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetButtonPower(); btnClose.OnClientClick = ActiveWindow.GetHideReference(); this.ClassifyItemId = Request.QueryString["ClassifyItemId"]; this.ClassifyId = Request.QueryString["ClassifyId"]; if (!string.IsNullOrEmpty(this.ClassifyItemId)) { var model = SafetyProblemClassifyItemService.GetClassifyItemById(this.ClassifyItemId); if (model != null) { this.ClassifyId = model.ClassifyId; this.txtClassifyItemCode.Text = model.ClassifyItemCode; this.txtClassifyItemName.Text = model.ClassifyItemName; this.txtCompileMan.Text = model.CompileManName; if (model.CompileDate != null) { txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", model.CompileDate); } } } else { this.txtCompileMan.Text = this.CurrUser.UserName; //this.txtClassifyItemName.Text = model.ClassifyName; //this.txtClassifyItemCode.Text = SQLHelper.RunProcNewId("SpGetNewCode3", "Base_SafetyProblemClassifyItem", "ClassifyItemCode", model.ClassifyItemCode + "-"); this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); } } } #endregion #region 保存 /// /// 保存数据 /// private void SaveData(bool isClose) { Model.Base_SafetyProblemClassifyItem newModel = new Base_SafetyProblemClassifyItem { ClassifyId = this.ClassifyId, ClassifyItemCode = this.txtClassifyItemCode.Text.Trim(), ClassifyItemName = this.txtClassifyItemName.Text.Trim(), CompileMan = this.CurrUser.UserId, CompileManName = this.CurrUser.UserName, }; if (!string.IsNullOrEmpty(txtCompileDate.Text.Trim())) { newModel.CompileDate = Convert.ToDateTime(txtCompileDate.Text.Trim()); } if (!string.IsNullOrEmpty(this.ClassifyItemId)) { newModel.ClassifyItemId = this.ClassifyItemId; BLL.SafetyProblemClassifyItemService.UpdateClassifyItem(newModel); BLL.LogService.AddSys_Log(this.CurrUser, newModel.ClassifyItemCode, newModel.ClassifyItemId, BLL.Const.SafetyProblemClassifyMenuId, BLL.Const.BtnModify); } else { this.ClassifyItemId = SQLHelper.GetNewID(typeof(Model.Base_SafetyProblemClassifyItem)); newModel.ClassifyItemId = this.ClassifyItemId; BLL.SafetyProblemClassifyItemService.AddClassifyItem(newModel); BLL.LogService.AddSys_Log(this.CurrUser, newModel.ClassifyItemCode, newModel.ClassifyItemId, BLL.Const.SafetyProblemClassifyMenuId, BLL.Const.BtnAdd); } if (isClose) { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { SaveData(true); } #endregion #region 验证安全问题分类是否存在 /// /// 验证安全问题分类是否存在 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { var q = Funs.DB.Base_SafetyProblemClassifyItem.FirstOrDefault(x => x.ClassifyId == this.ClassifyId && x.ClassifyItemCode == this.txtClassifyItemCode.Text.Trim() && (x.ClassifyItemId != this.ClassifyItemId || (this.ClassifyItemId == null && x.ClassifyItemId != null))); if (q != null) { ShowNotify("输入的安全问题分类编号已存在!", MessageBoxIcon.Warning); } var q2 = Funs.DB.Base_SafetyProblemClassifyItem.FirstOrDefault(x => x.ClassifyId == this.ClassifyId && x.ClassifyItemName == this.txtClassifyItemName.Text.Trim() && (x.ClassifyItemId != this.ClassifyItemId || (this.ClassifyItemId == null && x.ClassifyItemId != 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.SafetyProblemClassifyMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion } }