using BLL; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.ReportManage.SafeEnvBudget { public partial class HSEMonthReportEdit : PageBase { #region 定义变量 /// /// 主键 /// public string ReportId { get { return (string)ViewState["ReportId"]; } set { ViewState["ReportId"] = value; } } #endregion #region 加载页面 /// /// 加载数据 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //单位 UnitService.InitBranchUnitDropDownList(this.drpUnitId, true, true); if (!string.IsNullOrWhiteSpace(this.CurrUser.UnitId) && this.CurrUser.Base_Unit.IsBranch == true) { this.drpUnitId.SelectedValue = this.CurrUser.UnitId; this.drpUnitId.Readonly = true; } this.ReportId = Request.Params["reportId"]; if (!string.IsNullOrEmpty(this.ReportId)) { var report = BLL.HSEMonthReportService.GetHSEMonthReportById(this.ReportId); if (report != null) { txtReportDate.Text = string.Format("{0:yyyy-MM}", report.ReportDate); if (!string.IsNullOrEmpty(report.UnitId)) { this.drpUnitId.SelectedValue = report.UnitId; this.drpUnitId.Readonly = true; } this.txtReportDate.Readonly = true; txtTotalEmployees.Text = report.TotalEmployees.HasValue ? report.TotalEmployees.ToString() : ""; txtTotalHours.Text = report.TotalHours.HasValue ? report.TotalHours.ToString() : ""; txtContractorEmployees.Text = report.ContractorEmployees.HasValue ? report.ContractorEmployees.ToString() : ""; txtContractorHours.Text = report.ContractorHours.HasValue ? report.ContractorHours.ToString() : ""; txtMonthHours.Text = report.MonthHours.HasValue ? report.MonthHours.ToString() : ""; txtMonthHoursAvg.Text = report.MonthHoursAvg.HasValue ? report.MonthHoursAvg.ToString() : ""; txtYearHours.Text = report.YearHours.HasValue ? report.YearHours.ToString() : ""; txtBranchTraining.Text = report.BranchTraining.HasValue ? report.BranchTraining.ToString() : ""; txtProjectTraining.Text = report.ProjectTraining.HasValue ? report.ProjectTraining.ToString() : ""; txtTeamGroupTraining.Text = report.TeamGroupTraining.HasValue ? report.TeamGroupTraining.ToString() : ""; txtSelfTraining.Text = report.SelfTraining.HasValue ? report.SelfTraining.ToString() : ""; txtContractorOrganizeTraining.Text = report.ContractorOrganizeTraining.HasValue ? report.ContractorOrganizeTraining.ToString() : ""; txtContractorTraining.Text = report.ContractorTraining.HasValue ? report.ContractorTraining.ToString() : ""; txtRemark.Text = report.Remark; } } else { this.txtReportDate.Text = string.Format("{0:yyyy-MM}", DateTime.Now); } } } #endregion #region 保存 /// /// 保存数据 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { DateTime? reportDate = Funs.GetNewDateTime(this.txtReportDate.Text.Trim()); if (string.IsNullOrEmpty(this.ReportId)) { var data = BLL.HSEMonthReportService.GetHSEMonthReportByReportDate(this.drpUnitId.SelectedValue, reportDate); if (data != null) { Alert.ShowInTop("本月HSE月报已上报!", MessageBoxIcon.Warning); return; } if (this.drpUnitId.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(this.drpUnitId.SelectedValue)) { Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning); return; } } Model.Report_HSEMonthReport newReport = new Model.Report_HSEMonthReport(); newReport.UnitId = this.drpUnitId.SelectedValue; newReport.ReportDate = Convert.ToDateTime(reportDate); newReport.TotalEmployees = Funs.GetNewInt(txtTotalEmployees.Text); newReport.TotalHours = Funs.GetNewInt(txtTotalHours.Text); newReport.ContractorEmployees = Funs.GetNewInt(txtContractorEmployees.Text); newReport.ContractorHours = Funs.GetNewInt(txtContractorHours.Text); newReport.MonthHours = Funs.GetNewInt(txtMonthHours.Text); newReport.MonthHoursAvg = Funs.GetNewInt(txtMonthHoursAvg.Text); newReport.YearHours = Funs.GetNewInt(txtYearHours.Text); newReport.BranchTraining = Funs.GetNewInt(txtBranchTraining.Text); newReport.ProjectTraining = Funs.GetNewInt(txtProjectTraining.Text); newReport.TeamGroupTraining = Funs.GetNewInt(txtTeamGroupTraining.Text); newReport.SelfTraining = Funs.GetNewInt(txtSelfTraining.Text); newReport.ContractorOrganizeTraining = Funs.GetNewInt(txtContractorOrganizeTraining.Text); newReport.ContractorTraining = Funs.GetNewInt(txtContractorTraining.Text); newReport.Remark = this.txtRemark.Text; if (!string.IsNullOrEmpty(this.ReportId)) { newReport.ReportId = this.ReportId; BLL.HSEMonthReportService.UpdateHSEMonthReport(newReport); BLL.LogService.AddSys_Log(this.CurrUser, newReport.ReportId, newReport.ReportId, BLL.Const.HSEMonthReportMenuId, BLL.Const.BtnModify); ShowNotify("修改成功!", MessageBoxIcon.Success); } else { newReport.CompileMan = this.CurrUser.UserId; newReport.CompileDate = DateTime.Now; newReport.ReportId = SQLHelper.GetNewID(); BLL.HSEMonthReportService.AddHSEMonthReport(newReport); BLL.LogService.AddSys_Log(this.CurrUser, newReport.ReportId, newReport.ReportId, BLL.Const.HSEMonthReportMenuId, BLL.Const.BtnAdd); ShowNotify("保存成功!", MessageBoxIcon.Success); } PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } #endregion } }