CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/HSSE/Manager/MonthReportCEdit7.aspx.cs

296 lines
12 KiB
C#

using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
namespace FineUIPro.Web.HSSE.Manager
{
public partial class MonthReportCEdit7 : PageBase
{
#region
/// <summary>
/// 月报告查主键
/// </summary>
public string MonthReportId
{
get
{
return (string)ViewState["MonthReportId"];
}
set
{
ViewState["MonthReportId"] = value;
}
}
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#region
/// <summary>
/// 新增危险源识别及控制
/// </summary>
private static List<Model.Manager_Month_HazardC> hazardCs = new List<Model.Manager_Month_HazardC>();
/// <summary>
/// 其他HSE工作计划
/// </summary>
private static List<Model.Manager_Month_OtherWorkPlanC> otherWorkPlanCs = new List<Model.Manager_Month_OtherWorkPlanC>();
#endregion
#endregion
#region
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hazardCs.Clear();
otherWorkPlanCs.Clear();
this.MonthReportId = Request.Params["monthReportId"];
this.ProjectId = this.CurrUser.LoginProjectId;
DateTime months = Convert.ToDateTime(Request.Params["months"]);
Model.Manager_MonthReportC monthReport = BLL.MonthReportCService.GetMonthReportByMonths(months, this.CurrUser.LoginProjectId);
if (monthReport != null)
{
this.MonthReportId = monthReport.MonthReportId;
this.ProjectId = monthReport.ProjectId;
//新增危险源识别及控制
hazardCs = BLL.HazardCService.GetHazardByMonthReportId(this.MonthReportId);
if (hazardCs.Count > 0)
{
this.gvHazardC.DataSource = hazardCs;
this.gvHazardC.DataBind();
}
//其他HSE工作计划
otherWorkPlanCs = BLL.OtherWorkPlanCService.GetOtherWorkPlanByMonthReportId(this.MonthReportId);
if (otherWorkPlanCs.Count > 0)
{
this.gvOtherWorkPlanC.DataSource = otherWorkPlanCs;
this.gvOtherWorkPlanC.DataBind();
}
}
}
}
#endregion
#region HSE工作计划
#region
/// <summary>
/// 新增危险源识别及控制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewHazardC_Click(object sender, EventArgs e)
{
jerqueSaveHazardCList();
Model.Manager_Month_HazardC hazardC = new Model.Manager_Month_HazardC
{
HazardId = SQLHelper.GetNewID(typeof(Model.Manager_Month_HazardC))
};
hazardCs.Add(hazardC);
this.gvHazardC.DataSource = hazardCs;
this.gvHazardC.DataBind();
}
/// <summary>
/// 新增危险源识别及控制行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvHazardC_RowCommand(object sender, GridCommandEventArgs e)
{
jerqueSaveHazardCList();
string rowID = this.gvHazardC.DataKeys[e.RowIndex][0].ToString();
if (e.CommandName == "Delete")
{
foreach (var item in hazardCs)
{
if (item.HazardId == rowID)
{
hazardCs.Remove(item);
break;
}
}
gvHazardC.DataSource = hazardCs;
gvHazardC.DataBind();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
/// <summary>
/// 新增危险源识别及控制
/// </summary>
private void jerqueSaveHazardCList()
{
hazardCs.Clear();
JArray mergedData = gvHazardC.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
int i = mergedRow.Value<int>("index");
Model.Manager_Month_HazardC hazardC = new Model.Manager_Month_HazardC
{
HazardId = this.gvHazardC.Rows[i].DataKeys[0].ToString(),
WorkArea = values.Value<string>("WorkArea").ToString(),
EnvironmentalFactors = values.Value<string>("EnvironmentalFactors").ToString(),
Consequence = values.Value<string>("Consequence").ToString(),
ControlMeasures = values.Value<string>("ControlMeasures").ToString()
};
if (!string.IsNullOrEmpty(values.Value<string>("IsMajor").ToString()))
{
hazardC.IsMajor = Convert.ToBoolean(values.Value<string>("IsMajor").ToString());
}
hazardCs.Add(hazardC);
}
}
#endregion
#region HSE工作计划
/// <summary>
/// 增加其他HSE工作计划
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOtherWorkPlanC_Click(object sender, EventArgs e)
{
jerqueSaveOtherWorkPlanCList();
Model.Manager_Month_OtherWorkPlanC otherWorkPlanC = new Model.Manager_Month_OtherWorkPlanC
{
OtherWorkPlanId = SQLHelper.GetNewID(typeof(Model.Manager_Month_OtherWorkPlanC))
};
otherWorkPlanCs.Add(otherWorkPlanC);
this.gvOtherWorkPlanC.DataSource = otherWorkPlanCs;
this.gvOtherWorkPlanC.DataBind();
}
/// <summary>
/// 删除其他HSE工作计划
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOtherWorkPlanC_RowCommand(object sender, GridCommandEventArgs e)
{
jerqueSaveOtherWorkPlanCList();
string rowID = this.gvOtherWorkPlanC.DataKeys[e.RowIndex][0].ToString();
if (e.CommandName == "Delete")
{
foreach (var item in otherWorkPlanCs)
{
if (item.OtherWorkPlanId == rowID)
{
otherWorkPlanCs.Remove(item);
break;
}
}
gvOtherWorkPlanC.DataSource = otherWorkPlanCs;
gvOtherWorkPlanC.DataBind();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
/// <summary>
/// 其他HSE工作计划
/// </summary>
private void jerqueSaveOtherWorkPlanCList()
{
otherWorkPlanCs.Clear();
JArray mergedData = gvOtherWorkPlanC.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
int i = mergedRow.Value<int>("index");
Model.Manager_Month_OtherWorkPlanC otherWorkPlanC = new Model.Manager_Month_OtherWorkPlanC
{
OtherWorkPlanId = this.gvOtherWorkPlanC.Rows[i].DataKeys[0].ToString(),
SortIndex = i,
WorkContent = values.Value<string>("WorkContent").ToString()
};
otherWorkPlanCs.Add(otherWorkPlanC);
}
}
#endregion
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
Model.Manager_MonthReportC oldMonthReport = BLL.MonthReportCService.GetMonthReportByMonths(Convert.ToDateTime(Request.Params["months"]), this.CurrUser.LoginProjectId);
if (oldMonthReport != null)
{
BLL.MonthReportCService.UpdateMonthReport(oldMonthReport);
OperateHazardCSort(MonthReportId);
OperateOtherWorkPlanCSort(MonthReportId);
BLL.LogService.AddSys_Log(this.CurrUser, oldMonthReport.MonthReportCode, oldMonthReport.MonthReportId, BLL.Const.ProjectManagerMonthCMenuId, BLL.Const.BtnModify);
}
else
{
Model.Manager_MonthReportC monthReport = new Model.Manager_MonthReportC();
string newKeyID = SQLHelper.GetNewID(typeof(Model.Manager_MonthReportC));
monthReport.MonthReportId = newKeyID;
monthReport.ProjectId = this.CurrUser.LoginProjectId;
this.MonthReportId = newKeyID;
monthReport.MonthReportCode = BLL.CodeRecordsService.ReturnCodeByMenuIdProjectId(BLL.Const.ProjectManagerMonthCMenuId, this.ProjectId, this.CurrUser.UnitId);
monthReport.Months = Funs.GetNewDateTime(Request.Params["months"]);
monthReport.ReportMan = this.CurrUser.UserId;
monthReport.MonthReportDate = DateTime.Now;
BLL.MonthReportCService.AddMonthReport(monthReport);
OperateHazardCSort(MonthReportId);
OperateOtherWorkPlanCSort(MonthReportId);
BLL.LogService.AddSys_Log(this.CurrUser, monthReport.MonthReportCode, monthReport.MonthReportId, BLL.Const.ProjectManagerMonthCMenuId, BLL.Const.BtnAdd);
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
/// <summary>
/// 新增危险源识别及控制
/// </summary>
/// <param name="monthReportId"></param>
private void OperateHazardCSort(string monthReportId)
{
BLL.HazardCService.DeleteHazardByMonthReportId(monthReportId);
jerqueSaveHazardCList();
foreach (Model.Manager_Month_HazardC des in hazardCs)
{
des.MonthReportId = monthReportId;
BLL.HazardCService.AddHazard(des);
}
}
/// <summary>
/// 7.2 其他HSE工作计划
/// </summary>
/// <param name="monthReportId"></param>
private void OperateOtherWorkPlanCSort(string monthReportId)
{
BLL.OtherWorkPlanCService.DeleteOtherWorkPlanByMonthReportId(monthReportId);
jerqueSaveOtherWorkPlanCList();
foreach (Model.Manager_Month_OtherWorkPlanC item in otherWorkPlanCs)
{
item.MonthReportId = monthReportId;
BLL.OtherWorkPlanCService.AddOtherWorkPlan(item);
}
}
#endregion
}
}