220 lines
8.5 KiB
C#
220 lines
8.5 KiB
C#
|
using BLL;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using System.Web;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace FineUIPro.Web.Customization.CNCCG.HSSE.Rewards
|
|||
|
{
|
|||
|
public partial class EnvironmentalAwardEdit : PageBase
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 主键
|
|||
|
/// </summary>
|
|||
|
public string Id
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return (string)ViewState["Id"];
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
ViewState["Id"] = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (!IsPostBack) {
|
|||
|
|
|||
|
BLL.UnitService.InitBranchUnitDropDownList(this.drpUnitId, false);//分公司
|
|||
|
|
|||
|
//加载项目
|
|||
|
ProjectService.InitProjectDropDownList(this.drpProjectId, false);
|
|||
|
|
|||
|
//是本单位不能增加
|
|||
|
var thisUnit = BLL.CommonService.GetIsThisUnit();
|
|||
|
if ((!string.IsNullOrEmpty(this.CurrUser.UnitId) && thisUnit.UnitId == this.CurrUser.UnitId) || this.CurrUser.UserId == BLL.Const.sysglyId || this.CurrUser.UserId == BLL.Const.hfnbdId)
|
|||
|
{
|
|||
|
//this.btnNew.Hidden = true;
|
|||
|
//this.drpUnitId.Enabled = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.drpUnitId.Enabled = false;
|
|||
|
this.drpUnitId.SelectedValue = this.CurrUser.UnitId;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
btnClose.OnClientClick = ActiveWindow.GetHideReference();
|
|||
|
|
|||
|
this.Id = Request.Params["Id"];
|
|||
|
if (!string.IsNullOrEmpty(this.Id))
|
|||
|
{
|
|||
|
var model = EnvironmentalAwardService.Detail(this.Id);
|
|||
|
if (model != null)
|
|||
|
{
|
|||
|
drpUnitId.Readonly = true;
|
|||
|
drpProjectId.Readonly = true;
|
|||
|
drpUnitId.SelectedValue = model.UnitId;
|
|||
|
drpProjectId.SelectedValue = model.ProjectId;
|
|||
|
//hidUnitId.Text = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == drpProjectId.SelectedValue).UnitId;
|
|||
|
//txtUnitName.Text = UnitService.GetUnitNameByUnitId(Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == drpProjectId.SelectedValue).UnitId);
|
|||
|
|
|||
|
txtAwardsName.Text = model.AwardsName;
|
|||
|
txtAwardsUnit.Text = model.AwardsUnit;
|
|||
|
txtDocCode.Text = model.DocCode;
|
|||
|
drpAwardsLevel.SelectedValue = model.AwardsLevel;
|
|||
|
txtScores.Text = model.Scores.ToString();
|
|||
|
if (model.Scores == 0)
|
|||
|
{
|
|||
|
this.txtCreateTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
|
|||
|
}
|
|||
|
else {
|
|||
|
txtCreateTime.Text = model.CreateTime.ToString();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.txtCreateTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (drpUnitId.SelectedValue != Const._Null) {
|
|||
|
|
|||
|
|
|||
|
//hidUnitId.Text = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == drpProjectId.SelectedValue).UnitId;
|
|||
|
//txtUnitName.Text = UnitService.GetUnitNameByUnitId(Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == drpProjectId.SelectedValue).UnitId);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 保存按钮
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void btnSave_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.SaveData(BLL.Const.BtnSave);
|
|||
|
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
|
|||
|
}
|
|||
|
|
|||
|
private void SaveData(string type)
|
|||
|
{
|
|||
|
var model = new Model.HSSE_EnvironmentalAward
|
|||
|
{
|
|||
|
UnitId = drpUnitId.SelectedValue,
|
|||
|
AwardsName = txtAwardsName.Text,
|
|||
|
AwardsUnit=txtAwardsUnit.Text,
|
|||
|
DocCode= txtDocCode.Text,
|
|||
|
AwardsLevel=drpAwardsLevel.SelectedValue,
|
|||
|
Scores = Convert.ToDecimal(txtScores.Text),
|
|||
|
CreateTime = Funs.GetNewDateTime(this.txtCreateTime.Text.Trim()),
|
|||
|
CreateMan = CurrUser.UserId,
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
if (!string.IsNullOrEmpty(drpProjectId.SelectedValue))
|
|||
|
{
|
|||
|
model.ProjectId = drpProjectId.SelectedValue;
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.Id))
|
|||
|
{
|
|||
|
model.Id = this.Id;
|
|||
|
EnvironmentalAwardService.Update(model);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.Id = SQLHelper.GetNewID(typeof(Model.HSSESystem_SafetyInstitution));
|
|||
|
model.Id = this.Id;
|
|||
|
EnvironmentalAwardService.Insert(model);
|
|||
|
}
|
|||
|
#region 修改标杆企业日常管理总分
|
|||
|
var cmonth = Convert.ToDateTime(Convert.ToDateTime(model.CreateTime).ToString("yyyy-MM"));
|
|||
|
|
|||
|
var sTime = cmonth;
|
|||
|
var eTime = sTime.AddMonths(1);
|
|||
|
var uid = drpUnitId.SelectedValue;
|
|||
|
var poleList = Funs.DB.HSSE_PoleUnit.Where(x => x.UnitId == drpUnitId.SelectedValue && x.CreateMonth == cmonth).ToList();
|
|||
|
if (poleList.Count>0)
|
|||
|
{
|
|||
|
decimal score = 0;
|
|||
|
//先获取奖项得分
|
|||
|
var list = Funs.DB.HSSE_EnvironmentalAward.Where(x => x.UnitId == uid && x.CreateTime >= sTime && x.CreateTime <= eTime).ToList();
|
|||
|
if (list.Count > 0)
|
|||
|
{
|
|||
|
score = list.Sum(x => x.Scores) ?? 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
score = 0;
|
|||
|
}
|
|||
|
foreach (var item in poleList)
|
|||
|
{
|
|||
|
//重新计算总得分
|
|||
|
var poleModel = Funs.DB.HSSE_PoleUnit.FirstOrDefault(x => x.Id == item.Id);
|
|||
|
poleModel.AllScore = item.Score1+item.Score2+item.Score3 + score;
|
|||
|
Funs.DB.SubmitChanges();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 修改安全质量绿色环保示范工地评选推荐表总分
|
|||
|
var pid = drpProjectId.SelectedValue;
|
|||
|
//var greenList = Funs.DB.HSSE_GreenSite.Where(x => x.UnitId == drpUnitId.SelectedValue && x.ProjectId==pid
|
|||
|
//&& x.CreateMonth == cmonth).ToList();
|
|||
|
var greenList = Funs.DB.HSSE_GreenSite.Where(x => x.ProjectId == pid
|
|||
|
&& x.CreateMonth == cmonth).ToList();
|
|||
|
if (greenList.Count > 0) {
|
|||
|
// var list = Funs.DB.HSSE_EnvironmentalAward.Where(x => x.UnitId == uid
|
|||
|
//&& x.ProjectId == pid && x.CreateTime >= sTime && x.CreateTime <= eTime).ToList();
|
|||
|
var list = Funs.DB.HSSE_EnvironmentalAward.Where(x => x.ProjectId == pid && x.CreateTime >= sTime && x.CreateTime <= eTime).ToList();
|
|||
|
decimal score = 0;
|
|||
|
if (list.Count > 0)
|
|||
|
{
|
|||
|
score = list.Sum(x => x.Scores) ?? 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
score = 0;
|
|||
|
}
|
|||
|
foreach (var item in greenList) {
|
|||
|
//重新计算总得分
|
|||
|
var greenModel = Funs.DB.HSSE_GreenSite.FirstOrDefault(x => x.Id == item.Id);
|
|||
|
greenModel.AllScore = item.Score1 + item.Score2 + score;
|
|||
|
Funs.DB.SubmitChanges();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#region 附件上传
|
|||
|
/// <summary>
|
|||
|
/// 附件上传
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void btnAttach_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(this.Id)) //新增记录
|
|||
|
{
|
|||
|
this.SaveData(BLL.Const.BtnSave);
|
|||
|
}
|
|||
|
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/HSSE/EnvironmentalAward&menuId={1}",
|
|||
|
this.Id, BLL.Const.EnvironmentalAwardMenuId)));
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|