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;
namespace FineUIPro.Web.WeldingProcess.WeldingReport
{
    public partial class WeldNoHandle : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid1();
            }
        }
        #region 选项卡改变事件
        /// 
        /// 选项卡改变事件
        /// 
        /// 
        /// 
        protected void TabStrip1_TabIndexChanged(object sender, EventArgs e)
        {
            if (this.TabStrip1.ActiveTabIndex == 0)
            {
                BindGrid1();
            }
            else if (this.TabStrip1.ActiveTabIndex == 1)
            {
                BindGrid2();
            }
        }
        #endregion
        #region 数据绑定
        /// 
        /// Grid2数据绑定
        /// 
        /// 
        private void BindGrid1()
        {
            string strSql = @"SELECT u.UnitName,pipe.PipelineCode,jot.WeldJointCode,
                                      CONVERT(VARCHAR(100) ,batchItem.PointDate,23)AS  PointDate
                                 FROM dbo.Batch_PointBatchItem batchItem
                                 LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = batchItem.WeldJointId
                                 LEFT JOIN dbo.Batch_BatchTrustItem trustItem ON trustItem.PointBatchItemId = batchItem.PointBatchItemId
                                 LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = jot.PipelineId
                                 LEFT JOIN Base_Unit u on u.UnitId=pipe.UnitId
								WHERE batchItem.PointState IS NOT NULL AND trustItem.TrustBatchItemId IS NULL
                                      AND pipe.ProjectId= @ProjectId ";
            List listStr = new List();
            if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
            {
                listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            }
            if (!string.IsNullOrEmpty(txtIsoNo.Text))
            {
                strSql += " AND pipe.PipelineCode LIKE @PipelineCode";
                listStr.Add(new SqlParameter("@PipelineCode", "%" + txtIsoNo.Text.Trim() + "%"));
            }
            strSql += " ORDER BY batchItem.PointDate,pipe.PipelineCode DESC";
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid1.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(Grid1, tb);
            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        private void BindGrid2()
        {
            string strSql = @"select nde.NDECode,pipe.PipelineCode,jot.WeldJointCode,CONVERT(VARCHAR(100),
                                     nItem.SubmitDate,23)AS  CheckDate
                              from Batch_NDEItem nItem 
                              LEFT JOIN Batch_NDE nde on nde.NDEID=nItem.NDEID
                              LEFT JOIN Batch_BatchTrustItem bItem on nItem.TrustBatchItemId =bItem.TrustBatchItemId
                              LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = bItem.WeldJointId
                              LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = jot.PipelineId
                              LEFT JOIN Repair_RepairRecord re on re.NDEItemID=nItem.NDEItemID
                              where nItem.CheckResult='2' and nItem.SubmitDate is not null and re.RepairRecordId is null
                                    AND pipe.ProjectId= @ProjectId ";
            List listStr = new List();
            if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
            {
                listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
            }
            if (!string.IsNullOrEmpty(txtPipeLine.Text))
            {
                strSql += " AND pipe.PipelineCode LIKE @PipelineCode";
                listStr.Add(new SqlParameter("@PipelineCode", "%" + txtPipeLine.Text.Trim() + "%"));
            }
            strSql += " ORDER BY nItem.SubmitDate,pipe.PipelineCode DESC";
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid2.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(Grid2, tb);
            Grid2.DataSource = table;
            Grid2.DataBind();
        }
        #endregion
        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid1();
        }
        protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            Grid1.PageSize = Convert.ToInt32(drpPageSize.SelectedValue);
            BindGrid1();
        }
        protected void Grid2_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid2.PageIndex = e.NewPageIndex;
            BindGrid2();
        }
        protected void drpPageSize2_SelectedIndexChanged(object sender, EventArgs e)
        {
            Grid2.PageSize = Convert.ToInt32(drpPageSize.SelectedValue);
            BindGrid2();
        }
        #region 查询
        ///查询   
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindGrid1();
        }
        protected void btnSearch2_Click(object sender, EventArgs e)
        {
            BindGrid2();
        }
        #endregion
    }
}