308 lines
14 KiB
C#
308 lines
14 KiB
C#
using BLL;
|
|
using System;
|
|
|
|
namespace FineUIPro.Web.ReportManage.EnergyReport
|
|
{
|
|
public partial class EnergyStatisticsEdit : PageBase
|
|
{
|
|
#region 定义变量
|
|
/// <summary>
|
|
/// 主键
|
|
/// </summary>
|
|
public string EnergyStatisticsId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["EnergyStatisticsId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["EnergyStatisticsId"] = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 项目主键
|
|
/// </summary>
|
|
public string ProjectId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["ProjectId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["ProjectId"] = value;
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 加载页面
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList1(this.drpUnitId, this.CurrUser.LoginProjectId, true);
|
|
BLL.EnergySettingsService.InitEnergyDropDownList(this.drpEnergyId, true);
|
|
this.EnergyStatisticsId = Request.Params["energyStatisticsId"];
|
|
if (!string.IsNullOrEmpty(EnergyStatisticsId))
|
|
{
|
|
Model.EnergyReport_EnergyStatistics energyStatistics = BLL.EnergyStatisticsService.GetEnergyStatisticsById(this.EnergyStatisticsId);
|
|
if (energyStatistics != null)
|
|
{
|
|
if (!string.IsNullOrEmpty(energyStatistics.UnitId))
|
|
{
|
|
this.drpUnitId.SelectedValue = energyStatistics.UnitId;
|
|
}
|
|
if (energyStatistics.ReportDate != null)
|
|
{
|
|
this.txtReportDate.Text = string.Format("{0:yyyy-MM-dd}", energyStatistics.ReportDate);
|
|
}
|
|
if (!string.IsNullOrEmpty(energyStatistics.EnergyId))
|
|
{
|
|
this.drpEnergyId.SelectedValue = energyStatistics.EnergyId;
|
|
var energy = BLL.EnergySettingsService.GetEnergyById(this.drpEnergyId.SelectedValue);
|
|
if (energy != null)
|
|
{
|
|
if (!string.IsNullOrEmpty(energy.EnergyUnit))
|
|
{
|
|
this.txtEnergyUnit.Text = energy.EnergyUnit;
|
|
}
|
|
}
|
|
}
|
|
this.txtConsumption.Text = energyStatistics.Consumption.HasValue ? energyStatistics.Consumption.ToString() : ""; ;
|
|
this.txtAmount.Text = energyStatistics.Amount.HasValue ? energyStatistics.Amount.ToString() : "";
|
|
this.txtUnitPrice.Text = energyStatistics.UnitPrice.HasValue ? energyStatistics.UnitPrice.ToString() : "";
|
|
if (!string.IsNullOrEmpty(energyStatistics.ConversionUnit))
|
|
{
|
|
this.drpConversionUnit.SelectedValue = energyStatistics.ConversionUnit;
|
|
}
|
|
this.txtConvertedQuantity.Text = energyStatistics.ConvertedQuantity.HasValue ? energyStatistics.ConvertedQuantity.ToString() : "";
|
|
this.txtTCE.Text = energyStatistics.TCE.HasValue ? energyStatistics.TCE.ToString() : "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.txtReportDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 保存按钮
|
|
/// <summary>
|
|
/// 保存按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.drpUnitId.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(this.drpUnitId.SelectedValue))
|
|
{
|
|
Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
if (this.drpEnergyId.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(this.drpEnergyId.SelectedValue))
|
|
{
|
|
Alert.ShowInTop("请选择能源名称!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
this.SaveData();
|
|
ShowNotify("保存成功!", MessageBoxIcon.Success);
|
|
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 保存方法
|
|
/// <summary>
|
|
/// 保存数据
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
private void SaveData()
|
|
{
|
|
Model.EnergyReport_EnergyStatistics newData = new Model.EnergyReport_EnergyStatistics();
|
|
newData.ProjectId = this.CurrUser.LoginProjectId;
|
|
newData.UnitId = this.drpUnitId.SelectedValue;
|
|
if (!string.IsNullOrEmpty(this.txtReportDate.Text.Trim()))
|
|
{
|
|
try
|
|
{
|
|
newData.ReportDate = Convert.ToDateTime(this.txtReportDate.Text.Trim());
|
|
}
|
|
catch { }
|
|
}
|
|
newData.EnergyId = this.drpEnergyId.SelectedValue;
|
|
newData.Consumption = Funs.GetNewDecimalOrZero(this.txtConsumption.Text.Trim());
|
|
newData.Amount = Funs.GetNewDecimalOrZero(this.txtAmount.Text.Trim());
|
|
newData.UnitPrice = Funs.GetNewDecimalOrZero(this.txtUnitPrice.Text.Trim());
|
|
if (!string.IsNullOrEmpty(this.drpConversionUnit.SelectedValue))
|
|
{
|
|
newData.ConversionUnit = this.drpConversionUnit.SelectedValue.Trim();
|
|
}
|
|
newData.ConvertedQuantity = Funs.GetNewDecimalOrZero(this.txtConvertedQuantity.Text.Trim());
|
|
newData.TCE = Funs.GetNewDecimalOrZero(this.txtTCE.Text.Trim());
|
|
|
|
if (!string.IsNullOrEmpty(this.EnergyStatisticsId))
|
|
{
|
|
newData.EnergyStatisticsId = this.EnergyStatisticsId;
|
|
BLL.EnergyStatisticsService.UpdateEnergyStatistics(newData);
|
|
BLL.LogService.AddSys_Log(this.CurrUser, this.drpEnergyId.SelectedText, this.EnergyStatisticsId, BLL.Const.EnergyStatisticsMenuId, Const.BtnModify);
|
|
}
|
|
else
|
|
{
|
|
newData.CompileMan = this.CurrUser.UserId;
|
|
newData.CompileDate = DateTime.Now;
|
|
newData.EnergyStatisticsId = SQLHelper.GetNewID();
|
|
this.EnergyStatisticsId = newData.EnergyStatisticsId;
|
|
BLL.EnergyStatisticsService.AddEnergyStatistics(newData);
|
|
BLL.LogService.AddSys_Log(this.CurrUser, this.drpEnergyId.SelectedText, this.EnergyStatisticsId, BLL.Const.EnergyStatisticsMenuId, Const.BtnAdd);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 联动事件
|
|
/// <summary>
|
|
/// 能源下拉选择事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void drpEnergyId_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
this.txtEnergyUnit.Text = string.Empty;
|
|
if (this.drpEnergyId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpEnergyId.SelectedValue))
|
|
{
|
|
var energy = BLL.EnergySettingsService.GetEnergyById(this.drpEnergyId.SelectedValue);
|
|
if (energy != null)
|
|
{
|
|
this.txtEnergyUnit.Text = energy.EnergyUnit;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 单价=消费金额/转换量
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void txtAmount_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(this.txtAmount.Text.Trim()))
|
|
{
|
|
decimal a = Funs.GetNewDecimalOrZero(this.txtAmount.Text.Trim());
|
|
decimal b = Funs.GetNewDecimalOrZero(this.txtConvertedQuantity.Text.Trim());
|
|
if (b > 0)
|
|
{
|
|
txtUnitPrice.Text = (a / b).ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
txtUnitPrice.Text = "0.00";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换吨标计量=用量*不同能源不同值
|
|
/// 吨标煤=转换量*参考折标准煤系数
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void txtConsumption_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(this.txtConsumption.Text.Trim()) && this.drpEnergyId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpEnergyId.SelectedValue))
|
|
{
|
|
decimal c = Funs.GetNewDecimalOrZero(this.txtConsumption.Text.Trim());
|
|
var energy = BLL.EnergySettingsService.GetEnergyById(this.drpEnergyId.SelectedValue);
|
|
if (energy != null)
|
|
{
|
|
if (energy.EnergyName.Trim() == "电力")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "万千瓦时";
|
|
this.txtConvertedQuantity.Text = (c / 10000).ToString();
|
|
this.txtTCE.Text = ((c / 10000) * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "汽油")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "吨";
|
|
this.txtConvertedQuantity.Text = (c * Convert.ToDecimal(0.73) / 1000).ToString();
|
|
this.txtTCE.Text = ((c * Convert.ToDecimal(0.73) / 1000) * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "柴油")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "吨";
|
|
this.txtConvertedQuantity.Text = (c * Convert.ToDecimal(0.86) / 1000).ToString();
|
|
this.txtTCE.Text = ((c * Convert.ToDecimal(0.86) / 1000) * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "煤油")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "吨";
|
|
this.txtConvertedQuantity.Text = (c * Convert.ToDecimal(0.82) / 1000).ToString();
|
|
this.txtTCE.Text = ((c * Convert.ToDecimal(0.82) / 1000) * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "燃料油")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "吨";
|
|
this.txtConvertedQuantity.Text = (c * Convert.ToDecimal(0.91) / 1000).ToString();
|
|
this.txtTCE.Text = ((c * Convert.ToDecimal(0.91) / 1000) * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "润滑油")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "吨";
|
|
this.txtConvertedQuantity.Text = (c * Convert.ToDecimal(0.8) / 1000).ToString();
|
|
this.txtTCE.Text = ((c * Convert.ToDecimal(0.8) / 1000) * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "外购热力")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "百万千焦";
|
|
this.txtConvertedQuantity.Text = (c * Convert.ToDecimal(0.81)).ToString();
|
|
this.txtTCE.Text = (c * Convert.ToDecimal(0.81) * energy.ReferenceCoefficient / 6).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "煤炭")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "吨";
|
|
this.txtConvertedQuantity.Text = c.ToString();
|
|
this.txtTCE.Text = (c * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "焦炭")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "吨";
|
|
this.txtConvertedQuantity.Text = c.ToString();
|
|
this.txtTCE.Text = (c * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "管道煤气")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "立方米";
|
|
this.txtConvertedQuantity.Text = c.ToString();
|
|
this.txtTCE.Text = (c * energy.ReferenceCoefficient / 1000).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "天然气(气态)")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "立方米";
|
|
this.txtConvertedQuantity.Text = c.ToString();
|
|
this.txtTCE.Text = (c * energy.ReferenceCoefficient / 1000).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "液化天然气(液态)")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "吨";
|
|
this.txtConvertedQuantity.Text = c.ToString();
|
|
this.txtTCE.Text = (c * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
else if (energy.EnergyName.Trim() == "液化石油气")
|
|
{
|
|
this.drpConversionUnit.SelectedValue = "吨";
|
|
this.txtConvertedQuantity.Text = c.ToString();
|
|
this.txtTCE.Text = (c * energy.ReferenceCoefficient).ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |