using BLL; using System; using System.Web; namespace FineUIPro.Web.Accident { public partial class AccidentWarningEdit : PageBase { #region 定义项 /// /// 主键 /// private string Id { get { return (string)ViewState["Id"]; } set { ViewState["Id"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); this.Id = Request.Params["Id"]; if (!string.IsNullOrEmpty(this.Id)) { Model.Accident_Warning model = BLL.AccidentWarningService.GetAccidentWarningById(this.Id); if (model != null) { this.txtCode.Text = model.Code; this.txtTitle.Text = model.Title; this.txtContent.Text = model.Content; this.txtAddress.Text = model.Address; this.txtResponsibleUnit.Text = model.ResponsibleUnit; this.txtRemarks.Text = model.Remarks; if (model.AccidentDate != null) { this.txtAccidentDate.Text = string.Format("{0:yyyy-MM-dd}", model.AccidentDate); } this.txtCompileManName.Text = model.CompileManName; if (model.CreateTime != null) { this.txtCreateTime.Text = string.Format("{0:yyyy-MM-dd}", model.CreateTime); } } } else { this.txtCompileManName.Text = this.CurrUser.UserName; this.txtCreateTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); ////自动生成编码 this.txtCode.Text = BLL.SQLHelper.RunProcNewId("SpGetNewCode5", "Accident_Warning", "Code", $"SG-"); } } } #endregion #region 保存、提交 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { this.SaveData(); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存数据 /// private void SaveData() { Model.Accident_Warning model = new Model.Accident_Warning(); model.Code = this.txtCode.Text.Trim(); model.Title = this.txtTitle.Text.Trim(); model.Content = this.txtContent.Text.Trim(); model.Address = this.txtAddress.Text.Trim(); model.ResponsibleUnit = this.txtResponsibleUnit.Text.Trim(); model.Remarks = this.txtRemarks.Text.Trim(); model.AccidentDate = Funs.GetNewDateTimeOrNow(this.txtAccidentDate.Text.Trim()); model.AccidentMonthDay = model.AccidentDate.ToString("MM-dd"); if (!string.IsNullOrEmpty(this.Id)) { model.Id = this.Id; BLL.AccidentWarningService.UpdateAccidentWarning(model); BLL.LogService.AddSys_Log(this.CurrUser, model.Code, model.Id, BLL.Const.AccidentWarningMenuId, BLL.Const.BtnModify); } else { model.CompileMan = this.CurrUser.UserId; model.CompileManName = this.CurrUser.UserName; model.CreateTime = Funs.GetNewDateTimeOrNow(this.txtCreateTime.Text.Trim()); this.Id = SQLHelper.GetNewID(typeof(Model.Accident_Warning)); model.Id = this.Id; BLL.AccidentWarningService.AddAccidentWarning(model); BLL.LogService.AddSys_Log(this.CurrUser, model.Code, model.Id, BLL.Const.AccidentWarningMenuId, BLL.Const.BtnAdd); } } #endregion #region 附件上传 /// /// 上传附件 /// /// /// protected void btnAttachUrl_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.Id)) { SaveData(); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/AccidentWarning&menuId={1}", Id, BLL.Const.AccidentWarningMenuId))); } #endregion } }