2023-06-06 17:01:34 +08:00
|
|
|
|
using BLL;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace FineUIPro.Web.HSSE.CostGoods
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class CostSummary : PageBase
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 项目id
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string ProjectId
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return (string)ViewState["ProjectId"];
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
ViewState["ProjectId"] = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region Page_Init
|
|
|
|
|
|
|
|
|
|
|
|
// 注意:动态创建的代码需要放置于Page_Init(不是Page_Load),这样每次构造页面时都会执行
|
|
|
|
|
|
protected void Page_Init(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitYearGrid();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected static int sDate = 0;
|
|
|
|
|
|
protected static int eDate = 0;
|
|
|
|
|
|
#region 按年份
|
|
|
|
|
|
private void InitYearGrid()
|
|
|
|
|
|
{
|
|
|
|
|
|
FineUIPro.BoundField bf;
|
|
|
|
|
|
FineUIPro.GroupField gr;
|
|
|
|
|
|
|
|
|
|
|
|
bf = new FineUIPro.BoundField();
|
|
|
|
|
|
bf.DataField = "Id";
|
|
|
|
|
|
bf.DataFormatString = "{0}";
|
|
|
|
|
|
bf.HeaderText = "编号";
|
|
|
|
|
|
bf.Width = 60;
|
|
|
|
|
|
bf.Hidden = true;
|
|
|
|
|
|
Grid1.Columns.Add(bf);
|
|
|
|
|
|
|
|
|
|
|
|
bf = new FineUIPro.BoundField();
|
|
|
|
|
|
bf.DataField = "SupCostTypeName";
|
|
|
|
|
|
bf.DataFormatString = "{0}";
|
|
|
|
|
|
bf.HeaderText = "类别名称";
|
|
|
|
|
|
bf.ColumnID = "GroupB";
|
|
|
|
|
|
bf.Width = 90;
|
|
|
|
|
|
bf.HeaderTextAlign = TextAlign.Center;
|
|
|
|
|
|
Grid1.Columns.Add(bf);
|
|
|
|
|
|
|
|
|
|
|
|
bf = new FineUIPro.BoundField();
|
|
|
|
|
|
bf.DataField = "CostTypeName";
|
|
|
|
|
|
bf.DataFormatString = "{0}";
|
|
|
|
|
|
bf.HeaderText = "分项名称";
|
|
|
|
|
|
bf.Width = 120;
|
|
|
|
|
|
bf.HeaderTextAlign = TextAlign.Center;
|
|
|
|
|
|
Grid1.Columns.Add(bf);
|
|
|
|
|
|
|
|
|
|
|
|
this.ProjectId = this.ProjectId ?? this.CurrUser.LoginProjectId;
|
|
|
|
|
|
var getProject = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == this.ProjectId);
|
|
|
|
|
|
if (getProject != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
sDate = getProject.StartDate.HasValue ? getProject.StartDate.Value.Year : DateTime.Now.Year;
|
|
|
|
|
|
eDate = getProject.EndDate.HasValue ? getProject.EndDate.Value.Year : DateTime.Now.Year;
|
|
|
|
|
|
var getCostEx = Funs.DB.CostGoods_Expense.Where(x => x.ProjectId == this.ProjectId);
|
|
|
|
|
|
if (getCostEx.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var getMaxYear = getCostEx.Max(x => x.Year);
|
|
|
|
|
|
if (getMaxYear.HasValue && getMaxYear > eDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
eDate = getMaxYear.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
var getMinYear = getCostEx.Min(x => x.Year);
|
|
|
|
|
|
if (getMinYear.HasValue && getMinYear < sDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
sDate = getMinYear.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-10 14:33:21 +08:00
|
|
|
|
|
2023-06-06 17:01:34 +08:00
|
|
|
|
for (int i = 0; sDate + i <= eDate; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
gr = new FineUIPro.GroupField();
|
|
|
|
|
|
gr.HeaderText = (sDate + i).ToString() + "年(元)";
|
2025-10-10 14:33:21 +08:00
|
|
|
|
gr.HeaderTextAlign = TextAlign.Center;
|
2023-06-06 17:01:34 +08:00
|
|
|
|
|
|
|
|
|
|
bf = new FineUIPro.BoundField();
|
2025-10-10 14:33:21 +08:00
|
|
|
|
bf.DataField = (sDate + i).ToString() + "a";
|
2023-06-06 17:01:34 +08:00
|
|
|
|
bf.DataFormatString = "{0}";
|
|
|
|
|
|
bf.HeaderText = "计划";
|
|
|
|
|
|
bf.Width = 100;
|
2025-10-10 14:33:21 +08:00
|
|
|
|
bf.HeaderTextAlign = TextAlign.Center;
|
2023-06-06 17:01:34 +08:00
|
|
|
|
gr.Columns.Add(bf);
|
|
|
|
|
|
|
|
|
|
|
|
bf = new FineUIPro.BoundField();
|
2025-10-10 14:33:21 +08:00
|
|
|
|
bf.DataField = (sDate + i).ToString() + "b";
|
2023-06-06 17:01:34 +08:00
|
|
|
|
bf.DataFormatString = "{0}";
|
|
|
|
|
|
bf.HeaderText = "申请";
|
|
|
|
|
|
bf.Width = 100;
|
|
|
|
|
|
bf.HeaderTextAlign = TextAlign.Center;
|
|
|
|
|
|
gr.Columns.Add(bf);
|
|
|
|
|
|
|
|
|
|
|
|
Grid1.Columns.Add(gr);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-10 14:33:21 +08:00
|
|
|
|
|
2023-06-06 17:01:34 +08:00
|
|
|
|
gr = new FineUIPro.GroupField();
|
|
|
|
|
|
gr.HeaderText = "合计(元)";
|
|
|
|
|
|
gr.HeaderTextAlign = TextAlign.Center;
|
|
|
|
|
|
|
|
|
|
|
|
bf = new FineUIPro.BoundField();
|
|
|
|
|
|
bf.DataField = "SumC";
|
|
|
|
|
|
bf.DataFormatString = "{0}";
|
|
|
|
|
|
bf.HeaderText = "计划";
|
|
|
|
|
|
bf.Width = 90;
|
|
|
|
|
|
bf.HeaderTextAlign = TextAlign.Center;
|
|
|
|
|
|
gr.Columns.Add(bf);
|
|
|
|
|
|
|
|
|
|
|
|
bf = new FineUIPro.BoundField();
|
|
|
|
|
|
bf.DataField = "SumD";
|
|
|
|
|
|
bf.DataFormatString = "{0}";
|
|
|
|
|
|
bf.HeaderText = "申请";
|
|
|
|
|
|
bf.Width = 90;
|
|
|
|
|
|
bf.HeaderTextAlign = TextAlign.Center;
|
|
|
|
|
|
gr.Columns.Add(bf);
|
|
|
|
|
|
|
|
|
|
|
|
Grid1.Columns.Add(gr);
|
|
|
|
|
|
Grid1.DataKeyNames = new string[] { "Id", "CostTypeName" };
|
2025-10-10 14:33:21 +08:00
|
|
|
|
|
2023-06-06 17:01:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!IsPostBack)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.ProjectId = this.CurrUser.LoginProjectId;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.ProjectId)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.ProjectId = Request.Params["projectId"];
|
|
|
|
|
|
}
|
|
|
|
|
|
Funs.DropDownPageSize(this.ddlPageSize);
|
|
|
|
|
|
////权限按钮方法
|
|
|
|
|
|
this.btnUnit.OnClientClick = Window2.GetShowReference("CostSummaryUnit.aspx") + "return false;";
|
|
|
|
|
|
UnitService.InitUnitDropDownList(this.drpUnit, this.ProjectId, false);
|
|
|
|
|
|
Funs.FineUIPleaseSelect(drpUnit, "请选择单位");
|
|
|
|
|
|
LoadData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
|
{
|
|
|
|
|
|
DataTable tb = GetDataTable(); //this.LINQToDataTable(getData.ToList());
|
|
|
|
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
|
|
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
|
|
|
|
Grid1.DataSource = table;
|
|
|
|
|
|
Grid1.DataBind();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取模拟树表格
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public DataTable GetDataTable()
|
|
|
|
|
|
{
|
|
|
|
|
|
DataTable table = new DataTable();
|
|
|
|
|
|
table.Columns.Add(new DataColumn("Id", typeof(string)));
|
|
|
|
|
|
table.Columns.Add(new DataColumn("SupCostTypeName", typeof(string)));
|
2025-10-10 14:33:21 +08:00
|
|
|
|
table.Columns.Add(new DataColumn("CostTypeName", typeof(string)));
|
2023-06-06 17:01:34 +08:00
|
|
|
|
for (int i = 0; sDate + i <= eDate; i++)
|
|
|
|
|
|
{
|
2025-10-10 14:33:21 +08:00
|
|
|
|
table.Columns.Add(new DataColumn((sDate + i).ToString() + "a", typeof(string)));
|
2023-06-06 17:01:34 +08:00
|
|
|
|
table.Columns.Add(new DataColumn((sDate + i).ToString() + "b", typeof(string)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
table.Columns.Add(new DataColumn("SumC", typeof(String)));
|
|
|
|
|
|
table.Columns.Add(new DataColumn("SumD", typeof(String)));
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(this.drpUnit.SelectedValue) && this.drpUnit.SelectedValue != Const._Null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string unitId = this.drpUnit.SelectedValue;
|
|
|
|
|
|
SetRow(table, unitId);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SetRow(table, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return table;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置table
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="table"></param>
|
|
|
|
|
|
/// <param name="unitId"></param>
|
|
|
|
|
|
private void SetRow(DataTable table, string unitId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var getDetail = from x in Funs.DB.CostGoods_ExpenseDetail
|
|
|
|
|
|
join y in Funs.DB.CostGoods_Expense on x.ExpenseId equals y.ExpenseId
|
|
|
|
|
|
where y.ProjectId == this.ProjectId && (unitId == null || y.UnitId == unitId)
|
|
|
|
|
|
orderby y.Year, x.SupSortIndex, x.SortIndex
|
|
|
|
|
|
select new { x.ExpenseDetailId, x.ExpenseId, y.Year, x.SupCostTypeId, x.SupCostTypeName, x.SupSortIndex, x.CostType, x.CostTypeName, x.SortIndex, x.CostMoney };
|
|
|
|
|
|
var getType = (from x in getDetail select new { x.SupSortIndex, x.SortIndex, x.CostType }).Distinct();
|
|
|
|
|
|
|
|
|
|
|
|
var getCostManageItem = from x in Funs.DB.CostGoods_CostManageItem
|
|
|
|
|
|
join y in Funs.DB.CostGoods_CostManage on x.CostManageId equals y.CostManageId
|
2025-10-10 14:33:21 +08:00
|
|
|
|
where y.ProjectId == this.ProjectId && (unitId == null || y.UnitId == unitId) && y.States == Const.State_2
|
2023-06-06 17:01:34 +08:00
|
|
|
|
select new { x.CostManageId, x.CostManageItemId, Year = y.CostManageDate.Value.Year, x.SupCostTypeId, x.CostTypeId, x.PriceMoney };
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in getType)
|
|
|
|
|
|
{
|
|
|
|
|
|
decimal sumC = 0;
|
|
|
|
|
|
decimal sumCD = 0;
|
|
|
|
|
|
|
|
|
|
|
|
var getD = getDetail.FirstOrDefault(x => x.CostType == item.CostType);
|
|
|
|
|
|
if (getD != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DataRow row = table.NewRow();
|
|
|
|
|
|
row[0] = getD.ExpenseDetailId + "#" + getD.ExpenseId;
|
|
|
|
|
|
row[1] = getD.SupCostTypeName;
|
|
|
|
|
|
row[2] = getD.CostTypeName;
|
|
|
|
|
|
int r = 3;
|
|
|
|
|
|
for (int i = 0; sDate + i <= eDate; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
row[r] = 0.00;
|
|
|
|
|
|
var getV = getDetail.Where(x => x.Year == sDate + i && x.CostType == item.CostType);
|
|
|
|
|
|
if (getV.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
decimal c = getV.Sum(x => x.CostMoney ?? 0);
|
|
|
|
|
|
row[r] = c;
|
|
|
|
|
|
sumC += c;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
row[r + 1] = 0.00;
|
|
|
|
|
|
var getCD = getCostManageItem.Where(x => x.Year == sDate + i && x.CostTypeId == item.CostType);
|
|
|
|
|
|
if (getCD.Count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
decimal d = getCD.Sum(x => x.PriceMoney ?? 0);
|
|
|
|
|
|
row[r + 1] = d;
|
|
|
|
|
|
sumCD += d;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
r = r + 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
row[r] = sumC;
|
|
|
|
|
|
row[r + 1] = sumCD;
|
|
|
|
|
|
table.Rows.Add(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 导出按钮
|
|
|
|
|
|
/// 导出按钮
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
protected void btnOut_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Response.ClearContent();
|
|
|
|
|
|
string filename = Funs.GetNewFileName();
|
|
|
|
|
|
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("项目HSE费用汇总" + filename, System.Text.Encoding.UTF8) + ".xls");
|
|
|
|
|
|
Response.ContentType = "application/excel";
|
|
|
|
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
|
|
|
|
this.Grid1.PageSize = this.Grid1.RecordCount;
|
2025-10-10 14:33:21 +08:00
|
|
|
|
|
2023-06-06 17:01:34 +08:00
|
|
|
|
Response.Write(GetGridTableHtml(this.Grid1));
|
|
|
|
|
|
Response.End();
|
2025-10-10 14:33:21 +08:00
|
|
|
|
}
|
2023-06-06 17:01:34 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 分页 排序
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 改变索引事件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LoadData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 分页下拉选择事件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue);
|
|
|
|
|
|
LoadData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LoadData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 单位查询事件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2025-10-10 14:33:21 +08:00
|
|
|
|
this.LoadData();
|
2023-06-06 17:01:34 +08:00
|
|
|
|
}
|
2025-10-10 14:33:21 +08:00
|
|
|
|
|
2023-06-06 17:01:34 +08:00
|
|
|
|
|
|
|
|
|
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LoadData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|