341 lines
12 KiB
C#
341 lines
12 KiB
C#
using BLL;
|
||
using Model.Enums;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace FineUIPro.Web.Customization.CNCEC4.HSSE.Report
|
||
{
|
||
public partial class RiskIdentificationEdit : PageBase
|
||
{
|
||
public string Id
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["Id"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["Id"] = value;
|
||
}
|
||
}
|
||
|
||
public string RiskId
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["RiskId"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["RiskId"] = value;
|
||
}
|
||
}
|
||
|
||
public string action
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["action"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["action"] = value;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 定义集合
|
||
/// </summary>
|
||
private static List<Model.Report_RiskIdentification_c> details = new List<Model.Report_RiskIdentification_c>();
|
||
|
||
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
this.Id = Request.Params[nameof(Id)];
|
||
this.action = Request.Params[nameof(action)];
|
||
showInfo();
|
||
if (this.action == ActionEnums.View.ToString())
|
||
{
|
||
btnSave.Hidden = true;
|
||
btnSubmit.Hidden = true;
|
||
btnNew.Hidden = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 加载数据
|
||
/// </summary>
|
||
void showInfo()
|
||
{
|
||
// 删除选中单元格的客户端脚本
|
||
string deleteScript = GetDeleteScript();
|
||
|
||
var project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
|
||
if (project != null)
|
||
{
|
||
this.txtProjectName.Text = project.ProjectName;
|
||
this.txtUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(project.UnitId);
|
||
}
|
||
var resultDetail = Funs.DB.Report_RiskIdentification_c.FirstOrDefault(a => a.Id == this.Id);
|
||
|
||
|
||
|
||
if (resultDetail != null)
|
||
{
|
||
this.RiskId = resultDetail.RiskId;
|
||
var result = Funs.DB.Report_RiskIdentification.FirstOrDefault(a => a.Id == resultDetail.RiskId);
|
||
|
||
project = BLL.ProjectService.GetProjectByProjectId(result.ProjectId);
|
||
if (project != null)
|
||
{
|
||
this.txtProjectName.Text = project.ProjectName;
|
||
this.txtUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(project.UnitId);
|
||
}
|
||
this.txtMonths.Text = string.Format("{0:yyyy-MM}", result.Months);
|
||
this.txtSignPerson.Text = result.SignPerson;
|
||
txtWorkModuleA.Text = result.WorkModuleA;
|
||
txtWorkModuleB.Text = result.WorkModuleB;
|
||
txtCreateDate.Text = result.CreateDate.ToString();
|
||
|
||
//加载列表
|
||
details.Clear();
|
||
var RiskIdentification_cList = Funs.DB.Report_RiskIdentification_c.Where(x => x.RiskId == RiskId).ToList();
|
||
details = RiskIdentification_cList;
|
||
Grid1.DataSource = details;
|
||
Grid1.DataBind();
|
||
}
|
||
else
|
||
{
|
||
this.txtMonths.Text = string.Format("{0:yyyy-MM}", Request.Params["monts"].ToString());
|
||
this.txtCreateDate.Text = DateTime.Now.ToString();
|
||
}
|
||
}
|
||
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
SaveData(BLL.Const.BtnSave);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提交
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSubmit_Click(object sender, EventArgs e)
|
||
{
|
||
SaveData(BLL.Const.BtnSubmit);
|
||
|
||
}
|
||
|
||
void SaveData(string type)
|
||
{
|
||
Model.Report_RiskIdentification model = new Model.Report_RiskIdentification()
|
||
{
|
||
ProjectId = this.CurrUser.LoginProjectId,
|
||
Unitid = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId).UnitId,
|
||
Months = Convert.ToDateTime(this.txtMonths.Text),
|
||
WorkModuleA = txtWorkModuleA.Text,
|
||
WorkModuleB = txtWorkModuleB.Text,
|
||
SignPerson = txtSignPerson.Text,
|
||
CreateDate = Convert.ToDateTime(txtCreateDate.Text),
|
||
};
|
||
if (type == BLL.Const.BtnSave)
|
||
{
|
||
model.States = "0";
|
||
}
|
||
else
|
||
{
|
||
model.States = "1";
|
||
}
|
||
if (this.action == ActionEnums.Edit.ToString() || !string.IsNullOrEmpty(this.Id))
|
||
{
|
||
model.Id = this.RiskId;
|
||
RiskIdentificationService.Update(model);
|
||
//删除子表重新添加
|
||
RiskIdentificationService.DeleteCbyRiskId(model.Id);
|
||
}
|
||
else
|
||
{
|
||
model.Id = SQLHelper.GetNewID(typeof(Model.Report_HazardAdminister));
|
||
this.RiskId = model.Id;
|
||
RiskIdentificationService.Insert(model);
|
||
}
|
||
var str = this.SaveDetail(type, model);
|
||
if (str == "保存成功")
|
||
{
|
||
ShowNotify(this.SaveDetail(type, model), MessageBoxIcon.Success);
|
||
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
||
}
|
||
else {
|
||
ShowNotify(this.SaveDetail(type, model), MessageBoxIcon.Warning);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存明细项
|
||
/// </summary>
|
||
private string SaveDetail(string type, Model.Report_RiskIdentification model)
|
||
{
|
||
var errMsg = "";
|
||
try
|
||
{
|
||
|
||
var olddetailLists = Funs.DB.Report_RiskIdentification_c.Where(x => x.RiskId == this.RiskId).ToList();
|
||
List<string> needRemove = new List<string>();
|
||
foreach (var oldDetail in olddetailLists)
|
||
{
|
||
bool hasFind = false;
|
||
for (int i = 0; i < Grid1.Rows.Count; i++)
|
||
{
|
||
if (oldDetail.Id == Grid1.Rows[i].DataKeys[0].ToString())
|
||
{
|
||
hasFind = true;
|
||
break;
|
||
}
|
||
|
||
|
||
}
|
||
if (!hasFind)
|
||
{
|
||
RiskIdentificationService.DeleteC(oldDetail.Id);
|
||
|
||
}
|
||
}
|
||
List<Model.Report_RiskIdentification_c> detailLists = new List<Model.Report_RiskIdentification_c>();
|
||
JArray teamGroupData = Grid1.GetMergedData();
|
||
var fIndex = 1;
|
||
foreach (JObject teamGroupRow in teamGroupData)
|
||
{
|
||
JObject values = teamGroupRow.Value<JObject>("values");
|
||
int rowIndex = teamGroupRow.Value<int>("index");
|
||
Model.Report_RiskIdentification_c newDetail = new Model.Report_RiskIdentification_c()
|
||
{
|
||
Id = values.Value<string>("Id"),
|
||
RiskId = this.RiskId,
|
||
HazardText = values.Value<string>("HazardText"),
|
||
Accident = values.Value<string>("Accident"),
|
||
NodelL = values.Value<string>("NodelL"),
|
||
NodelE = values.Value<string>("NodelE"),
|
||
NodelC = values.Value<string>("NodelC"),
|
||
Measures = values.Value<string>("Measures"),
|
||
ControlLevel = values.Value<string>("ControlLevel"),
|
||
ResPerson = values.Value<string>("ResPerson"),
|
||
};
|
||
if (string.IsNullOrEmpty(newDetail.NodelL))
|
||
{
|
||
errMsg = "第" + fIndex.ToString() + "L(可能性)(0.1-10)不能为空";
|
||
return "请选择L(可能性)(0.1-10)";
|
||
}
|
||
if (string.IsNullOrEmpty(newDetail.NodelE))
|
||
{
|
||
errMsg = "第" + fIndex.ToString() + "E(频繁程度)(0.5-10)不能为空";
|
||
return "请选择E(频繁程度)(0.5-10)";
|
||
}
|
||
if (string.IsNullOrEmpty(newDetail.NodelC))
|
||
{
|
||
errMsg= "第" + fIndex.ToString() + "C(伤害程度)(1-100)不能为空";
|
||
return "请选择C(伤害程度)(1-100)";
|
||
}
|
||
|
||
//D(风险值)=L*E*C
|
||
newDetail.NodelD = (Convert.ToDouble(newDetail.NodelL) * Convert.ToDouble(newDetail.NodelE) * Convert.ToDouble(newDetail.NodelC)).ToString();
|
||
var LevelNum = Convert.ToDouble(newDetail.NodelD);
|
||
if (LevelNum < 70)
|
||
{
|
||
newDetail.RiskLevel = "低风险";
|
||
}
|
||
else if (LevelNum >= 70 && LevelNum < 160)
|
||
{
|
||
newDetail.RiskLevel = "一般风险";
|
||
}
|
||
else if (LevelNum >= 160 && LevelNum < 320)
|
||
{
|
||
newDetail.RiskLevel = "较大风险";
|
||
}
|
||
else if (LevelNum >= 320)
|
||
{
|
||
newDetail.RiskLevel = "重大风险";
|
||
}
|
||
|
||
if (Grid1.Rows[rowIndex].DataKeys.Length > 0)
|
||
{
|
||
newDetail.Id = Grid1.Rows[rowIndex].DataKeys[0].ToString();
|
||
}
|
||
var newDetailModel = Funs.DB.Report_RiskIdentification_c.FirstOrDefault(x => x.Id == newDetail.Id);
|
||
if (newDetailModel==null)
|
||
{
|
||
RiskIdentificationService.InsertC(newDetail);
|
||
}
|
||
else
|
||
{
|
||
RiskIdentificationService.UpdateC(newDetail);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
if (!string.IsNullOrEmpty(errMsg))
|
||
{
|
||
return errMsg;
|
||
}
|
||
|
||
return "保存成功";
|
||
}
|
||
|
||
protected void btnAdd_Click(object sender, EventArgs e)
|
||
{
|
||
JArray teamGroupData = Grid1.GetMergedData();
|
||
List<JObject> list = new List<JObject>();
|
||
foreach (JObject teamGroupRow in teamGroupData)
|
||
{
|
||
JObject values = teamGroupRow.Value<JObject>("values");
|
||
values.Add("Id", teamGroupRow.Value<string>("id"));
|
||
list.Add(values);
|
||
}
|
||
JObject defaultObj = new JObject
|
||
{ { "Id",Guid.NewGuid() },
|
||
{ "HazardText", "" },
|
||
{ "Accident", "" },
|
||
{ "NodelL",""},
|
||
{ "NodelE", "" },
|
||
{ "NodelC","" },
|
||
{ "Measures", "" },
|
||
{ "ControlLevel","" },
|
||
{ "Suggestions",""},
|
||
{ "ResPerson", "" },
|
||
{ "Delete", String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>", GetDeleteScript(), IconHelper.GetResolvedIconUrl(Icon.Delete)) }
|
||
};
|
||
list.Add(defaultObj);
|
||
Grid1.DataSource = list;
|
||
Grid1.DataBind();
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_PreDataBound(object sender, EventArgs e)
|
||
{
|
||
// 设置LinkButtonField的点击客户端事件
|
||
LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField;
|
||
deleteField.OnClientClick = GetDeleteScript();
|
||
}
|
||
/// <summary>
|
||
/// 删除提示
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private string GetDeleteScript()
|
||
{
|
||
return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty);
|
||
}
|
||
}
|
||
} |