using BLL; using System; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.HSSE.Hazard { public partial class HazardReEvaluator : PageBase { #region 定义变量 /// /// 主键 /// public string HazardSelectedItemId { get { return (string)ViewState["HazardSelectedItemId"]; } set { ViewState["HazardSelectedItemId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { btnClose.OnClientClick = ActiveWindow.GetHideReference(); ////权限按钮方法 this.GetButtonPower(); BLL.ConstValue.InitConstValueDropDownList(this.ddlHelperMethod, ConstValue.Group_0006, true); BLL.RiskLevelService.InitRiskLevelDropDownList(this.ddlHazardLevel, true); BLL.UserService.InitFlowOperateControlUserDropDownList(this.drpDutyPerson, this.CurrUser.LoginProjectId, string.Empty, true); this.txtPlanExistDate.Enabled = false; this.txtCheckStartDate.Enabled = false; this.drpDutyPerson.Enabled = false; this.HazardSelectedItemId = Request.Params["HazardSelectedItemId"]; if (!string.IsNullOrEmpty(this.HazardSelectedItemId)) { Model.Hazard_HazardSelectedItem item = BLL.Hazard_HazardSelectedItemService.GetHazardSelectedItemByHazardSelectedItemId(this.HazardSelectedItemId); if (item != null) { var q = BLL.HazardListService.GetHazardListById(item.HazardId); if (q != null) { this.txtHazardCode.Text = q.HazardCode; this.txtHazardItems.Text = item.HazardItems; this.txtDefectsType.Text = item.DefectsType; this.txtMayLeadAccidents.Text = item.MayLeadAccidents; if (item.HelperMethod != "null") { this.ddlHelperMethod.SelectedValue = item.HelperMethod; } if (item.HazardJudge_L != null) { this.txtHazardJudge_L.Text = Convert.ToString(item.HazardJudge_L); } if (item.HazardJudge_E != null) { this.txtHazardJudge_E.Text = Convert.ToString(item.HazardJudge_E); } if (item.HazardJudge_C != null) { this.txtHazardJudge_C.Text = Convert.ToString(item.HazardJudge_C); } if (item.HazardJudge_D != null) { this.txtHazardJudge_D.Text = Convert.ToString(item.HazardJudge_D); } if (item.HazardLevel != "0") { this.ddlHazardLevel.SelectedValue = item.HazardLevel; } this.txtControlMeasures.Text = item.ControlMeasures; if (item.IsStart == true) { this.ckbIsStart.Checked = true; this.txtPlanExistDate.Enabled = true; this.txtCheckStartDate.Enabled = true; this.drpDutyPerson.Enabled = true; } if (item.CheckStartDate != null) { this.txtCheckStartDate.Text = string.Format("{0:yyyy-MM-dd}", item.CheckStartDate); } if (!string.IsNullOrEmpty(item.DutyPerson)) { //this.drpDutyPerson.SelectedValue = item.DutyPerson; this.drpDutyPerson.SelectedValueArray = item.DutyPerson.Split(','); } if (item.PlanExistDate != null) { this.txtPlanExistDate.Text = string.Format("{0:yyyy-MM-dd}", item.PlanExistDate); } this.txtPosition.Text = item.Position; } } } } } #endregion #region 保存 /// /// 保存数据 /// private void SaveData() { if (this.ckbIsStart.Checked) { if (string.IsNullOrEmpty(this.txtCheckStartDate.Text.Trim())) { Alert.ShowInTop("巡检启动时间不能为空!", MessageBoxIcon.Warning); return; } if (this.drpDutyPerson.SelectedValue == BLL.Const._Null && this.drpDutyPerson.SelectedValueArray.Length == 1) { Alert.ShowInTop("请选择风险责任人!", MessageBoxIcon.Warning); return; } } Model.Hazard_HazardSelectedItem item = BLL.Hazard_HazardSelectedItemService.GetHazardSelectedItemByHazardSelectedItemId(this.HazardSelectedItemId); if (item != null) { item.HazardJudge_L = Funs.GetNewDecimalOrZero(this.txtHazardJudge_L.Text.Trim()); item.HazardJudge_E = Funs.GetNewDecimalOrZero(this.txtHazardJudge_E.Text.Trim()); item.HazardJudge_C = Funs.GetNewDecimalOrZero(this.txtHazardJudge_C.Text.Trim()); item.HazardJudge_D = Funs.GetNewDecimalOrZero(this.txtHazardJudge_D.Text.Trim()); item.HazardLevel = this.ddlHazardLevel.SelectedValue; item.ControlMeasures = this.txtControlMeasures.Text.Trim(); item.IsStart = this.ckbIsStart.Checked; item.CheckStartDate = Funs.GetNewDateTime(this.txtCheckStartDate.Text.Trim()); //if (this.drpDutyPerson.SelectedValue != BLL.Const._Null) //{ // item.DutyPerson = this.drpDutyPerson.SelectedValue; //} string dutyPerson = string.Empty; foreach (var personId in this.drpDutyPerson.SelectedValueArray) { if (personId != BLL.Const._Null) { dutyPerson += personId + ","; } } if (!string.IsNullOrEmpty(dutyPerson)) { item.DutyPerson = dutyPerson.Substring(0, dutyPerson.Length - 1); } item.PlanExistDate = Funs.GetNewDateTime(this.txtPlanExistDate.Text.Trim()); item.State = "1"; //存在 item.Position = this.txtPosition.Text.Trim(); } BLL.Hazard_HazardSelectedItemService.UpdateHazardSelectedItem(item); string LECItemRecordId = Request.Params["LECItemRecordId"]; if (string.IsNullOrEmpty(LECItemRecordId)) { //二次评价记录 Model.Hazard_RiskEvaluationRecord record = new Model.Hazard_RiskEvaluationRecord(); record.LECItemRecordId = SQLHelper.GetNewID(); record.DataId = item.HazardSelectedItemId; record.DataType = "Project"; record.Evaluatorld = this.CurrUser.UserId; record.EvaluatorDate = DateTime.Now; record.L = item.HazardJudge_L; record.E = item.HazardJudge_E; record.C = item.HazardJudge_C; record.D = item.HazardJudge_D; record.RiskLevel = item.HazardLevel; record.ControlMeasures = item.ControlMeasures; record.Remark = item.Remark; BLL.RiskEvaluationRecordService.AddRiskEvaluationRecord(record); } else { var oldRecord = BLL.RiskEvaluationRecordService.GetRiskEvaluationRecordByLECItemRecordId(LECItemRecordId); if (oldRecord != null) { oldRecord.DataId = item.HazardSelectedItemId; oldRecord.DataType = "Project"; oldRecord.Evaluatorld = this.CurrUser.UserId; oldRecord.EvaluatorDate = DateTime.Now; oldRecord.L = item.HazardJudge_L; oldRecord.E = item.HazardJudge_E; oldRecord.C = item.HazardJudge_C; oldRecord.D = item.HazardJudge_D; oldRecord.RiskLevel = item.HazardLevel; oldRecord.ControlMeasures = item.ControlMeasures; oldRecord.Remark = item.Remark; BLL.RiskEvaluationRecordService.UpdateRiskEvaluationRecord(oldRecord); } } if (item.IsStart == true) { foreach (var personId in this.drpDutyPerson.SelectedValueArray) { //巡检计划 Model.Hazard_PatrolPlan plan = new Model.Hazard_PatrolPlan(); plan.PatrolPlanId = SQLHelper.GetNewID(); plan.HazardSelectedItemId = this.HazardSelectedItemId; plan.HazardLevel = item.HazardLevel; plan.DutyPerson = personId; Model.Base_RiskLevel level = BLL.RiskLevelService.GetRiskLevel(item.HazardLevel); if (level != null) { plan.Days = level.Days; } plan.CheckStartDate = item.CheckStartDate; plan.LimitCheckDate = item.CheckStartDate.Value.AddDays(level.Days.Value); plan.State = "0"; BLL.Hazard_PatrolPlanService.AddPatrolPlan(plan); } } BLL.LogService.AddSys_Log(this.CurrUser, item.HazardItems, item.HazardSelectedItemId, BLL.Const.ProjectHazardInfoMenuId, Const.BtnModify); if (string.IsNullOrEmpty(Request.Params["Main"])) { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { PageContext.RegisterStartupScript(String.Format("window.close();")); } } /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { SaveData(); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HazardListMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion protected void txtHazardJudge_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.txtHazardJudge_L.Text) && !string.IsNullOrEmpty(this.txtHazardJudge_E.Text) && !string.IsNullOrEmpty(this.txtHazardJudge_C.Text)) { decimal D = decimal.Parse(this.txtHazardJudge_L.Text) * decimal.Parse(this.txtHazardJudge_E.Text) * decimal.Parse(this.txtHazardJudge_C.Text); this.txtHazardJudge_D.Text = D.ToString("0.0"); var riskLevel = Funs.DB.Base_RiskLevel.FirstOrDefault(x => (!x.MinValue.HasValue || x.MinValue <= D) && (D <= x.MaxValue || !x.MaxValue.HasValue)); if (riskLevel != null) { this.ddlHazardLevel.SelectedValue = riskLevel.RiskLevelId; } } } protected void ckbIsStart_CheckedChanged(object sender, CheckedEventArgs e) { if (this.ckbIsStart.Checked) { this.txtPlanExistDate.Enabled = true; this.txtCheckStartDate.Enabled = true; this.drpDutyPerson.Enabled = true; } else { this.txtPlanExistDate.Enabled = false; this.txtPlanExistDate.Text = string.Empty; this.txtCheckStartDate.Enabled = false; this.txtCheckStartDate.Text = string.Empty; this.drpDutyPerson.Enabled = false; this.drpDutyPerson.SelectedValue = BLL.Const._Null; } } } }