using BLL; using System; using System.Linq; namespace FineUIPro.Web.CQMS.Comprehensive { public partial class QualityAccidentEdit : PageBase { #region 定义变量 /// /// 主键 /// public string QualityAccidentId { get { return (string)ViewState["QualityAccidentId"]; } set { ViewState["QualityAccidentId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower(); BLL.UnitWorkService.InitUnitWorkDownList(this.drpUnitWorkId, this.CurrUser.LoginProjectId, false); BLL.UnitService.InitUnitDownList(this.drpUnit, this.CurrUser.LoginProjectId, true); this.QualityAccidentId = Request.Params["QualityAccidentId"]; Model.Comprehensive_QualityAccident pressurePipe = BLL.QualityAccidentService.GetQualityAccidentById(this.QualityAccidentId); if (pressurePipe != null) { this.hdAttachUrl.Text = this.QualityAccidentId; this.QualityAccidentId = pressurePipe.QualityAccidentId; this.txtCorrectiveActions.Text = pressurePipe.CorrectiveActions; this.txtPlace.Text = pressurePipe.Place; this.txtDirectEconomicLoss.Text = pressurePipe.DirectEconomicLoss; this.txtRemedialMeasures.Text = pressurePipe.RemedialMeasures; this.txtResponsibilityDetermination.Text = pressurePipe.ResponsibilityDetermination; this.txtTime.Text = pressurePipe.Time.HasValue ? string.Format("{0:yyyy-MM-dd}", pressurePipe.Time) : ""; this.drpUnit.SelectedValue = pressurePipe.UnitId; if (!string.IsNullOrEmpty(pressurePipe.UnitWorkId)) { this.drpUnitWorkId.SelectedValueArray = pressurePipe.UnitWorkId.Split(','); } } else { this.txtTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); } } } #endregion #region 保存 /// /// 保存方法 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (drpUnit.SelectedValue != BLL.Const._Null) { Model.Comprehensive_QualityAccident pressurePipe = new Model.Comprehensive_QualityAccident(); pressurePipe.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(this.txtTime.Text)) { pressurePipe.Time = Convert.ToDateTime(this.txtTime.Text); } else { pressurePipe.Time = DateTime.Now; } pressurePipe.Place = this.txtPlace.Text; pressurePipe.DirectEconomicLoss = this.txtDirectEconomicLoss.Text; pressurePipe.RemedialMeasures = this.txtRemedialMeasures.Text; pressurePipe.ResponsibilityDetermination = this.txtResponsibilityDetermination.Text; pressurePipe.CorrectiveActions = this.txtCorrectiveActions.Text; pressurePipe.UnitId = this.drpUnit.SelectedValue; string ids = string.Empty; var lists = this.drpUnitWorkId.SelectedValueArray; foreach (var item in lists) { ids += item + ","; } if (!string.IsNullOrEmpty(ids)) { ids = ids.Substring(0, ids.LastIndexOf(",")); } pressurePipe.UnitWorkId = ids; if (string.IsNullOrEmpty(this.QualityAccidentId)) { if (!string.IsNullOrEmpty(this.hdAttachUrl.Text)) { pressurePipe.QualityAccidentId = this.hdAttachUrl.Text; } else { pressurePipe.QualityAccidentId = SQLHelper.GetNewID(typeof(Model.Comprehensive_QualityAccident)); this.hdAttachUrl.Text = pressurePipe.QualityAccidentId; } pressurePipe.CompileMan = this.CurrUser.UserId; pressurePipe.CompileDate = DateTime.Now; BLL.QualityAccidentService.AddQualityAccident(pressurePipe); } else { pressurePipe.QualityAccidentId = this.QualityAccidentId; BLL.QualityAccidentService.UpdateQualityAccident(pressurePipe); } ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { Alert.ShowInTop("请选择所属单位!", MessageBoxIcon.Warning); } } #endregion #region 附件上传 /// /// 附件上传 /// /// /// protected void btnAttach_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.hdAttachUrl.Text)) //新增记录 { this.hdAttachUrl.Text = SQLHelper.GetNewID(typeof(Model.Comprehensive_QualityAccident)); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/QualityAccident&menuId={1}", this.hdAttachUrl.Text, BLL.Const.QualityAccidentMenuId))); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == BLL.Const._Null) { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.QualityAccidentMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion } }