187 lines
6.7 KiB
C#
187 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BLL;
|
|
using AspNet = System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.ZHGL.ManagementReport
|
|
{
|
|
public partial class CQMSMonthReportProjectSum : PageBase
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
////权限按钮方法
|
|
this.GetButtonPower();
|
|
|
|
// 绑定表格
|
|
//BindGrid();
|
|
InitTreeMenu();
|
|
}
|
|
}
|
|
|
|
private void InitTreeMenu()
|
|
{
|
|
this.tvControlItem.Nodes.Clear();
|
|
TreeNode rootNode = new TreeNode();
|
|
rootNode.Text = "年份";
|
|
rootNode.NodeID = "0";
|
|
rootNode.Expanded = true;
|
|
this.tvControlItem.Nodes.Add(rootNode);
|
|
var years=(from x in Funs.DB.CQMS_MonthReport select x.Years).Distinct();
|
|
foreach (var year in years)
|
|
{
|
|
TreeNode tnYear = new TreeNode();//年节点
|
|
tnYear.Text = year.ToString();
|
|
tnYear.NodeID = year.ToString();
|
|
tnYear.EnableClickEvent = true;
|
|
rootNode.Nodes.Add(tnYear);
|
|
|
|
//var project = (from x in Funs.DB.HSSE_MonthReport
|
|
// join y in Funs.DB.Base_Project on x.ProjectId equals y.ProjectId
|
|
// where x.Years == year
|
|
// select new { x.ProjectId, y.ProjectName }).Distinct();
|
|
//if (project.Count() > 0)
|
|
//{
|
|
// foreach (var pro in project)
|
|
// {
|
|
// TreeNode tnProject = new TreeNode();//年节点
|
|
// tnProject.Text = SubStr(pro.ProjectName);
|
|
// tnProject.NodeID = pro.ProjectId+"$"+year;
|
|
// tnProject.EnableClickEvent = true;
|
|
// tnProject.ToolTip = pro.ProjectName;
|
|
// tnYear.Nodes.Add(tnProject);
|
|
|
|
// }
|
|
//}
|
|
}
|
|
|
|
}
|
|
|
|
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string strSql = @"SELECT NEWID() MonthReportItemId,ReportItem,Unit,AVG (Sort) Sort ,SUM (Month1) Month1,SUM (Month2) Month2,SUM (Month3) Month3,SUM (Month4)Month4,SUM (Month5)Month5,SUM (Month6)Month6,SUM (Month7)Month7,SUM (Month8)Month8,SUM (Month9)Month9,SUM (Month10)Month10,SUM (Month11)Month11,SUM (Month12)Month12,SUM (YearTotal)YearTotal,SUM(ProjectTotal)ProjectTotal
|
|
FROM dbo.CQMS_MonthReportItem a left join CQMS_MonthReport b on a.MonthReportId = b.MonthReportId
|
|
--WHERE MonthReportId=@MonthReportId
|
|
where b.Years = @Year and ( @ProjectId = '' or b.ProjectId = @ProjectId)
|
|
group by ReportItem,Unit
|
|
ORDER BY Sort";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
if (tvControlItem.SelectedNodeID.Contains("$"))
|
|
{
|
|
listStr.Add(new SqlParameter("@ProjectId", tvControlItem.SelectedNodeID.Split('$')[0]));
|
|
listStr.Add(new SqlParameter("@Year", tvControlItem.SelectedNodeID.Split('$')[1]));
|
|
}
|
|
else
|
|
{
|
|
listStr.Add(new SqlParameter("@ProjectId", ""));
|
|
listStr.Add(new SqlParameter("@Year", tvControlItem.SelectedNodeID));
|
|
}
|
|
|
|
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
// 2.获取当前分页数据
|
|
//var table = this.GetPagedDataTable(Grid1, tb1);
|
|
|
|
Grid1.DataSource = dt;
|
|
Grid1.DataBind();
|
|
|
|
}
|
|
|
|
private string SubStr(string str)
|
|
{
|
|
string reStr = string.Empty;
|
|
if (!string.IsNullOrEmpty(str) && str.Length > 16)
|
|
{
|
|
reStr = str.Substring(0, 16) + "..";
|
|
}
|
|
return reStr;
|
|
}
|
|
|
|
#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("管理月报B" + filename, System.Text.Encoding.UTF8) + ".xls");
|
|
Response.ContentType = "application/excel";
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
this.Grid1.PageSize = 500;
|
|
this.BindGrid();
|
|
Response.Write(GetGridTableHtml(Grid1));
|
|
Response.End();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出方法
|
|
/// </summary>
|
|
/// <param name="grid"></param>
|
|
/// <returns></returns>
|
|
private string GetGridTableHtml(Grid grid)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
|
|
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
|
|
sb.Append("<tr>");
|
|
foreach (GridColumn column in grid.Columns)
|
|
{
|
|
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
|
|
}
|
|
sb.Append("</tr>");
|
|
foreach (GridRow row in grid.Rows)
|
|
{
|
|
sb.Append("<tr>");
|
|
foreach (GridColumn column in grid.Columns)
|
|
{
|
|
string html = row.Values[column.ColumnIndex].ToString();
|
|
if (column.ColumnID == "tfNumber")
|
|
{
|
|
html = (row.FindControl("lblNumber") as AspNet.Label).Text;
|
|
}
|
|
sb.AppendFormat("<td>{0}</td>", html);
|
|
}
|
|
|
|
sb.Append("</tr>");
|
|
}
|
|
|
|
sb.Append("</table>");
|
|
|
|
return sb.ToString();
|
|
}
|
|
#endregion
|
|
|
|
#region 获取按钮权限
|
|
/// <summary>
|
|
/// 获取按钮权限
|
|
/// </summary>
|
|
/// <param name="button"></param>
|
|
/// <returns></returns>
|
|
private void GetButtonPower()
|
|
{
|
|
if (Request.Params["value"] == "0")
|
|
{
|
|
return;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
} |