426 lines
18 KiB
C#
426 lines
18 KiB
C#
using BLL;
|
||
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace FineUIPro.Web.ZHGL.ManagementReport
|
||
{
|
||
public partial class SubSafetyWorkReportEdit : PageBase
|
||
{
|
||
#region 定义项
|
||
/// <summary>
|
||
/// 公司
|
||
/// </summary>
|
||
public string CompanyId
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["CompanyId"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["CompanyId"] = value;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 月报告查主键
|
||
/// </summary>
|
||
public string SafetyWorkReportId
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["SafetyWorkReportId"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["SafetyWorkReportId"] = value;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 菜单主键
|
||
/// </summary>
|
||
public string MenuId
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["MenuId"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["MenuId"] = value;
|
||
}
|
||
}
|
||
private static DateTime months;
|
||
#endregion
|
||
|
||
#region 加载页面
|
||
/// <summary>
|
||
/// 加载页面
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
btnClose.OnClientClick = ActiveWindow.GetHideReference();
|
||
this.CompanyId = this.CurrUser.UnitId ?? BLL.CommonService.GetThisUnitId();
|
||
UnitService.InitBranchUnitDropDownList(this.drpSubUnit, false);
|
||
drpSubUnit_SelectedIndexChanged(null, null);
|
||
SafetyWorkReportId = Request.Params["SafetyWorkReportId"];
|
||
if (!string.IsNullOrEmpty(SafetyWorkReportId))
|
||
{
|
||
var getSafetyWorkReport = SafetyWorkReportService.GetManager_SafetyWorkReportById(this.SafetyWorkReportId);
|
||
if (getSafetyWorkReport != null)
|
||
{
|
||
this.drpSubUnit.SelectedValue = getSafetyWorkReport.UnitId;
|
||
drpSubUnit_SelectedIndexChanged(null, null);
|
||
this.drpReportMan.SelectedValue = getSafetyWorkReport.ReportManId;
|
||
this.txtMonths.Text = string.Format("{0:yyyy-MM}", getSafetyWorkReport.Months);
|
||
this.txtReportDate.Text = string.Format("{0:yyyy-MM-dd}", getSafetyWorkReport.ReportDate);
|
||
Bind(getSafetyWorkReport);
|
||
getYears = from x in Funs.DB.Manager_SafetyWorkReport
|
||
where x.UnitId == this.drpSubUnit.SelectedValue && x.Months.Value.Year == months.Year
|
||
select x;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.drpSubUnit.SelectedValue = this.CompanyId;
|
||
var getM = Request.Params["months"];
|
||
months = Funs.GetNewDateTimeOrNow(getM);
|
||
this.txtMonths.Text = getM;
|
||
this.txtReportDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
|
||
getYears = from x in Funs.DB.Manager_SafetyWorkReport
|
||
where x.UnitId == this.drpSubUnit.SelectedValue && x.Months.Value.Year == months.Year
|
||
select x;
|
||
PageInfo();
|
||
}
|
||
MenuId = Const.ServerSafetyWorkReportMenuId;
|
||
this.drpSubUnit.Readonly = true;
|
||
if (this.drpSubUnit.SelectedValue != this.CompanyId)
|
||
{
|
||
this.btnSave.Hidden = true;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
public static IQueryable<Model.Manager_SafetyWorkReport> getYears;
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
protected void PageInfo()
|
||
{
|
||
var getProjects = from x in Funs.DB.Base_Project
|
||
where x.UnitId == this.drpSubUnit.SelectedValue && (x.ProjectState == null || x.ProjectState == Const.ProjectState_1)
|
||
&& x.StartDate <= months && (!x.EndDate.HasValue || x.EndDate >= months.AddMonths(1))
|
||
select x;
|
||
int pCounts = getProjects.Count();
|
||
this.txtNum1.Text = pCounts.ToString();
|
||
if (pCounts > 0)
|
||
{
|
||
var getMPersons = from x in Funs.DB.SitePerson_Person
|
||
join y in getProjects on x.ProjectId equals y.ProjectId
|
||
join z in Funs.DB.Base_WorkPost on x.WorkPostId equals z.WorkPostId
|
||
where z.IsHsse == true && (x.OutTime == null || x.OutTime >= months.AddMonths(1)) && x.IsUsed == true
|
||
select x;
|
||
this.txtNum2.Text = getMPersons.Count().ToString();
|
||
|
||
var getAccidentHandles = from x in Funs.DB.Accident_AccidentHandle
|
||
join y in getProjects on x.ProjectId equals y.ProjectId
|
||
select x;
|
||
int accidentCounts = getAccidentHandles.Count();
|
||
this.txtAccidentNum.Text = accidentCounts.ToString();
|
||
if (accidentCounts > 0)
|
||
{
|
||
string selectL = string.Empty;
|
||
string qk = string.Empty;
|
||
int mNum = getAccidentHandles.Sum(x => x.MinorInjuriesPersonNum ?? 0);
|
||
if (mNum > 0)
|
||
{
|
||
selectL += "轻伤,";
|
||
qk += "轻伤" + mNum.ToString() + ";";
|
||
}
|
||
int iNum = getAccidentHandles.Sum(x => x.InjuriesPersonNum ?? 0);
|
||
if (iNum > 0)
|
||
{
|
||
selectL += "重伤,";
|
||
qk += "重伤" + iNum.ToString() + ";";
|
||
}
|
||
int dNum = getAccidentHandles.Sum(x => x.DeathPersonNum ?? 0);
|
||
if (dNum > 0)
|
||
{
|
||
selectL += "死亡,";
|
||
qk += "死亡" + dNum.ToString() + ";";
|
||
}
|
||
if (!string.IsNullOrEmpty(selectL))
|
||
{
|
||
string[] strs = selectL.Split(',');
|
||
this.cblAccidentType.SelectedValueArray = strs;
|
||
this.txtInjurySituation.Text = qk;
|
||
}
|
||
|
||
decimal MoneyLoss = getAccidentHandles.Sum(x => x.MoneyLoss ?? 0);
|
||
this.txtLossMoney.Text = MoneyLoss.ToString();
|
||
|
||
decimal WorkHoursLoss = getAccidentHandles.Sum(x => x.WorkHoursLoss ?? 0);
|
||
this.txtLossWorkDay.Text = MoneyLoss.ToString();
|
||
}
|
||
}
|
||
if (getYears.Count() > 0)
|
||
{
|
||
this.txtCost2.Text = getYears.Sum(x => x.Cost2 ?? 0).ToString();
|
||
this.txtHour2.Text = getYears.Sum(x => x.Hour2 ?? 0).ToString();
|
||
}
|
||
}
|
||
|
||
#region 页面显示
|
||
void Bind(Manager_SafetyWorkReport model)
|
||
{
|
||
txtNum1.Text = model.Num1.HasValue ? model.Num1.ToString() : "";
|
||
txtNum2.Text = model.Num2.HasValue ? model.Num2.ToString() : "";
|
||
txtNum3.Text = model.Num3.HasValue ? model.Num3.ToString() : "";
|
||
txtNum4.Text = model.Num4.HasValue ? model.Num4.ToString() : "";
|
||
txtNum5.Text = model.Num5.HasValue ? model.Num5.ToString() : "";
|
||
//txtNum6.Text = model.Num6.HasValue ? model.Num6.ToString() : "";
|
||
//txtNum7.Text = model.Num7.HasValue ? model.Num7.ToString() : "";
|
||
//txtNum8.Text = model.Num8.HasValue ? model.Num8.ToString() : "";
|
||
//txtNum9.Text = model.Num9.HasValue ? model.Num9.ToString() : "";
|
||
txtCost1.Text = model.Cost1.HasValue ? model.Cost1.ToString() : "";
|
||
txtCost2.Text = model.Cost2.HasValue ? model.Cost2.ToString() : "";
|
||
txtHour1.Text = model.Hour1.HasValue ? model.Hour1.ToString() : "";
|
||
txtHour2.Text = model.Hour2.HasValue ? model.Hour2.ToString() : "";
|
||
ckbExistAccident.Checked = (bool)model.ExistAccident;
|
||
txtAccidentNum.Text = model.AccidentNum.HasValue ? model.AccidentNum.ToString() : "";
|
||
cblAccidentType.SelectedValueArray = model.AccidentType.Split(',');
|
||
txtInjurySituation.Text = model.InjurySituation;
|
||
txtLossMoney.Text = model.LossMoney.HasValue ? model.LossMoney.ToString() : "";
|
||
txtLossWorkDay.Text = model.LossWorkDay.HasValue ? model.LossWorkDay.ToString() : "";
|
||
ckbExistMeeting.Checked = (bool)model.ExistMeeting;
|
||
txtMeetingNum.Text = model.MeetingNum.HasValue ? model.MeetingNum.ToString() : "";
|
||
cblMeetingType.SelectedValueArray = model.MeetingType.Split(',');
|
||
ckbExistLeaderCheck.Checked = (bool)model.ExistLeaderCheck;
|
||
txtLeaderCheckNum.Text = model.LeaderCheckNum.HasValue ? model.LeaderCheckNum.ToString() : "";
|
||
ckbExistSafetyCheck.Checked = (bool)model.ExistSafetyCheck;
|
||
txtCheckNum1.Text = model.CheckNum1.HasValue ? model.CheckNum1.ToString() : "";
|
||
txtCheckNum2.Text = model.CheckNum2.HasValue ? model.CheckNum2.ToString() : "";
|
||
txtCheckNum3.Text = model.CheckNum3.HasValue ? model.CheckNum3.ToString() : "";
|
||
txtCheckNum4.Text = model.CheckNum4.HasValue ? model.CheckNum4.ToString() : "";
|
||
txtCheckLimitDate.SelectedDate = model.CheckLimitDate;
|
||
ckbExistTrain.Checked = (bool)model.ExistTrain;
|
||
txtTrainNum.Text = model.TrainNum.HasValue ? model.TrainNum.ToString() : "";
|
||
ckbExistContribution.Checked = (bool)model.ExistContribution;
|
||
txtContributionNum1.Text = model.ContributionNum1.HasValue ? model.ContributionNum1.ToString() : "";
|
||
txtContributionNum2.Text = model.ContributionNum2.HasValue ? model.ContributionNum2.ToString() : "";
|
||
txtNextWork.Text = model.NextWork;
|
||
txtProblem.Text = model.Problem;
|
||
txtSuggestion.Text = model.Suggestion;
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 保存事件
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
protected bool Save()
|
||
{
|
||
bool isOk = true;
|
||
Manager_SafetyWorkReport newReport = new Manager_SafetyWorkReport
|
||
{
|
||
Num1 = Funs.GetNewIntOrZero(txtNum1.Text.Trim()),
|
||
Num2 = Funs.GetNewIntOrZero(txtNum2.Text.Trim()),
|
||
Num3 = Funs.GetNewIntOrZero(txtNum3.Text.Trim()),
|
||
Num4 = Funs.GetNewIntOrZero(txtNum4.Text.Trim()),
|
||
Num5 = Funs.GetNewIntOrZero(txtNum5.Text.Trim()),
|
||
//model.Num6 = Funs.GetNewIntOrZero(txtNum6.Text.Trim());
|
||
//model.Num7 = Funs.GetNewIntOrZero(txtNum7.Text.Trim());
|
||
//model.Num8 = Funs.GetNewIntOrZero(txtNum8.Text.Trim());
|
||
//model.Num9 = Funs.GetNewIntOrZero(txtNum9.Text.Trim());
|
||
Cost1 = Funs.GetNewIntOrZero(txtCost1.Text.Trim()),
|
||
Cost2 = Funs.GetNewIntOrZero(txtCost2.Text.Trim()),
|
||
Hour1 = Funs.GetNewIntOrZero(txtHour1.Text.Trim()),
|
||
Hour2 = Funs.GetNewIntOrZero(txtHour2.Text.Trim()),
|
||
ExistAccident = ckbExistAccident.Checked,
|
||
AccidentNum = Funs.GetNewIntOrZero(txtAccidentNum.Text.Trim()),
|
||
AccidentType = String.Join(",", cblAccidentType.SelectedValueArray),
|
||
InjurySituation = txtInjurySituation.Text.Trim(),
|
||
LossMoney = Funs.GetNewIntOrZero(txtLossMoney.Text.Trim()),
|
||
LossWorkDay = Funs.GetNewIntOrZero(txtLossWorkDay.Text.Trim()),
|
||
ExistMeeting = ckbExistMeeting.Checked,
|
||
MeetingNum = Funs.GetNewIntOrZero(txtMeetingNum.Text.Trim()),
|
||
MeetingType = String.Join(",", cblMeetingType.SelectedValueArray),
|
||
ExistLeaderCheck = ckbExistLeaderCheck.Checked,
|
||
LeaderCheckNum = Funs.GetNewIntOrZero(txtLeaderCheckNum.Text.Trim()),
|
||
ExistSafetyCheck = ckbExistSafetyCheck.Checked,
|
||
CheckNum1 = Funs.GetNewIntOrZero(txtCheckNum1.Text.Trim()),
|
||
CheckNum2 = Funs.GetNewIntOrZero(txtCheckNum2.Text.Trim()),
|
||
CheckNum3 = Funs.GetNewIntOrZero(txtCheckNum3.Text.Trim()),
|
||
CheckNum4 = Funs.GetNewIntOrZero(txtCheckNum4.Text.Trim()),
|
||
CheckLimitDate = txtCheckLimitDate.SelectedDate,
|
||
ExistTrain = ckbExistTrain.Checked,
|
||
TrainNum = Funs.GetNewIntOrZero(txtTrainNum.Text.Trim()),
|
||
ExistContribution = ckbExistContribution.Checked,
|
||
ContributionNum1 = Funs.GetNewIntOrZero(txtContributionNum1.Text.Trim()),
|
||
ContributionNum2 = Funs.GetNewIntOrZero(txtContributionNum2.Text.Trim()),
|
||
NextWork = txtNextWork.Text,
|
||
Problem = txtProblem.Text,
|
||
Suggestion = txtSuggestion.Text,
|
||
ReportDate = Funs.GetNewDateTimeOrNow(this.txtReportDate.Text),
|
||
};
|
||
newReport.UnitId = this.drpSubUnit.SelectedValue;
|
||
newReport.Months = Funs.GetNewDateTime(this.txtMonths.Text);
|
||
newReport.ReportManId = this.drpReportMan.SelectedValue;
|
||
if (!string.IsNullOrEmpty(newReport.UnitId) && !string.IsNullOrEmpty(newReport.ReportManId) && newReport.Months.HasValue)
|
||
{
|
||
if (string.IsNullOrEmpty(SafetyWorkReportId))
|
||
{
|
||
newReport.CompileMan = this.CurrUser.UserId;
|
||
newReport.CompileDate = DateTime.Now;
|
||
this.SafetyWorkReportId = newReport.SafetyWorkReportId = SQLHelper.GetNewID();
|
||
BLL.SafetyWorkReportService.AddManager_SafetyWorkReport(newReport);
|
||
}
|
||
else
|
||
{
|
||
newReport.SafetyWorkReportId = SafetyWorkReportId;
|
||
BLL.SafetyWorkReportService.UpdateManager_SafetyWorkReport(newReport);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
isOk = false;
|
||
}
|
||
return isOk;
|
||
}
|
||
#endregion
|
||
|
||
#region 保存按钮
|
||
/// <summary>
|
||
/// 保存按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
if (Save())
|
||
{
|
||
ShowNotify("保存成功!", MessageBoxIcon.Success);
|
||
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInParent("分公司、月份、报告人必填!");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 附件上传
|
||
/// <summary>
|
||
/// 上传附件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnAttachUrl_Click(object sender, EventArgs e)
|
||
{
|
||
UpAtt(null);
|
||
}
|
||
|
||
protected void btnAtt1_Click(object sender, EventArgs e)
|
||
{
|
||
UpAtt("1");
|
||
}
|
||
|
||
protected void btnAtt2_Click(object sender, EventArgs e)
|
||
{
|
||
UpAtt("2");
|
||
}
|
||
|
||
protected void btnAtt3_Click(object sender, EventArgs e)
|
||
{
|
||
UpAtt("3");
|
||
}
|
||
|
||
protected void btnAtt4_Click(object sender, EventArgs e)
|
||
{
|
||
UpAtt("4");
|
||
}
|
||
|
||
protected void UpAtt(string type)
|
||
{
|
||
if (string.IsNullOrEmpty(this.SafetyWorkReportId))
|
||
{
|
||
if (!this.btnSave.Hidden)
|
||
{
|
||
Save();
|
||
}
|
||
}
|
||
string id = this.SafetyWorkReportId;
|
||
if (!string.IsNullOrEmpty(type))
|
||
{
|
||
id = this.SafetyWorkReportId + "$" + type;
|
||
}
|
||
if (!this.btnSave.Hidden)
|
||
{
|
||
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/SubSafetyWorkReport&menuId={1}", id, this.MenuId)));
|
||
}
|
||
else
|
||
{
|
||
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/SubSafetyWorkReport&menuId={1}type=-1", id, this.MenuId)));
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 单位下拉框事件
|
||
/// <summary>
|
||
/// 单位下拉框事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void drpSubUnit_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
this.drpReportMan.Items.Clear();
|
||
UserService.InitUserProjectIdUnitIdDropDownList(this.drpReportMan, this.CurrUser.LoginProjectId, this.drpSubUnit.SelectedValue, false);
|
||
if (this.CurrUser.UserId != Const.sysglyId && this.CurrUser.UserId != Const.hfnbdId)
|
||
{
|
||
this.drpReportMan.SelectedValue = this.CurrUser.UserId;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 获取按钮权限
|
||
/// <summary>
|
||
/// 获取按钮权限
|
||
/// </summary>
|
||
/// <param name="button"></param>
|
||
/// <returns></returns>
|
||
private void GetButtonPower()
|
||
{
|
||
if (Request.Params["value"] == "0")
|
||
{
|
||
return;
|
||
}
|
||
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, this.MenuId);
|
||
if (buttonList.Count() > 0)
|
||
{
|
||
if (buttonList.Contains(BLL.Const.BtnAdd))
|
||
{
|
||
this.btnSave.Hidden = false;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
protected void txtCost2_Blur(object sender, EventArgs e)
|
||
{
|
||
if (getYears.Count() > 0)
|
||
{
|
||
this.txtCost2.Text = (getYears.Sum(x => x.Cost2 ?? 0) + Funs.GetNewIntOrZero(this.txtCost2.Text)).ToString();
|
||
this.txtHour2.Text = (getYears.Sum(x => x.Hour2 ?? 0) + Funs.GetNewIntOrZero(this.txtHour2.Text)).ToString();
|
||
}
|
||
}
|
||
}
|
||
} |