using BLL; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; namespace FineUIPro.Web.HSSE.Manager { public partial class MonthReportCEdit7 : PageBase { #region 定义项 /// /// 月报告查主键 /// public string MonthReportId { get { return (string)ViewState["MonthReportId"]; } set { ViewState["MonthReportId"] = value; } } /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #region 定义集合 /// /// 新增危险源识别及控制 /// private static List hazardCs = new List(); /// /// 其他HSE工作计划 /// private static List otherWorkPlanCs = new List(); #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 新增危险源识别及控制 /// /// 新增危险源识别及控制 /// /// /// 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(); } /// /// 新增危险源识别及控制行点击事件 /// /// /// 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); } } /// /// 新增危险源识别及控制 /// private void jerqueSaveHazardCList() { hazardCs.Clear(); JArray mergedData = gvHazardC.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); Model.Manager_Month_HazardC hazardC = new Model.Manager_Month_HazardC { HazardId = this.gvHazardC.Rows[i].DataKeys[0].ToString(), WorkArea = values.Value("WorkArea").ToString(), EnvironmentalFactors = values.Value("EnvironmentalFactors").ToString(), Consequence = values.Value("Consequence").ToString(), ControlMeasures = values.Value("ControlMeasures").ToString() }; if (!string.IsNullOrEmpty(values.Value("IsMajor").ToString())) { hazardC.IsMajor = Convert.ToBoolean(values.Value("IsMajor").ToString()); } hazardCs.Add(hazardC); } } #endregion #region 其他HSE工作计划 /// /// 增加其他HSE工作计划 /// /// /// 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(); } /// /// 删除其他HSE工作计划 /// /// /// 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); } } /// /// 其他HSE工作计划 /// private void jerqueSaveOtherWorkPlanCList() { otherWorkPlanCs.Clear(); JArray mergedData = gvOtherWorkPlanC.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); Model.Manager_Month_OtherWorkPlanC otherWorkPlanC = new Model.Manager_Month_OtherWorkPlanC { OtherWorkPlanId = this.gvOtherWorkPlanC.Rows[i].DataKeys[0].ToString(), SortIndex = i, WorkContent = values.Value("WorkContent").ToString() }; otherWorkPlanCs.Add(otherWorkPlanC); } } #endregion #endregion #region 保存按钮 /// /// 保存按钮 /// /// /// 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()); } /// /// 新增危险源识别及控制 /// /// 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); } } /// /// 7.2 其他HSE工作计划 /// /// 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 } }