using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BLL; using Newtonsoft.Json.Linq; namespace FineUIPro.Web.HSSE.Manager { public partial class MonthReportCEdit8 : 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; } } private static DateTime startTime; private static DateTime endTime; private static DateTime yearStartTime; private static DateTime projectStartTime; #region 定义集合 /// /// 9.1 危险源动态识别及控制集合 /// private static List hazards = new List(); /// /// 9.2 HSSE培训集合 /// private static List trains = new List(); /// /// 9.3 HSSE检查集合 /// private static List checks = new List(); /// /// 9.4 HSSE会议集合 /// private static List meetings = new List(); /// /// 9.5 HSSE活动集合 /// private static List activitiess = new List(); /// /// 9.6.1 应急预案修编集合 /// private static List emergencyPlans = new List(); /// /// 9.6.2 应急演练活动集合 /// private static List emergencyExercisess = new List(); /// /// 9.7 HSE费用投入计划集合 /// private static List costInvestmentPlans = new List(); /// /// 9.8 HSE管理文件/方案修编计划集合 /// private static List manageDocPlans = new List(); /// /// 9.9 其他HSE工作计划 /// private static List otherWorkPlans = new List(); #endregion #endregion #region 加载 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { hazards.Clear(); trains.Clear(); checks.Clear(); meetings.Clear(); activitiess.Clear(); emergencyPlans.Clear(); emergencyExercisess.Clear(); costInvestmentPlans.Clear(); manageDocPlans.Clear(); otherWorkPlans.Clear(); this.MonthReportId = Request.Params["monthReportId"]; this.ProjectId = this.CurrUser.LoginProjectId; DateTime months = Convert.ToDateTime(Request.Params["months"]); startTime = Convert.ToDateTime(Request.Params["startTime"]); endTime = Convert.ToDateTime(Request.Params["endTime"]); yearStartTime = Convert.ToDateTime(Request.Params["yearStartTime"]); Model.Manager_MonthReportC monthReport = BLL.MonthReportCService.GetMonthReportByMonths(months, this.CurrUser.LoginProjectId); Model.Manager_MonthReportC mr = BLL.MonthReportCService.GetLastMonthReportByDate(endTime, this.ProjectId); Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(ProjectId); if (project.StartDate != null) { projectStartTime = Convert.ToDateTime(project.StartDate); } if (monthReport != null) { this.MonthReportId = monthReport.MonthReportId; this.ProjectId = monthReport.ProjectId; months = Convert.ToDateTime(monthReport.Months); this.txtNextEmergencyResponse.Text = monthReport.NextEmergencyResponse; Model.SGGLDB db = Funs.DB; //9.1 危险源动态识别及控制 hazards = (from x in db.Manager_Month_HazardC where x.MonthReportId == MonthReportId orderby x.SortIndex select x).ToList(); if (hazards.Count > 0) { this.gvHazard.DataSource = hazards; this.gvHazard.DataBind(); } //9.3 HSSE检查 checks = (from x in db.Manager_Month_CheckC where x.MonthReportId == MonthReportId orderby x.SortIndex select x).ToList(); if (checks.Count > 0) { this.gvCheck.DataSource = checks; this.gvCheck.DataBind(); } //9.8 HSE管理文件/方案修编计划 manageDocPlans = (from x in db.Manager_Month_ManageDocPlanC where x.MonthReportId == MonthReportId orderby x.SortIndex select x).ToList(); if (manageDocPlans.Count > 0) { this.gvManageDocPlan.DataSource = manageDocPlans; this.gvManageDocPlan.DataBind(); } //9.9其他HSE工作计划 otherWorkPlans = (from x in db.Manager_Month_OtherWorkPlanC where x.MonthReportId == MonthReportId orderby x.SortIndex select x).ToList(); if (otherWorkPlans.Count > 0) { this.gvOtherWorkPlan.DataSource = otherWorkPlans; this.gvOtherWorkPlan.DataBind(); } } } } #endregion #region 危险源动态识别及控制 /// /// 增加危险源动态识别及控制 /// /// /// protected void btnNewHazard_Click(object sender, EventArgs e) { jerqueSaveMonthHazardList(); Model.Manager_Month_HazardC hazardSort = new Model.Manager_Month_HazardC { HazardId = SQLHelper.GetNewID(typeof(Model.Manager_Month_HazardC)) }; hazards.Add(hazardSort); this.gvHazard.DataSource = hazards; this.gvHazard.DataBind(); } /// /// 检查并保存危险源动态识别及控制集合 /// private void jerqueSaveMonthHazardList() { hazards.Clear(); JArray mergedData = gvHazard.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 hazardSort = new Model.Manager_Month_HazardC { HazardId = this.gvHazard.Rows[i].DataKeys[0].ToString(), SortIndex = i, WorkArea = values.Value("WorkArea").ToString(), Subcontractor = values.Value("Subcontractor").ToString(), DangerousSource = values.Value("DangerousSource").ToString(), ControlMeasures = values.Value("ControlMeasures").ToString() }; hazards.Add(hazardSort); } } protected void gvHazard_RowCommand(object sender, GridCommandEventArgs e) { jerqueSaveMonthHazardList(); string rowID = this.gvHazard.DataKeys[e.RowIndex][0].ToString(); if (e.CommandName == "Delete") { foreach (var item in hazards) { if (item.HazardId == rowID) { hazards.Remove(item); break; } } gvHazard.DataSource = hazards; gvHazard.DataBind(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #endregion #region HSE检查 /// /// 增加HSE检查 /// /// /// protected void btnNewCheck_Click(object sender, EventArgs e) { jerqueSaveMonthCheckList(); Model.Manager_Month_CheckC checkSort = new Model.Manager_Month_CheckC { CheckId = SQLHelper.GetNewID(typeof(Model.Manager_Month_CheckC)) }; checks.Add(checkSort); this.gvCheck.DataSource = checks; this.gvCheck.DataBind(); } /// /// 检查并保存HSE检查集合 /// private void jerqueSaveMonthCheckList() { checks.Clear(); JArray mergedData = gvCheck.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); Model.Manager_Month_CheckC checkSort = new Model.Manager_Month_CheckC { CheckId = this.gvCheck.Rows[i].DataKeys[0].ToString(), SortIndex = i, CheckType = values.Value("CheckType").ToString(), Inspectors = values.Value("Inspectors").ToString(), CheckDate = values.Value("CheckDate").ToString(), Remark = values.Value("Remark").ToString() }; checks.Add(checkSort); } } protected void gvCheck_RowCommand(object sender, GridCommandEventArgs e) { jerqueSaveMonthCheckList(); string rowID = this.gvCheck.DataKeys[e.RowIndex][0].ToString(); if (e.CommandName == "Delete") { foreach (var item in checks) { if (item.CheckId == rowID) { checks.Remove(item); break; } } gvCheck.DataSource = checks; gvCheck.DataBind(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #endregion #region HSE管理文件/方案修编计划 /// /// 增加HSE管理文件/方案修编计划 /// /// /// protected void btnNewManageDocPlan_Click(object sender, EventArgs e) { jerqueSaveMonthManageDocPlanList(); Model.Manager_Month_ManageDocPlanC manageDocPlanSort = new Model.Manager_Month_ManageDocPlanC { ManageDocPlanId = SQLHelper.GetNewID(typeof(Model.Manager_Month_ManageDocPlanC)) }; manageDocPlans.Add(manageDocPlanSort); this.gvManageDocPlan.DataSource = manageDocPlans; this.gvManageDocPlan.DataBind(); } /// /// 检查并保存HSE管理文件/方案修编计划集合 /// private void jerqueSaveMonthManageDocPlanList() { manageDocPlans.Clear(); JArray mergedData = gvManageDocPlan.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); Model.Manager_Month_ManageDocPlanC manageDocPlanSort = new Model.Manager_Month_ManageDocPlanC { ManageDocPlanId = this.gvManageDocPlan.Rows[i].DataKeys[0].ToString(), SortIndex = i, ManageDocPlanName = values.Value("ManageDocPlanName").ToString(), CompileMan = values.Value("CompileMan").ToString(), CompileDate = values.Value("CompileDate").ToString() }; manageDocPlans.Add(manageDocPlanSort); } } protected void gvManageDocPlan_RowCommand(object sender, GridCommandEventArgs e) { jerqueSaveMonthManageDocPlanList(); string rowID = this.gvManageDocPlan.DataKeys[e.RowIndex][0].ToString(); if (e.CommandName == "Delete") { foreach (var item in manageDocPlans) { if (item.ManageDocPlanId == rowID) { manageDocPlans.Remove(item); break; } } gvManageDocPlan.DataSource = manageDocPlans; gvManageDocPlan.DataBind(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #endregion #region 其他HSE工作计划 /// /// 增加其他HSE工作计划 /// /// /// protected void btnNewOtherWorkPlan_Click(object sender, EventArgs e) { jerqueSaveMonthOtherWorkPlanList(); Model.Manager_Month_OtherWorkPlanC otherWorkPlanSort = new Model.Manager_Month_OtherWorkPlanC { OtherWorkPlanId = SQLHelper.GetNewID(typeof(Model.Manager_Month_OtherWorkPlanC)) }; otherWorkPlans.Add(otherWorkPlanSort); this.gvOtherWorkPlan.DataSource = otherWorkPlans; this.gvOtherWorkPlan.DataBind(); } /// /// 检查并保存其他HSE工作计划集合 /// private void jerqueSaveMonthOtherWorkPlanList() { otherWorkPlans.Clear(); JArray mergedData = gvOtherWorkPlan.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 otherWorkPlanSort = new Model.Manager_Month_OtherWorkPlanC { OtherWorkPlanId = this.gvOtherWorkPlan.Rows[i].DataKeys[0].ToString(), SortIndex = i, WorkContent = values.Value("WorkContent").ToString() }; otherWorkPlans.Add(otherWorkPlanSort); } } protected void gvOtherWorkPlan_RowCommand(object sender, GridCommandEventArgs e) { jerqueSaveMonthOtherWorkPlanList(); string rowID = this.gvOtherWorkPlan.DataKeys[e.RowIndex][0].ToString(); if (e.CommandName == "Delete") { foreach (var item in otherWorkPlans) { if (item.OtherWorkPlanId == rowID) { otherWorkPlans.Remove(item); break; } } gvOtherWorkPlan.DataSource = otherWorkPlans; gvOtherWorkPlan.DataBind(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #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) { oldMonthReport.NextEmergencyResponse = this.txtNextEmergencyResponse.Text.Trim(); BLL.MonthReportCService.UpdateMonthReport(oldMonthReport); OperateHazardListSort(MonthReportId); OperateCheckListSort(MonthReportId); OperateManageDocPlanSort(MonthReportId); OperateOtherWorkPlanSort(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; monthReport.NextEmergencyResponse = this.txtNextEmergencyResponse.Text.Trim(); BLL.MonthReportCService.AddMonthReport(monthReport); OperateHazardListSort(MonthReportId); OperateCheckListSort(MonthReportId); OperateManageDocPlanSort(MonthReportId); OperateOtherWorkPlanSort(MonthReportId); BLL.LogService.AddSys_Log(this.CurrUser, monthReport.MonthReportCode, monthReport.MonthReportId, BLL.Const.ProjectManagerMonthCMenuId, BLL.Const.BtnAdd); } ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 9.1 危险源动态识别及控制 /// /// private void OperateHazardListSort(string monthReportId) { BLL.HazardCService.DeleteHazardByMonthReportId(monthReportId); jerqueSaveMonthHazardList(); foreach (Model.Manager_Month_HazardC hazard in hazards) { hazard.MonthReportId = monthReportId; BLL.HazardCService.AddHazard(hazard); } } /// /// 9.3 HSSE检查 /// /// private void OperateCheckListSort(string monthReportId) { BLL.CheckCService.DeleteCheckByMonthReportId(monthReportId); jerqueSaveMonthCheckList(); foreach (Model.Manager_Month_CheckC check in checks) { check.MonthReportId = monthReportId; BLL.CheckCService.AddCheck(check); } } /// /// 9.8 HSE管理文件/方案修编计划 /// /// private void OperateManageDocPlanSort(string monthReportId) { BLL.ManageDocPlanCService.DeleteManageDocPlanByMonthReportId(monthReportId); jerqueSaveMonthManageDocPlanList(); foreach (Model.Manager_Month_ManageDocPlanC item in manageDocPlans) { item.MonthReportId = monthReportId; BLL.ManageDocPlanCService.AddManageDocPlan(item); } } /// /// 9.9 其他HSE工作计划 /// /// private void OperateOtherWorkPlanSort(string monthReportId) { BLL.OtherWorkPlanCService.DeleteOtherWorkPlanByMonthReportId(monthReportId); jerqueSaveMonthOtherWorkPlanList(); foreach (Model.Manager_Month_OtherWorkPlanC item in otherWorkPlans) { item.MonthReportId = monthReportId; BLL.OtherWorkPlanCService.AddOtherWorkPlan(item); } } #endregion } }