using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using BLL;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.ZHGL.ServerCheck
{
public partial class CheckRectify : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetButtonPower();
//btnNew.OnClientClick = Window1.GetShowReference("CheckRectifyEdit.aspx") + "return false;";
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
///
/// 绑定数据
///
private void BindGrid()
{
string strSql = string.Empty;
SqlParameter[] parameter = new SqlParameter[] { };
strSql = "SELECT S.CheckRectifyId,S.CheckRectifyCode,S.ProjectId,S.UnitId,U.UnitName,S.CheckDate,CASE S.HandleState WHEN '" + BLL.Const.State_1 + "' THEN '未签发' WHEN '" + BLL.Const.State_2 + "' THEN '未上报' ELSE '已上报' END AS HandleState,"
+ @" S.IssueMan,S.IssueDate,ISNULL(TotalCount.TotalCount,0) AS TotalCount ,ISNULL(CompleteCount.CompleteCount,0) AS CompleteCount,(ISNULL(TotalCount.TotalCount,0) -ISNULL(CompleteCount.CompleteCount,0)) AS UnCompleteCount"
+ @" FROM dbo.Check_CheckRectify AS S LEFT JOIN dbo.Base_Unit AS U ON U.UnitId = S.UnitId"
+ @" LEFT JOIN (SELECT COUNT(*) AS TotalCount, CheckRectifyId FROM dbo.Check_CheckRectifyItem GROUP BY CheckRectifyId) AS TotalCount ON S.CheckRectifyId=TotalCount.CheckRectifyId"
+ @" LEFT JOIN (SELECT COUNT(*) AS CompleteCount, CheckRectifyId FROM dbo.Check_CheckRectifyItem WHERE RealEndDate IS NOT NULL GROUP BY CheckRectifyId) AS CompleteCount ON S.CheckRectifyId=CompleteCount.CheckRectifyId"
+ @" ORDER BY HandleState";
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
for (int i = 0; i < Grid1.Rows.Count; i++)
{
Model.Check_CheckRectify rectify = BLL.CheckRectifyService.GetCheckRectifyByCheckRectifyId(Grid1.Rows[i].DataKeys[0].ToString());
if (rectify != null)
{
if (rectify.HandleState == "1")
{
Grid1.Rows[i].RowCssClass = "yellow";
}
else if (rectify.HandleState == "2")
{
Grid1.Rows[i].RowCssClass = "red";
}
}
}
}
///
/// 分页
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
///
/// 分页显示条数下拉框
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#region 数据编辑事件
///
/// 右键编辑事件
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
///
/// Grid行双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
///
/// 编辑数据方法
///
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string CheckRectifyId = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckRectifyEdit.aspx?CheckRectifyId={0}", CheckRectifyId, "编辑 - ")));
}
#endregion
///
/// 关闭弹出窗
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#region 获取权限按钮
///
/// 获取按钮权限
///
///
///
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CheckRectifyMenuId);
if (buttonList.Count > 0)
{
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuEdit.Hidden = false;
}
}
}
#endregion
#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("集团下发监督检查整改" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
///
/// 导出方法
///
///
///
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
MultiHeaderTable mht = new MultiHeaderTable();
mht.ResolveMultiHeaderTable(Grid1.Columns);
sb.Append("");
sb.Append("
");
foreach (List
");
return sb.ToString();
}
#region 多表头处理
///
/// 多表头处理
///
public class MultiHeaderTable
{
// 包含 rowspan,colspan 的多表头,方便生成 HTML 的 table 标签
public List> MultiTable = new List>();
// 最终渲染的列数组
public List Columns = new List();
public void ResolveMultiHeaderTable(GridColumnCollection columns)
{
List