using BLL; using System; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web.HSSE.Material { public partial class MaterialEdit : PageBase { #region 定义项 /// /// 主键 /// private string MaterialId { get { return (string)ViewState["MaterialId"]; } set { ViewState["MaterialId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); this.MaterialId = Request.Params["MaterialId"]; if (!string.IsNullOrEmpty(this.MaterialId)) { this.hdId.Text = this.MaterialId; Model.HSSE_Material material = Funs.DB.HSSE_Material.FirstOrDefault(x=>x.MaterialId==this.MaterialId); if (material != null) { if (material.PublishDate != null) { this.txtInDate.Text = string.Format("{0:yyyy-MM-dd}", material.PublishDate); } if (!string.IsNullOrEmpty(material.Name)) { this.txtName.Text = material.Name; } if (!string.IsNullOrEmpty(material.Remark)) { this.txtRemark.Text = material.Remark; } } } else { ////自动生成编码 this.txtInDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); } if (Request.Params["value"] == "0") { this.btnSave.Hidden = true; } } } #endregion #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { SaveData(true); } /// /// 保存数据 /// /// private void SaveData(bool isClose) { Model.HSSE_Material material = new Model.HSSE_Material { ProjectId = this.CurrUser.LoginProjectId , CreateMan = this.CurrUser.UserId, PublishMan=this.CurrUser.UserId }; material.PublishDate = Funs.GetNewDateTimeOrNow(this.txtInDate.Text.Trim()); material.Name = this.txtName.Text.Trim(); material.Remark = this.txtRemark.Text.Trim(); material.CreateMan = this.CurrUser.UserId; material.CreateDate = DateTime.Now; if (!string.IsNullOrEmpty(this.MaterialId)) { material.MaterialId = this.MaterialId; BLL.HSSE.MaterialService.UpdateMaterial(material); BLL.LogService.AddSys_Log(this.CurrUser, material.Name, material.MaterialId, BLL.Const.GeneralEquipmentQualityMenuId, BLL.Const.BtnModify); } else { if (!string.IsNullOrEmpty(hdId.Text)) { material.MaterialId = this.hdId.Text; } else { material.MaterialId = SQLHelper.GetNewID(typeof(Model.HSSE_Material)); } BLL.HSSE.MaterialService.AddMaterial(material); BLL.LogService.AddSys_Log(this.CurrUser, material.Name, material.MaterialId, BLL.Const.GeneralEquipmentQualityMenuId, BLL.Const.BtnAdd); } if (isClose) { PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } } #endregion #region 附件上传 /// /// 上传附件 /// /// /// protected void btnAttachUrl_Click(object sender, EventArgs e) { if (this.btnSave.Hidden) { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/GeneralEquipmentQualityAttachUrl&type=-1", this.hdId.Text, BLL.Const.HSSEMaterialMenuId))); } else { if (string.IsNullOrEmpty(this.hdId.Text)) { this.hdId.Text = SQLHelper.GetNewID(typeof(Model.HSSE_Material)); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/GeneralEquipmentQualityAttachUrl&menuId={1}", this.hdId.Text, BLL.Const.HSSEMaterialMenuId))); } } #endregion } }