2026-08-17 10:43:21 +08:00
|
|
|
using BLL;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.UI;
|
|
|
|
|
using System.Web.UI.WebControls;
|
|
|
|
|
|
2026-08-17 11:05:58 +08:00
|
|
|
namespace FineUIPro.Web.ReportManage.EnergyReport
|
2026-08-17 10:43:21 +08:00
|
|
|
{
|
|
|
|
|
public partial class EnergyStatistics : PageBase
|
|
|
|
|
{
|
|
|
|
|
#region 项目id
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 项目id
|
|
|
|
|
/// </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.EnergySettingsService.InitEnergyDropDownList(this.drpEnergyId, true);
|
|
|
|
|
Funs.DropDownPageSize(this.ddlPageSize);
|
|
|
|
|
this.ProjectId = this.CurrUser.LoginProjectId;
|
|
|
|
|
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId)
|
|
|
|
|
{
|
|
|
|
|
this.ProjectId = Request.Params["projectId"];
|
|
|
|
|
}
|
|
|
|
|
////权限按钮方法
|
|
|
|
|
this.ucTree.UnitId = this.CurrUser.UnitId;
|
|
|
|
|
this.ucTree.ProjectId = this.ProjectId;
|
|
|
|
|
if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
|
|
|
|
|
{
|
|
|
|
|
this.panelLeftRegion.Hidden = true;
|
|
|
|
|
////权限按钮方法
|
|
|
|
|
this.GetButtonPower();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.btnNew.Hidden = true;
|
|
|
|
|
this.btnMenuModify.Hidden = true;
|
|
|
|
|
this.btnMenuDel.Hidden = true;
|
|
|
|
|
this.Grid1.EnableRowDoubleClickEvent = false;
|
|
|
|
|
}
|
|
|
|
|
if (this.CurrUser != null && this.CurrUser.PageSize.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Grid1.PageSize = this.CurrUser.PageSize.Value;
|
|
|
|
|
}
|
|
|
|
|
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|
|
|
|
// 绑定表格
|
|
|
|
|
this.BindGrid();
|
|
|
|
|
btnNew.OnClientClick = Window1.GetShowReference("EnergyStatisticsEdit.aspx") + "return false;";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载树
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void changeTree(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.ProjectId = this.ucTree.ProjectId;
|
|
|
|
|
this.BindGrid();
|
|
|
|
|
this.GetButtonPower();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 绑定数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void BindGrid()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(this.ProjectId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string strSql = @"select s.EnergyStatisticsId,
|
|
|
|
|
s.ProjectId,
|
|
|
|
|
s.UnitId,
|
|
|
|
|
s.ReportDate,
|
|
|
|
|
s.EnergyId,
|
|
|
|
|
s.Consumption,
|
|
|
|
|
s.Amount,
|
|
|
|
|
s.UnitPrice,
|
|
|
|
|
s.ConversionUnit,
|
|
|
|
|
s.ConvertedQuantity,
|
|
|
|
|
s.TCE,
|
|
|
|
|
s.CompileMan,
|
|
|
|
|
s.CompileDate,
|
|
|
|
|
y.EnergyName,
|
|
|
|
|
y.EnergyUnit,
|
|
|
|
|
y.ReferenceCoefficient,
|
|
|
|
|
p.ProjectName,
|
|
|
|
|
u.UnitName
|
|
|
|
|
from EnergyReport_EnergyStatistics s
|
|
|
|
|
left join Base_Energy y on y.EnergyId = s.EnergyId
|
|
|
|
|
left join Base_Project p on p.ProjectId = s.ProjectId
|
|
|
|
|
left join Base_Unit u on u.UnitId= s.UnitId WHERE 1=1 ";
|
|
|
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
|
|
|
|
|
|
|
|
strSql += " AND s.ProjectId = @ProjectId";
|
|
|
|
|
listStr.Add(new SqlParameter("@ProjectId", this.ProjectId));
|
|
|
|
|
if (!string.IsNullOrEmpty(this.drpEnergyId.SelectedValue) && this.drpEnergyId.SelectedValue != BLL.Const._Null)
|
|
|
|
|
{
|
|
|
|
|
strSql += " AND s.EnergyId = @energyId";
|
|
|
|
|
listStr.Add(new SqlParameter("@energyId", this.drpEnergyId.SelectedValue));
|
|
|
|
|
}
|
|
|
|
|
if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.ProjectId, this.CurrUser.UnitId))
|
|
|
|
|
{
|
|
|
|
|
strSql += " AND s.UnitId =@unitId";
|
|
|
|
|
listStr.Add(new SqlParameter("@unitId", this.CurrUser.UnitId));
|
|
|
|
|
}
|
|
|
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
|
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
|
|
|
|
|
|
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
|
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
|
|
|
Grid1.DataSource = table;
|
|
|
|
|
Grid1.DataBind();
|
|
|
|
|
|
|
|
|
|
OutputSummaryData(tb);//求和
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 计算和
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tb"></param>
|
|
|
|
|
private void OutputSummaryData(DataTable tb)
|
|
|
|
|
{
|
|
|
|
|
//decimal consumption = 0;//用量
|
|
|
|
|
decimal amount = 0;//消费金额
|
|
|
|
|
//decimal unitPrice = 0;//单价
|
|
|
|
|
decimal convertedQuantity = 0; //转换吨标计量
|
|
|
|
|
decimal tce = 0; //吨标煤
|
|
|
|
|
foreach (DataRow row in tb.Rows)
|
|
|
|
|
{
|
|
|
|
|
//consumption += Convert.ToDecimal(row["Consumption"]);
|
|
|
|
|
amount += Convert.ToDecimal(row["Amount"]);
|
|
|
|
|
//unitPrice += Convert.ToDecimal(row["UnitPrice"]);
|
|
|
|
|
convertedQuantity += Convert.ToDecimal(row["ConvertedQuantity"]);
|
|
|
|
|
tce += Convert.ToDecimal(row["TCE"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JObject summary = new JObject();
|
|
|
|
|
summary.Add("EnergyName", "能源合计");
|
|
|
|
|
//summary.Add("Consumption", consumption.ToString("F2"));
|
|
|
|
|
summary.Add("Amount", amount.ToString("F2"));
|
|
|
|
|
//summary.Add("UnitPrice", unitPrice.ToString("F2"));
|
|
|
|
|
summary.Add("ConvertedQuantity", convertedQuantity.ToString("G7"));
|
|
|
|
|
summary.Add("TCE", tce.ToString("G5"));
|
|
|
|
|
|
|
|
|
|
Grid1.SummaryData = summary;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 分页、排序
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 改变索引事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
BindGrid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页下拉选择事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
|
|
|
|
BindGrid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 排序
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
BindGrid();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 查询
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void drpEnergyId_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.BindGrid();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 关闭弹出窗
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭弹出窗
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
BindGrid();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取按钮权限
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取按钮权限
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="button"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private void GetButtonPower()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(this.ProjectId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (Request.Params["value"] == "0") ///文件柜时 没有操作权限
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.EnergyStatisticsMenuId);
|
|
|
|
|
if (buttonList.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
if (buttonList.Contains(BLL.Const.BtnAdd))
|
|
|
|
|
{
|
|
|
|
|
this.btnNew.Hidden = false;
|
|
|
|
|
}
|
|
|
|
|
if (buttonList.Contains(BLL.Const.BtnModify))
|
|
|
|
|
{
|
|
|
|
|
this.btnMenuModify.Hidden = false;
|
|
|
|
|
this.Grid1.EnableRowDoubleClickEvent = true;
|
|
|
|
|
}
|
|
|
|
|
if (buttonList.Contains(BLL.Const.BtnDelete))
|
|
|
|
|
{
|
|
|
|
|
this.btnMenuDel.Hidden = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 编辑
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 编辑按钮
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void btnMenuModify_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("EnergyStatisticsEdit.aspx?energyStatisticsId={0}", this.Grid1.SelectedRowID, "编辑 - ")));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Grid双击事件
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Grid行双击事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
btnMenuModify_Click(null, null);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 删除
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
protected void btnMenuDel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Grid1.SelectedRowIndexArray.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var db = Funs.DB;
|
|
|
|
|
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
|
|
|
|
{
|
|
|
|
|
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
|
|
|
|
if (!string.IsNullOrEmpty(rowID))
|
|
|
|
|
{
|
|
|
|
|
BLL.EnergyStatisticsService.DeleteEnergyStatisticsById(rowID);
|
|
|
|
|
BLL.LogService.AddSys_Log(this.CurrUser, rowID, rowID, BLL.Const.EnergyStatisticsMenuId, BLL.Const.BtnDelete);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BindGrid();
|
|
|
|
|
ShowNotify("删除数据成功!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|