using System; using System.Collections.Generic; using System.Linq; namespace FineUIPro.Web.HSSE.HazardousMG { /// /// 编辑安全巡检记录页面 /// public partial class SafetyPatrolEdit : PageBase { #region 定义项 /// /// 主键 /// private string PatrolId { get { return (string)ViewState["PatrolId"]; } set { ViewState["PatrolId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); this.InitDropDownList(); ////巡检人关联当前登录账号 if (this.CurrUser != null) { this.lblPatrolMan.Text = this.CurrUser.UserName; } this.PatrolId = Request.Params["PatrolId"]; if (!string.IsNullOrEmpty(this.PatrolId)) { ////编辑:回填数据 Model.HSSE_SafetyPatrol info = BLL.SafetyPatrolService.GetById(this.PatrolId); if (info != null) { if (!string.IsNullOrEmpty(info.HazardProjectId)) { this.ddlHazardProject.SelectedValue = info.HazardProjectId; } if (info.PatrolDate.HasValue) { this.dpPatrolDate.SelectedDate = info.PatrolDate.Value; } if (!string.IsNullOrEmpty(info.PatrolStatus)) { this.ddlPatrolStatus.SelectedValue = info.PatrolStatus; } this.txtContent.Text = info.Content; } } else { ////新增(扫码巡检):默认巡检日期为当天、巡检状态为正常 this.dpPatrolDate.SelectedDate = DateTime.Now; this.ddlPatrolStatus.SelectedValue = "正常"; } } } /// /// 初始化危大、超危清单下拉 /// private void InitDropDownList() { if (this.CurrUser == null || string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { return; } List projects = BLL.HazardProjectService.GetList(this.CurrUser.LoginProjectId); foreach (Model.HSSE_HazardProject p in projects) { this.ddlHazardProject.Items.Add(new FineUIPro.ListItem(p.ProjectName + "(" + p.ProjectCode + ")", p.HazardProjectId)); } } #endregion #region 保存 /// /// 保存按钮事件 /// protected void btnSave_Click(object sender, EventArgs e) { if (this.CurrUser == null || string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { Alert.ShowInTop("请先选择项目!", MessageBoxIcon.Warning); return; } ////新增时先生成主键,保证附件能挂到同一记录 if (string.IsNullOrEmpty(this.PatrolId)) { this.PatrolId = Guid.NewGuid().ToString(); } ////校验附件是否已上传 Model.AttachFile attach = BLL.Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == this.PatrolId); if (attach == null || string.IsNullOrEmpty(attach.AttachUrl)) { Alert.ShowInTop("请上传巡检图片!", MessageBoxIcon.Warning); return; } ////根据所选清单回填工程名称 string hazardProjectName = string.Empty; Model.HSSE_HazardProject project = BLL.HazardProjectService.GetById(this.ddlHazardProject.SelectedValue); if (project != null) { hazardProjectName = project.ProjectName; } Model.HSSE_SafetyPatrol info = new Model.HSSE_SafetyPatrol { PatrolId = this.PatrolId, ProjectId = this.CurrUser.LoginProjectId, HazardProjectId = this.ddlHazardProject.SelectedValue, HazardProjectName = hazardProjectName, PatrolDate = this.dpPatrolDate.SelectedDate, PatrolMan = this.CurrUser.UserName, PatrolStatus = this.ddlPatrolStatus.SelectedValue, Content = this.txtContent.Text.Trim() }; ////存在则更新,不存在则新增(服务层已处理) BLL.SafetyPatrolService.Update(info); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } /// /// 上传巡检图片 /// protected void btnAttach_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.PatrolId)) { this.PatrolId = Guid.NewGuid().ToString(); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/SafetyPatrol&menuId={1}", this.PatrolId, BLL.Const.SafetyPatrolMenuId))); } #endregion } }