using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using BLL;
using Newtonsoft.Json.Linq;
namespace FineUIPro.Web.JDGL.Check
{
    public partial class TotalCompletion : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetButtonPower();
                BindGrid0();
                BindGrid1();
                BindGrid2();
                BindGrid3();
                BindGrid4();
                BindGrid5();
                BindGrid6();
                BindGrid7();
            }
        }
        #region 获取按钮权限
        /// 
        /// 获取按钮权限
        /// 
        /// 
        /// 
        private void GetButtonPower()
        {
            if (Request.Params["value"] == BLL.Const._Null)
            {
                return;
            }
            var buttonList0 = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.QuantityCompletionMenuId);
            if (buttonList0.Count() > 0)
            {
                if (buttonList0.Contains(BLL.Const.BtnSave))
                {
                    this.btnImport0.Hidden = false;
                }
            }
            var buttonList1 = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SteelStructureCompletionMenuId);
            if (buttonList1.Count() > 0)
            {
                if (buttonList1.Contains(BLL.Const.BtnSave))
                {
                    this.btnImport1.Hidden = false;
                }
            }
            var buttonList2 = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.EquipmentCompletionMenuId);
            if (buttonList2.Count() > 0)
            {
                if (buttonList2.Contains(BLL.Const.BtnSave))
                {
                    this.btnImport2.Hidden = false;
                }
            }
            var buttonList3 = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.PipelineCompletionMenuId);
            if (buttonList3.Count() > 0)
            {
                if (buttonList3.Contains(BLL.Const.BtnSave))
                {
                    this.btnImport3.Hidden = false;
                }
            }
            var buttonList4 = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ElectricalCompletionMenuId);
            if (buttonList4.Count() > 0)
            {
                if (buttonList4.Contains(BLL.Const.BtnSave))
                {
                    this.btnImport4.Hidden = false;
                }
            }
            var buttonList5 = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.MeterCompletionMenuId);
            if (buttonList5.Count() > 0)
            {
                if (buttonList5.Contains(BLL.Const.BtnSave))
                {
                    this.btnImport5.Hidden = false;
                }
            }
            var buttonList6 = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.UndergroundPipeCompletionMenuId);
            if (buttonList6.Count() > 0)
            {
                if (buttonList6.Contains(BLL.Const.BtnSave))
                {
                    this.btnImport6.Hidden = false;
                }
            }
            var buttonList7 = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.LowTankCompletionMenuId);
            if (buttonList7.Count() > 0)
            {
                if (buttonList7.Contains(BLL.Const.BtnSave))
                {
                    this.btnImport7.Hidden = false;
                }
            }
        }
        #endregion
        /// 
        /// 加载Grid
        /// 
        private void BindGrid0()
        {
            //GetQuantityCompletion();
            string strSql = @"select *
                            from dbo.View_JDGL_QuantityCompletion qc 
                            where qc.ProjectId=@ProjectId order by qc.Name";
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid0.RecordCount = tb.Rows.Count;
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid0, tb);
            Grid0.DataSource = table;
            Grid0.DataBind();
        }
        /// 
        /// 加载Grid
        /// 
        private void BindGrid1()
        {
            string strSql = @"select *
                            from dbo.View_JDGL_SteelStructureCompletion qc 
                            where qc.ProjectId=@ProjectId order by qc.UnitName";
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid1.RecordCount = tb.Rows.Count;
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid1, tb);
            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        /// 
        /// 加载Grid
        /// 
        private void BindGrid2()
        {
            string strSql = @"select *
                            from dbo.View_JDGL_EquipmentCompletion qc 
                            where qc.ProjectId=@ProjectId order by qc.UnitName";
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid2.RecordCount = tb.Rows.Count;
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid2, tb);
            Grid2.DataSource = table;
            Grid2.DataBind();
        }
        /// 
        /// 加载Grid
        /// 
        private void BindGrid3()
        {
            string strSql = @"select *
                            from dbo.View_JDGL_PipelineCompletion qc 
                            where qc.ProjectId=@ProjectId order by qc.UnitName";
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid3.RecordCount = tb.Rows.Count;
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid3, tb);
            Grid3.DataSource = table;
            Grid3.DataBind();
        }
        /// 
        /// 加载Grid
        /// 
        private void BindGrid4()
        {
            string strSql = @"select *
                            from dbo.View_JDGL_ElectricalCompletion qc 
                            where qc.ProjectId=@ProjectId order by qc.UnitName";
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid4.RecordCount = tb.Rows.Count;
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid4, tb);
            Grid4.DataSource = table;
            Grid4.DataBind();
        }
        /// 
        /// 加载Grid
        /// 
        private void BindGrid5()
        {
            string strSql = @"select *
                            from dbo.View_JDGL_MeterCompletion qc 
                            where qc.ProjectId=@ProjectId order by qc.UnitName";
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid5.RecordCount = tb.Rows.Count;
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid5, tb);
            Grid5.DataSource = table;
            Grid5.DataBind();
        }
        /// 
        /// 加载Grid
        /// 
        private void BindGrid6()
        {
            string strSql = @"select *
                            from dbo.View_JDGL_UndergroundPipeCompletion qc 
                            where qc.ProjectId=@ProjectId order by qc.UnitName";
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid6.RecordCount = tb.Rows.Count;
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid6, tb);
            Grid6.DataSource = table;
            Grid6.DataBind();
        }
        /// 
        /// 加载Grid
        /// 
        private void BindGrid7()
        {
            string strSql = @"select *
                            from dbo.View_JDGL_LowTankCompletion qc 
                            where qc.ProjectId=@ProjectId order by qc.Code";
            List listStr = new List();
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid7.RecordCount = tb.Rows.Count;
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid7, tb);
            Grid7.DataSource = table;
            Grid7.DataBind();
        }
        #region 导入
        /// 
        /// 导入按钮
        /// 
        /// 
        /// 
        protected void btnImport0_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("QuantityCompletionIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
        }
        /// 
        /// 导入按钮
        /// 
        /// 
        /// 
        protected void btnImport1_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SteelStructureCompletionIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
        }
        /// 
        /// 导入按钮
        /// 
        /// 
        /// 
        protected void btnImport2_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("EquipmentCompletionIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
        }
        /// 
        /// 导入按钮
        /// 
        /// 
        /// 
        protected void btnImport3_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineCompletionIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
        }
        /// 
        /// 导入按钮
        /// 
        /// 
        /// 
        protected void btnImport4_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ElectricalCompletionIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
        }
        /// 
        /// 导入按钮
        /// 
        /// 
        /// 
        protected void btnImport5_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MeterCompletionIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
        }
        /// 
        /// 导入按钮
        /// 
        /// 
        /// 
        protected void btnImport6_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UndergroundPipeCompletionIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
        }
        /// 
        /// 导入按钮
        /// 
        /// 
        /// 
        protected void btnImport7_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("LowTankCompletionIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
        }
        /// 
        /// 关闭导入弹出窗口
        /// 
        /// 
        /// 
        protected void Window1_Close(object sender, WindowCloseEventArgs e)
        {
            BindGrid0();
            BindGrid1();
            BindGrid2();
            BindGrid3();
            BindGrid4();
            BindGrid5();
            BindGrid6();
            BindGrid7();
        }
        #endregion
    }
}