using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;

namespace FineUIPro.Web.common
{
    public partial class main : PageBase
    {
        #region 加载
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //类型
                this.drpJobType.DataTextField = "ConstText";
                this.drpJobType.DataValueField = "ConstId";
                this.drpJobType.DataSource = BLL.ConstService.GetConstListByGroupId(BLL.Const.ProjectPlanner_JobType);
                this.drpJobType.DataBind();
                Funs.FineUIPleaseSelectJobType(this.drpJobType);

                //状态
                this.drpJobStatus.DataTextField = "ConstText";
                this.drpJobStatus.DataValueField = "ConstId";
                this.drpJobStatus.DataSource = BLL.ConstService.GetConstListByGroupId(BLL.Const.ProjectPlanner_JobStatus);
                this.drpJobStatus.DataBind();
                Funs.FineUIPleaseSelectJobStatus(this.drpJobStatus);

                //部门
                this.drpDivision.DataTextField = "DepartName";
                this.drpDivision.DataValueField = "DepartId";
                this.drpDivision.DataSource = BLL.DepartService.GetDepartList();
                this.drpDivision.DataBind();
                Funs.FineUIPleaseSelectDivision(this.drpDivision);

                this.BindGrid();
                string eprojectId = this.Grid1.Rows[0].RowID;
                if (!string.IsNullOrEmpty(eprojectId))
                {
                    LoadData(eprojectId);
                }
                this.Grid1.SelectedRowIndex = 0;
            }
            else if (GetRequestEventArgument() == "FilterChange")
            {
                BindGrid();
            }
        }

        /// <summary>
        /// BindGrid
        /// </summary>
        private void BindGrid()
        {
            string status = String.Join(",", drpJobStatus.SelectedItemArray.Select(e=>e.Text));//drpJobStatus.SelectedValueArray;

            string strSql = @"SELECT eProject.EProjectId,eProject.ProjectControl_JobNo,eProject.PM_Critical,
                                     eProject.ProjectControl_JobType, eProject.ProjectControl_JobTitle,
                                     (ISNULL(eProject.ProjectControl_OrginalBudget,0)+ISNULL(eProject.ProjectControl_ChangedBudget,0)) AS ProjectControl_OrginalBudget,
                                     (CASE WHEN (eProject.ProjectControl_ProjectManager IS NULL OR eProject.ProjectControl_ProjectManager='') THEN 'N/A' 
									 ELSE eProject.ProjectControl_ProjectManager END) AS ProjectControl_ProjectManager,
									 (CASE WHEN (eProject.ProjectControl_ConstManager IS NULL OR eProject.ProjectControl_ConstManager='') THEN 'N/A' 
									 ELSE eProject.ProjectControl_ConstManager END) AS ProjectControl_ConstManager,
                                     eProject.ProjectControl_OperationRep,eProject.ProjectControl_JobStatus,
                                     eProject.ProjectControl_BUCode,eProject.PM_MA_ProjectApproval,eProject.ProjectControl_MS_MC
                               FROM dbo.Editor_EProject AS eProject
                              WHERE 1=1 ";

            List<SqlParameter> listStr = new List<SqlParameter>();
            if (this.drpJobType.SelectedValue != BLL.Const._Null)
            {
                strSql += " AND eProject.ProjectControl_JobType=@jobType";
                listStr.Add(new SqlParameter("@jobType", this.drpJobType.SelectedItem.Text));
            }  // AND CHARINDEX(Trust.ProjectId,@ProjectId)>0
            if (this.drpJobStatus.SelectedValue != BLL.Const._Null)
            {
                //strSql += " AND eProject.ProjectControl_JobStatus=@jobStatus";
                strSql += " AND CHARINDEX(eProject.ProjectControl_JobStatus,@jobStatus)>0";
                listStr.Add(new SqlParameter("@jobStatus", status));
            }
            if (this.drpDivision.SelectedValue != BLL.Const._Null)
            {
                strSql += " AND eProject.ProjectControl_BUCode=@division";
                listStr.Add(new SqlParameter("@division", this.drpDivision.SelectedItem.Text));
            }
            if (!string.IsNullOrEmpty(this.hdJobNo.Text.Trim()) || !string.IsNullOrEmpty(this.txtJobNoS.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_JobNo LIKE @Job_NO";
                if (!string.IsNullOrEmpty(this.txtJobNoS.Text.Trim()))
                {
                    listStr.Add(new SqlParameter("@Job_NO", "%" + this.txtJobNoS.Text.Trim() + "%"));
                }
                else
                {
                    listStr.Add(new SqlParameter("@Job_NO", "%" + this.hdJobNo.Text.Trim() + "%"));
                }
            }
        
            if (!string.IsNullOrEmpty(this.hdJobTitle.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_JobTitle LIKE @Job_Title";
                listStr.Add(new SqlParameter("@Job_Title", "%" + this.hdJobTitle.Text.Trim() + "%"));
            }
            if (!string.IsNullOrEmpty(hdType.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_JobType = @jobTyps";
                listStr.Add(new SqlParameter("@jobTyps", this.hdType.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(hdStatus.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_JobStatus = @status";
                listStr.Add(new SqlParameter("@status", this.hdStatus.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(hdDivision.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_BUCode = @depart";
                listStr.Add(new SqlParameter("@depart", this.hdDivision.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(this.hdProjectManager.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_ProjectManager = @ProjectManager";
                listStr.Add(new SqlParameter("@ProjectManager", this.hdProjectManager.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(this.hdConstManager.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_ConstManager = @ProjectControl_ConstManager";
                listStr.Add(new SqlParameter("@ProjectControl_ConstManager", this.hdConstManager.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(this.hdOperationRep.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_OperationRep = @ProjectControl_OperationRep";
                listStr.Add(new SqlParameter("@ProjectControl_OperationRep", this.hdOperationRep.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(this.hdAccount.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_Account = @ProjectControl_Account";
                listStr.Add(new SqlParameter("@ProjectControl_Account", this.hdAccount.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(this.hdMOCFormNo.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_MOCFormNo LIKE @ProjectControl_MOCFormNo";
                listStr.Add(new SqlParameter("@ProjectControl_MOCFormNo", "%" + this.hdMOCFormNo.Text.Trim() + "%"));
            }
            if (!string.IsNullOrEmpty(this.hdLeadBy.Text.Trim()))
            {
                strSql += " AND eProject.ProjectControl_LeadByName = @ProjectControl_LeadByName";
                listStr.Add(new SqlParameter("@ProjectControl_LeadByName", this.hdLeadBy.Text.Trim()));
            }
            if (!string.IsNullOrEmpty(this.hdEngineer.Text.Trim()))
            {
                strSql += " AND (stuff((select distinct ','+u.UserName from ManHours_Plan as p left join Sys_User as u on u.UserId = p.EngineerId where p.EProjectId = eProject.EProjectId for xml Path('')),1,1,'')) LIKE @Engineering";
                listStr.Add(new SqlParameter("@Engineering", "%" + this.hdEngineer.Text.Trim() + "%"));
            }
            if (!string.IsNullOrEmpty(this.hdCritical.Text.Trim()))
            {
                strSql += " AND eProject.PM_Critical = @PM_Critical";
                listStr.Add(new SqlParameter("@PM_Critical", this.hdCritical.Text.Trim()));
            }
            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();
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="eProjectId"></param>
        private void LoadData(string eProjectId)
        {
            var eProject = BLL.EProjectService.GeteProjectById(eProjectId);
            if (eProject != null)
            {
                if (this.TabStrip1.ActiveTabIndex == 1)
                {
                    BindGrid10(eProjectId);//Schedule
                    BindGrid11(eProjectId);//ProjectSchDetail
                    BindGrid12(eProjectId); //ClosuerDetail
                }
                else if (this.TabStrip1.ActiveTabIndex == 2)
                {
                    GetCost(eProjectId);
                }
                else if (this.TabStrip1.ActiveTabIndex == 3)
                {
                    BindGrid5(eProjectId);//Permits
                }
                else if (this.TabStrip1.ActiveTabIndex == 4)
                {
                    BindGrid6(eProjectId);//Resource
                    OutputSummaryData();//计算和
                }
                else if (this.TabStrip1.ActiveTabIndex == 5)
                {
                    #region Development Remarks
                    this.txtEnginering.Text = eProject.PM_Remarks_Engineering;
                    this.txtProcurement.Text = eProject.PM_Remarks_Procurement;
                    this.txtConstruction.Text = eProject.CM_Remarks_Construction;
                    this.txtQuilaityHSE.Text = eProject.CM_Remarks_QualityHSE;
                    #endregion
                }
                else if (this.TabStrip1.ActiveTabIndex == 6)
                {
                    BindGrid7(eProjectId);//Area Concern
                }
                else if (this.TabStrip1.ActiveTabIndex == 7)
                {
                    BindGridTDC(eProjectId);//TDC
                }
                else if (this.TabStrip1.ActiveTabIndex == 8)
                {
                    BindGrid8(eProjectId);//Punch List
                }
                else if (this.TabStrip1.ActiveTabIndex == 9)
                {
                    BindGrid2(eProjectId);//Lesson Learned
                }
                else if (this.TabStrip1.ActiveTabIndex == 10)
                {
                    BindGrid9(eProjectId);//FCR Log
                }
                else
                {
                    #region General
                    this.txtBuCode.Text = eProject.ProjectControl_BUCode; //部门代码
                    this.txtJobNo.Text = eProject.ProjectControl_JobNo;//项目号 
                    this.txtJobType.Text = eProject.ProjectControl_JobType;//项目类型              
                    this.txtJobTitle.Text = eProject.ProjectControl_JobTitle;//项目标题
                    if (!string.IsNullOrEmpty(eProject.ProjectControl_LeadBy))
                    {
                        this.txtLeadBy.Text = BLL.DepartService.GetDepartNameById(eProject.ProjectControl_LeadBy);//主导部门
                    }
                    else
                    {
                        this.txtLeadBy.Text = string.Empty;
                    }
                    this.txtPriority.Text = eProject.PM_General_Priority; //优先级
                    this.txtCategory.Text = eProject.PM_General_Category;//目录
                    this.txtMOCFormNo.Text = eProject.ProjectControl_MOCFormNo;//MOC表格编号
                    if (eProject.ProjectControl_OrginalBudget.HasValue)//批准的预算
                    {
                        this.txtApprovedBudget.Text = eProject.ProjectControl_OrginalBudget.ToString();
                    }
                    else
                    {
                        this.txtApprovedBudget.Text = string.Empty;
                    }
                    this.txtAccountNo.Text = eProject.ProjectControl_Account;//账户编号
                    this.txtNetworkNo.Text = eProject.ProjectControl_NetworkNo;//网络编号
                    this.txtCostEffectivity.Text = eProject.ProjectControl_CostEffectvitity;//花费有效性(成本效益)
                    if (eProject.ProjectControl_PVIPrediction.HasValue)
                    {
                        this.txtPVIPredition.Text = eProject.ProjectControl_PVIPrediction.ToString(); //PVI预算
                    }
                    else
                    {
                        this.txtPVIPredition.Text = string.Empty;
                    }

                    if (!string.IsNullOrEmpty(eProject.ProjectControl_ProjectManager))
                    {
                        this.txtProjManager.Text = eProject.ProjectControl_ProjectManager;//项目经理
                    }
                    else
                    {
                        this.txtProjManager.Text = "N/A";
                    }

                    if (!string.IsNullOrEmpty(eProject.ProjectControl_ConstManager))
                    {
                        this.txtConstManager.Text = eProject.ProjectControl_ConstManager; //设计经理
                    }
                    else
                    {
                        this.txtConstManager.Text = "N/A";
                    }

                    if (!string.IsNullOrEmpty(eProject.ProjectControl_EMManager))
                    {
                        this.txtEngManager.Text = eProject.ProjectControl_EMManager; //
                    }
                    else
                    {
                        this.txtConstManager.Text = "N/A";
                    }

                    //this.txtConstManager.Text = eProject.ProjectControl_ConstManager;
                    this.txtOperationRep.Text = eProject.ProjectControl_OperationRep;//操作代表               
                    this.txtJobStatus.Text = eProject.ProjectControl_JobStatus;//项目状态      
                    if (!string.IsNullOrEmpty(eProject.ProjectControl_CI_Process))
                    {
                        this.txtProcePipEng.Text = BLL.Sys_UserService.GetUserNameByUserId(eProject.ProjectControl_CI_Process); //工艺及配管工程
                    }
                    else
                    {
                        this.txtProcePipEng.Text = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(eProject.ProjectControl_CI_Equipment))
                    {
                        this.txtEquipEng.Text = BLL.Sys_UserService.GetUserNameByUserId(eProject.ProjectControl_CI_Equipment);//设备工程
                    }
                    else
                    {
                        this.txtEquipEng.Text = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(eProject.ProjectControl_CI_Instrument))
                    {
                        this.txtInstrumentEng.Text = BLL.Sys_UserService.GetUserNameByUserId(eProject.ProjectControl_CI_Instrument);//仪表工程
                    }
                    else
                    {
                        this.txtInstrumentEng.Text = string.Empty;
                    }

                    if (!string.IsNullOrEmpty(eProject.ProjectControl_CI_Electrical))
                    {
                        this.txtElectrialEng.Text = BLL.Sys_UserService.GetUserNameByUserId(eProject.ProjectControl_CI_Electrical);//电力工程
                    }
                    else
                    {
                        this.txtElectrialEng.Text = string.Empty;
                    }

                    if (!string.IsNullOrEmpty(eProject.ProjectControl_CI_Civil))
                    {
                        this.txtCivilEng.Text = BLL.Sys_UserService.GetUserNameByUserId(eProject.ProjectControl_CI_Civil);//土建工程
                    }
                    else
                    {
                        this.txtCivilEng.Text = string.Empty; 
                    }
                    //变更范围
                    if (eProject.PM_SC_ApprovedQty.HasValue)//批准的质量
                    {
                        this.txtApprovedQty.Text = eProject.PM_SC_ApprovedQty.ToString();
                    }
                    else
                    {
                        this.txtApprovedQty.Text = string.Empty;
                    }

                    if (eProject.PM_SC_ApprovedCost.HasValue)//批准的花费
                    {
                        this.txtApprovedCost.Text = eProject.PM_SC_ApprovedCost.ToString();
                    }
                    else
                    {
                        this.txtApprovedCost.Text = string.Empty;
                    }

                    if (eProject.PM_SC_PendingQty.HasValue)//延后的质量
                    {
                        this.txtPendingQty.Text = eProject.PM_SC_PendingQty.ToString();
                    }
                    else
                    {
                        this.txtPendingQty.Text = string.Empty;
                    }
                    if (eProject.PM_SC_PendingCost.HasValue)//延后的花费
                    {
                        this.txtPendingCost.Text = eProject.PM_SC_PendingCost.ToString();
                    }
                    else
                    {
                        this.txtPendingCost.Text = string.Empty;
                    }
                    //this.txtDocStatus.Text= //文档状态                
                    this.txtCDI.Text = eProject.PM_General_CDI; //CDI                
                    this.txtRemarks.Text = eProject.ProjectControl_Remarks; //备注
                    this.txtOutSourceType.Text = eProject.OutSourceType;
                    this.txtCAPEXPlanNo.Text = eProject.CAPEXPlanNo;
                    #endregion
                }
            }
        }
        #endregion

        #region 过滤表头
        /// <summary>
        /// 过滤表头
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void Grid1_FilterChange(object sender, EventArgs e)
        //{
        //    BindGrid();
        //}

        /// <summary>
        /// 根据表头信息过滤列表数据
        /// </summary>
        /// <param name="sourceObj"></param>
        /// <param name="fillteredOperator"></param>
        /// <param name="fillteredObj"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        private bool FilterDataRowItemImplement(object sourceObj, string fillteredOperator, object fillteredObj, string column)
        {
            bool valid = false;
            if (column == "ProjectControl_JobNo")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "ProjectControl_JobType")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "ProjectControl_JobTitle")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "ProjectControl_OrginalBudget")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "ProjectControl_ProjectManager")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "ProjectControl_ConstManager")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "ProjectControl_OperationRep")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "ProjectControl_JobStatus")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "ProjectControl_BUCode")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "PM_MA_ProjectApproval")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            if (column == "ProjectControl_MS_MC")
            {
                string sourceValue = sourceObj.ToString();
                string fillteredValue = fillteredObj.ToString();
                if (fillteredOperator == "equal" && sourceValue == fillteredValue)
                {
                    valid = true;
                }
                else if (fillteredOperator == "contain" && sourceValue.Contains(fillteredValue))
                {
                    valid = true;
                }
            }
            return valid;
        }
        #endregion

        #region Grid1行选择事件
        /// <summary>
        /// Grid行选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Grid1_RowSelect(object sender, GridRowSelectEventArgs e)
        {
            string eProjectId = this.Grid1.SelectedRowID;
            if (!string.IsNullOrEmpty(eProjectId))
            {
                LoadData(eProjectId);
                // PageContext.RegisterStartupScript("onGrid1RowSelect('" + eProjectId + "')");
            }
        }
        #endregion

        #region 选项卡改变事件
        /// <summary>
        /// 选项卡改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void TabStrip1_TabIndexChanged(object sender, EventArgs e)
        {
            string eProjectId = this.Grid1.SelectedRowID;
            if (!string.IsNullOrEmpty(eProjectId))
            {
                LoadData(eProjectId);
            }
            else
            {
                string id = Grid1.Rows[0].RowID;
                if (!string.IsNullOrEmpty(id))
                {
                    LoadData(id);
                }
            }
        }
        #endregion

        #region 分页、排序
        /// <summary>
        /// 分页下拉选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
        //    BindGrid();
        //}

        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid();
        }

        protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
        {
            Grid1.SortDirection = e.SortDirection;
            Grid1.SortField = e.SortField;

            BindGrid();
        }
        #endregion

        #region 加载GetCost
        private void GetCost(string eProjectId)
        {
            var cost = from x in Funs.DB.Editor_EProject
                       where x.EProjectId == eProjectId
                       select new
                       {
                           x.ProjectControl_OrginalBudget,
                           x.ProjectControl_ChangedBudget,
                           x.ProjectControl_CommittedPRPO,
                           x.ProjectControl_CommittedSSRs,
                           x.ProjectControl_Actual,
                           x.PM_General_CostToComplete
                       };
            //string strSql = @"SELECT TOP 1 [CostReportId] ,[EProjectId] ,[Monthly] ,[OrginalBudget] ,[ChangedBudget] ,[ActualCost],"
            //               + @" [CommittedPRPO],[CommittedSSRs] ,[CostToComplete] FROM [Editor_CostReport]"
            //               + @" WHERE EProjectId=@eProjectId order by Monthly DESC";

            //List<SqlParameter> listStr = new List<SqlParameter>();
            //listStr.Add(new SqlParameter("@EProjectId", eProjectId));
            //SqlParameter[] parameter = listStr.ToArray();
            //DataTable table = SQLHelper.GetDataTableRunText(strSql, parameter);
            txtOrginalBudget.Text = "0";
            txtChangedBudget.Text = "0";
            txtActualCost.Text = "0";
            txtCommitted_PRPO.Text = "0";
            txtCommitted_SSRs.Text = "0";
            txtCostToComplete.Text = "0";
            txtEstimatedFinalCost.Text = "0";
            txtVariance.Text = "0";
            if (cost.Count() > 0)
            {
                txtOrginalBudget.Text = cost.First().ProjectControl_OrginalBudget != null ? cost.First().ProjectControl_OrginalBudget.ToString() : "0";
                txtChangedBudget.Text = cost.First().ProjectControl_ChangedBudget != null ? cost.First().ProjectControl_ChangedBudget.ToString() : "0";
                txtActualCost.Text = cost.First().ProjectControl_Actual != null ? cost.First().ProjectControl_Actual.ToString() : "0";
                txtCommitted_PRPO.Text = cost.First().ProjectControl_CommittedPRPO != null ? cost.First().ProjectControl_CommittedPRPO.ToString() : "0";
                txtCommitted_SSRs.Text = cost.First().ProjectControl_CommittedSSRs != null ? cost.First().ProjectControl_CommittedSSRs.ToString() : "0";
                txtCostToComplete.Text = cost.First().PM_General_CostToComplete != null ? cost.First().PM_General_CostToComplete.ToString() : "0";
                //DataRow item = table.Rows[0];
                //if (!string.IsNullOrEmpty(item["OrginalBudget"].ToString()))
                //{
                //    txtOrginalBudget.Text = item["OrginalBudget"].ToString();
                //}
                //if (!string.IsNullOrEmpty(item["ChangedBudget"].ToString()))
                //{
                //    txtChangedBudget.Text = item["ChangedBudget"].ToString();
                //}
                //if (!string.IsNullOrEmpty(item["ActualCost"].ToString()))
                //{
                //    txtActualCost.Text = item["ActualCost"].ToString();
                //}
                //if (!string.IsNullOrEmpty(item["CommittedPRPO"].ToString()))
                //{
                //    txtCommitted_PRPO.Text = item["CommittedPRPO"].ToString();
                //}
                //if (!string.IsNullOrEmpty(item["CommittedSSRs"].ToString()))
                //{
                //    txtCommitted_SSRs.Text = item["CommittedSSRs"].ToString();
                //}
                //if (!string.IsNullOrEmpty(item["CostToComplete"].ToString()))
                //{
                //    txtCostToComplete.Text = item["CostToComplete"].ToString();
                //}
                decimal FinalCost = Decimal.Parse(txtActualCost.Text.ToString()) + Decimal.Parse(txtCommitted_PRPO.Text.ToString()) + Decimal.Parse(txtCommitted_SSRs.Text.ToString()) + Decimal.Parse(txtCostToComplete.Text.ToString());
                txtEstimatedFinalCost.Text = FinalCost.ToString();
                if ((Decimal.Parse(txtOrginalBudget.Text.ToString()) + Decimal.Parse(txtChangedBudget.Text.ToString())) != 0)
                {
                    decimal Variance = (FinalCost - Decimal.Parse(txtOrginalBudget.Text.ToString()) - Decimal.Parse(txtChangedBudget.Text.ToString())) / (Decimal.Parse(txtOrginalBudget.Text.ToString()) + Decimal.Parse(txtChangedBudget.Text.ToString())) * 100;
                    txtVariance.Text = Math.Round(Variance, 2).ToString();
                }
            }
        }
        #endregion

        #region 加载Lesson Learned
        private void BindGrid2(string eProjectId)
        {
            string strSql = @"SELECT LessonsLearnedId,
                                     EProjectId,
                                     Id,
                                     PostBy,
                                     EntryDate,
                                     AppliedDiscip,
                                     Stage,
                                     Keyword,
                                     Description
                                FROM dbo.Editor_LessonsLearned WHERE EProjectId =@EProjectId ";

            List<SqlParameter> listStr = new List<SqlParameter>();

            listStr.Add(new SqlParameter("@EProjectId", eProjectId));

            SqlParameter[] parameter = listStr.ToArray();

            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            GridLessonLearned.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(GridLessonLearned, tb);
            GridLessonLearned.DataSource = table;
            GridLessonLearned.DataBind();
        }
        #endregion

        #region 加载Permits
        private void BindGrid5(string eProjectId)
        {
            string strSql = @"SELECT EProjectId,
                                     sort,
                                     Name,
                                     ScheduledDate,
                                     ActualDate,
                                     Need"
                             + @" FROM View_HomePage_Permits "
                             + @" WHERE EProjectId=@eProjectId order by sort";

            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@eProjectId", eProjectId));
            SqlParameter[] parameter = listStr.ToArray();

            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid5.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(Grid5, tb);
            Grid5.DataSource = table;
            Grid5.DataBind();
        }
        #endregion

        #region 加载Resource List
        private void BindGrid6(string eProjectId)
        {
            string strSql = @"SELECT EProjectId ,EngineerId,ProjectControl_JobStatus,UserName,Account,AccountDisabled,
                                     DisciplineId,Discipline,ManHours,Hourss
                                FROM View_ResourceDisc
                                WHERE EProjectId=@eProjectId 
                                ORDER BY Discipline";

            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@EProjectId", eProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable table = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid6.RecordCount = table.Rows.Count;
            Grid6.DataSource = table;
            Grid6.DataBind();
        }

        protected void Grid6_RowDataBound(object sender, GridRowEventArgs e)
        {
            DataRowView row = e.DataItem as DataRowView;
            if (row["AccountDisabled"].ToString() != string.Empty)
            {
                bool validity = Convert.ToBoolean(row["AccountDisabled"]);
                string state = string.Empty;
                if (row["ProjectControl_JobStatus"] != null && row["ProjectControl_JobStatus"].ToString() != "")
                {
                    state = row["ProjectControl_JobStatus"].ToString();
                }
                    
                if (validity || state== "Cancelled" || state== "Hold")
                {
                    e.RowCssClass = "color1";
                }
            }
        }

        private void OutputSummaryData()
        {
            double Hourss = 0.0f;
            double ManHours = 0.0f;
            int rowsCount = this.Grid6.Rows.Count;
            for (int i = 0; i < rowsCount; i++)
            {
                if (this.Grid6.Rows[i].Values[4] != null && this.Grid6.Rows[i].Values[4].ToString() != "")
                {
                    ManHours += Convert.ToDouble(this.Grid6.Rows[i].Values[4]);
                }
                if (this.Grid6.Rows[i].Values[5] != null && this.Grid6.Rows[i].Values[5].ToString() != "")
                {
                    Hourss += Convert.ToDouble(this.Grid6.Rows[i].Values[5]);
                }
            }

            JObject summary = new JObject();
            //summary.Add("major", "全部合计");
            summary.Add("ManHours", ManHours.ToString("F2"));
            summary.Add("Hourss", Hourss.ToString("F2"));

            Grid6.SummaryData = summary;
        }
        #endregion

        #region 加载Area Concern
        private void BindGrid7(string eProjectId)
        {
            string strSql = @"SELECT AreaConcernId,
                                     EProjectId,
                                     SN,
                                     EntryDate,
                                     CreatedByName,
                                     CategoryCauseName,
                                     Remark "
                             + @" FROM Editor_AreaConcern "
                             + @" WHERE EProjectId=@eProjectId ";

            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@eProjectId", eProjectId));
            SqlParameter[] parameter = listStr.ToArray();

            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid7.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(Grid7, tb);
            Grid7.DataSource = table;
            Grid7.DataBind();
        }
        #endregion

        #region 加载TDC
        private void BindGridTDC(string eProjectId)
        {
            DataTable tb = BLL.TDCService.GetDataTable(eProjectId);

            // 2.获取当前分页数据
            //var table = this.GetPagedDataTable(Grid1, tb1);
            GridTDC.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(GridTDC, tb);
            GridTDC.DataSource = table;
            GridTDC.DataBind();
        }
        #endregion

        #region 加载Punch List
        private void BindGrid8(string eProjectId)
        {
            string strSql = @"SELECT PunchId,
                                     EProjectId,
                                     DisciplineName,
                                     ClassName,
                                     TagNo,
                                     RespUnitPerson,
                                     ResiedByName,
                                     PlanedFinishDate,
                                     CTECheckerName,
                                     CTECheckDate,
                                     OwnerCheckerName,
                                     OwnerCheckDate,
                                     Remark "
                             + @" FROM Editor_Punch "
                             + @" WHERE EProjectId=@eProjectId";

            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@eProjectId", eProjectId));
            SqlParameter[] parameter = listStr.ToArray();

            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid8.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(Grid8, tb);
            Grid8.DataSource = table;
            Grid8.DataBind();
        }
        #endregion

        #region 加载FCR Log
        private void BindGrid9(string eProjectId)
        {
            string strSql = @"SELECT FCRLogId,
                                     EProjectId,
                                     FCRNo,
                                     DisciplineName,
                                     CategoryName,
                                     U.UserName AS Initiator,
                                     CDIName,
                                     TDCRecDate,
                                     FCRIssueDate,
                                     ConReturnDate,
                                     CostYorN,
                                     CostCNY,
                                     SchYorN,
                                     SchDays "
                             + @" FROM Editor_FCRLog "
                             + @" LEFT JOIN Sys_User AS U ON U.UserId = Editor_FCRLog.Initiator"
                             + @" WHERE EProjectId=@eProjectId ";

            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@eProjectId", eProjectId));
            SqlParameter[] parameter = listStr.ToArray();

            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            Grid9.RecordCount = tb.Rows.Count;
            var table = this.GetPagedDataTable(Grid9, tb);
            Grid9.DataSource = table;
            Grid9.DataBind();
        }
        #endregion

        #region 加载Schedule
        private void BindGrid10(string eProjectId)
        {
            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@EProjectId", eProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunProc("ProjectSchedule", parameter);
            grdSchedule.DataSource = tb;
            grdSchedule.DataBind();
        }

        #region 加载ProjectSchDetail
        private void BindGrid11(string eProjectId)
        {
            grdScheduleDetail.DataSource = null;
            grdScheduleDetail.DataBind();

            List<SqlParameter> listStr = new List<SqlParameter>();
            listStr.Add(new SqlParameter("@EProjectId", eProjectId));
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunProc("ProjectSchDetail", parameter);
            grdScheduleDetail.DataSource = tb;
            grdScheduleDetail.DataBind();
        }
        #endregion

        #region 加载ClosuerDetail
        private void BindGrid12(string eProjectId)
        {
            var eproject = BLL.EProjectService.GeteProjectById(eProjectId);
            if (eproject != null)
            {
                if (eproject.ProjectControl_JobType == "MOC")
                {
                    List<SqlParameter> listStr = new List<SqlParameter>();
                    listStr.Add(new SqlParameter("@EProjectId", eProjectId));
                    SqlParameter[] parameter = listStr.ToArray();
                    DataTable tb = SQLHelper.GetDataTableRunProc("Schedule_MOC", parameter);
                    grdClosuerDetail.DataSource = tb;
                }
                else if (eproject.ProjectControl_JobType == "Other")
                {
                    List<SqlParameter> listStr = new List<SqlParameter>();
                    listStr.Add(new SqlParameter("@EProjectId", eProjectId));
                    SqlParameter[] parameter = listStr.ToArray();
                    DataTable tb = SQLHelper.GetDataTableRunProc("Schedule_Other", parameter);
                    grdClosuerDetail.DataSource = tb;
                }
                else if (eproject.ProjectControl_JobType == "Small Invest")
                {
                    List<SqlParameter> listStr = new List<SqlParameter>();
                    listStr.Add(new SqlParameter("@EProjectId", eProjectId));
                    SqlParameter[] parameter = listStr.ToArray();
                    DataTable tb = SQLHelper.GetDataTableRunProc("Schedule_OrginalBudgetMin", parameter);
                    grdClosuerDetail.DataSource = tb;
                }
                else if (eproject.ProjectControl_JobType == "Projects")
                {
                    List<SqlParameter> listStr = new List<SqlParameter>();
                    listStr.Add(new SqlParameter("@EProjectId", eProjectId));
                    SqlParameter[] parameter = listStr.ToArray();
                    if (eproject.ProjectControl_OrginalBudget >= 1000000 && eproject.PM_MA_ProjectApproval.HasValue)
                    {
                        DataTable tb = SQLHelper.GetDataTableRunProc("Schedule_OrginalBudgetMax", parameter);
                        grdClosuerDetail.DataSource = tb;
                    }
                    else
                    {
                        DataTable tb = SQLHelper.GetDataTableRunProc("Schedule_OrginalBudgetMin", parameter);
                        grdClosuerDetail.DataSource = tb;
                    }
                }
            }
            grdClosuerDetail.DataBind();
        }
        #endregion
        #endregion

        #region 查看编辑器详细信息
        /// <summary>
        /// 查看编辑器详细信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnViewDetail_Click(object sender, EventArgs e)
        {
            if (Grid1.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInParent("Please select at least one record!");
                return;
            }
            string Id = Grid1.SelectedRowID;
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../EditorManage/EProjectDetail.aspx?eProjectId={0}", Id, "编辑 - ")));
        }
        #endregion

        #region 红绿灯状态显示、附件图标显示
        protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
        {
            int i = e.RowIndex;
            System.Web.UI.WebControls.Label lblEproject = (System.Web.UI.WebControls.Label)this.Grid1.Rows[i].FindControl("EProjectId");
            string eprojectId = lblEproject.Text.Trim();
            if (!string.IsNullOrEmpty(eprojectId))
            {
                var eproject = BLL.EProjectService.GeteProjectById(eprojectId);
                if (eproject != null)
                {
                    #region 红绿灯
                    #region 进度
                    // Schedule进度
                    System.Web.UI.WebControls.Image imgSchedule = (System.Web.UI.WebControls.Image)this.Grid1.Rows[i].FindControl("imgSchedule");
                    DateTime? ms = eproject.ProjectControl_Revised_MC_Date.HasValue ? eproject.ProjectControl_Revised_MC_Date : null; //项目机械竣工计划时间
                    //DateTime? x = eproject.ProjectControl_CM_SchEnd.HasValue ? eproject.ProjectControl_CM_SchEnd : null;//计划的机械电仪施工结束时间
                    DateTime? x = eproject.PM_MA_ProjectApproval.HasValue ? eproject.PM_MA_ProjectApproval : null;//项目的批准时间
                    
                    //修正的机械电仪施工结束时间
                    DateTime? y = null;
                    if (eproject.CM_MA_MC.HasValue)
                    {
                        y = eproject.CM_MA_MC;
                    }
                    else if (eproject.CM_CM_RevisedEnd.HasValue)
                    {
                        y = eproject.CM_CM_RevisedEnd;
                    }
                    else
                    {
                        y = eproject.ProjectControl_CM_SchEnd.HasValue ? eproject.ProjectControl_CM_SchEnd : null;
                    }
                    
                    int a = 0;
                    int b = 0;
                    double c = 0;
                    if (y.HasValue && ms.HasValue)
                    {
                        a = (y - ms).Value.Days;
                    }
                    if (x.HasValue && ms.HasValue)
                    {
                        b = (ms - x).Value.Days;
                    }
                    if (b != 0)
                    {
                        c = a * 1.0 / b;
                        if (c > 0.1)
                        {
                            imgSchedule.ImageUrl = "../Images/RedLight.jpg";
                        }
                        else if (0.1 >= c && c > 0.05)
                        {
                            imgSchedule.ImageUrl = "../Images/YellowLight.jpg";
                        }
                        else if (c <= 0.05)
                        {
                            imgSchedule.ImageUrl = "../Images/GreenLight.jpg";
                        }
                        else
                        {
                            imgSchedule.ImageUrl = "../Images/NoLight.jpg";
                        }
                    }
                    else
                    {
                        imgSchedule.ImageUrl = "../Images/NoLight.jpg";
                    }
                    #endregion
                    #region 成本
                    //Cost 成本
                    System.Web.UI.WebControls.Image imgCost = (System.Web.UI.WebControls.Image)this.Grid1.Rows[i].FindControl("imgCost");
                    double s = 0;
                    //获取项目的最新成本
                    var costManage = BLL.CostReportService.GetMaxMonthCostReportByEprojectId(eprojectId);
                    if (costManage != null)
                    {
                        decimal? orginalBudget = costManage.OrginalBudget.HasValue ? costManage.OrginalBudget : 0;//原始的预算
                        decimal? changedBudget = costManage.ChangedBudget.HasValue ? costManage.ChangedBudget : 0;//变更的预算
                        decimal? actualCost = costManage.ActualCost.HasValue ? costManage.ActualCost : 0;//实际的成本
                        decimal? committedPRPO = costManage.CommittedPRPO.HasValue ? costManage.CommittedPRPO : 0;//承诺的PR或PO成本
                        decimal? committedSSRs = costManage.CommittedSSRs.HasValue ? costManage.CommittedSSRs : 0; //承诺的SSR成本
                        decimal? costToComplete = costManage.CostToComplete.HasValue ? costManage.CostToComplete : 0; //预估的完工任需成本                                                                                                                      
                        decimal? rmb = actualCost + committedPRPO + committedSSRs + costToComplete;//预估的最终成本=实际的成本+承诺的PR或PO成本+承诺的SSR成本+预估的完工任需成本
                        //成本差异=(预估的最终成本-原始的预算-变更的预算)/(原始的预算+变更的预算)*100%
                        if (orginalBudget + changedBudget > 0)
                        {
                            s = Convert.ToDouble((rmb - orginalBudget - changedBudget) / (orginalBudget + changedBudget));
                            if (s > 0.1)
                            {
                                imgCost.ImageUrl = "../Images/RedLight.jpg";
                            }
                            else if (0.1 >= s && s > 0.05)
                            {
                                imgCost.ImageUrl = "../Images/YellowLight.jpg";
                            }
                            else if (s <= 0.05)
                            {
                                imgCost.ImageUrl = "../Images/GreenLight.jpg";
                            }
                        }
                        else
                        {
                            imgCost.ImageUrl = "../Images/NoLight.jpg";
                        }
                    }
                    else
                    {
                        imgCost.ImageUrl = "../Images/NoLight.jpg";
                    }

                    #endregion
                    #region 范围指标
                    // Scope 范围指标
                    System.Web.UI.WebControls.Image imgScope = (System.Web.UI.WebControls.Image)this.Grid1.Rows[i].FindControl("imgScope");
                    decimal? m = eproject.PM_SC_ApprovedQty;//批准的变更数
                    decimal? n = eproject.PM_SC_PendingQty;//待定的变更数
                    if (n > 0)
                    {
                        imgScope.ImageUrl = "../Images/RedLight.jpg";
                    }
                    else if (n == 0 && m > 0)
                    {
                        imgScope.ImageUrl = "../Images/YellowLight.jpg";
                    }
                    else if (m == 0 && n == 0)
                    {
                        imgScope.ImageUrl = "../Images/GreenLight.jpg";
                    }
                    else
                    {
                        imgScope.ImageUrl = "../Images/NoLight.jpg";
                    }
                    #endregion
                    #endregion

                    #region 附件
                    //附件
                    if (!string.IsNullOrEmpty(eproject.ProjectControl_FilesLink) && eproject.ProjectControl_FilesLink != null)
                    {
                        System.Web.UI.WebControls.HyperLink files = (System.Web.UI.WebControls.HyperLink)this.Grid1.Rows[i].FindControl("FilesLinks");
                        files.ImageUrl = "../Images/icon_G.gif";
                        files.NavigateUrl = eproject.ProjectControl_FilesLink;
                    }
                    if (!string.IsNullOrEmpty(eproject.ProjectControl_NotesLink) && eproject.ProjectControl_NotesLink != null)
                    {
                        System.Web.UI.WebControls.HyperLink notes = (System.Web.UI.WebControls.HyperLink)this.Grid1.Rows[i].FindControl("NotesLinks");
                        notes.ImageUrl = "../Images/icon_moc.gif";
                        notes.NavigateUrl = eproject.ProjectControl_NotesLink;
                    }
                    #endregion
                }
            }
        }
        #endregion

        #region 查询
        protected void drpJobStatus_Click(object sender, EventArgs e)
        {
            if (drpJobStatus.SelectedValueArray.Count() >1)
            {
                drpJobStatus.Items[0].Selected = false;
            }
            if(drpJobStatus.SelectedValueArray.Count()==0)
            {
                drpJobStatus.Items[0].Selected = true;
            }
            BindGrid();
        }

        protected void dropDownList_Click(object sender, EventArgs e)
        {
            BindGrid();
        }

        protected void btnFind_Click(object sender, EventArgs e)
        {
            BindGrid();
        }

        ///查询条件   
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string s = this.hdJobNo.Text.Trim() + "|" +
                this.hdJobTitle.Text.Trim() + "|" +
                this.hdType.Text.Trim() + "|" +
                this.hdStatus.Text.Trim() + "|" +
                this.hdDivision.Text.Trim() + "|" +
                this.hdProjectManager.Text.Trim() + "|" +
                this.hdConstManager.Text.Trim() + "|" +
                this.hdOperationRep.Text.Trim() + "|" +
                this.hdAccount.Text.Trim() + "|" +
                this.hdMOCFormNo.Text.Trim() + "|" +
                this.hdLeadBy.Text.Trim() + "|" +
                this.hdEngineer.Text.Trim() + "|" +
                hdCritical.Text.Trim();

            string window = String.Format("Search.aspx?s={0}", s, "查询 - ");
            PageContext.RegisterStartupScript(Window2.GetSaveStateReference(hdItemsString.ClientID) + Window2.GetShowReference(window));
        }

        /// <summary>
        /// 关闭查询窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Window2_Close(object sender, WindowCloseEventArgs e)
        {
            List<string> lists = Funs.GetStrListByStr(hdItemsString.Text, '|');

            this.hdJobNo.Text = lists[0];
            this.hdJobTitle.Text = lists[1];
            this.hdType.Text = lists[2];
            this.hdStatus.Text = lists[3];
            this.hdDivision.Text = lists[4];
            this.hdProjectManager.Text = lists[5];
            this.hdConstManager.Text = lists[6];
            this.hdOperationRep.Text = lists[7];
            this.hdAccount.Text = lists[8];
            this.hdMOCFormNo.Text = lists[9];
            this.hdLeadBy.Text = lists[10];
            this.hdEngineer.Text = lists[11];
            this.hdCritical.Text = lists[12];

            BindGrid();
            if (this.Grid1.Rows.Count() > 0)
            {
                string eprojectId = this.Grid1.Rows[0].RowID;
                if (!string.IsNullOrEmpty(eprojectId))
                {
                    LoadData(eprojectId);
                }
                this.Grid1.SelectedRowIndex = 0;
            }
        }
        #endregion

        #region 格式化字符串
        protected string ConvertPro(object p)
        {
            if (p!=null && p.ToString()!="" && p.ToString() != "N.A")
            {
                decimal pro = Convert.ToDecimal(p.ToString().Substring(0, p.ToString().IndexOf('%')));
                if (pro > 100)
                {
                    return "100.00%";
                }
                else if (pro < 0)
                {
                    return "0.00%";
                }
                else
                {
                    return pro.ToString() + "%";
                }
            }
            return "0.00%";
        }
        #endregion
    }
}