ChengDa_English/SGGL/FineUIPro.Web/HSSE/Hazard/HazardInfoEdit.aspx.cs

251 lines
11 KiB
C#
Raw Normal View History

2023-06-19 09:04:34 +08:00
using BLL;
using System;
using System.Linq;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.Hazard
{
public partial class HazardInfoEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string HazardSelectedItemId
{
get
{
return (string)ViewState["HazardSelectedItemId"];
}
set
{
ViewState["HazardSelectedItemId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 保存数据
/// </summary>
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.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);
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);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
SaveData();
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
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;
}
}
}
}