using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using Model;
using BLL;
using BLL.Common;
namespace FineUIPro.Web.EditorManage
{
    public partial class PMEditor : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // 表头过滤
            FilterDataRowItem = FilterDataRowItemImplement;
            if (!IsPostBack)
            {
                // 特殊控制,不需要
                // GetButtonPower();//权限设置
                //类型
                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);
                ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
                this.BindGrid();
                if (CurrUser.UserId == Const.GlyId)
                {
                    btnImport.Hidden = false;
                    fuAttachUrl.Hidden = false;
                }
                else
                {
                    btnImport.Hidden = true;
                    fuAttachUrl.Hidden = true;
                }
            }
        }
        #region 过滤表头
        /// 
        /// 过滤表头
        /// 
        /// 
        /// 
        protected void Grid1_FilterChange(object sender, EventArgs e)
        {
            BindGrid();
        }
        /// 
        /// 根据表头信息过滤列表数据
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        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_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_General_Priority")
            {
                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_General_Category")
            {
                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 分页、排序
        /// 
        /// 分页
        /// 
        /// 
        /// 
        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            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)
        {
            Grid1.SortDirection = e.SortDirection;
            Grid1.SortField = e.SortField;
            BindGrid();
        }
        #endregion
        #region 关闭弹出窗口
        /// 
        /// 关闭窗口
        /// 
        /// 
        /// 
        protected void Window1_Close(object sender, EventArgs e)
        {
            BindGrid();
        }
        #endregion
        #region 编辑
        /// 
        /// 编辑
        /// 
        /// 
        /// 
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            if (Grid1.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInParent("Please select at least one line!");
                return;
            }
            string Id = Grid1.SelectedRowID;
            var eproject = BLL.EProjectService.GeteProjectById(Id);
            if (eproject != null)
            {
                Window1.Title = "PM Editor(Job No. " + eproject.ProjectControl_JobNo + ")";
                PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PMEditorEdit.aspx?EProjectId={0}", Id, "编辑 - ")));
            }
        }
        /// 
        /// Grid行双击事件
        /// 
        /// 
        /// 
        protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
        {
            btnEdit_Click(null, null);
        }
        /// 
        /// 右键编辑事件
        /// 
        /// 
        /// 
        protected void btnMenuEdit_Click(object sender, EventArgs e)
        {
            btnEdit_Click(null, null);
        }
        #endregion
        #region 查询
        protected void drpJobType_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.drpJobStatus.Items.Clear();
            if (drpJobType.SelectedText == "Other")
            {
                BLL.ConstService.InitConstValueProjectStatus(this.drpJobStatus, BLL.Const.ProjectPlanner_JobStatus, "3", true);
            }
            if (drpJobType.SelectedText != "Other")
            {
                BLL.ConstService.InitConstValueProjectStatus(this.drpJobStatus, BLL.Const.ProjectPlanner_JobStatus, "2", true);
            }
        }
        ///查询   
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindGrid();
        }
        #endregion
        /// 
        /// BindGrid
        /// 
        private void BindGrid()
        {
            string strSql = @"SELECT EProjectId,ProjectControl_JobNo,ProjectControl_JobType,
                                     ProjectControl_JobStatus,ProjectControl_JobTitle,ProjectControl_BUCode,
                                     PM_General_Priority,PM_General_Category
                               FROM dbo.Editor_EProject 
                               WHERE 1=1 ";
            List listStr = new List();
            if (this.CurrUser.UserId != Const.GlyId && this.CurrUser.RoleId != Const.Role_PPE)
            {
                strSql += " AND (ProjectControl_ProjectManagerId = @UserId OR ProjectControl_EMManagerId = @UserId) ";
                listStr.Add(new SqlParameter("@UserId", this.CurrUser.UserId));
            }
            
            if (this.drpJobType.SelectedValue != BLL.Const._Null)
            {
                strSql += " AND ProjectControl_JobType=@JobType ";
                listStr.Add(new SqlParameter("@JobType", this.drpJobType.SelectedItem.Text));
            }
            if (this.drpJobStatus.SelectedValue != BLL.Const._Null && this.drpJobStatus.SelectedValue != null)
            {
                strSql += " AND ProjectControl_JobStatus=@Status ";
                listStr.Add(new SqlParameter("@Status", this.drpJobStatus.SelectedItem.Text));
            }
            if (!string.IsNullOrEmpty(this.txtJobNO.Text.Trim()))
            {
                strSql += " AND ProjectControl_JobNo LIKE @jobNO ";
                listStr.Add(new SqlParameter("@jobNO", this.txtJobNO.Text.Trim() + "%"));
            }
            SqlParameter[] parameter = listStr.ToArray();
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
            // 2.获取当前分页数据
            //var table = this.GetPagedDataTable(Grid1, tb1);
            Grid1.RecordCount = tb.Rows.Count;
            tb = GetFilteredTable(Grid1.FilteredData, tb);
            var table = this.GetPagedDataTable(Grid1, tb);
            Grid1.DataSource = table;
            Grid1.DataBind();
        }
        #region 权限设置
        /// 
        /// 菜单按钮权限
        /// 
        private void GetButtonPower()
        {
            var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.PMEditorMenuId);
            if (buttonList.Count() > 0)
            {
                if (buttonList.Contains(BLL.Const.BtnModify))
                {
                    this.btnEdit.Hidden = false;
                    this.btnMenuEdit.Hidden = false;
                    this.Grid1.EnableRowDoubleClickEvent = true;
                }
                else
                {
                    this.Grid1.EnableRowDoubleClickEvent = false;
                }
            }
        }
        #endregion
        #region 查看
        /// 
        /// 查看
        /// 
        /// 
        /// 
        protected void btnMenuView_Click(object sender, EventArgs e)
        {
            if (Grid1.SelectedRowIndexArray.Length == 0)
            {
                Alert.ShowInParent("Please select at least one line!");
                return;
            }
            string Id = Grid1.SelectedRowID;
            var eproject = BLL.EProjectService.GeteProjectById(Id);
            if (eproject != null)
            {
                Window1.Title = "PM Editor(Job No. " + eproject.ProjectControl_JobNo + ")";
            }
            PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PMEditorEdit.aspx?EProjectId={0}&view=1", Id, "查看 - ")));
        }
        #endregion
        #region 导入
        #region 定义项
        /// 
        /// 上传预设的虚拟路径
        /// 
        private string initPath = Const.ExcelUrl;
        /// 
        /// 错误集合
        /// 
        public static string errorInfos = string.Empty;
        #endregion
        #region 格式验证及转换
        /// 
        /// 时间格式验证
        /// 
        /// 
        /// 
        private static string TimeValidation(object time)
        {
            string message = string.Empty;
            try
            {
                if (time.ToString().Contains("."))
                {
                    DateTime.ParseExact(time.ToString(), "dd.MM.yyyy", CultureInfo.InvariantCulture);
                }
                else
                {
                    Convert.ToDateTime(time);
                }
            }
            catch (Exception ex)
            {
                message = "Please enter a valid time format!";
            }
            return message;
        }
        public static DateTime TimeValue(object value)
        {
            string dateValue = string.Empty;
            if (value != null)
            {
                if (value.ToString().Contains("."))
                {
                    dateValue = DateTime.ParseExact(value.ToString(), "dd.MM.yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd");
                }
                else
                {
                    dateValue = DateTime.Parse(value.ToString()).ToString("yyyy-MM-dd");
                }
            }
            return DateTime.Parse(dateValue);
        }
        #endregion
        #region 导入
        /// 
        /// 导入
        /// 
        /// 
        /// 
        protected void btnImport_Click(object sender, EventArgs e)
        {
            string message = string.Empty;
            errorInfos = string.Empty;
            List ProjectList = new List();
            try
            {
                if (this.fuAttachUrl.HasFile == false)
                {
                    ShowNotify("Please select Excel file!", MessageBoxIcon.Warning);
                    return;
                }
                string IsXls = Path.GetExtension(this.fuAttachUrl.FileName).ToString().Trim().ToLower();
                if (IsXls != ".xls" && IsXls != ".xlsx")
                {
                    ShowNotify("Only Excel files can be selected!", MessageBoxIcon.Warning);
                    return;
                }
                if (ProjectList != null)
                {
                    ProjectList.Clear();
                }
                if (!string.IsNullOrEmpty(errorInfos))
                {
                    errorInfos = string.Empty;
                }
                string rootPath = Server.MapPath("~/");
                string initFullPath = rootPath + initPath;
                if (!Directory.Exists(initFullPath))
                {
                    Directory.CreateDirectory(initFullPath);
                }
                //指定上传文件名称
                this.hdFileName.Text = BLL.Funs.GetNewFileName() + IsXls;
                //上传文件路径
                string filePath = initFullPath + this.hdFileName.Text;
                //文件上传服务器
                this.fuAttachUrl.PostedFile.SaveAs(filePath);
                //文件上传服务器后的名称
                string fileName = rootPath + initPath + this.hdFileName.Text;
                //读取Excel
                DataSet ds = NPOIHelper.ExcelToDataSet(fileName, out errorInfos, true);
                //验证Excel读取是否有误
                if (!string.IsNullOrEmpty(errorInfos))
                {
                    ShowNotify(errorInfos, MessageBoxIcon.Warning,15000);
                    return;
                }
                if (ds.Tables.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        Editor_EProject project = new Editor_EProject();
                        #region 数据验证和赋值
                        string jobNo = ds.Tables[0].Rows[i]["Job No."].ToString();
                        if (!string.IsNullOrEmpty(jobNo))
                        {
                            var pro = BLL.EProjectService.GeteProjectByJobNO(jobNo);
                            if (pro != null)
                            {
                                project.EProjectId = pro.EProjectId;
                            }
                            else
                            {
                                errorInfos += (i + 2) + "Line, [Job No.] does not exist!";
                            }
                        }
                        else
                        {
                            errorInfos += (i + 2) + "Line, [Job No.] cannot be empty!";
                        }
                        if (ds.Tables[0].Rows[i]["Date_Plan EHS Review Files"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Date_Plan EHS Review Files"].ToString()))
                        {
                            try
                            {
                                message = TimeValidation(ds.Tables[0].Rows[i]["Date_Plan EHS Review Files"]);
                                if (string.IsNullOrEmpty(message))
                                {
                                    project.Job_PlanEHSReview_Files = TimeValue(ds.Tables[0].Rows[i]["Date_Plan EHS Review Files"]);
                                }
                                else
                                {
                                    errorInfos += (i + 2) + " Line, [Date_Plan EHS Review Files]" + message + "";
                                }
                            }
                            catch (Exception)
                            {
                                errorInfos += (i + 2) + " Line, [Date_Plan EHS Review Files]" + message + "";
                            }
                        }
                        if (ds.Tables[0].Rows[i]["Date_Act EHS Review Files"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Date_Act EHS Review Files"].ToString()))
                        {
                            try
                            {
                                message = TimeValidation(ds.Tables[0].Rows[i]["Date_Act EHS Review Files"]);
                                if (string.IsNullOrEmpty(message))
                                {
                                    project.Job_EHSReview_Files = TimeValue(ds.Tables[0].Rows[i]["Date_Act EHS Review Files"]);
                                }
                                else
                                {
                                    errorInfos += (i + 2) + " Line, [Date_Act EHS Review Files]" + message + "";
                                }
                            }
                            catch (Exception)
                            {
                                errorInfos += (i + 2) + " Line, [Date_Act EHS Review Files]" + message + "";
                            }
                        }
                        if (ds.Tables[0].Rows[i]["Date_EHS Review Meeting"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Date_EHS Review Meeting"].ToString()))
                        {
                            try
                            {
                                message = TimeValidation(ds.Tables[0].Rows[i]["Date_EHS Review Meeting"]);
                                if (string.IsNullOrEmpty(message))
                                {
                                    project.Job_EHSReview_Meeting = TimeValue(ds.Tables[0].Rows[i]["Date_EHS Review Meeting"]);
                                }
                                else
                                {
                                    errorInfos += (i + 2) + " Line, [Date_EHS Review Meeting]" + message + "";
                                }
                            }
                            catch (Exception)
                            {
                                errorInfos += (i + 2) + " Line, [Date_EHS Review Meeting]" + message + "";
                            }
                        }
                        if (ds.Tables[0].Rows[i]["Date_Estimate Worksheet"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Date_Estimate Worksheet"].ToString()))
                        {
                            try
                            {
                                message = TimeValidation(ds.Tables[0].Rows[i]["Date_Estimate Worksheet"]);
                                if (string.IsNullOrEmpty(message))
                                {
                                    project.Job_Estimate_Worksheet = TimeValue(ds.Tables[0].Rows[i]["Date_Estimate Worksheet"]);
                                }
                                else
                                {
                                    errorInfos += (i + 2) + " Line, [Date_Estimate Worksheet]" + message + "";
                                }
                            }
                            catch (Exception)
                            {
                                errorInfos += (i + 2) + " Line, [Date_Estimate Worksheet]" + message + "";
                            }
                        }
                        if (ds.Tables[0].Rows[i]["Date_Budget"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Date_Budget"].ToString()))
                        {
                            try
                            {
                                message = TimeValidation(ds.Tables[0].Rows[i]["Date_Budget"]);
                                if (string.IsNullOrEmpty(message))
                                {
                                    project.Job_Budget = TimeValue(ds.Tables[0].Rows[i]["Date_Budget"]);
                                }
                                else
                                {
                                    errorInfos += (i + 2) + " Line, [Date_Budget]" + message + "";
                                }
                            }
                            catch (Exception)
                            {
                                errorInfos += (i + 2) + " Line, [Date_Budget]" + message + "";
                            }
                        }
                        if (ds.Tables[0].Rows[i]["Date_Teco_Study"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Date_Teco_Study"].ToString()))
                        {
                            try
                            {
                                message = TimeValidation(ds.Tables[0].Rows[i]["Date_Teco_Study"]);
                                if (string.IsNullOrEmpty(message))
                                {
                                    project.Job_TecoAlarm_Study = TimeValue(ds.Tables[0].Rows[i]["Date_Teco_Study"]);
                                }
                                else
                                {
                                    errorInfos += (i + 2) + " Line, [Date_Teco_Study]" + message + "";
                                }
                            }
                            catch (Exception)
                            {
                                errorInfos += (i + 2) + " Line, [Date_Teco_Study]" + message + "";
                            }
                        }
                        if (ds.Tables[0].Rows[i]["Date_Plan IFC"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Date_Plan IFC"].ToString()))
                        {
                            try
                            {
                                message = TimeValidation(ds.Tables[0].Rows[i]["Date_Plan IFC"]);
                                if (string.IsNullOrEmpty(message))
                                {
                                    project.Job_Plan_IFC = TimeValue(ds.Tables[0].Rows[i]["Date_Plan IFC"]);
                                }
                                else
                                {
                                    errorInfos += (i + 2) + " Line, [Date_Plan IFC]" + message + "";
                                }
                            }
                            catch (Exception)
                            {
                                errorInfos += (i + 2) + " Line, [Date_Plan IFC]" + message + "";
                            }
                        }
                        if (ds.Tables[0].Rows[i]["Hold_Date"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Hold_Date"].ToString()))
                        {
                            try
                            {
                                message = TimeValidation(ds.Tables[0].Rows[i]["Hold_Date"]);
                                if (string.IsNullOrEmpty(message))
                                {
                                    project.Job_Hold = TimeValue(ds.Tables[0].Rows[i]["Hold_Date"]);
                                }
                                else
                                {
                                    errorInfos += (i + 2) + " Line, [Hold_Date]" + message + "";
                                }
                            }
                            catch (Exception)
                            {
                                errorInfos += (i + 2) + " Line, [Hold_Date]" + message + "";
                            }
                        }
                        if (ds.Tables[0].Rows[i]["Delay by team 1"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Delay by team 1"].ToString()))
                        {
                            project.Job_Delaybyteam1 = ds.Tables[0].Rows[i]["Delay by team 1"].ToString();
                        }
                        else
                        {
                            project.Job_Delaybyteam1 = null;
                        }
                        if (ds.Tables[0].Rows[i]["Delay by personel 1"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Delay by personel 1"].ToString()))
                        {
                            project.Job_Delaybypersonel1 = ds.Tables[0].Rows[i]["Delay by personel 1"].ToString();
                        }
                        else
                        {
                            project.Job_Delaybypersonel1 = null;
                        }
                        if (ds.Tables[0].Rows[i]["Remark 1"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Remark 1"].ToString()))
                        {
                            project.Job_Remark1 = ds.Tables[0].Rows[i]["Remark 1"].ToString();
                        }
                        else
                        {
                            project.Job_Remark1 = null;
                        }
                        if (ds.Tables[0].Rows[i]["Delay by team 2"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Delay by team 2"].ToString()))
                        {
                            project.Job_Delaybyteam2 = ds.Tables[0].Rows[i]["Delay by team 2"].ToString();
                        }
                        else
                        {
                            project.Job_Delaybyteam2 = null;
                        }
                        if (ds.Tables[0].Rows[i]["Delay by personel 2"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Delay by personel 2"].ToString()))
                        {
                            project.Job_Delaybypersonel2 = ds.Tables[0].Rows[i]["Delay by personel 2"].ToString();
                        }
                        else
                        {
                            project.Job_Delaybypersonel2 = null;
                        }
                        if (ds.Tables[0].Rows[i]["Remark 2"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Remark 2"].ToString()))
                        {
                            project.Job_Remark2 = ds.Tables[0].Rows[i]["Remark 2"].ToString();
                        }
                        else
                        {
                            project.Job_Remark2 = null;
                        }
                        if (ds.Tables[0].Rows[i]["Delay by team 3"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Delay by team 3"].ToString()))
                        {
                            project.Job_Delaybyteam3 = ds.Tables[0].Rows[i]["Delay by team 3"].ToString();
                        }
                        else
                        {
                            project.Job_Delaybyteam3 = null;
                        }
                        if (ds.Tables[0].Rows[i]["Delay by personel 3"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Delay by personel 3"].ToString()))
                        {
                            project.Job_Delaybypersonel3 = ds.Tables[0].Rows[i]["Delay by personel 3"].ToString();
                        }
                        else
                        {
                            project.Job_Delaybypersonel3 = null;
                        }
                        if (ds.Tables[0].Rows[i]["Remark 3"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Remark 3"].ToString()))
                        {
                            project.Job_Remark3 = ds.Tables[0].Rows[i]["Remark 3"].ToString();
                        }
                        else
                        {
                            project.Job_Remark3 = null;
                        }
                        ProjectList.Add(project);
                        #endregion
                    }
                    if (!string.IsNullOrEmpty(errorInfos))
                    {
                        ShowNotify(errorInfos, MessageBoxIcon.Warning, 10000);
                        return;
                    }
                    if (ProjectList.Count > 0)
                    {
                        foreach (var item in ProjectList)
                        {
                            Model.Editor_EProject upEpro = Funs.DB.Editor_EProject.FirstOrDefault(x => x.EProjectId == item.EProjectId);
                            if (upEpro != null)
                            {
                                upEpro.Job_PlanEHSReview_Files = item.Job_PlanEHSReview_Files;
                                upEpro.Job_EHSReview_Files = item.Job_EHSReview_Files;
                                upEpro.Job_EHSReview_Meeting = item.Job_EHSReview_Meeting;
                                upEpro.Job_Estimate_Worksheet = item.Job_Estimate_Worksheet;
                                upEpro.Job_Budget = item.Job_Budget;
                                upEpro.Job_TecoAlarm_Study = item.Job_TecoAlarm_Study;
                                upEpro.Job_Plan_IFC = item.Job_Plan_IFC;
                                upEpro.Job_Hold = item.Job_Hold;
                                upEpro.Job_Delaybyteam1 = item.Job_Delaybyteam1;
                                upEpro.Job_Delaybypersonel1 = item.Job_Delaybypersonel1;
                                upEpro.Job_Remark1 = item.Job_Remark1;
                                upEpro.Job_Delaybyteam2 = item.Job_Delaybyteam2;
                                upEpro.Job_Delaybypersonel2 = item.Job_Delaybypersonel2;
                                upEpro.Job_Remark2 = item.Job_Remark2;
                                upEpro.Job_Delaybyteam3 = item.Job_Delaybyteam3;
                                upEpro.Job_Delaybypersonel3 = item.Job_Delaybypersonel3;
                                upEpro.Job_Remark3 = item.Job_Remark3;
                                Funs.DB.SubmitChanges();
                            }
                            
                        }
                    }
                    //BindGrid();
                    ShowNotify("Import success!", MessageBoxIcon.Success);
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else
                {
                    ShowAlert("No data!", MessageBoxIcon.Warning);
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowAlert("'" + ex.Message + "'", MessageBoxIcon.Warning);
            }
        }
        #endregion
        #endregion
    }
}