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 MonthReportCEdit6 : 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 定义集合 /// /// 本月伤害事故统计 /// private static List injuryAccidents = new List(); /// /// 无伤害事故统计 /// private static List noInjuryAccidents = new List(); /// /// HSE绩效指标 /// private static List performanceIndicators = new List(); #endregion #endregion #region 加载 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { injuryAccidents.Clear(); noInjuryAccidents.Clear(); performanceIndicators.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); txtDef.Text = monthReport.AccidentDef; #region 本月伤害事故统计 injuryAccidents = BLL.InjuryAccidentCService.GetInjuryAccidentCByMonthReportId(this.MonthReportId); if (injuryAccidents.Count > 0) { this.gvInjuryAccident.DataSource = injuryAccidents; this.gvInjuryAccident.DataBind(); OutputSummaryData(); } else { GetInjuryAccident(); } #endregion #region 本月无伤害事故统计 noInjuryAccidents = BLL.NoInjuryAccidentCService.GetNoInjuryAccidentByMonthReportId(this.MonthReportId); if (noInjuryAccidents.Count > 0) { this.gvNoInjuryAccident.DataSource = noInjuryAccidents; this.gvNoInjuryAccident.DataBind(); } else { GetNoInjuryAccident(); } #endregion #region HSE绩效指标 performanceIndicators = BLL.PerformanceIndicatorCService.GetPerformanceIndicatorByMonthReportId(this.MonthReportId); if (performanceIndicators.Count > 0) { this.gvPerformanceIndicator.DataSource = performanceIndicators; this.gvPerformanceIndicator.DataBind(); } else { GetPerformanceIndicator(); } #endregion } else { GetInjuryAccident(); GetNoInjuryAccident(); GetPerformanceIndicator(); } } } #region 本月伤害事故统计 /// /// 本月伤害事故统计 /// private void GetInjuryAccident() { List reports = AccidentReportService.GetAccidentReportsByAccidentTime(startTime, endTime, this.ProjectId); List deathReports = AccidentReportService.GetAccidentReportsByAccidentType("1", startTime, endTime, this.ProjectId); int i = 0; Model.Manager_Month_InjuryAccidentC injury = new Model.Manager_Month_InjuryAccidentC { InjuryAccidentId = SQLHelper.GetNewID(typeof(Model.Manager_Month_InjuryAccidentC)), UnitName = "五环", AttemptedIncidents = BLL.AccidentHandleService.GetAccidentHandleByAccidentDate(startTime, endTime, this.ProjectId, BLL.Const.UnitId_CWCEC),//未遂事件起数 FirstAidDressing = null, // MedicalTreatment = null,// WorkLimitation = null,// LossPerson = (from x in reports where x.UnitId==Const.UnitId_CWCEC select x.PeopleNum).Sum(), LossWorkTime = (from x in reports where x.UnitId == Const.UnitId_CWCEC select x.WorkingHoursLoss).Sum(), LossEconomy = (from x in reports where x.UnitId == Const.UnitId_CWCEC select x.EconomicLoss).Sum() + (from x in reports where x.UnitId == Const.UnitId_CWCEC select x.EconomicOtherLoss).Sum(), DeathPerson = (from x in deathReports where x.UnitId == Const.UnitId_CWCEC select x.PeopleNum).Sum(), DeathWorkTime = (from x in deathReports where x.UnitId == Const.UnitId_CWCEC select x.WorkingHoursLoss).Sum(), DeathEconomy = (from x in deathReports where x.UnitId == Const.UnitId_CWCEC select x.EconomicLoss).Sum() + (from x in deathReports where x.UnitId == Const.UnitId_CWCEC select x.EconomicOtherLoss).Sum(), }; injuryAccidents.Add(injury); i++; Model.Manager_Month_InjuryAccidentC injury2 = new Model.Manager_Month_InjuryAccidentC { InjuryAccidentId = SQLHelper.GetNewID(typeof(Model.Manager_Month_InjuryAccidentC)), UnitName = "分包商", AttemptedIncidents = BLL.AccidentHandleService.GetAccidentHandleByAccidentDate(startTime, endTime, this.ProjectId, BLL.Const.UnitId_Con),//未遂事件起数,//未遂事件起数 FirstAidDressing = null, // MedicalTreatment = null,// WorkLimitation = null,// LossPerson = (from x in reports join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId where y.UnitType == Const.ProjectUnitType_2 select x.PeopleNum).Sum(), LossWorkTime = (from x in reports join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId where y.UnitType == Const.ProjectUnitType_2 select x.WorkingHoursLoss).Sum(), LossEconomy = (from x in reports join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId where y.UnitType == Const.ProjectUnitType_2 select x.EconomicLoss).Sum() + (from x in reports join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId where y.UnitType == Const.ProjectUnitType_2 select x.EconomicOtherLoss).Sum(), DeathPerson = (from x in deathReports join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId where y.UnitType == Const.ProjectUnitType_2 select x.PeopleNum).Sum(), DeathWorkTime = (from x in deathReports join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId where y.UnitType == Const.ProjectUnitType_2 select x.WorkingHoursLoss).Sum(), DeathEconomy = (from x in deathReports join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId where y.UnitType == Const.ProjectUnitType_2 select x.EconomicLoss).Sum() + (from x in deathReports join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId where y.UnitType == Const.ProjectUnitType_2 select x.EconomicOtherLoss).Sum(), }; injuryAccidents.Add(injury2); this.gvInjuryAccident.DataSource = injuryAccidents; this.gvInjuryAccident.DataBind(); OutputSummaryData(); } /// /// 求和 /// private void OutputSummaryData() { JObject summary = new JObject(); int TotalAttemptedIncidents = 0, TotalFirstAidDressing = 0, TotalMedicalTreatment = 0, TotalWorkLimitation = 0, TotalLossPerson = 0, TotalDeathPerson = 0; decimal TotalLossWorkTime = 0, TotalLossEconomy = 0, TotalDeathWorkTime = 0, TotalDeathEconomy = 0; foreach (JObject mergedRow in gvInjuryAccident.GetMergedData()) { JObject values = mergedRow.Value("values"); if (!string.IsNullOrEmpty(values["AttemptedIncidents"].ToString())) { TotalAttemptedIncidents += values.Value("AttemptedIncidents"); } if (!string.IsNullOrEmpty(values["FirstAidDressing"].ToString())) { TotalFirstAidDressing += values.Value("FirstAidDressing"); } if (!string.IsNullOrEmpty(values["MedicalTreatment"].ToString())) { TotalMedicalTreatment += values.Value("MedicalTreatment"); } if (!string.IsNullOrEmpty(values["WorkLimitation"].ToString())) { TotalWorkLimitation += values.Value("WorkLimitation"); } if (!string.IsNullOrEmpty(values["LossPerson"].ToString())) { TotalLossPerson += values.Value("LossPerson"); } if (!string.IsNullOrEmpty(values["LossWorkTime"].ToString())) { TotalLossWorkTime += values.Value("LossWorkTime"); } if (!string.IsNullOrEmpty(values["LossEconomy"].ToString())) { TotalLossEconomy += values.Value("LossEconomy"); } if (!string.IsNullOrEmpty(values["DeathPerson"].ToString())) { TotalDeathPerson += values.Value("DeathPerson"); } if (!string.IsNullOrEmpty(values["DeathWorkTime"].ToString())) { TotalDeathWorkTime += values.Value("DeathWorkTime"); } if (!string.IsNullOrEmpty(values["DeathEconomy"].ToString())) { TotalDeathEconomy += values.Value("DeathEconomy"); } } summary.Add("UnitName", "项目合计"); summary.Add("AttemptedIncidents", TotalAttemptedIncidents.ToString("F2")); summary.Add("FirstAidDressing", TotalFirstAidDressing.ToString("F2")); summary.Add("MedicalTreatment", TotalMedicalTreatment.ToString("F2")); summary.Add("WorkLimitation", TotalWorkLimitation.ToString("F2")); summary.Add("LossPerson", TotalLossPerson.ToString("F2")); summary.Add("LossWorkTime", TotalLossWorkTime.ToString("F2")); summary.Add("LossEconomy", TotalLossEconomy.ToString("F2")); summary.Add("DeathPerson", TotalDeathPerson.ToString("F2")); summary.Add("DeathWorkTime", TotalDeathWorkTime.ToString("F2")); summary.Add("DeathEconomy", TotalDeathEconomy.ToString("F2")); gvInjuryAccident.SummaryData = summary; } #endregion #region 本月无伤害事故统计 /// /// 本月无伤害事故统计 /// private void GetNoInjuryAccident() { Model.Manager_Month_NoInjuryAccidentC noInjury = new Model.Manager_Month_NoInjuryAccidentC { NoInjuryAccidentId = SQLHelper.GetNewID(typeof(Model.Manager_Month_NoInjuryAccidentC)), AccidentType = null, EconomicLosses = null, WHAccidentCount = null, SubAccidentCount = null, }; noInjuryAccidents.Add(noInjury); this.gvNoInjuryAccident.DataSource = noInjuryAccidents; this.gvNoInjuryAccident.DataBind(); } #endregion #region HSE绩效指标 /// /// HSE绩效指标 /// private void GetPerformanceIndicator() { int i = 0; Model.Manager_Month_PerformanceIndicatorC performanceIndicator = new Model.Manager_Month_PerformanceIndicatorC { PerformanceIndicatorId = SQLHelper.GetNewID(typeof(Model.Manager_Month_PerformanceIndicatorC)), IndicatorType = "指导性指标", IndicatorName = "不安全行为指数(不安全行为数/审核小时数)", IndicatorValue = null, SortIndex = 1, }; performanceIndicators.Add(performanceIndicator); i++; var units = from x in Funs.DB.Project_ProjectUnit where x.ProjectId == this.ProjectId && x.UnitType == "2" orderby x.UnitType select x; if (units.Count() > 0) { foreach (Model.Project_ProjectUnit u in units) { Model.Manager_Month_PerformanceIndicatorC performanceIndicator2 = new Model.Manager_Month_PerformanceIndicatorC { PerformanceIndicatorId = SQLHelper.GetNewID(typeof(Model.Manager_Month_PerformanceIndicatorC)), IndicatorType = "过程性指标", IndicatorName = "HSE隐患按时整改率 | " + BLL.UnitService.GetUnitNameByUnitId(u.UnitId), IndicatorValue = null, SortIndex = 2, }; performanceIndicators.Add(performanceIndicator2); } i++; } Model.Manager_Month_PerformanceIndicatorC performanceIndicator3 = new Model.Manager_Month_PerformanceIndicatorC { PerformanceIndicatorId = SQLHelper.GetNewID(typeof(Model.Manager_Month_PerformanceIndicatorC)), IndicatorType = "结果性指标", IndicatorName = "百万工时总可记录事件率(总可记录事件人数/总工时)*10^6", IndicatorValue = null, SortIndex = 3, }; performanceIndicators.Add(performanceIndicator3); i++; Model.Manager_Month_PerformanceIndicatorC performanceIndicator4 = new Model.Manager_Month_PerformanceIndicatorC { PerformanceIndicatorId = SQLHelper.GetNewID(typeof(Model.Manager_Month_PerformanceIndicatorC)), IndicatorType = "结果性指标", IndicatorName = "百万工时损失工时率(总损失工时/总工时)*10^6", IndicatorValue = null, SortIndex = 4, }; performanceIndicators.Add(performanceIndicator4); i++; Model.Manager_Month_PerformanceIndicatorC performanceIndicator5 = new Model.Manager_Month_PerformanceIndicatorC { PerformanceIndicatorId = SQLHelper.GetNewID(typeof(Model.Manager_Month_PerformanceIndicatorC)), IndicatorType = "结果性指标", IndicatorName = "百万工时损失工时伤害事故率(损失工时伤害事故人数/总工时)*10^6", IndicatorValue = null, SortIndex = 5, }; performanceIndicators.Add(performanceIndicator5); i++; Model.Manager_Month_PerformanceIndicatorC performanceIndicator6 = new Model.Manager_Month_PerformanceIndicatorC { PerformanceIndicatorId = SQLHelper.GetNewID(typeof(Model.Manager_Month_PerformanceIndicatorC)), IndicatorType = "结果性指标", IndicatorName = "百万工时事故发生频率(损失工时伤害事故起数/总工时)*10^6", IndicatorValue = null, SortIndex = 6, }; performanceIndicators.Add(performanceIndicator6); i++; Model.Manager_Month_PerformanceIndicatorC performanceIndicator7 = new Model.Manager_Month_PerformanceIndicatorC { PerformanceIndicatorId = SQLHelper.GetNewID(typeof(Model.Manager_Month_PerformanceIndicatorC)), IndicatorType = "结果性指标", IndicatorName = "百万工时死亡事故频率(死亡事故起数/总工时)*10^6", IndicatorValue = null, SortIndex = 7, }; performanceIndicators.Add(performanceIndicator7); i++; Model.Manager_Month_PerformanceIndicatorC performanceIndicator8 = new Model.Manager_Month_PerformanceIndicatorC { PerformanceIndicatorId = SQLHelper.GetNewID(typeof(Model.Manager_Month_PerformanceIndicatorC)), IndicatorType = "结果性指标", IndicatorName = "百万工时事故死亡率(死亡事故人数/总工时)*10^6", IndicatorValue = null, SortIndex = 8, }; performanceIndicators.Add(performanceIndicator8); this.gvPerformanceIndicator.DataSource = performanceIndicators; this.gvPerformanceIndicator.DataBind(); } #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) { oldMonthReport.AccidentDef = this.txtDef.Text.Trim(); BLL.MonthReportCService.UpdateMonthReport(oldMonthReport); OperateInjuryAccidentSort(MonthReportId); OperateNoInjuryAccidentSort(MonthReportId); OperatePerformanceIndicatorSort(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.AccidentDef = this.txtDef.Text.Trim(); BLL.MonthReportCService.AddMonthReport(monthReport); OperateInjuryAccidentSort(this.MonthReportId); OperateNoInjuryAccidentSort(this.MonthReportId); OperatePerformanceIndicatorSort(this.MonthReportId); BLL.LogService.AddSys_Log(this.CurrUser, monthReport.MonthReportCode, monthReport.MonthReportId, BLL.Const.ProjectManagerMonthCMenuId, BLL.Const.BtnAdd); } ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } #region 本月伤害事故统计 /// /// 本月伤害事故统计 /// /// private void OperateInjuryAccidentSort(string monthReportId) { BLL.InjuryAccidentCService.DeleteInjuryAccidengtByMonthReportId(monthReportId); jerqueSaveInjuryAccidentCList(); foreach (Model.Manager_Month_InjuryAccidentC injury in injuryAccidents) { injury.MonthReportId = monthReportId; BLL.InjuryAccidentCService.AddInjuryAccidentC(injury); } } /// /// 检查并保存本月伤害事故统计 /// private void jerqueSaveInjuryAccidentCList() { injuryAccidents.Clear(); JArray mergedData = gvInjuryAccident.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); Model.Manager_Month_InjuryAccidentC monthPlanSort = new Model.Manager_Month_InjuryAccidentC { InjuryAccidentId = this.gvInjuryAccident.Rows[i].DataKeys[0].ToString(), UnitName = values.Value("UnitName").ToString(), AttemptedIncidents = Funs.GetNewInt(values.Value("AttemptedIncidents").ToString()), FirstAidDressing = Funs.GetNewInt(values.Value("FirstAidDressing").ToString()), MedicalTreatment = Funs.GetNewInt(values.Value("MedicalTreatment").ToString()), WorkLimitation = Funs.GetNewInt(values.Value("WorkLimitation").ToString()), LossPerson = Funs.GetNewInt(values.Value("LossPerson").ToString()), LossWorkTime = Funs.GetNewDecimal(values.Value("LossWorkTime").ToString()), LossEconomy = Funs.GetNewDecimal(values.Value("LossEconomy").ToString()), DeathPerson = Funs.GetNewInt(values.Value("DeathPerson").ToString()), DeathWorkTime = Funs.GetNewDecimal(values.Value("DeathWorkTime").ToString()), DeathEconomy = Funs.GetNewDecimal(values.Value("DeathEconomy").ToString()), }; injuryAccidents.Add(monthPlanSort); } } #endregion #region 本月无伤害事故统计 /// /// 本月伤害事故统计 /// /// private void OperateNoInjuryAccidentSort(string monthReportId) { BLL.NoInjuryAccidentCService.DeleteNoInjuryAccidentByMonthReportId(monthReportId); jerqueSaveNoInjuryAccidentCList(); foreach (Model.Manager_Month_NoInjuryAccidentC noInjury in noInjuryAccidents) { noInjury.MonthReportId = monthReportId; BLL.NoInjuryAccidentCService.AddNoInjuryAccident(noInjury); } } /// /// 检查并保存本月无伤害事故统计 /// private void jerqueSaveNoInjuryAccidentCList() { noInjuryAccidents.Clear(); JArray mergedData = gvNoInjuryAccident.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); Model.Manager_Month_NoInjuryAccidentC noInjuryAccident = new Model.Manager_Month_NoInjuryAccidentC { NoInjuryAccidentId = this.gvNoInjuryAccident.Rows[i].DataKeys[0].ToString(), AccidentType = values.Value("AccidentType").ToString(), EconomicLosses = Funs.GetNewDecimal(values.Value("EconomicLosses").ToString()), WHAccidentCount = Funs.GetNewInt(values.Value("WHAccidentCount").ToString()), SubAccidentCount = Funs.GetNewInt(values.Value("SubAccidentCount").ToString()), }; noInjuryAccidents.Add(noInjuryAccident); } } #endregion #region HSE绩效指标 /// /// HSE绩效指标 /// /// private void OperatePerformanceIndicatorSort(string monthReportId) { BLL.PerformanceIndicatorCService.DeletePerformanceIndicatorByMonthReportId(monthReportId); jerqueSavePerformanceIndicatorCList(); foreach (Model.Manager_Month_PerformanceIndicatorC performanceIndicator in performanceIndicators) { performanceIndicator.MonthReportId = monthReportId; BLL.PerformanceIndicatorCService.AddPerformanceIndicator(performanceIndicator); } } /// /// 检查并保存HSE绩效指标 /// private void jerqueSavePerformanceIndicatorCList() { performanceIndicators.Clear(); JArray mergedData = gvPerformanceIndicator.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); Model.Manager_Month_PerformanceIndicatorC performanceIndicator = new Model.Manager_Month_PerformanceIndicatorC { PerformanceIndicatorId = this.gvPerformanceIndicator.Rows[i].DataKeys[0].ToString(), IndicatorType = values.Value("IndicatorType").ToString(), IndicatorName = values.Value("IndicatorName").ToString(), IndicatorValue = values.Value("IndicatorValue").ToString(), SortIndex = Funs.GetNewInt(values.Value("SortIndex").ToString()), }; performanceIndicators.Add(performanceIndicator); } } #endregion #endregion } }