using BLL;
using FineUIPro.Web.Controls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HJGL.WeldingReport
{
    public partial class PointTrustCheckTaskList : PageBase
    {
        #region 加载
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Funs.DropDownPageSize(this.ddlPageSize);
                this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
                BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnitId, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true);
                Funs.FineUIPleaseSelect(this.drpWorkAreaId);
                BLL.Base_DetectionTypeService.InitDetectionTypeDropDownList(this.drpNDTType, true);
            }
        }
        #endregion
        #region 绑定BindGrid
        /// 
        /// 
        /// 
        private DataTable tb = null;
        /// 
        /// 绑定数据
        /// 
        private void BindGrid()
        {
            List listStr = new List
            {
                new SqlParameter("@projectId", this.CurrUser.LoginProjectId)
            };
            if (this.drpUnitId.SelectedValue != BLL.Const._Null)
            {
                listStr.Add(new SqlParameter("@unitId", this.drpUnitId.SelectedValue));
            }
            else
            {
                listStr.Add(new SqlParameter("@unitId", null));
            }
            if (this.drpWorkAreaId.SelectedValue != BLL.Const._Null)
            {
                listStr.Add(new SqlParameter("@workAreaId", this.drpWorkAreaId.SelectedValue));
            }
            else
            {
                listStr.Add(new SqlParameter("@workAreaId", null));
            }
            if (this.drpNDTType.SelectedValue != BLL.Const._Null)
            {
                listStr.Add(new SqlParameter("@ndtMethod", this.drpNDTType.SelectedValue));
            }
            else
            {
                listStr.Add(new SqlParameter("@ndtMethod", null));
            }
            if (!string.IsNullOrEmpty(this.txtStartDate.Text))
            {
                listStr.Add(new SqlParameter("@startDate",Funs.GetNewDateTime(this.txtStartDate.Text)));
            }
            else
            {
                listStr.Add(new SqlParameter("@startDate", null));
            }
            if (!string.IsNullOrEmpty(this.txtEndDate.Text))
            {
                listStr.Add(new SqlParameter("@endDate", Funs.GetNewDateTime(this.txtEndDate.Text)));
            }
            else
            {
                listStr.Add(new SqlParameter("@endDate", null));
            }
            SqlParameter[] parameter = listStr.ToArray();
            tb = SQLHelper.GetDataTableRunProc("sp_rpt_PointTrustCheckTaskList", parameter);
            this.Grid1.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(Grid1, tb);
            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        /// 
        /// 改变索引事件
        /// 
        /// 
        /// 
        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            BindGrid();
        }
        /// 
        /// 分页下拉选择事件
        /// 
        /// 
        /// 
        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
            BindGrid();
        }
        /// 
        /// 排序
        /// 
        /// 
        /// 
        protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
        {
            this.BindGrid();
        }
        #endregion
        #region 统计按钮事件
        /// 
        /// 统计
        /// 
        /// 
        /// 
        protected void BtnAnalyse_Click(object sender, EventArgs e)
        {
            BindGrid();
        }
        #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();
            grid.PageSize = this.Grid1.RecordCount;
            BindGrid();
            MultiHeaderTable mht = new MultiHeaderTable();
            mht.ResolveMultiHeaderTable(Grid1.Columns);
            sb.Append("");
            sb.Append("");
            foreach (List
");
            return sb.ToString();
        }
        #endregion
        #region DropDownList 下拉选择
        /// 
        /// 根据单位加载区域
        /// 
        /// 
        /// 
        protected void drpUnitId_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.drpWorkAreaId.Items.Clear();
            if (this.drpUnitId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpUnitId.SelectedValue))
            {
                BLL.WorkAreaService.InitWorkAreaProjectUnitDropDownList(this.drpWorkAreaId, this.CurrUser.LoginProjectId, this.drpUnitId.SelectedValue, true);
                this.drpWorkAreaId.SelectedIndex = 0;
            }
        }
        #endregion
    }
}