using System; using System.Linq; using BLL; namespace FineUIPro.Web.PublicInfo.FileControl { public partial class DomesticStandardsEdit : PageBase { #region 定义变量 /// /// 主键 /// private string DomesticStandardsId { get { return (string)ViewState["DomesticStandardsId"]; } set { ViewState["DomesticStandardsId"] = value; } } #endregion #region 加载 /// ///加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); //整理人 this.drpCompileMan.DataTextField = "UserName"; this.drpCompileMan.DataValueField = "UserId"; this.drpCompileMan.DataSource = BLL.Sys_UserService.GetUserList(); this.drpCompileMan.DataBind(); Funs.FineUIPleaseSelect(this.drpCompileMan, Resources.Lan.PleaseSelect); this.DomesticStandardsId = Request.Params["DomesticStandardsId"]; if (!string.IsNullOrEmpty(this.DomesticStandardsId)) { Model.FileControl_DomesticStandards domesticStandards = BLL.FileControl_DomesticStandardsService.GetDomesticStandardsById(this.DomesticStandardsId); if (domesticStandards != null) { this.txtDomesticStandardsCode.Text = domesticStandards.DomesticStandardsCode; this.txtDomesticStandardsName.Text = domesticStandards.DomesticStandardsName; this.txtAbstract.Text = domesticStandards.Abstract; if (!string.IsNullOrEmpty(domesticStandards.CompileMan)) { this.drpCompileMan.SelectedValue = domesticStandards.CompileMan; } if (domesticStandards.CompileDate.HasValue) { this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", domesticStandards.CompileDate); } this.txtRemark.Text = domesticStandards.Remarks; } } else { this.drpCompileMan.SelectedValue = this.CurrUser.UserId; this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); } } } #endregion #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.DomesticStandardsMenuId, Const.BtnSave)) { SaveData("1");//保存方法 } else { Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); return; } } /// /// 保存方法 /// private void SaveData(string state) { //判断编号是否存在 var q1 = Funs.DB.FileControl_DomesticStandards.FirstOrDefault(x => x.DomesticStandardsCode == this.txtDomesticStandardsCode.Text.Trim() && (x.DomesticStandardsId.ToString() != this.DomesticStandardsId || (this.DomesticStandardsId == null && x.DomesticStandardsId != null))); if (q1 != null) { Alert.ShowInTop(Resources.Lan.DomesticStandardsCodeExists, MessageBoxIcon.Warning); return; } //判断名称是否存在 var q2 = Funs.DB.FileControl_DomesticStandards.FirstOrDefault(x => x.DomesticStandardsName == this.txtDomesticStandardsName.Text.Trim() && (x.DomesticStandardsId.ToString() != this.DomesticStandardsId || (this.DomesticStandardsId == null && x.DomesticStandardsId != null))); if (q2 != null) { Alert.ShowInTop(Resources.Lan.DomesticStandardsNameExists, MessageBoxIcon.Warning); return; } Model.FileControl_DomesticStandards newDomesticStandards = new Model.FileControl_DomesticStandards(); newDomesticStandards.DomesticStandardsCode = this.txtDomesticStandardsCode.Text.Trim(); newDomesticStandards.DomesticStandardsName = this.txtDomesticStandardsName.Text.Trim(); newDomesticStandards.Abstract = this.txtAbstract.Text.Trim(); if (this.drpCompileMan.SelectedValue != BLL.Const._Null) { newDomesticStandards.CompileMan = this.drpCompileMan.SelectedValue; } newDomesticStandards.CompileDate = Funs.GetNewDateTime(this.txtCompileDate.Text.Trim()); newDomesticStandards.Remarks = this.txtRemark.Text.Trim(); if (!string.IsNullOrEmpty(this.DomesticStandardsId)) { newDomesticStandards.DomesticStandardsId = this.DomesticStandardsId; BLL.FileControl_DomesticStandardsService.UpdateDomesticStandards(newDomesticStandards); BLL.Sys_LogService.AddLog(Const.System_2, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.DomesticStandardsMenuId, Const.BtnModify, newDomesticStandards.DomesticStandardsId); } else { this.DomesticStandardsId = SQLHelper.GetNewID(typeof(Model.FileControl_DomesticStandards)); newDomesticStandards.DomesticStandardsId = this.DomesticStandardsId; BLL.FileControl_DomesticStandardsService.AddDomesticStandards(newDomesticStandards); BLL.Sys_LogService.AddLog(Const.System_2, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.DomesticStandardsMenuId, Const.BtnAdd, newDomesticStandards.DomesticStandardsId); } if (state == "1") { ShowNotify(Resources.Lan.SaveSuccessfully, MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } #endregion #region 附件上传 /// /// 上传附件资源 /// /// /// protected void btnAttachUrl_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.DomesticStandardsId)) { SaveData("0"); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/FileControl/DomesticStandards&menuId={1}&edit=1", this.DomesticStandardsId, BLL.Const.DomesticStandardsMenuId))); } #endregion } }