using BLL; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.ZHGL.Information { public partial class MillionsMonthlyReportSave : PageBase { #region 定义变量 /// /// 报表主键Id /// public string MillionsMonthlyReportId { get { return (string)ViewState["MillionsMonthlyReportId"]; } set { ViewState["MillionsMonthlyReportId"] = value; } } /// /// 定义集合 /// private static List items = new List(); #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetButtonPower(); items.Clear(); BLL.ConstValue.InitConstValueDropDownList(this.drpMonth, ConstValue.Group_0009, false); BLL.ConstValue.InitConstValueDropDownList(this.drpYear, ConstValue.Group_0008, false); this.drpUnit.DataTextField = "UnitName"; drpUnit.DataValueField = "UnitId"; drpUnit.DataSource = BLL.UnitService.GetThisUnitDropDownList(); drpUnit.DataBind(); this.drpUnit.Readonly = true; string unitId = Request.QueryString["UnitId"]; string year = Request.QueryString["Year"]; string months = Request.QueryString["Months"]; MillionsMonthlyReportId = Request.QueryString["MillionsMonthlyReportId"]; if (!String.IsNullOrEmpty(MillionsMonthlyReportId)) { items = BLL.MillionsMonthlyReportItemService.GetItemsNoSum(MillionsMonthlyReportId); this.Grid1.DataSource = items; this.Grid1.DataBind(); var report = BLL.MillionsMonthlyReportService.GetMillionsMonthlyReportByMillionsMonthlyReportId(MillionsMonthlyReportId); if (report != null) { this.btnSave.Hidden = true; this.btnSubmit.Hidden = true; this.btnCopy.Hidden = true; if (report.HandleState == BLL.Const.HandleState_4) { this.btnUpdata.Hidden = false; } else { if (report.HandleMan == this.CurrUser.UserId || this.CurrUser.UserId == BLL.Const.sysglyId) { this.btnSave.Hidden = false; this.btnSubmit.Hidden = false; } } if (report.UpState == BLL.Const.UpState_3) { this.btnSave.Hidden = true; this.btnUpdata.Hidden = true; } drpMonth.SelectedValue = report.Month.ToString(); drpYear.SelectedValue = report.Year.ToString(); drpUnit.SelectedValue = report.UnitId; if (report.FillingDate != null) { txtFillingDate.Text = string.Format("{0:yyyy-MM-dd}", report.FillingDate); } txtDutyPerson.Text = report.DutyPerson; if (report.RecordableIncidentRate != null) { txtRecordableIncidentRate.Text = report.RecordableIncidentRate.ToString(); } if (report.LostTimeRate != null) { txtLostTimeRate.Text = report.LostTimeRate.ToString(); } if (report.LostTimeInjuryRate != null) { txtLostTimeInjuryRate.Text = report.LostTimeInjuryRate.ToString(); } if (report.DeathAccidentFrequency != null) { txtDeathAccidentFrequency.Text = report.DeathAccidentFrequency.ToString(); } if (report.AccidentMortality != null) { txtAccidentMortality.Text = report.AccidentMortality.ToString(); } if (report.InputCosts != null) { this.txtInputCosts.Text = Convert.ToString(report.InputCosts); } if (report.TrainNum != null) { this.txtTrainNum.Text = Convert.ToString(report.TrainNum); } if (report.GeneralHazardNum != null) { this.txtGeneralHazardNum.Text = Convert.ToString(report.GeneralHazardNum); } if (report.MajorHazardNum != null) { this.txtMajorHazardNum.Text = Convert.ToString(report.MajorHazardNum); } if (report.NotProofLargeProjectNum != null) { this.txtNotProofLargeProjectNum.Text = Convert.ToString(report.NotProofLargeProjectNum); } if (report.ProofLargeProjectNum != null) { this.txtProofLargeProjectNum.Text = Convert.ToString(report.ProofLargeProjectNum); } if (report.FireLicenseNum != null) { this.txtFireLicenseNum.Text = Convert.ToString(report.FireLicenseNum); } if (report.LimitLicenseNum != null) { this.txtLimitLicenseNum.Text = Convert.ToString(report.LimitLicenseNum); } if (report.HighLicenseNum != null) { this.txtHighLicenseNum.Text = Convert.ToString(report.HighLicenseNum); } if (report.HoistingLicenseNum != null) { this.txtHoistingLicenseNum.Text = Convert.ToString(report.HoistingLicenseNum); } if (report.BreakGroundLicenseNum != null) { this.txtBreakGroundLicenseNum.Text = Convert.ToString(report.BreakGroundLicenseNum); } if (report.ElectricityLicenseNum != null) { this.txtElectricityLicenseNum.Text = Convert.ToString(report.ElectricityLicenseNum); } if (report.RTLicenseNum != null) { this.txtRTLicenseNum.Text = Convert.ToString(report.RTLicenseNum); } if (report.NightLicenseNum != null) { this.txtNightLicenseNum.Text = Convert.ToString(report.NightLicenseNum); } if (report.CommissionerNum != null) { this.txtCommissionerNum.Text = Convert.ToString(report.CommissionerNum); } if (report.SoleDutyNum != null) { this.txtSoleDutyNum.Text = Convert.ToString(report.SoleDutyNum); } } } else { this.btnCopy.Hidden = false; drpMonth.SelectedValue = months; drpYear.SelectedValue = year; txtFillingDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); txtDutyPerson.Text = this.CurrUser.UserName; //增加明细集合 GetNewItems(year, months); this.Grid1.DataSource = items; this.Grid1.DataBind(); this.txtRecordableIncidentRate.Text = "0"; this.txtLostTimeRate.Text = "0"; this.txtLostTimeInjuryRate.Text = "0"; this.txtDeathAccidentFrequency.Text = "0"; this.txtAccidentMortality.Text = "0"; } } } #endregion #region 关闭窗口 /// /// 关闭窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { Model.Information_MillionsMonthlyReport report = BLL.MillionsMonthlyReportService.GetMillionsMonthlyReportByMillionsMonthlyReportId(MillionsMonthlyReportId); if (report.HandleMan == this.CurrUser.UserId) { this.btnSave.Hidden = false; this.btnSubmit.Hidden = false; } else { this.btnSave.Hidden = true; this.btnSubmit.Hidden = true; } } #endregion #region 保存、提交、上报 /// /// 保存数据 /// /// private void Save(string type) { //string millionsMonthlyReportId = Request.QueryString["MillionsMonthlyReportId"]; Model.Information_MillionsMonthlyReport report = new Information_MillionsMonthlyReport { UnitId = drpUnit.SelectedValue, Year = Funs.GetNewIntOrZero(drpYear.SelectedValue), Month = Funs.GetNewIntOrZero(drpMonth.SelectedValue) }; if (!string.IsNullOrEmpty(txtFillingDate.Text.Trim())) { report.FillingDate = Convert.ToDateTime(txtFillingDate.Text.Trim()); } report.DutyPerson = txtDutyPerson.Text.Trim(); if (!string.IsNullOrEmpty(txtRecordableIncidentRate.Text.Trim())) { report.RecordableIncidentRate = Convert.ToDecimal(txtRecordableIncidentRate.Text.Trim()); } if (!string.IsNullOrEmpty(txtLostTimeRate.Text.Trim())) { report.LostTimeRate = Convert.ToDecimal(txtLostTimeRate.Text.Trim()); } if (!string.IsNullOrEmpty(txtLostTimeInjuryRate.Text.Trim())) { report.LostTimeInjuryRate = Convert.ToDecimal(txtLostTimeInjuryRate.Text.Trim()); } if (!string.IsNullOrEmpty(txtDeathAccidentFrequency.Text.Trim())) { report.DeathAccidentFrequency = Convert.ToDecimal(txtDeathAccidentFrequency.Text.Trim()); } if (!string.IsNullOrEmpty(txtAccidentMortality.Text.Trim())) { report.AccidentMortality = Convert.ToDecimal(txtAccidentMortality.Text.Trim()); } report.InputCosts = Funs.GetNewDecimalOrZero(this.txtInputCosts.Text.Trim()); report.TrainNum = Funs.GetNewInt(this.txtTrainNum.Text.Trim()); report.GeneralHazardNum = Funs.GetNewInt(this.txtGeneralHazardNum.Text.Trim()); report.MajorHazardNum = Funs.GetNewInt(this.txtMajorHazardNum.Text.Trim()); report.NotProofLargeProjectNum = Funs.GetNewInt(this.txtNotProofLargeProjectNum.Text.Trim()); report.ProofLargeProjectNum = Funs.GetNewInt(this.txtProofLargeProjectNum.Text.Trim()); report.FireLicenseNum = Funs.GetNewInt(this.txtFireLicenseNum.Text.Trim()); report.LimitLicenseNum = Funs.GetNewInt(this.txtLimitLicenseNum.Text.Trim()); report.HighLicenseNum = Funs.GetNewInt(this.txtHighLicenseNum.Text.Trim()); report.HoistingLicenseNum = Funs.GetNewInt(this.txtHoistingLicenseNum.Text.Trim()); report.BreakGroundLicenseNum = Funs.GetNewInt(this.txtBreakGroundLicenseNum.Text.Trim()); report.ElectricityLicenseNum = Funs.GetNewInt(this.txtElectricityLicenseNum.Text.Trim()); report.RTLicenseNum = Funs.GetNewInt(this.txtRTLicenseNum.Text.Trim()); report.NightLicenseNum = Funs.GetNewInt(this.txtNightLicenseNum.Text.Trim()); report.CommissionerNum = Funs.GetNewInt(this.txtCommissionerNum.Text.Trim()); report.SoleDutyNum = Funs.GetNewInt(this.txtSoleDutyNum.Text.Trim()); if (String.IsNullOrEmpty(MillionsMonthlyReportId)) { Information_MillionsMonthlyReport old = MillionsMonthlyReportService.GetMillionsMonthlyReportByUnitIdDate(drpUnit.SelectedValue, Funs.GetNewIntOrZero(drpYear.SelectedValue), Funs.GetNewIntOrZero(drpMonth.SelectedValue)); if (old == null) { report.MillionsMonthlyReportId = SQLHelper.GetNewID(typeof(Model.Information_MillionsMonthlyReport)); report.UpState = BLL.Const.UpState_2; report.FillingMan = this.CurrUser.UserName; report.HandleState = BLL.Const.HandleState_1; report.HandleMan = this.CurrUser.UserId; BLL.MillionsMonthlyReportService.AddMillionsMonthlyReport(report); BLL.LogService.AddSys_Log(this.CurrUser, report.Year.ToString() + "-" + report.Month.ToString(), report.MillionsMonthlyReportId, BLL.Const.MillionsMonthlyReportMenuId, BLL.Const.BtnAdd); } else { ShowNotify("该月份记录已存在!", MessageBoxIcon.Warning); return; } } else { Model.Information_MillionsMonthlyReport oldReport = BLL.MillionsMonthlyReportService.GetMillionsMonthlyReportByMillionsMonthlyReportId(MillionsMonthlyReportId); if (oldReport != null) { report.HandleMan = oldReport.HandleMan; report.HandleState = oldReport.HandleState; } report.MillionsMonthlyReportId = MillionsMonthlyReportId; report.UpState = BLL.Const.UpState_2; BLL.MillionsMonthlyReportService.UpdateMillionsMonthlyReport(report); BLL.LogService.AddSys_Log(this.CurrUser, report.Year.ToString() + "-" + report.Month.ToString(), report.MillionsMonthlyReportId, BLL.Const.MillionsMonthlyReportMenuId, BLL.Const.BtnModify); } MillionsMonthlyReportId = report.MillionsMonthlyReportId; BLL.MillionsMonthlyReportItemService.DeleteMillionsMonthlyReportItemByMillionsMonthlyReportId(report.MillionsMonthlyReportId); List mReportItemList = new List(); GetItems(report.MillionsMonthlyReportId); foreach (var item in items) { if (!string.IsNullOrEmpty(item.Name)) { item.Affiliation = System.Web.HttpUtility.HtmlDecode(item.Affiliation); item.Name = System.Web.HttpUtility.HtmlDecode(item.Name); MillionsMonthlyReportItemService.AddMillionsMonthlyReportItem(item); mReportItemList.Add(item); } } if (type == "updata") //数据同步 { if (report.UpState == BLL.Const.UpState_2) { string code = CNCECHSSEWebService.UpMillionsMonthlyReport(report.MillionsMonthlyReportId, this.CurrUser); if (code == "1") { ShowNotify("同步成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); return; } else { Alert.ShowInParent("同步异常,请退出后重试!", MessageBoxIcon.Error); } } else { ShowNotify("当前单据状态不能同步!", MessageBoxIcon.Warning); return; } } if (type == "submit") { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ReportSubmit.aspx?Type=MillionsMonthlyReport&Id={0}", report.MillionsMonthlyReportId, "编辑 - "))); } } protected void btnSave_Click(object sender, EventArgs e) { Save("add"); } protected void btnUpdata_Click(object sender, EventArgs e) { Save("updata"); } protected void btnSubmit_Click(object sender, EventArgs e) { Save("submit"); } #endregion #region 增加本月明细 private void GetItems(string millionsMonthlyReportId) { decimal TotalWorkNumSum = 0; int PostPersonNumSum = 0, SnapPersonNumSum = 0, ContractorNumSum = 0, SumPersonNumSum = 0, SeriousInjuriesNumSum = 0, SeriousInjuriesPersonNumSum = 0, SeriousInjuriesLossHourSum = 0, MinorAccidentNumSum = 0, MinorAccidentPersonNumSum = 0, MinorAccidentLossHourSum = 0, DeathAccidentNumSum = 0, DeathAccidentPersonNumSum = 0, DeathAccidentLossHourSum = 0, RestrictedWorkPersonNumSum = 0, RestrictedWorkLossHourSum = 0, MedicalTreatmentPersonNumSum = 0, MedicalTreatmentLossHourSum = 0, FireNumSum = 0, EnvironmenNumSum = 0, TrafficNumSum = 0, EquipmentNumSum = 0, QualityNumSum = 0, OtherNumSum = 0, FirstAidDressingsNumSum = 0, AttemptedEventNumSum = 0, LossDayNumSum = 0; items.Clear(); int i = 10; foreach (JObject mergedRow in Grid1.GetMergedData()) { JObject values = mergedRow.Value("values"); int SumPersonNum = 0; Model.Information_MillionsMonthlyReportItem item = new Information_MillionsMonthlyReportItem(); if (values["MillionsMonthlyReportItemId"].ToString() != "") { item.MillionsMonthlyReportItemId = values.Value("MillionsMonthlyReportItemId"); } item.MillionsMonthlyReportId = millionsMonthlyReportId; item.SortIndex = i; if (!string.IsNullOrEmpty(values["Affiliation"].ToString())) { item.Affiliation = values.Value("Affiliation"); } if (!string.IsNullOrEmpty(values["Name"].ToString())) { item.Name = values.Value("Name"); } if (!string.IsNullOrEmpty(values["PostPersonNum"].ToString())) { item.PostPersonNum = values.Value("PostPersonNum"); SumPersonNum += values.Value("PostPersonNum"); PostPersonNumSum += values.Value("PostPersonNum"); SumPersonNumSum += values.Value("PostPersonNum"); } else { item.PostPersonNum = 0; } if (!string.IsNullOrEmpty(values["SnapPersonNum"].ToString())) { item.SnapPersonNum = values.Value("SnapPersonNum"); SumPersonNum += values.Value("SnapPersonNum"); SnapPersonNumSum += values.Value("SnapPersonNum"); SumPersonNumSum += values.Value("SnapPersonNum"); } else { item.SnapPersonNum = 0; } if (!string.IsNullOrEmpty(values["ContractorNum"].ToString())) { item.ContractorNum = values.Value("ContractorNum"); SumPersonNum += values.Value("ContractorNum"); ContractorNumSum += values.Value("ContractorNum"); SumPersonNumSum += values.Value("ContractorNum"); } else { item.ContractorNum = 0; } if (SumPersonNum != 0) { item.SumPersonNum = SumPersonNum; //获取每条明细记录员工总数合计值 } if (!string.IsNullOrEmpty(values["TotalWorkNum"].ToString())) { item.TotalWorkNum = values.Value("TotalWorkNum"); TotalWorkNumSum += values.Value("TotalWorkNum"); } else { item.TotalWorkNum = 0; } if (!string.IsNullOrEmpty(values["SeriousInjuriesNum"].ToString())) { item.SeriousInjuriesNum = values.Value("SeriousInjuriesNum"); SeriousInjuriesNumSum += values.Value("SeriousInjuriesNum"); } else { item.SeriousInjuriesNum = 0; } if (!string.IsNullOrEmpty(values["SeriousInjuriesPersonNum"].ToString())) { item.SeriousInjuriesPersonNum = values.Value("SeriousInjuriesPersonNum"); SeriousInjuriesPersonNumSum += values.Value("SeriousInjuriesPersonNum"); } else { item.SeriousInjuriesPersonNum = 0; } if (values["SeriousInjuriesLossHour"].ToString() != "") { item.SeriousInjuriesLossHour = values.Value("SeriousInjuriesLossHour"); SeriousInjuriesLossHourSum += values.Value("SeriousInjuriesLossHour"); } else { item.SeriousInjuriesLossHour = 0; } if (values["MinorAccidentNum"].ToString() != "") { item.MinorAccidentNum = values.Value("MinorAccidentNum"); MinorAccidentNumSum += values.Value("MinorAccidentNum"); } else { item.MinorAccidentNum = 0; } if (values["MinorAccidentPersonNum"].ToString() != "") { item.MinorAccidentPersonNum = values.Value("MinorAccidentPersonNum"); MinorAccidentPersonNumSum += values.Value("MinorAccidentPersonNum"); } if (values["MinorAccidentLossHour"].ToString() != "") { item.MinorAccidentLossHour = values.Value("MinorAccidentLossHour"); MinorAccidentLossHourSum += values.Value("MinorAccidentLossHour"); } else { item.MinorAccidentLossHour = 0; } if (values["DeathAccidentNum"].ToString() != "") { item.DeathAccidentNum = values.Value("DeathAccidentNum"); DeathAccidentNumSum += values.Value("DeathAccidentNum"); } if (values["DeathAccidentPersonNum"].ToString() != "") { item.DeathAccidentPersonNum = values.Value("DeathAccidentPersonNum"); DeathAccidentPersonNumSum += values.Value("DeathAccidentPersonNum"); } else { item.DeathAccidentPersonNum = 0; } if (values["DeathAccidentLossHour"].ToString() != "") { item.DeathAccidentLossHour = values.Value("DeathAccidentLossHour"); DeathAccidentLossHourSum += values.Value("DeathAccidentLossHour"); } else { item.DeathAccidentLossHour = 0; } if (values["RestrictedWorkPersonNum"].ToString() != "") { item.RestrictedWorkPersonNum = values.Value("RestrictedWorkPersonNum"); RestrictedWorkPersonNumSum += values.Value("RestrictedWorkPersonNum"); } else { item.RestrictedWorkPersonNum = 0; } if (values["RestrictedWorkLossHour"].ToString() != "") { item.RestrictedWorkLossHour = values.Value("RestrictedWorkLossHour"); RestrictedWorkLossHourSum += values.Value("RestrictedWorkLossHour"); } else { item.RestrictedWorkLossHour = 0; } if (values["MedicalTreatmentPersonNum"].ToString() != "") { item.MedicalTreatmentPersonNum = values.Value("MedicalTreatmentPersonNum"); MedicalTreatmentPersonNumSum += values.Value("MedicalTreatmentPersonNum"); } else { item.MedicalTreatmentPersonNum = 0; } if (values["MedicalTreatmentLossHour"].ToString() != "") { item.MedicalTreatmentLossHour = values.Value("MedicalTreatmentLossHour"); MedicalTreatmentLossHourSum += values.Value("MedicalTreatmentLossHour"); } else { item.MedicalTreatmentLossHour = 0; } if (values["FireNum"].ToString() != "") { item.FireNum = values.Value("FireNum"); FireNumSum += values.Value("FireNum"); } else { item.FireNum = 0; } if (values["EnvironmenNum"].ToString() != "") { item.EnvironmenNum = values.Value("EnvironmenNum"); EnvironmenNumSum += values.Value("EnvironmenNum"); } else { item.EnvironmenNum = 0; } if (values["TrafficNum"].ToString() != "") { item.TrafficNum = values.Value("TrafficNum"); TrafficNumSum += values.Value("TrafficNum"); } else { item.TrafficNum = 0; } if (values["EquipmentNum"].ToString() != "") { item.EquipmentNum = values.Value("EquipmentNum"); EquipmentNumSum += values.Value("EquipmentNum"); } else { item.EquipmentNum = 0; } if (values["QualityNum"].ToString() != "") { item.QualityNum = values.Value("QualityNum"); QualityNumSum += values.Value("QualityNum"); } else { item.QualityNum = 0; } if (values["OtherNum"].ToString() != "") { item.OtherNum = values.Value("OtherNum"); OtherNumSum += values.Value("OtherNum"); } else { item.OtherNum = 0; } if (values["FirstAidDressingsNum"].ToString() != "") { item.FirstAidDressingsNum = values.Value("FirstAidDressingsNum"); FirstAidDressingsNumSum += values.Value("FirstAidDressingsNum"); } else { item.FirstAidDressingsNum = 0; } if (values["AttemptedEventNum"].ToString() != "") { item.AttemptedEventNum = values.Value("AttemptedEventNum"); AttemptedEventNumSum += values.Value("AttemptedEventNum"); } else { item.AttemptedEventNum = 0; } if (values["LossDayNum"].ToString() != "") { item.LossDayNum = values.Value("LossDayNum"); LossDayNumSum += values.Value("LossDayNum"); } else { item.LossDayNum = 0; } items.Add(item); i += 10; } Information_MillionsMonthlyReportItem totalItem = new Information_MillionsMonthlyReportItem { MillionsMonthlyReportItemId = SQLHelper.GetNewID(typeof(Model.Information_MillionsMonthlyReportItem)), MillionsMonthlyReportId = millionsMonthlyReportId, SortIndex = i + 10, Affiliation = "本月合计", Name = "本月合计", PostPersonNum = PostPersonNumSum, SnapPersonNum = SnapPersonNumSum, ContractorNum = ContractorNumSum, SumPersonNum = SumPersonNumSum, TotalWorkNum = TotalWorkNumSum, SeriousInjuriesNum = SeriousInjuriesNumSum, SeriousInjuriesPersonNum = SeriousInjuriesPersonNumSum, SeriousInjuriesLossHour = SeriousInjuriesLossHourSum, MinorAccidentNum = MinorAccidentNumSum, MinorAccidentPersonNum = MinorAccidentPersonNumSum, MinorAccidentLossHour = MinorAccidentLossHourSum, DeathAccidentNum = DeathAccidentNumSum, DeathAccidentPersonNum = DeathAccidentPersonNumSum, DeathAccidentLossHour = DeathAccidentLossHourSum, RestrictedWorkPersonNum = RestrictedWorkPersonNumSum, RestrictedWorkLossHour = RestrictedWorkLossHourSum, MedicalTreatmentPersonNum = MedicalTreatmentPersonNumSum, MedicalTreatmentLossHour = MedicalTreatmentLossHourSum, FireNum = FireNumSum, EnvironmenNum = EnvironmenNumSum, TrafficNum = TrafficNumSum, EquipmentNum = EquipmentNumSum, QualityNum = QualityNumSum, OtherNum = OtherNumSum, FirstAidDressingsNum = FirstAidDressingsNumSum, AttemptedEventNum = AttemptedEventNumSum, LossDayNum = LossDayNumSum }; items.Add(totalItem); } #endregion #region Grid行点击事件 protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string rowID = Grid1.DataKeys[e.RowIndex][0].ToString(); GetItems(string.Empty); Model.Information_MillionsMonthlyReportItem totalItem = items.FirstOrDefault(x => x.Affiliation == "本月合计"); items.Remove(totalItem); if (e.CommandName == "Add") { Model.Information_MillionsMonthlyReportItem oldItem = items.FirstOrDefault(x => x.MillionsMonthlyReportItemId == rowID); Model.Information_MillionsMonthlyReportItem newItem = new Information_MillionsMonthlyReportItem { MillionsMonthlyReportItemId = SQLHelper.GetNewID(typeof(Model.Information_MillionsMonthlyReportItem)) }; if (oldItem != null) { newItem.SortIndex = oldItem.SortIndex + 1; newItem.Affiliation = oldItem.Affiliation; } else { newItem.SortIndex = 0; } items.Add(newItem); items = items.OrderBy(x => x.SortIndex).ToList(); Grid1.DataSource = items; Grid1.DataBind(); } if (e.CommandName == "Delete") { foreach (var item in items) { if (item.MillionsMonthlyReportItemId == rowID) { items.Remove(item); break; } } Grid1.DataSource = items; Grid1.DataBind(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #endregion #region 获取明细 private void GetNewItems(string year, string months) { //获取项目集合 List millionsMonthlyReports = (from x in Funs.DB.InformationProject_MillionsMonthlyReport where x.Year.ToString() == year && x.Month.ToString() == months && x.States == BLL.Const.State_2 select x).ToList(); this.txtInputCosts.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.InputCosts ?? 0)); this.txtTrainNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.TrainNum ?? 0)); this.txtGeneralHazardNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.GeneralHazardNum ?? 0)); this.txtMajorHazardNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.MajorHazardNum ?? 0)); this.txtNotProofLargeProjectNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.NotProofLargeProjectNum ?? 0)); this.txtProofLargeProjectNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.ProofLargeProjectNum ?? 0)); this.txtFireLicenseNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.FireLicenseNum ?? 0)); this.txtLimitLicenseNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.LimitLicenseNum ?? 0)); this.txtHighLicenseNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.HighLicenseNum ?? 0)); this.txtHoistingLicenseNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.HoistingLicenseNum ?? 0)); this.txtBreakGroundLicenseNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.BreakGroundLicenseNum ?? 0)); this.txtElectricityLicenseNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.ElectricityLicenseNum ?? 0)); this.txtRTLicenseNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.RTLicenseNum ?? 0)); this.txtNightLicenseNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.NightLicenseNum ?? 0)); this.txtCommissionerNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.CommissionerNum ?? 0)); this.txtSoleDutyNum.Text = Convert.ToString(millionsMonthlyReports.Sum(x => x.SoleDutyNum ?? 0)); List projectIds = millionsMonthlyReports.Select(x => x.ProjectId).ToList(); //增加明细集合 Model.Information_MillionsMonthlyReportItem item1 = new Information_MillionsMonthlyReportItem { MillionsMonthlyReportItemId = SQLHelper.GetNewID(typeof(Model.Information_MillionsMonthlyReportItem)), Affiliation = "机关后勤服务", Name = "总部", SortIndex = 10, PostPersonNum = 0, SnapPersonNum = 0, ContractorNum = 0, SumPersonNum = 0, TotalWorkNum = 0, SeriousInjuriesNum = 0, SeriousInjuriesPersonNum = 0, SeriousInjuriesLossHour = 0, MinorAccidentNum = 0, MinorAccidentPersonNum = 0, MinorAccidentLossHour = 0, DeathAccidentNum = 0, DeathAccidentPersonNum = 0, DeathAccidentLossHour = 0, RestrictedWorkPersonNum = 0, RestrictedWorkLossHour = 0, MedicalTreatmentPersonNum = 0, MedicalTreatmentLossHour = 0, FireNum = 0, EnvironmenNum = 0, TrafficNum = 0, EquipmentNum = 0, QualityNum = 0, OtherNum = 0, FirstAidDressingsNum = 0, AttemptedEventNum = 0, LossDayNum = 0, }; items.Add(item1); Model.Information_MillionsMonthlyReportItem item2 = new Information_MillionsMonthlyReportItem { MillionsMonthlyReportItemId = SQLHelper.GetNewID(typeof(Model.Information_MillionsMonthlyReportItem)), Affiliation = "机关后勤服务", Name = "二级单位", SortIndex = 20, PostPersonNum = 0, SnapPersonNum = 0, ContractorNum = 0, SumPersonNum = 0, TotalWorkNum = 0, SeriousInjuriesNum = 0, SeriousInjuriesPersonNum = 0, SeriousInjuriesLossHour = 0, MinorAccidentNum = 0, MinorAccidentPersonNum = 0, MinorAccidentLossHour = 0, DeathAccidentNum = 0, DeathAccidentPersonNum = 0, DeathAccidentLossHour = 0, RestrictedWorkPersonNum = 0, RestrictedWorkLossHour = 0, MedicalTreatmentPersonNum = 0, MedicalTreatmentLossHour = 0, FireNum = 0, EnvironmenNum = 0, TrafficNum = 0, EquipmentNum = 0, QualityNum = 0, OtherNum = 0, FirstAidDressingsNum = 0, AttemptedEventNum = 0, LossDayNum = 0, }; items.Add(item2); var projects = (from x in Funs.DB.Base_Project where projectIds.Contains(x.ProjectId) select x).ToList(); if (this.CurrUser.UnitId == Const.UnitId_CD) { projects = BLL.ProjectService.GetProjectWorkList(); } int i = 20; foreach (var p in projects) { i += 10; Model.Information_MillionsMonthlyReportItem item = new Information_MillionsMonthlyReportItem { MillionsMonthlyReportItemId = SQLHelper.GetNewID(typeof(Model.Information_MillionsMonthlyReportItem)), Affiliation = "项目现场", Name = p.ProjectName, SortIndex = i }; if (!string.IsNullOrEmpty(p.UnitId)) { var name = BLL.UnitService.GetUnitNameByUnitId(p.UnitId); if (!string.IsNullOrEmpty(name)) { item.Affiliation = name; item.Name = "[" + p.ProjectCode + "]" + p.ProjectName; } } Model.InformationProject_MillionsMonthlyReport report = millionsMonthlyReports.FirstOrDefault(x => x.ProjectId == p.ProjectId); if (report != null) { item.PostPersonNum = report.PostPersonNum; item.SnapPersonNum = report.SnapPersonNum; item.ContractorNum = report.ContractorNum; item.SumPersonNum = report.SumPersonNum; item.TotalWorkNum = report.TotalWorkNum; item.SeriousInjuriesNum = report.SeriousInjuriesNum; item.SeriousInjuriesPersonNum = report.SeriousInjuriesPersonNum; item.SeriousInjuriesLossHour = report.SeriousInjuriesLossHour; item.MinorAccidentNum = report.MinorAccidentNum; item.MinorAccidentPersonNum = report.MinorAccidentPersonNum; item.MinorAccidentLossHour = report.MinorAccidentLossHour; item.DeathAccidentNum = report.DeathAccidentNum; item.DeathAccidentPersonNum = report.DeathAccidentPersonNum; item.DeathAccidentLossHour = report.DeathAccidentLossHour; item.RestrictedWorkPersonNum = report.RestrictedWorkPersonNum; item.RestrictedWorkLossHour = report.RestrictedWorkLossHour; item.MedicalTreatmentPersonNum = report.MedicalTreatmentPersonNum; item.MedicalTreatmentLossHour = report.MedicalTreatmentLossHour; item.FireNum = report.FireNum; item.EnvironmenNum = report.EnvironmenNum; item.TrafficNum = report.TrafficNum; item.EquipmentNum = report.EquipmentNum; item.QualityNum = report.QualityNum; item.OtherNum = report.OtherNum; item.FirstAidDressingsNum = report.FirstAidDressingsNum; item.AttemptedEventNum = report.AttemptedEventNum; item.LossDayNum = report.LossDayNum; } else { item.PostPersonNum = 0; item.SnapPersonNum = 0; item.ContractorNum = 0; item.SumPersonNum = 0; item.TotalWorkNum = 0; item.SeriousInjuriesNum = 0; item.SeriousInjuriesPersonNum = 0; item.SeriousInjuriesLossHour = 0; item.MinorAccidentNum = 0; item.MinorAccidentPersonNum = 0; item.MinorAccidentLossHour = 0; item.DeathAccidentNum = 0; item.DeathAccidentPersonNum = 0; item.DeathAccidentLossHour = 0; item.RestrictedWorkPersonNum = 0; item.RestrictedWorkLossHour = 0; item.MedicalTreatmentPersonNum = 0; item.MedicalTreatmentLossHour = 0; item.FireNum = 0; item.EnvironmenNum = 0; item.TrafficNum = 0; item.EquipmentNum = 0; item.QualityNum = 0; item.OtherNum = 0; item.FirstAidDressingsNum = 0; item.AttemptedEventNum = 0; item.LossDayNum = 0; } items.Add(item); } } #endregion #region 单位下拉选择事件 /// /// 单位下拉选择事件 /// /// /// protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e) { items.Clear(); if (drpUnit.SelectedValue != BLL.Const._Null) { //GetNewItems(); } Grid1.DataSource = items; Grid1.DataBind(); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.MillionsMonthlyReportMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; this.btnCopy.Hidden = false; } //if (buttonList.Contains(BLL.Const.BtnSaveUp)) //{ // this.btnUpdata.Hidden = false; //} if (buttonList.Contains(BLL.Const.BtnSubmit)) { this.btnSubmit.Hidden = false; //this.btnCopy.Hidden = false; } } } #endregion #region 复制上个月数据 /// /// 复制上个月的数据 /// /// /// protected void btnCopy_Click(object sender, EventArgs e) { DateTime? nowDate = Funs.GetNewDateTime(this.drpYear.SelectedValue + "-" + this.drpMonth.SelectedValue); if (nowDate.HasValue) { DateTime showDate = new DateTime(); showDate = nowDate.Value.AddMonths(-1); Model.Information_MillionsMonthlyReport millionsMonthlyReport = BLL.MillionsMonthlyReportService.GetMillionsMonthlyReportByUnitIdAndYearAndMonth(this.drpUnit.SelectedValue, showDate.Year, showDate.Month); if (millionsMonthlyReport != null) { Model.Information_MillionsMonthlyReport newMillionsMonthlyReport = new Information_MillionsMonthlyReport(); this.MillionsMonthlyReportId = SQLHelper.GetNewID(typeof(Model.Information_MillionsMonthlyReport)); newMillionsMonthlyReport.MillionsMonthlyReportId = this.MillionsMonthlyReportId; newMillionsMonthlyReport.UnitId = this.drpUnit.SelectedValue; newMillionsMonthlyReport.Year = Convert.ToInt32(this.drpYear.SelectedValue); newMillionsMonthlyReport.Month = Convert.ToInt32(this.drpMonth.SelectedValue); newMillionsMonthlyReport.FillingMan = this.CurrUser.UserName; newMillionsMonthlyReport.FillingDate = DateTime.Now; newMillionsMonthlyReport.DutyPerson = this.CurrUser.UserName; newMillionsMonthlyReport.RecordableIncidentRate = millionsMonthlyReport.RecordableIncidentRate; newMillionsMonthlyReport.LostTimeRate = millionsMonthlyReport.LostTimeRate; newMillionsMonthlyReport.LostTimeInjuryRate = millionsMonthlyReport.LostTimeInjuryRate; newMillionsMonthlyReport.DeathAccidentFrequency = millionsMonthlyReport.DeathAccidentFrequency; newMillionsMonthlyReport.AccidentMortality = millionsMonthlyReport.AccidentMortality; newMillionsMonthlyReport.UpState = BLL.Const.UpState_2; newMillionsMonthlyReport.HandleState = BLL.Const.HandleState_1; newMillionsMonthlyReport.HandleMan = this.CurrUser.UserId; newMillionsMonthlyReport.InputCosts = millionsMonthlyReport.InputCosts; newMillionsMonthlyReport.TrainNum = millionsMonthlyReport.TrainNum; newMillionsMonthlyReport.GeneralHazardNum = millionsMonthlyReport.GeneralHazardNum; newMillionsMonthlyReport.MajorHazardNum = millionsMonthlyReport.MajorHazardNum; newMillionsMonthlyReport.NotProofLargeProjectNum = millionsMonthlyReport.NotProofLargeProjectNum; newMillionsMonthlyReport.ProofLargeProjectNum = millionsMonthlyReport.ProofLargeProjectNum; newMillionsMonthlyReport.FireLicenseNum = millionsMonthlyReport.FireLicenseNum; newMillionsMonthlyReport.LimitLicenseNum = millionsMonthlyReport.LimitLicenseNum; newMillionsMonthlyReport.HighLicenseNum = millionsMonthlyReport.HighLicenseNum; newMillionsMonthlyReport.HoistingLicenseNum = millionsMonthlyReport.HoistingLicenseNum; newMillionsMonthlyReport.BreakGroundLicenseNum = millionsMonthlyReport.BreakGroundLicenseNum; newMillionsMonthlyReport.ElectricityLicenseNum = millionsMonthlyReport.ElectricityLicenseNum; newMillionsMonthlyReport.RTLicenseNum = millionsMonthlyReport.RTLicenseNum; newMillionsMonthlyReport.NightLicenseNum = millionsMonthlyReport.NightLicenseNum; newMillionsMonthlyReport.CommissionerNum = millionsMonthlyReport.CommissionerNum; newMillionsMonthlyReport.SoleDutyNum = millionsMonthlyReport.SoleDutyNum; BLL.MillionsMonthlyReportService.AddMillionsMonthlyReport(newMillionsMonthlyReport); items = BLL.MillionsMonthlyReportItemService.GetItems(millionsMonthlyReport.MillionsMonthlyReportId); if (items.Count > 0) { foreach (var item in items) { if (item.Affiliation != "本月合计" || item.Name != "本月合计") { Model.Information_MillionsMonthlyReportItem newItem = new Information_MillionsMonthlyReportItem { MillionsMonthlyReportItemId = SQLHelper.GetNewID(typeof(Model.Information_MillionsMonthlyReportItem)), MillionsMonthlyReportId = this.MillionsMonthlyReportId, SortIndex = item.SortIndex, Affiliation = item.Affiliation, Name = item.Name, PostPersonNum = item.PostPersonNum, SnapPersonNum = item.SnapPersonNum, ContractorNum = item.ContractorNum, SumPersonNum = item.SumPersonNum, TotalWorkNum = item.TotalWorkNum, SeriousInjuriesNum = item.SeriousInjuriesNum, SeriousInjuriesPersonNum = item.SeriousInjuriesPersonNum, SeriousInjuriesLossHour = item.SeriousInjuriesLossHour, MinorAccidentNum = item.MinorAccidentNum, MinorAccidentPersonNum = item.MinorAccidentPersonNum, MinorAccidentLossHour = item.MinorAccidentLossHour, DeathAccidentNum = item.DeathAccidentNum, DeathAccidentPersonNum = item.DeathAccidentPersonNum, DeathAccidentLossHour = item.DeathAccidentLossHour, RestrictedWorkPersonNum = item.RestrictedWorkPersonNum, RestrictedWorkLossHour = item.RestrictedWorkLossHour, MedicalTreatmentPersonNum = item.MedicalTreatmentPersonNum, MedicalTreatmentLossHour = item.MedicalTreatmentLossHour, FireNum = item.FireNum, EnvironmenNum = item.EnvironmenNum, TrafficNum = item.TrafficNum, EquipmentNum = item.EquipmentNum, QualityNum = item.QualityNum, OtherNum = item.OtherNum, FirstAidDressingsNum = item.FirstAidDressingsNum, AttemptedEventNum = item.AttemptedEventNum, LossDayNum = item.LossDayNum }; BLL.MillionsMonthlyReportItemService.AddMillionsMonthlyReportItem(newItem); } } } GetValues(newMillionsMonthlyReport.MillionsMonthlyReportId); } } } /// /// 获取复制的值绑定到文本中 /// private void GetValues(string millionsMonthlyReportId) { var report = BLL.MillionsMonthlyReportService.GetMillionsMonthlyReportByMillionsMonthlyReportId(millionsMonthlyReportId); if (report != null) { drpMonth.SelectedValue = report.Month.ToString(); drpYear.SelectedValue = report.Year.ToString(); drpUnit.SelectedValue = report.UnitId; if (report.FillingDate != null) { txtFillingDate.Text = string.Format("{0:yyyy-MM-dd}", report.FillingDate); } txtDutyPerson.Text = report.DutyPerson; if (report.RecordableIncidentRate != null) { txtRecordableIncidentRate.Text = report.RecordableIncidentRate.ToString(); } if (report.LostTimeRate != null) { txtLostTimeRate.Text = report.LostTimeRate.ToString(); } if (report.LostTimeInjuryRate != null) { txtLostTimeInjuryRate.Text = report.LostTimeInjuryRate.ToString(); } if (report.DeathAccidentFrequency != null) { txtDeathAccidentFrequency.Text = report.DeathAccidentFrequency.ToString(); } if (report.AccidentMortality != null) { txtAccidentMortality.Text = report.AccidentMortality.ToString(); } if (report.InputCosts != null) { this.txtInputCosts.Text = Convert.ToString(report.InputCosts); } if (report.TrainNum != null) { this.txtTrainNum.Text = Convert.ToString(report.TrainNum); } if (report.GeneralHazardNum != null) { this.txtGeneralHazardNum.Text = Convert.ToString(report.GeneralHazardNum); } if (report.MajorHazardNum != null) { this.txtMajorHazardNum.Text = Convert.ToString(report.MajorHazardNum); } if (report.NotProofLargeProjectNum != null) { this.txtNotProofLargeProjectNum.Text = Convert.ToString(report.NotProofLargeProjectNum); } if (report.ProofLargeProjectNum != null) { this.txtProofLargeProjectNum.Text = Convert.ToString(report.ProofLargeProjectNum); } if (report.FireLicenseNum != null) { this.txtFireLicenseNum.Text = Convert.ToString(report.FireLicenseNum); } if (report.LimitLicenseNum != null) { this.txtLimitLicenseNum.Text = Convert.ToString(report.LimitLicenseNum); } if (report.HighLicenseNum != null) { this.txtHighLicenseNum.Text = Convert.ToString(report.HighLicenseNum); } if (report.HoistingLicenseNum != null) { this.txtHoistingLicenseNum.Text = Convert.ToString(report.HoistingLicenseNum); } if (report.BreakGroundLicenseNum != null) { this.txtBreakGroundLicenseNum.Text = Convert.ToString(report.BreakGroundLicenseNum); } if (report.ElectricityLicenseNum != null) { this.txtElectricityLicenseNum.Text = Convert.ToString(report.ElectricityLicenseNum); } if (report.RTLicenseNum != null) { this.txtRTLicenseNum.Text = Convert.ToString(report.RTLicenseNum); } if (report.NightLicenseNum != null) { this.txtNightLicenseNum.Text = Convert.ToString(report.NightLicenseNum); } if (report.CommissionerNum != null) { this.txtCommissionerNum.Text = Convert.ToString(report.CommissionerNum); } if (report.SoleDutyNum != null) { this.txtSoleDutyNum.Text = Convert.ToString(report.SoleDutyNum); } items = BLL.MillionsMonthlyReportItemService.GetItems(millionsMonthlyReportId); this.Grid1.DataSource = items; this.Grid1.DataBind(); } } #endregion } }