using BLL;
using BLL.CQMS.Comprehensive;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
namespace FineUIPro.Web.Transfer.Chart
{
    public partial class PunchlistFromProgress : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }
        /// 
        /// 数据绑定
        /// 
        public void BindGrid()
        {
            StringBuilder strSql = new StringBuilder("");
            strSql.AppendLine("IF OBJECT_ID('tempdb..#AllPunchlistFromProgressTemp') IS NOT NULL drop table #AllPunchlistFromProgressTemp; ");
            strSql.AppendLine("IF OBJECT_ID('tempdb..#PunchlistFromProgressTemp') IS NOT NULL drop table #PunchlistFromProgressTemp; ");
            strSql.AppendLine(" select System_No,Actual_Date,Cleared_By,Confirmed_By,Verified_By,ProjectId ");
            strSql.AppendLine(" INTO #AllPunchlistFromProgressTemp from Transfer_PunchlistFrom where ProjectId = @ProjectId ");
            strSql.AppendLine(" select System_No,count(System_No) SystemNoCount,cast(0 as decimal(18,2)) ActualDateCount ");
            strSql.AppendLine(" ,cast(0 as decimal(18,2)) ClearedByCount,cast(0 as decimal(18,2)) ConfirmedByCount,cast(0 as decimal(18,2)) VerifiedByCount ");
            strSql.AppendLine(" INTO #PunchlistFromProgressTemp from #AllPunchlistFromProgressTemp where ProjectId = @ProjectId group by System_No ");
            strSql.AppendLine(" update  a set a.ActualDateCount=(select count(1) from #AllPunchlistFromProgressTemp b where a.System_No=b.System_No AND isnull(b.Actual_Date,'')<>'')  ");
            strSql.AppendLine(" ,a.ClearedByCount=(select count(1) from #AllPunchlistFromProgressTemp b where a.System_No=b.System_No AND isnull(b.Cleared_By,'')<>'') ");
            strSql.AppendLine(" ,a.ConfirmedByCount=(select count(1) from #AllPunchlistFromProgressTemp b where a.System_No=b.System_No AND isnull(b.Confirmed_By,'')<>'')  ");
            strSql.AppendLine(" ,a.VerifiedByCount=(select count(1) from #AllPunchlistFromProgressTemp b where a.System_No=b.System_No AND isnull(b.Verified_By,'')<>'') ");
            strSql.AppendLine(" from #PunchlistFromProgressTemp a ");
            strSql.AppendLine(" select *  from #PunchlistFromProgressTemp ");
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            strSql.AppendLine(" order by System_No ");
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql.ToString(), parameter);
            Grid1.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(Grid1, tb);
            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        /// 
        /// 分页下拉
        /// 
        /// 
        /// 
        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
            BindGrid();
        }
        /// 
        /// 分页索引事件
        /// 
        /// 
        /// 
        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            BindGrid();
        }
        /// 
        /// 排序
        /// 
        /// 
        /// 
        protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
        {
            Grid1.SortDirection = e.SortDirection;
            Grid1.SortField = e.SortField;
            BindGrid();
        }
        /// 
        /// 查询
        /// 
        /// 
        /// 
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindGrid();
        }
    }
}