using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Data;
using System.Text;
namespace FineUIPro.Web.DigData
{
public partial class DailyProblemAnalysis : PageBase
{
#region 加载
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ProjectService.InitProjectDropDownList(this.drpProject, false);
Funs.FineUIPleaseSelect(drpProject, "请选择项目");
// 绑定表格
this.BindGrid();
}
}
#endregion
#region 绑定数据Grid1
///
/// 绑定数据Grid1
///
private void BindGrid()
{
var getData = ProblemAnalysisService.getDailyProblemData(this.rblType.SelectedValue, this.drpProject.SelectedValue,
Funs.GetNewDateTime(this.txtStartTime.Text), Funs.GetNewDateTime(this.txtEndTime.Text));
DataTable tb = this.LINQToDataTable(getData);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
this.OutputSummaryData(tb); ///取合计值
}
///
/// 计算合计
///
private void OutputSummaryData(DataTable tb)
{
int allCount = 0, okCount = 0, unCount = 0;
string rate = "0%";
for (int i = 0; i < tb.Rows.Count; i++)
{
allCount += Funs.GetNewIntOrZero(tb.Rows[i]["AllCount"].ToString());
okCount += Funs.GetNewIntOrZero(tb.Rows[i]["OkCount"].ToString());
unCount += Funs.GetNewIntOrZero(tb.Rows[i]["UnCount"].ToString());
}
if (allCount > 0)
{
rate = Math.Round(okCount * 1.0 / allCount * 100, 1).ToString() + "%";
}
JObject summary = new JObject
{
{ "Name", "合计" },
{ "AllCount", allCount.ToString() },
{ "OkCount", okCount.ToString() },
{ "UnCount", unCount.ToString() },
{ "Rate", rate}
};
Grid1.SummaryData = summary;
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region 查询
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
///
/// 查询
///
///
///
protected void btSearch_Click(object sender, EventArgs e)
{
this.BindGrid();
}
#region 导出按钮
/// 导出按钮
///
///
///
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 = Encoding.UTF8;
this.Grid1.PageSize = this.Grid1.RecordCount;
this.BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
#endregion
}
}