294 lines
12 KiB
C#
294 lines
12 KiB
C#
|
|
using BLL;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web.UI.WebControls;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
namespace FineUIPro.Web.ReportManage.SafeEnvBudget
|
|
{
|
|
public partial class SafeEnvBudgetTotal : PageBase
|
|
{
|
|
#region 加载页面
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
List<ListItem> years = new List<ListItem>();
|
|
for (int i = DateTime.Now.Year - 5; i < DateTime.Now.Year + 10; i++)
|
|
{
|
|
if (i == DateTime.Now.Year)
|
|
{
|
|
var item = new ListItem(i + "", i + "");
|
|
years.Add(item);
|
|
}
|
|
else
|
|
{
|
|
var item = new ListItem(i + "", i + "");
|
|
years.Add(item);
|
|
}
|
|
|
|
}
|
|
drpYear.DataTextField = "Text";
|
|
drpYear.DataValueField = "Value";
|
|
drpYear.DataSource = years;
|
|
drpYear.DataBind();
|
|
drpYear.SelectedValue = DateTime.Now.Year + "";
|
|
|
|
// 绑定表格
|
|
BindGrid();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string strSql = @" SELECT SafeEnvBudget.* ,0.0 LastYearBudgetAmount from SafeEnvBudget SafeEnvBudget
|
|
where SafeEnvBudget.State = 2 ";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
|
|
if (!string.IsNullOrEmpty(this.drpYear.SelectedText.Trim()))
|
|
{
|
|
strSql += " AND SafeEnvBudget.Year = @Year";
|
|
listStr.Add(new SqlParameter("@Year", this.drpYear.SelectedText.Trim()));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
if (tb != null)
|
|
{
|
|
string strSqlPre = @" SELECT SafeEnvBudget.* from SafeEnvBudget SafeEnvBudget
|
|
where SafeEnvBudget.State = 2 ";
|
|
List<SqlParameter> listStrPre = new List<SqlParameter>();
|
|
|
|
if (!string.IsNullOrEmpty(this.drpYear.SelectedText.Trim()))
|
|
{
|
|
strSqlPre += " AND SafeEnvBudget.Year = @Year";
|
|
listStrPre.Add(new SqlParameter("@Year", int.Parse(this.drpYear.SelectedText.Trim()) - 1));
|
|
}
|
|
SqlParameter[] parameterPre = listStrPre.ToArray();
|
|
DataTable tbPre = SQLHelper.GetDataTableRunText(strSqlPre, parameterPre);
|
|
HashSet<string> set = new HashSet<string>();
|
|
HashSet<string> set1 = new HashSet<string>();
|
|
HashSet<string> set2 = new HashSet<string>();
|
|
HashSet<string> set3 = new HashSet<string>();
|
|
HashSet<string> set4 = new HashSet<string>();
|
|
HashSet<string> set5 = new HashSet<string>();
|
|
foreach (DataRow row in tb.Rows)
|
|
{
|
|
set.Add(row["ProjectId"].ToString());
|
|
set1.Add(row["Subject1"].ToString());
|
|
}
|
|
List<string> prjectids = set.ToList();
|
|
var projects = Funs.DB.Base_Project.Where(x => prjectids.Contains(x.ProjectId)).ToList();
|
|
Dictionary<string, string> projectName = new Dictionary<string, string>();
|
|
foreach (var p in projects)
|
|
{
|
|
|
|
tb.Columns.Add(p.ProjectId);
|
|
BoundField bf = new FineUIPro.BoundField();
|
|
bf.DataField = p.ProjectId;
|
|
bf.DataFormatString = "{0}";
|
|
if (!string.IsNullOrEmpty(p.ShortName))
|
|
{
|
|
bf.HeaderText = p.ShortName;
|
|
}
|
|
else
|
|
{
|
|
bf.HeaderText = p.ProjectName;
|
|
}
|
|
projectName.Add(p.ProjectId, bf.HeaderText);
|
|
Grid1.Columns.Add(bf);
|
|
|
|
}
|
|
BoundField bf1 = new FineUIPro.BoundField();
|
|
bf1.DataField = "Remark";
|
|
bf1.DataFormatString = "{0}";
|
|
bf1.HeaderText = "说明";
|
|
Grid1.Columns.Add(bf1);
|
|
DataTable dtRes = tb.Clone();
|
|
decimal BudgetAmount1 = 0;
|
|
decimal BudgetAmount2 = 0;
|
|
decimal BudgetAmount3 = 0;
|
|
decimal BudgetAmount4 = 0;
|
|
decimal BudgetAmount5 = 0;
|
|
foreach (string Subject1 in set1)
|
|
{
|
|
|
|
BudgetAmount1 = 0;
|
|
var row1 = dtRes.NewRow();
|
|
dtRes.Rows.Add(row1);
|
|
|
|
row1["BudgetId"] = Guid.NewGuid().ToString();
|
|
row1["Subject1"] = Subject1;
|
|
DataRow[] rowData1= tb.Select("Subject1 = '"+ Subject1 + "'");
|
|
set2.Clear();
|
|
foreach(DataRow row in rowData1)
|
|
{
|
|
set2.Add(row["Subject2"].ToString());
|
|
}
|
|
foreach (string Subject2 in set2)
|
|
{
|
|
BudgetAmount2 = 0;
|
|
var row2 = dtRes.NewRow();
|
|
row2["BudgetId"] = Guid.NewGuid().ToString();
|
|
row2["Subject2"] = Subject2;
|
|
dtRes.Rows.Add(row2);
|
|
|
|
DataRow[] rowData2 = tb.Select("Subject1 = '" + Subject1 + "' and Subject2= '" + Subject2 + "'");
|
|
set3.Clear();
|
|
foreach (DataRow row in rowData2)
|
|
{
|
|
set3.Add(row["Subject3"].ToString());
|
|
}
|
|
foreach (string Subject3 in set3)
|
|
{
|
|
BudgetAmount3 = 0;
|
|
var row3 = dtRes.NewRow();
|
|
row3["BudgetId"] = Guid.NewGuid().ToString();
|
|
row3["Subject3"] = Subject3;
|
|
dtRes.Rows.Add(row3);
|
|
|
|
DataRow[] rowData4 = tb.Select("Subject1 = '" + Subject1 + "' and Subject2= '" + Subject2 + "' and Subject3= '"+ Subject3 + "'");
|
|
set4.Clear();
|
|
foreach (DataRow row in rowData4)
|
|
{
|
|
set4.Add(row["Subject4"].ToString());
|
|
}
|
|
foreach (string Subject4 in set4)
|
|
{
|
|
BudgetAmount4 = 0;
|
|
var row4 = dtRes.NewRow();
|
|
row4["BudgetId"] = Guid.NewGuid().ToString();
|
|
row4["Subject4"] = Subject4;
|
|
dtRes.Rows.Add(row4);
|
|
DataRow[] rowData5 = tb.Select("Subject1 = '" + Subject1 + "' and Subject2= '" + Subject2 + "' and Subject3= '" + Subject3 + "' and Subject4 = '"+ Subject4 + "'");
|
|
set5.Clear();
|
|
foreach (DataRow row in rowData5)
|
|
{
|
|
set5.Add(row["Subject5"].ToString());
|
|
}
|
|
|
|
foreach (string Subject5 in set5)
|
|
{
|
|
BudgetAmount5 = 0;
|
|
var row5 = dtRes.NewRow();
|
|
row5["BudgetId"] = Guid.NewGuid().ToString();
|
|
dtRes.Rows.Add(row5);
|
|
DataRow[] rowData6 = tb.Select("Subject1 = '" + Subject1 + "' and Subject2= '" + Subject2 + "' and Subject3= '" + Subject3 + "' and Subject4 = '" + Subject4 + "' and Subject5 = '" + Subject5 + "'");
|
|
foreach (DataRow row6 in rowData6)
|
|
{
|
|
|
|
row5["Subject5"] = Subject5;
|
|
row5[row6["ProjectId"].ToString()] = row6["BudgetAmount"];
|
|
if (!string.IsNullOrEmpty(row6["Remark"].ToString()))
|
|
{
|
|
row5["Remark"] = row5["Remark"].ToString() + projectName[row6["ProjectId"].ToString()] + ":"+ row6["Remark"].ToString();
|
|
}
|
|
decimal BudgetAmount = Funs.GetNewDecimalOrZero(row6["BudgetAmount"].ToString());
|
|
BudgetAmount1 += BudgetAmount;
|
|
BudgetAmount2 += BudgetAmount;
|
|
BudgetAmount3 += BudgetAmount;
|
|
BudgetAmount4 += BudgetAmount;
|
|
BudgetAmount5 += BudgetAmount;
|
|
}
|
|
row5["LastYearBudgetAmount"] = tbPre.Compute ("Sum(BudgetAmount)", "Subject1 = '" + Subject1 + "' and Subject2= '" + Subject2 + "' and Subject3= '" + Subject3 + "' and Subject4 = '" + Subject4 + "' and Subject5 = '" + Subject5 + "'") ;
|
|
row5["BudgetAmount"] = BudgetAmount5;
|
|
}
|
|
row4["LastYearBudgetAmount"] = tbPre.Compute("Sum(BudgetAmount)", "Subject1 = '" + Subject1 + "' and Subject2= '" + Subject2 + "' and Subject3= '" + Subject3 + "' and Subject4 = '" + Subject4 + "'");
|
|
row4["BudgetAmount"] = BudgetAmount4;
|
|
}
|
|
row3["LastYearBudgetAmount"] = tbPre.Compute("Sum(BudgetAmount)", "Subject1 = '" + Subject1 + "' and Subject2= '" + Subject2 + "' and Subject3= '" + Subject3 + "'");
|
|
row3["BudgetAmount"] = BudgetAmount3;
|
|
|
|
}
|
|
row2["LastYearBudgetAmount"] = tbPre.Compute("Sum(BudgetAmount)", "Subject1 = '" + Subject1 + "' and Subject2= '" + Subject2 + "'");
|
|
|
|
row2["BudgetAmount"] = BudgetAmount2;
|
|
}
|
|
|
|
row1["LastYearBudgetAmount"] = tbPre.Compute("Sum(BudgetAmount)", "Subject1 = '" + Subject1 + "'") ;
|
|
row1["BudgetAmount"] = BudgetAmount1;
|
|
|
|
}
|
|
|
|
Grid1.RecordCount = dtRes.Rows.Count;
|
|
Grid1.DataSource = dtRes;
|
|
Grid1.DataBind();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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("专项检查" + filename, System.Text.Encoding.UTF8) + ".xls");
|
|
Response.ContentType = "application/excel";
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
this.Grid1.PageSize = this.Grid1.RecordCount;
|
|
BindGrid();
|
|
Response.Write(GetGridTableHtml(Grid1));
|
|
Response.End();
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 查询
|
|
/// <summary>
|
|
/// 查询
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void TextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
this.BindGrid();
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
} |