572 lines
		
	
	
		
			32 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			572 lines
		
	
	
		
			32 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | ||
| using Model;
 | ||
| using Newtonsoft.Json.Linq;
 | ||
| using Org.BouncyCastle.Asn1.Ocsp;
 | ||
| using System;
 | ||
| using System.Collections.Generic;
 | ||
| using System.Data;
 | ||
| using System.Linq;
 | ||
| using System.Web.UI.WebControls;
 | ||
| 
 | ||
| namespace FineUIPro.Web.ZHGL.Environmental
 | ||
| {
 | ||
|     public partial class EnergyReportSave : PageBase
 | ||
|     {
 | ||
|         #region 定义变量
 | ||
|         /// <summary>
 | ||
|         /// 报表主键Id
 | ||
|         /// </summary>
 | ||
|         public string EnergyReportId
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return (string)ViewState["EnergyReportId"];
 | ||
|             }
 | ||
|             set
 | ||
|             {
 | ||
|                 ViewState["EnergyReportId"] = value;
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 定义集合
 | ||
|         /// </summary>
 | ||
|         private static List<Model.Environmental_EnergyReportItem> items = new List<Model.Environmental_EnergyReportItem>();
 | ||
|         #endregion
 | ||
| 
 | ||
|         #region 加载页面
 | ||
|         /// <summary> 
 | ||
|         /// 加载页面
 | ||
|         /// </summary>
 | ||
|         /// <param name="sender"></param>
 | ||
|         /// <param name="e"></param>
 | ||
|         protected void Page_Load(object sender, EventArgs e)
 | ||
|         {
 | ||
|             if (!IsPostBack)
 | ||
|             {
 | ||
|                 if (Request.Params["type"] != "-1")
 | ||
|                 {
 | ||
|                     this.GetButtonPower();
 | ||
|                 }
 | ||
|                 items.Clear();
 | ||
|                 BLL.ConstValue.InitConstValueDropDownList(this.drpQuarters, ConstValue.Group_0011, 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 quarters = Request.QueryString["Quarters"];
 | ||
|                 EnergyReportId = Request.QueryString["EnergyReportId"];
 | ||
|                 if (!string.IsNullOrEmpty(Request.QueryString["type"]))
 | ||
|                 {
 | ||
|                     this.btnSave.Hidden = true;
 | ||
|                     this.btnUpdata.Hidden = false;
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     this.btnSave.Hidden = false;
 | ||
|                     this.btnUpdata.Hidden = true;
 | ||
|                 }
 | ||
|                 if (!String.IsNullOrEmpty(EnergyReportId))
 | ||
|                 {
 | ||
|                     items = BLL.EnergyreportItemService.GetShowItems(EnergyReportId);
 | ||
|                     this.Grid1.DataSource = items;
 | ||
|                     this.Grid1.DataBind();
 | ||
|                     var report = BLL.EnergyReportService.GetEnvironmental_EnergyReportById(EnergyReportId);
 | ||
|                     if (report != null)
 | ||
|                     {
 | ||
|                         //this.btnCopy.Hidden = true;
 | ||
|                         //if (this.CurrUser.UserId == BLL.Const.sysglyId || this.CurrUser.UserId == BLL.Const.hfnbdId)
 | ||
|                         //{
 | ||
|                         //    this.btnSave.Hidden = false;
 | ||
|                         //}
 | ||
|                         if (report.UpState == BLL.Const.UpState_3)
 | ||
|                         {
 | ||
|                             this.btnSave.Hidden = true;
 | ||
|                             this.btnUpdata.Hidden = true;
 | ||
|                         }
 | ||
|                         drpQuarters.SelectedValue = report.Quarters.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;
 | ||
|                     }
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     //this.btnCopy.Hidden = false;
 | ||
|                     drpQuarters.SelectedValue = quarters;
 | ||
|                     drpYear.SelectedValue = year;
 | ||
|                     txtFillingDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
 | ||
|                     txtDutyPerson.Text = this.CurrUser.UserName;
 | ||
|                     //增加明细集合
 | ||
|                     GetNewItems(Funs.GetNewIntOrZero(year), Funs.GetNewIntOrZero(quarters));
 | ||
|                     this.Grid1.DataSource = items;
 | ||
|                     this.Grid1.DataBind();
 | ||
|                 }
 | ||
| 
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 string arg = GetRequestEventArgument(); // 此函数所在文件:PageBase.cs
 | ||
|                 if (arg == "UPDATE_SUMMARY")
 | ||
|                 {
 | ||
|                     SaveData();
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|         }
 | ||
|         void SaveData()
 | ||
|         {
 | ||
|             List<Model.Environmental_EnergyReportItem> _EnergyReportItems = new List<Environmental_EnergyReportItem>();
 | ||
| 
 | ||
|             foreach (JObject mergedRow in Grid1.GetMergedData())
 | ||
|             {
 | ||
|                 JObject values = mergedRow.Value<JObject>("values");
 | ||
|                 string sortIndex = values.Value<string>("SortIndex");
 | ||
|                 var newItem = items.FirstOrDefault(x => x.SortIndex == sortIndex);
 | ||
|                 if (newItem != null)
 | ||
|                 {
 | ||
|                     newItem.EnergyReportItemId = SQLHelper.GetNewID();
 | ||
|                     newItem.EnergyReportId = EnergyReportId;
 | ||
|                     newItem.SortIndex = values.Value<string>("SortIndex");
 | ||
|                     newItem.BusinessCategory = values.Value<string>("BusinessCategory");
 | ||
|                     newItem.Throughput_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Throughput_BasePeriod")).ToString();
 | ||
|                     newItem.Throughput_LastPeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Throughput_LastPeriod")).ToString(); 
 | ||
|                     newItem.Throughput_ThisPeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Throughput_ThisPeriod")).ToString(); 
 | ||
|                     newItem.Throughput_UnitOfMeasurement = values.Value<string>("Throughput_UnitOfMeasurement");
 | ||
|                     newItem.Yield_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Yield_BasePeriod")).ToString(); 
 | ||
|                     newItem.Yield_LastPeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Yield_LastPeriod")).ToString(); 
 | ||
|                     newItem.Yield_ThisPeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Yield_ThisPeriod")).ToString(); 
 | ||
|                     newItem.Yield_UnitOfMeasurement = values.Value<string>("Yield_UnitOfMeasurement");
 | ||
|                     newItem.OutputValue_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("OutputValue_BasePeriod")).ToString(); 
 | ||
|                     newItem.OutputValue_LastYear = Funs.GetNewDecimalOrZero(values.Value<string>("OutputValue_LastYear")).ToString(); 
 | ||
|                     newItem.OutputValue_ThisYear = Funs.GetNewDecimalOrZero(values.Value<string>("OutputValue_ThisYear")).ToString(); 
 | ||
|                     newItem.OperationScale_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("OperationScale_BasePeriod")).ToString(); 
 | ||
|                     newItem.OperationScale_LastYear = Funs.GetNewDecimalOrZero(values.Value<string>("OperationScale_LastYear")).ToString();
 | ||
|                     newItem.OperationScale_ThisYear = Funs.GetNewDecimalOrZero(values.Value<string>("OperationScale_ThisYear")).ToString();
 | ||
|                     newItem.OperationScale_UnitOfMeasurement = values.Value<string>("OperationScale_UnitOfMeasurement");
 | ||
|                     newItem.ServiceOperatingIncome_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("ServiceOperatingIncome_BasePeriod")).ToString();
 | ||
|                     newItem.ServiceOperatingIncome_LastYear = Funs.GetNewDecimalOrZero(values.Value<string>("ServiceOperatingIncome_LastYear")).ToString();
 | ||
|                     newItem.ServiceOperatingIncome_ThisYear = Funs.GetNewDecimalOrZero(values.Value<string>("ServiceOperatingIncome_ThisYear")).ToString();
 | ||
|                     _EnergyReportItems.Add(newItem);
 | ||
| 
 | ||
|                 }
 | ||
|             }
 | ||
|             this.Grid1.DataSource = _EnergyReportItems;
 | ||
|             this.Grid1.DataBind();
 | ||
|             _EnergyReportItems.RemoveAll(x => x.SortIndex == "01");
 | ||
|             var q = (from x in _EnergyReportItems
 | ||
|                      group x by x.EnergyReportId into g
 | ||
|                      select new
 | ||
|                      {
 | ||
|                          g.Key,
 | ||
|                          Throughput_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Throughput_BasePeriod)),
 | ||
|                          Throughput_LastPeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Throughput_LastPeriod)),
 | ||
|                          Throughput_ThisPeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Throughput_ThisPeriod)),
 | ||
|                          Yield_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Yield_BasePeriod)),
 | ||
|                          Yield_LastPeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Yield_LastPeriod)),
 | ||
|                          Yield_ThisPeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Yield_ThisPeriod)),
 | ||
|                          OutputValue_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.OutputValue_BasePeriod)),
 | ||
|                          OutputValue_LastYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.OutputValue_LastYear)),
 | ||
|                          OutputValue_ThisYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.OutputValue_ThisYear)),
 | ||
|                          OperationScale_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.OperationScale_BasePeriod)),
 | ||
|                          OperationScale_LastYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.OperationScale_LastYear)),
 | ||
|                          OperationScale_ThisYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.OperationScale_ThisYear)),
 | ||
|                          ServiceOperatingIncome_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.ServiceOperatingIncome_BasePeriod)),
 | ||
|                          ServiceOperatingIncome_LastYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.ServiceOperatingIncome_LastYear)),
 | ||
|                          ServiceOperatingIncome_ThisYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.ServiceOperatingIncome_ThisYear)),
 | ||
|                      }
 | ||
|                     ).FirstOrDefault();
 | ||
|             this.Grid1.Rows[0].Values[4] = q.Throughput_BasePeriod;
 | ||
|             this.Grid1.Rows[0].Values[5] = q.Throughput_LastPeriod;
 | ||
|             this.Grid1.Rows[0].Values[6] = q.Throughput_ThisPeriod;
 | ||
|             this.Grid1.Rows[0].Values[9] = q.Yield_BasePeriod;
 | ||
|             this.Grid1.Rows[0].Values[10] = q.Yield_LastPeriod;
 | ||
|             this.Grid1.Rows[0].Values[11] = q.Yield_ThisPeriod;
 | ||
|             this.Grid1.Rows[0].Values[14] = q.OutputValue_BasePeriod;
 | ||
|             this.Grid1.Rows[0].Values[15] = q.OutputValue_LastYear;
 | ||
|             this.Grid1.Rows[0].Values[16] = q.OutputValue_ThisYear;
 | ||
|             this.Grid1.Rows[0].Values[19] = q.OperationScale_BasePeriod;
 | ||
|             this.Grid1.Rows[0].Values[20] = q.OperationScale_LastYear;
 | ||
|             this.Grid1.Rows[0].Values[21] = q.OperationScale_ThisYear;
 | ||
|             this.Grid1.Rows[0].Values[24] = q.ServiceOperatingIncome_BasePeriod;
 | ||
|             this.Grid1.Rows[0].Values[25] = q.ServiceOperatingIncome_LastYear;
 | ||
|             this.Grid1.Rows[0].Values[26] = q.ServiceOperatingIncome_ThisYear;
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
 | ||
|         {
 | ||
|              Model.Environmental_EnergyReportItem a = (Model.Environmental_EnergyReportItem)e.DataItem;
 | ||
|             e.DataItem.ToString();
 | ||
| 
 | ||
|             //string SortIndex = Convert.ToString(row["SortIndex"]);
 | ||
|             if (a.SortIndex == "01")
 | ||
|             {
 | ||
|                 
 | ||
|                 for (int i = 0; i < e.CellCssClasses.Count(); i++)
 | ||
|                 {
 | ||
|                     e.CellCssClasses[i] = "f-grid-cell-uneditable";
 | ||
|                 }
 | ||
|                 
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         #endregion
 | ||
| 
 | ||
| 
 | ||
|         #region 关闭窗口
 | ||
|         /// <summary>
 | ||
|         /// 关闭窗口
 | ||
|         /// </summary>
 | ||
|         /// <param name="sender"></param>
 | ||
|         /// <param name="e"></param>
 | ||
|         protected void Window1_Close(object sender, WindowCloseEventArgs e)
 | ||
|         {
 | ||
|             var report = BLL.EnergyReportService.GetEnvironmental_EnergyReportById(EnergyReportId);
 | ||
|             this.btnSave.Hidden = false;
 | ||
|         }
 | ||
|         #endregion
 | ||
| 
 | ||
|         #region 保存、上报
 | ||
|         /// <summary>
 | ||
|         /// 保存数据
 | ||
|         /// </summary>
 | ||
|         /// <param name="type"></param>
 | ||
|         private void Save(string type)
 | ||
|         {
 | ||
|             //string EnergyReportId = Request.QueryString["EnergyReportId"];
 | ||
|             Model.Environmental_EnergyReport report = new Environmental_EnergyReport
 | ||
|             {
 | ||
|                 UnitId = drpUnit.SelectedValue,
 | ||
|                 Year = Funs.GetNewIntOrZero(drpYear.SelectedValue),
 | ||
|                 Quarters = Funs.GetNewIntOrZero(drpQuarters.SelectedValue)
 | ||
|             };
 | ||
|             if (!string.IsNullOrEmpty(txtFillingDate.Text.Trim()))
 | ||
|             {
 | ||
|                 report.FillingDate = Convert.ToDateTime(txtFillingDate.Text.Trim());
 | ||
|             }
 | ||
|             report.DutyPerson = txtDutyPerson.Text.Trim();
 | ||
|             if (String.IsNullOrEmpty(EnergyReportId))
 | ||
|             {
 | ||
|                 Environmental_EnergyReport old = EnergyReportService.GetEnergyReportByUnitIdDate(drpUnit.SelectedValue, Funs.GetNewIntOrZero(drpYear.SelectedValue), Funs.GetNewIntOrZero(drpQuarters.SelectedValue));
 | ||
|                 if (old == null)
 | ||
|                 {
 | ||
|                     report.EnergyReportId = SQLHelper.GetNewID(typeof(Model.Environmental_EnergyReport));
 | ||
|                     report.UpState = BLL.Const.UpState_2;
 | ||
|                     report.FillingMan = this.CurrUser.UserName;
 | ||
|                     BLL.EnergyReportService.AddEnvironmental_EnergyReport(report);
 | ||
|                     BLL.LogService.AddSys_Log(this.CurrUser, report.Year.ToString() + "-" + report.Quarters.ToString(), report.EnergyReportId, BLL.Const.EnergyReportMenuId, BLL.Const.BtnAdd);
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     ShowNotify("该月份记录已存在!", MessageBoxIcon.Warning);
 | ||
|                     return;
 | ||
|                 }
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 Model.Environmental_EnergyReport oldReport = BLL.EnergyReportService.GetEnvironmental_EnergyReportById(EnergyReportId);
 | ||
|                 report.EnergyReportId = EnergyReportId;
 | ||
|                 report.UpState = BLL.Const.UpState_2;
 | ||
|                 BLL.EnergyReportService.UpdateEnvironmental_EnergyReport(report);
 | ||
|                 BLL.LogService.AddSys_Log(this.CurrUser, report.Year.ToString() + "-" + report.Quarters.ToString(), report.EnergyReportId, BLL.Const.EnergyReportMenuId, BLL.Const.BtnModify);
 | ||
|             }
 | ||
|             EnergyReportId = report.EnergyReportId;
 | ||
|             BLL.EnergyreportItemService.DeleteEnergyReportItemByChemicalReportId(report.EnergyReportId);
 | ||
|             GetItems(report.EnergyReportId);
 | ||
|             List<Model.Environmental_EnergyReportItem> mReportItemList = new List<Environmental_EnergyReportItem>();
 | ||
|             foreach (var item in items)
 | ||
|             {
 | ||
|                 Model.Environmental_EnergyReportItem newItem = new Environmental_EnergyReportItem();
 | ||
|                 newItem.EnergyReportItemId = item.EnergyReportItemId;
 | ||
|                 newItem.EnergyReportId = item.EnergyReportId;
 | ||
|                 newItem.SortIndex = item.SortIndex;
 | ||
|                 newItem.BusinessCategory = item.BusinessCategory;
 | ||
|                 newItem.Throughput_BasePeriod = item.Throughput_BasePeriod;
 | ||
|                 newItem.Throughput_LastPeriod = item.Throughput_LastPeriod;
 | ||
|                 newItem.Throughput_ThisPeriod = item.Throughput_ThisPeriod;
 | ||
|                 newItem.Throughput_UnitOfMeasurement = item.Throughput_UnitOfMeasurement;
 | ||
|                 newItem.Yield_BasePeriod = item.Yield_BasePeriod;
 | ||
|                 newItem.Yield_LastPeriod = item.Yield_LastPeriod;
 | ||
|                 newItem.Yield_ThisPeriod = item.Yield_ThisPeriod;
 | ||
|                 newItem.Yield_UnitOfMeasurement = item.Yield_UnitOfMeasurement;
 | ||
|                 newItem.OutputValue_BasePeriod = item.OutputValue_BasePeriod;
 | ||
|                 newItem.OutputValue_LastYear = item.OutputValue_LastYear;
 | ||
|                 newItem.OutputValue_ThisYear = item.OutputValue_ThisYear;
 | ||
|                 newItem.OperationScale_BasePeriod = item.OperationScale_BasePeriod;
 | ||
|                 newItem.OperationScale_LastYear = item.OperationScale_LastYear;
 | ||
|                 newItem.OperationScale_ThisYear = item.OperationScale_ThisYear;
 | ||
|                 newItem.OperationScale_UnitOfMeasurement = item.OperationScale_UnitOfMeasurement;
 | ||
|                 newItem.ServiceOperatingIncome_BasePeriod = item.ServiceOperatingIncome_BasePeriod;
 | ||
|                 newItem.ServiceOperatingIncome_LastYear = item.ServiceOperatingIncome_LastYear;
 | ||
|                 newItem.ServiceOperatingIncome_ThisYear = item.ServiceOperatingIncome_ThisYear;
 | ||
|                 EnergyreportItemService.AddEnvironmental_EnergyReportItem(newItem);
 | ||
|                 mReportItemList.Add(newItem);
 | ||
|             }
 | ||
|             if (type == "updata")     //数据同步
 | ||
|             {
 | ||
|                 if (report.UpState == BLL.Const.UpState_2)
 | ||
|                 {
 | ||
|                     string code = CNCECHSSEWebService.UpEnergyReport(report.EnergyReportId, this.CurrUser);
 | ||
|                     if (code == "1")
 | ||
|                     {
 | ||
|                         ShowNotify("同步成功!", MessageBoxIcon.Success);
 | ||
|                         PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
 | ||
|                         return;
 | ||
|                     }
 | ||
|                     else
 | ||
|                     {
 | ||
|                         Alert.ShowInParent("同步异常,请退出后重试!", MessageBoxIcon.Error);
 | ||
|                     }
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     ShowNotify("当前单据状态不能同步!", MessageBoxIcon.Warning);
 | ||
|                     return;
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         protected void btnSave_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             Save("add");
 | ||
|             ShowNotify("保存成功!", MessageBoxIcon.Success);
 | ||
|             PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
 | ||
|         }
 | ||
| 
 | ||
|         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 EnergyReportId)
 | ||
|         {
 | ||
|             List<Model.Environmental_EnergyReportItem> newItemLists = new List<Environmental_EnergyReportItem>();
 | ||
| 
 | ||
|             foreach (JObject mergedRow in Grid1.GetMergedData())
 | ||
|             {
 | ||
|                 JObject values = mergedRow.Value<JObject>("values");
 | ||
|                 string sortIndex = values.Value<string>("SortIndex");
 | ||
|                 var newItem = items.FirstOrDefault(x => x.SortIndex == sortIndex);
 | ||
|                 if (newItem != null)
 | ||
|                 {
 | ||
|                     newItem.EnergyReportItemId = SQLHelper.GetNewID();
 | ||
|                     newItem.EnergyReportId = EnergyReportId;
 | ||
|                     newItem.SortIndex = values.Value<string>("SortIndex");
 | ||
|                     newItem.BusinessCategory = values.Value<string>("BusinessCategory");
 | ||
|                     newItem.Throughput_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Throughput_BasePeriod")).ToString();
 | ||
|                     newItem.Throughput_LastPeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Throughput_LastPeriod")).ToString();
 | ||
|                     newItem.Throughput_ThisPeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Throughput_ThisPeriod")).ToString();
 | ||
|                     newItem.Throughput_UnitOfMeasurement = values.Value<string>("Throughput_UnitOfMeasurement");
 | ||
|                     newItem.Yield_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Yield_BasePeriod")).ToString();
 | ||
|                     newItem.Yield_LastPeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Yield_LastPeriod")).ToString();
 | ||
|                     newItem.Yield_ThisPeriod = Funs.GetNewDecimalOrZero(values.Value<string>("Yield_ThisPeriod")).ToString();
 | ||
|                     newItem.Yield_UnitOfMeasurement = values.Value<string>("Yield_UnitOfMeasurement");
 | ||
|                     newItem.OutputValue_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("OutputValue_BasePeriod")).ToString();
 | ||
|                     newItem.OutputValue_LastYear = Funs.GetNewDecimalOrZero(values.Value<string>("OutputValue_LastYear")).ToString();
 | ||
|                     newItem.OutputValue_ThisYear = Funs.GetNewDecimalOrZero(values.Value<string>("OutputValue_ThisYear")).ToString();
 | ||
|                     newItem.OperationScale_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("OperationScale_BasePeriod")).ToString();
 | ||
|                     newItem.OperationScale_LastYear = Funs.GetNewDecimalOrZero(values.Value<string>("OperationScale_LastYear")).ToString();
 | ||
|                     newItem.OperationScale_ThisYear = Funs.GetNewDecimalOrZero(values.Value<string>("OperationScale_ThisYear")).ToString();
 | ||
|                     newItem.OperationScale_UnitOfMeasurement = values.Value<string>("OperationScale_UnitOfMeasurement");
 | ||
|                     newItem.ServiceOperatingIncome_BasePeriod = Funs.GetNewDecimalOrZero(values.Value<string>("ServiceOperatingIncome_BasePeriod")).ToString();
 | ||
|                     newItem.ServiceOperatingIncome_LastYear = Funs.GetNewDecimalOrZero(values.Value<string>("ServiceOperatingIncome_LastYear")).ToString();
 | ||
|                     newItem.ServiceOperatingIncome_ThisYear = Funs.GetNewDecimalOrZero(values.Value<string>("ServiceOperatingIncome_ThisYear")).ToString();
 | ||
|                     newItemLists.Add(newItem);
 | ||
|                 }
 | ||
|             }
 | ||
|             items = newItemLists;
 | ||
|         }
 | ||
|         #endregion
 | ||
| 
 | ||
|         #region 获取明细
 | ||
|         private void GetNewItems(int  year, int Quarters)
 | ||
|         {
 | ||
|             var indexNames = EnergyreportItemService.GetItems("Template");
 | ||
|             foreach (var indexName in indexNames)
 | ||
|             {
 | ||
|                 //增加明细集合
 | ||
|                 Model.Environmental_EnergyReportItem item = new Environmental_EnergyReportItem
 | ||
|                 {
 | ||
|                     EnergyReportItemId = SQLHelper.GetNewID(typeof(Model.Environmental_EnergyReportItem)),
 | ||
|                     BusinessCategory = indexName.BusinessCategory,
 | ||
|                     SortIndex = indexName.SortIndex,
 | ||
|                 };
 | ||
| 
 | ||
|                 items.Add(item);
 | ||
|             }
 | ||
|             var ListProjectEnergyItemReport= ProjectEnergyreportItemService.GetItemsByDate(year, Quarters);
 | ||
|             var q = from x in ListProjectEnergyItemReport
 | ||
|                     group x by x.SortIndex into g
 | ||
|                     select new
 | ||
|                     {
 | ||
|                         g.Key,
 | ||
|                         Throughput_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Throughput_BasePeriod)),
 | ||
|                         Throughput_LastPeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Throughput_LastPeriod)),
 | ||
|                         Throughput_ThisPeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Throughput_ThisPeriod)),
 | ||
|                         Yield_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Yield_BasePeriod)),
 | ||
|                         Yield_LastPeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Yield_LastPeriod)),
 | ||
|                         Yield_ThisPeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.Yield_ThisPeriod)),
 | ||
|                         OutputValue_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.OutputValue_BasePeriod)),
 | ||
|                         OutputValue_LastYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.OutputValue_LastYear)),
 | ||
|                         OutputValue_ThisYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.OutputValue_ThisYear)),
 | ||
|                         OperationScale_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.OperationScale_BasePeriod)),
 | ||
|                         OperationScale_LastYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.OperationScale_LastYear)),
 | ||
|                         OperationScale_ThisYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.OperationScale_ThisYear)),
 | ||
|                         ServiceOperatingIncome_BasePeriod = g.Sum(x => Funs.GetNewDecimalOrZero(x.ServiceOperatingIncome_BasePeriod)),
 | ||
|                         ServiceOperatingIncome_LastYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.ServiceOperatingIncome_LastYear)),
 | ||
|                         ServiceOperatingIncome_ThisYear = g.Sum(x => Funs.GetNewDecimalOrZero(x.ServiceOperatingIncome_ThisYear)),
 | ||
|                     };
 | ||
|             foreach (var item in items)
 | ||
|             {
 | ||
|                 item.Throughput_BasePeriod = q.Where(x => x.Key == item.SortIndex).Select(y => y.Throughput_BasePeriod).FirstOrDefault().ToString();
 | ||
|                 item.Throughput_LastPeriod = q.Where(x => x.Key == item.SortIndex).Select(y => y.Throughput_LastPeriod).FirstOrDefault().ToString();
 | ||
|                 item.Throughput_ThisPeriod = q.Where(x => x.Key == item.SortIndex).Select(y => y.Throughput_ThisPeriod).FirstOrDefault().ToString();
 | ||
|                 item.Yield_BasePeriod = q.Where(x => x.Key == item.SortIndex).Select(y => y.Yield_BasePeriod).FirstOrDefault().ToString();
 | ||
|                 item.Yield_LastPeriod = q.Where(x => x.Key == item.SortIndex).Select(y => y.Yield_LastPeriod).FirstOrDefault().ToString();
 | ||
|                 item.Yield_ThisPeriod = q.Where(x => x.Key == item.SortIndex).Select(y => y.Yield_ThisPeriod).FirstOrDefault().ToString();
 | ||
|                 item.OutputValue_BasePeriod = q.Where(x => x.Key == item.SortIndex).Select(y => y.OutputValue_BasePeriod).FirstOrDefault().ToString();
 | ||
|                 item.OutputValue_LastYear = q.Where(x => x.Key == item.SortIndex).Select(y => y.OutputValue_LastYear).FirstOrDefault().ToString();
 | ||
|                 item.OutputValue_ThisYear = q.Where(x => x.Key == item.SortIndex).Select(y => y.OutputValue_ThisYear).FirstOrDefault().ToString();
 | ||
|                 item.OperationScale_BasePeriod = q.Where(x => x.Key == item.SortIndex).Select(y => y.OperationScale_BasePeriod).FirstOrDefault().ToString();
 | ||
|                 item.OperationScale_LastYear = q.Where(x => x.Key == item.SortIndex).Select(y => y.OperationScale_LastYear).FirstOrDefault().ToString();
 | ||
|                 item.OperationScale_ThisYear = q.Where(x => x.Key == item.SortIndex).Select(y => y.OperationScale_ThisYear).FirstOrDefault().ToString();
 | ||
|                 item.ServiceOperatingIncome_BasePeriod = q.Where(x => x.Key == item.SortIndex).Select(y => y.ServiceOperatingIncome_BasePeriod).FirstOrDefault().ToString();
 | ||
|                 item.ServiceOperatingIncome_LastYear = q.Where(x => x.Key == item.SortIndex).Select(y => y.ServiceOperatingIncome_LastYear).FirstOrDefault().ToString();
 | ||
|                 item.ServiceOperatingIncome_ThisYear = q.Where(x => x.Key == item.SortIndex).Select(y => y.ServiceOperatingIncome_ThisYear).FirstOrDefault().ToString();
 | ||
|             }
 | ||
|         }
 | ||
|         #endregion
 | ||
| 
 | ||
|         #region 单位下拉选择事件
 | ||
|         /// <summary>
 | ||
|         /// 单位下拉选择事件
 | ||
|         /// </summary>
 | ||
|         /// <param name="sender"></param>
 | ||
|         /// <param name="e"></param>
 | ||
|         protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             items.Clear();
 | ||
|             if (drpUnit.SelectedValue != BLL.Const._Null)
 | ||
|             {
 | ||
|                 //GetNewItems();
 | ||
|             }
 | ||
|             Grid1.DataSource = items;
 | ||
|             Grid1.DataBind();
 | ||
|         }
 | ||
|         #endregion
 | ||
| 
 | ||
|         #region 获取按钮权限
 | ||
|         /// <summary>
 | ||
|         /// 获取按钮权限
 | ||
|         /// </summary>
 | ||
|         /// <param name="button"></param>
 | ||
|         /// <returns></returns>
 | ||
|         private void GetButtonPower()
 | ||
|         {
 | ||
|             var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.EnergyReportMenuId);
 | ||
|             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;
 | ||
|                 //}
 | ||
|             }
 | ||
|         }
 | ||
|         #endregion
 | ||
| 
 | ||
|         #region 复制上个月数据
 | ||
|         /// <summary>
 | ||
|         /// 复制上个月的数据
 | ||
|         /// </summary>
 | ||
|         /// <param name="sender"></param>
 | ||
|         /// <param name="e"></param>
 | ||
|         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.Environmental_EnergyReport ChemicalReport = BLL.EnergyReportService.GetEnvironmental_EnergyReportByUnitIdAndYearAndMonth(this.drpUnit.SelectedValue, showDate.Year, showDate.Month);
 | ||
|             //    if (ChemicalReport != null)
 | ||
|             //    {
 | ||
|             //        Model.Environmental_EnergyReport newChemicalReport = new Environmental_EnergyReport();
 | ||
|             //        this.EnergyReportId = SQLHelper.GetNewID(typeof(Model.Environmental_EnergyReport));
 | ||
|             //        newChemicalReport.EnergyReportId = this.EnergyReportId;
 | ||
|             //        newChemicalReport.UnitId = this.drpUnit.SelectedValue;
 | ||
|             //        newChemicalReport.Year = Convert.ToInt32(this.drpYear.SelectedValue);
 | ||
|             //        newChemicalReport.Month = Convert.ToInt32(this.drpMonth.SelectedValue);
 | ||
|             //        newChemicalReport.FillingMan = this.CurrUser.UserName;
 | ||
|             //        newChemicalReport.FillingDate = DateTime.Now;
 | ||
|             //        newChemicalReport.DutyPerson = this.CurrUser.UserName;
 | ||
|             //        newChemicalReport.UpState = BLL.Const.UpState_2;
 | ||
|             //        BLL.EnergyReportService.ad(newChemicalReport);
 | ||
| 
 | ||
|             //        var oldItems = BLL.EnergyreportItemService.GetItems(ChemicalReport.EnergyReportId);
 | ||
|             //        if (oldItems.Count > 0)
 | ||
|             //        {
 | ||
|             //            foreach (var item in oldItems)
 | ||
|             //            {
 | ||
|             //                Model.Environmental_EnergyReportItem newItem = new Environmental_EnergyReportItem
 | ||
|             //                {
 | ||
|             //                    ChemicalReportItemId = SQLHelper.GetNewID(typeof(Model.Environmental_EnergyReportItem)),
 | ||
|             //                    EnergyReportId = this.EnergyReportId,
 | ||
|             //                    SortIndex = item.SortIndex,
 | ||
|             //                    LastYearValue = item.LastYearValue,
 | ||
|             //                    ThisYearValue = item.ThisYearValue,
 | ||
|             //                    Rate = item.Rate,
 | ||
|             //                };
 | ||
|             //                BLL.EnergyreportItemService.AddChemicalReportItem(newItem);
 | ||
|             //            }
 | ||
|             //        }
 | ||
| 
 | ||
|             //        GetValues(newChemicalReport.EnergyReportId);
 | ||
|             //    }
 | ||
|             //}
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 获取复制的值绑定到文本中
 | ||
|         /// </summary>
 | ||
|         private void GetValues(string EnergyReportId)
 | ||
|         {
 | ||
|             var report = BLL.EnergyReportService.GetEnvironmental_EnergyReportById(EnergyReportId);
 | ||
|             if (report != null)
 | ||
|             {
 | ||
|                 drpQuarters.SelectedValue = report.Quarters.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;
 | ||
|                 items = BLL.EnergyreportItemService.GetShowItems(EnergyReportId);
 | ||
|                 this.Grid1.DataSource = items;
 | ||
|                 this.Grid1.DataBind();
 | ||
|             }
 | ||
|         }
 | ||
|         #endregion
 | ||
|     }
 | ||
| } |