using BLL; using FineUIPro.Web.BaseInfo; using Model; using System; using System.Web.UI.WebControls; namespace FineUIPro.Web.ZHGL.Supervise { public partial class UnitHazardRegisterRecordEdit : PageBase { #region 定义项 /// /// 问题明细ID /// private string ItemId { get { return (string)ViewState["ItemId"]; } set { ViewState["ItemId"] = value; } } /// /// 主单ID /// private string RegisterId { get { return (string)ViewState["RegisterId"]; } set { ViewState["RegisterId"] = value; } } /// /// 检查大类(0=安全,1=质量) /// private string CheckMainType { get { return (string)ViewState["CheckMainType"]; } set { ViewState["CheckMainType"] = value; } } #endregion #region 页面加载 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); // 获取参数 this.ItemId = Request.Params["ItemId"]; this.RegisterId = Request.Params["RegisterId"]; this.CheckMainType = Request["type"] ?? "0"; // 加载数据 if (!string.IsNullOrEmpty(this.ItemId)) { LoadData(); } } } /// /// 加载数据 /// private void LoadData() { // 获取明细记录 var item = BLL.UnitHazardRegisterItemService.GetUnitHazardRegisterItemById(this.ItemId); if (item == null) { Alert.ShowInTop("问题记录不存在!", MessageBoxIcon.Error); return; } // 获取主单记录 var register = BLL.UnitHazardRegisterService.GetUnitHazardRegisterById(this.RegisterId); if (register == null) { Alert.ShowInTop("检查记录不存在!", MessageBoxIcon.Error); return; } // 填充只读字段 this.txtCheckType.Text = BLL.SuperviseCheckTypeService.GetCheckTypeName( register.CheckMainType, register.CheckType); this.txtProblemType.Text = item.ProblemType; this.txtRiskLevel.Text = item.RiskLevel; if (register.CheckDate != null) { this.txtCheckDate.Text = string.Format("{0:yyyy-MM-dd}", register.CheckDate); } this.txtInspectionUnit.Text = BLL.UnitService.GetUnitNameByUnitId(register.InspectionUnit); this.txtCheckTeam.Text = register.CheckTeam; //this.txtCheckUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(register.CheckUnitId); this.txtProblemDescription.Text = item.ProblemDescription; this.txtRectifyRequirement.Text = item.RectifyRequirement; this.txtInsResponsibleUserName.Text = Person_PersonsService.GetUserNameByUserId(register.InsResponsibleUserId); // 填充可编辑字段 this.txtRectificationMeasures.Text = item.RectificationMeasures; if (item.CompletedDate != null) { this.dpkCompletedDate.Text = string.Format("{0:yyyy-MM-dd}", item.CompletedDate); } else { this.dpkCompletedDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); } bool isPowerEdit= (this.CurrUser.PersonId == Const.sysglyId|| this.CurrUser.PersonId == Const.hfnbdId || this.CurrUser.PersonId == register.InsResponsibleUserId) ? true: false; // 判断是否已整改,如果已整改则隐藏保存和提交按钮 if (item.CompleteStatus == 1 || !isPowerEdit) { this.btnSave.Hidden = true; this.btnSubmit.Hidden = true; this.txtRectificationMeasures.Readonly = true; this.dpkCompletedDate.Readonly = true; // this.btnAfterImage.Enabled = false; if (item.CompleteStatus != 1 && !isPowerEdit) { ShowNotify("您不是整改责任人,不允许修改!", MessageBoxIcon.Information); } } } #endregion #region 保存和提交 /// /// 保存按钮 /// protected void btnSave_Click(object sender, EventArgs e) { SaveData(false); } /// /// 提交按钮 /// protected void btnSubmit_Click(object sender, EventArgs e) { SaveData(true); } /// /// 保存数据 /// /// 是否提交 private void SaveData(bool isSubmit) { var item = BLL.UnitHazardRegisterItemService.GetUnitHazardRegisterItemById(this.ItemId); if (item == null) { Alert.ShowInTop("问题记录不存在!", MessageBoxIcon.Error); return; } // 验证:如果已整改,不允许修改 if (item.CompleteStatus == 1) { Alert.ShowInTop("该问题已整改完成,不允许修改!", MessageBoxIcon.Warning); return; } // 更新明细字段 item.RectificationMeasures = this.txtRectificationMeasures.Text.Trim(); item.CompletedDate = Funs.GetNewDateTime(this.dpkCompletedDate.Text.Trim()); // 如果提交,确保标记为已完成 if (isSubmit) { item.CompleteStatus = 1; if (!item.CompletedDate.HasValue) { item.CompletedDate = DateTime.Now; } } // 更新数据库 BLL.UnitHazardRegisterItemService.UpdateUnitHazardRegisterItem(item); if (isSubmit) { // 更新主单状态 UnitHazardRegisterService.UpdateRegisterStatus(this.RegisterId); } // 记录日志 string menuId = this.CheckMainType == "0" ? BLL.Const.UnitHazardRegisterMenu_Safety : BLL.Const.UnitHazardRegisterMenu_Quality; BLL.LogService.AddSys_Log(this.CurrUser, item.UnitHazardRegisterItemId, this.ItemId, menuId, BLL.Const.BtnModify); ShowNotify(isSubmit ? "提交成功!" : "保存成功!", MessageBoxIcon.Success); // 关闭窗口 PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } #endregion #region 附件操作 /// /// 查看整改前照片 /// protected void btnBeforeImage_Click(object sender, EventArgs e) { string menuId = this.CheckMainType == "0" ? BLL.Const.UnitHazardRegisterMenu_Safety : BLL.Const.UnitHazardRegisterMenu_Quality; PageContext.RegisterStartupScript(Window1.GetShowReference( String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/UnitHazardRegister&menuId={1}&edit=0&type=-1", this.ItemId, menuId))); } /// /// 上传和查看整改后照片 /// protected void btnAfterImage_Click(object sender, EventArgs e) { string menuId = this.CheckMainType == "0" ? BLL.Const.UnitHazardRegisterMenu_Safety : BLL.Const.UnitHazardRegisterMenu_Quality; var item = BLL.UnitHazardRegisterItemService.GetUnitHazardRegisterItemById(this.ItemId); if (item != null && item.CompleteStatus == 1) //已整改不允许上传 { PageContext.RegisterStartupScript(Window1.GetShowReference( String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/UnitHazardRegister/&menuId={1}&edit=1&type=-1 ", this.ItemId + "-R", menuId))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference( String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/UnitHazardRegister/&menuId={1}&edit=1 ", this.ItemId + "-R", menuId))); } } #endregion } }