ASP.NET EXCEL導入,身份證、手機號長度校驗數據校驗

<cc1:MiniButton ID="btnBathAdd" Width="35px" Height="25px" runat="server" Plain="true"
                                ToolTip="批量導入" IconClass="Wimport" OnClick="btnBathAdd_Click" Text="批量導入" ACCode="Import" />
<cc1:Window ID="wpWin" runat="server" ShowFooter="true" Title="人員臺賬批量導入" Height="350px"
            Width="700px">
            <cc1:Toolbar ID="Toolbar2" runat="server" Width="99%" Style="text-align: right;">
                <div class="toolbarTitle">
                    批量導入
                </div>
                <cc1:LinkButton ID="lbExportModule" runat="server" Visible="false" Text="導出樣表" Width="80px"
                    ShowProcess="true" OnClick="lbExportModule_Click">
                </cc1:LinkButton>
                <a id="atemplate" href="TempFiles/人員臺賬模板.xlsx" style="display: none">樣表導出</a>&nbsp;&nbsp;
            </cc1:Toolbar>
            <div style="width: 100%; height: 200px;">
                <cc1:MiniForm ID="fileForm" runat="server">
                    <%--<cc1:FileUpload ID="fileUpload" runat="server" Width="500px" Label="選擇文件" LimitType="*.xlsx;"
                        Name="fileName" LabelWidth="100" OnUpload="fileUpload_Upload" OnCustomAction="fileUpload_CustomAction" />--%>
                    <cc1:FileUpload ID="fileUpload" runat="server" Width="500px" Label="選擇文件" LimitType="*.xls;"
                        Name="fileName" LabelWidth="100" OnUpload="fileUpload_Upload" OnCustomAction="fileUpload_CustomAction" />
                    <cc1:MiniButton ID="btnBathImport" runat="server" IconClass="Wimport" ToolTip="導入"
                        ACCode="" OnClick="btnBathImport_Click" Plain="true" ShowProcess="true" />
                    <br />
                    <cc1:MiniTextBox ID="itbComments" runat="server" InputMode="Textarea" Height="200px"
                        Width="650px" LabelWidth="60" Label="" Name="ErrMsg" />
                </cc1:MiniForm>
            </div>
        </cc1:Window>
#region 批量導入相關
        /// <summary>
        /// 批量導入按鈕
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnBathAdd_Click(MiniButton sender, AjaxActionEventArgs e)
        {
            this.wpWin.JSShowAtPos(XAlign.center, YAlign.middle);
            fileUpload.JSClear();

            UploadeEntity item = new UploadeEntity();
            fileForm.JSSetData(item);
        }

        //下載樣表
        protected void lbExportModule_Click(WuhanIns.Web.MiniUI.LinkButton sender, AjaxActionEventArgs e)
        {
            WriteToExcel();
            this.JSCallMethod("downTemplate", "");
        }
        //導入
        protected void btnBathImport_Click(MiniButton sender, AjaxActionEventArgs e)
        {
            //上傳前判斷是否存在相同的更新包
            this.fileUpload.JSStartUpload();
        }

        [FormPostBack("fileForm")]
        protected void fileUpload_CustomAction(MiniControl sender, AjaxCustomEventArgs e)
        {
            UploadeEntity FormData = e.GetRequestParam<UploadeEntity>("fileForm");
            string fileName = "";
            if (FormData != null)
            {
                fileName = FormData.fileName;
            }
            if (e.ActionType == "uploadsuccess")
            {
                //上傳成功
                UploadeEntity item = new UploadeEntity();
                item.ErrMsg = "上傳成功!";
                if (Session["FILE_UP_ERR_MGS"] != null && Session["FILE_UP_ERR_MGS"].ToString() != "")
                {
                    item.ErrMsg = Session["FILE_UP_ERR_MGS"].ToString();
                }
                fileForm.JSSetData(item);
                dgList.JSLoadData();
            }
            else if (e.ActionType == "uploaderror")
            {
                string strMgs = "文件上傳失敗!";
                this.JSAlert(strMgs);
            }
            else if (e.ActionType == "uploadcomplete")
            {
                //文件上傳完成
                this.JSShowTips("上傳完成!");
            }
        }

        /// <summary>
        /// Excel導入事件【1、將excel上傳至服務器並生成datatable 2、校驗datatable中數據 3、保存數據至db中】
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void fileUpload_Upload(WuhanIns.Web.MiniUI.FileUpload sender, FileUploadEventArgs e)
        {
            #region
            StringBuilder strErr = new StringBuilder();
            //IDbConnection sqlCon = DBUtil.GetDbConnection();
            //IDbTransaction sqlTrans = sqlCon.BeginTransaction();
            try
            {
                Session["FILE_UP_ERR_MGS"] = "";
                if (string.IsNullOrEmpty(e.PostFile.FileName)) return;

                HttpPostedFile httpFile = e.PostFile;
                string curProjectId = EntityIdSessionConfig.GetCurEntityIdSession(this, EntityIdSessionConfig.Project_Id);
                //string curProjectId = e.GetRequestParam<string>("Project_Id");
                string strAddress = Server.MapPath("TempFiles");
                if (!Directory.Exists(strAddress)) //如果文件夾不存在則創建
                {
                    Directory.CreateDirectory(strAddress);
                }
                //保存數據包到服務器
                string descFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + httpFile.FileName;
                string strFullAddress = Server.MapPath("TempFiles") + "\\" + descFileName;
                httpFile.SaveAs(strFullAddress);//將excel保存至服務器
                DataSet ds = ExcelInput(strFullAddress);//Excel轉換DataTable
                //獲取所有的分包商信息
                List<Tuple<string, string, string>> htSuppliers = GetSuppliers();
                //獲取所屬部門
                //Hashtable ht = GetDept();
                //獲取工作崗位或者工種,
                //Hashtable htWork = GetProjectWork();
                //獲取發放方式
                IdTextItem[] payWaylist = IdTextItem.ToItems(typeof(EPC發放方式));

                //獲取發放方式
                IdTextItem[] positionNamelist = IdTextItem.ToItems(typeof(工種));
                //獲取身份證hashtable,
                List<Tuple<string, string>> sfzhtWork = GetIdCardHt();
                int irowIndex = 1;
                //默認本部門人員
                string deptid = UserContext.CurrentUser.DeptId;
                string deptName = UserContext.CurrentUser.DeptName;
                //身份證列表
                List<string> idCardList = new List<string>();
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        #region 遍歷datatable
                        irowIndex++;

                        #region 數據校驗,構造數據
                        string identityCard = dr["身份證號碼"] == DBNull.Value ? "" : dr["身份證號碼"].ToString().Trim();
                        if (string.IsNullOrEmpty(identityCard))
                        {
                            strErr.Append("第" + irowIndex + "行【身份證號碼】未填寫!\r\n");
                            //continue;
                        }
                        if (identityCard.Length != 15 && identityCard.Length != 18)
                        {
                            strErr.Append("第" + irowIndex + "行【身份證號碼】格式不正確!\r\n");
                            //continue;
                        }
                        if ((identityCard.Length == 15 && !CheckIDCard15(identityCard)) || (identityCard.Length == 18 && !CheckIDCard18(identityCard)))
                        {
                            strErr.Append("第" + irowIndex + "行【身份證號碼】格式不正確!\r\n");
                            //continue;
                        }
                        else
                        {
                            //身份證驗證正確的情況
                            if (idCardList.Contains(identityCard))
                            {
                                strErr.Append("第" + irowIndex + "行【身份證號碼】的數據在模板中存在多條!\r\n");
                                //continue;
                            }
                            else
                            {
                                idCardList.Add(identityCard);
                            }
                        }

                        HrStaffBase curData = HrStaffBaseManager.GetByIdCard(identityCard); //根據身份證號查詢人員信息
                        //if (curData != null)
                        //{
                        //    curData.DataState = InsSysLib.Core.DataState.Modify;
                        //}
                        //else
                        //{
                        //    curData = new HrStaffBase();
                        //    curData.DataState = InsSysLib.Core.DataState.New;
                        //    curData.Id = Guid.NewGuid().ToString();
                        //    curData.IdentityCard = identityCard;
                        //}
                        if (curData == null)
                        {
                            strErr.Append("第" + irowIndex + "行,用戶未採集進場信息,不能導入!\r\n");
                            //continue;
                        }
                        else
                        {
                            if (curData.IdentityCard.Length == 15)
                            {
                                string birth = curData.IdentityCard.Substring(6, 6).Insert(4, "-").Insert(2, "-");
                                curData.Birthday = StrHelper.ParseDate(birth, DateTime.Now);//出生年月
                            }
                            if (curData.IdentityCard.Length == 18)
                            {
                                string birthday = curData.IdentityCard.Substring(6, 4) + "-" + curData.IdentityCard.Substring(10, 2) + "-" + curData.IdentityCard.Substring(12, 2);
                                curData.Birthday = StrHelper.ParseDate(birthday, DateTime.Now);//出生年月
                            }

                            if (curData.Birthday.HasValue)
                                curData.Age = DateTime.Now.Year - curData.Birthday.Value.Year;//年齡
                            if (curData.Age == 0 || curData.Age == null)
                            {
                                strErr.Append("第" + irowIndex + "行【年齡】未填寫!\r\n");
                                //continue;
                            }
                            if (string.IsNullOrEmpty(dr["姓名"].ToString()))
                            {
                                strErr.Append("第" + irowIndex + "行【姓名】未填寫!\r\n");
                                //continue;
                            }
                            else
                            {
                                curData.Name = dr["姓名"] == DBNull.Value ? "" : dr["姓名"].ToString();
                            }
                            if (string.IsNullOrEmpty(dr["性別"].ToString()))
                            {
                                strErr.Append("第" + irowIndex + "行【性別】未填寫!\r\n");
                                //continue;
                            }
                            else
                            {
                                curData.Sex = dr["性別"] == DBNull.Value ? (int)性別.男 : (int)Enum.Parse(typeof(性別), dr["性別"].ToString());
                            }
                            if (!string.IsNullOrEmpty(curData.IdentityCard) && sfzhtWork.Count(x => x.Item2.Contains(dr["身份證號碼"].ToString().Trim())) > 0)
                            {
                                curData.Id = sfzhtWork.FirstOrDefault(x => x.Item2.Contains(dr["身份證號碼"].ToString().Trim())) == null ? ""
                                    : sfzhtWork.FirstOrDefault(x => x.Item2.Contains(dr["身份證號碼"].ToString().Trim())).Item1;
                            }
                            curData.AnmeldenLocationNumber = dr["戶口所在地"] == DBNull.Value ? "" : dr["戶口所在地"].ToString().Trim();
                            if (string.IsNullOrEmpty(curData.AnmeldenLocationNumber))
                            {
                                strErr.Append("第" + irowIndex + "行【戶口所在地】未填寫!\r\n");
                                //continue;
                            }
                            if (string.IsNullOrEmpty(dr["學歷"].ToString()))
                            {
                                strErr.Append("第" + irowIndex + "行【學歷】未填寫!\r\n");
                                //continue;
                            }
                            else
                            {
                                curData.EducationalLevel = dr["學歷"] == DBNull.Value ? (int)學歷.本科 : (int)Enum.Parse(typeof(學歷), dr["學歷"].ToString());
                            }

                            //人員和項目信息關聯
                            curData.ProjectId = curProjectId;
                            if (String.IsNullOrEmpty(curData.SubcontractorId))
                            {
                                strErr.Append("第" + irowIndex + "行【所屬分包商】未填寫!\r\n");
                                //continue;
                            }
                            else
                            {
                                //所屬分包商
                                curData.SubcontractorId = dr["所屬分包商"] == DBNull.Value ? "" : htSuppliers.Count(x => x.Item2 == dr["所屬分包商"].ToString()) > 0 ? htSuppliers.FirstOrDefault(x => x.Item2 == dr["所屬分包商"].ToString()).Item1 : "";
                            }
                            //else
                            //{
                            //    // 判斷如果是黑名單,則continue
                            //    var isblacklist = htSuppliers.FirstOrDefault(x => x.Item2 == dr["所屬分包商"].ToString()).Item3;
                            //    if (isblacklist == "1")
                            //    {
                            //        strErr.Append("第" + irowIndex + "行【所屬分包商】屬於黑名單,無法導入!\r\n");
                            //        continue;
                            //    }
                            //}
                            //所屬勞務組織
                            //curData.SignDeptId = dr["所屬勞務組織"] == DBNull.Value ? "" : htSuppliers.Count(x => x.Item2 == dr["所屬勞務組織"].ToString()) > 0 ? htSuppliers.FirstOrDefault(x => x.Item2 == dr["所屬勞務組織"].ToString()).Item1 : "";
                            //if (String.IsNullOrEmpty(curData.Sign_dept_id))
                            //{
                            //    strErr.Append("第" + irowIndex + "行【所屬勞務組織】未填寫!\r\n");
                            //    continue;
                            //}

                            curData.PositionName = dr["工種"] == DBNull.Value ? "" : dr["工種"].ToString();
                            if (!string.IsNullOrEmpty(curData.PositionName))
                            {
                                curData.Position = ((int)Enum.Parse(typeof(工種), dr["工種"].ToString())).ToString();
                            }
                            //curData.Position = dr["工種"] == DBNull.Value ? "" : htWork.ContainsKey(dr["工種"].ToString()) ? htWork[dr["工種"].ToString()].ToString() : "";
                            //curData.Position = dr["工種"] == DBNull.Value ? "" : ((int)Enum.Parse(typeof(工種), dr["工種"].ToString())).ToString();
                            if (string.IsNullOrEmpty(curData.Position))
                            {
                                strErr.Append("第" + irowIndex + "行【工種】未填寫!\r\n");
                                //continue;
                            }

                            curData.Seniority = dr["工作年限"] == DBNull.Value ? DBUtil.INVALID_ID : StrHelper.ParseInt(dr["工作年限"].ToString(), DBUtil.INVALID_ID);
                            int outintvalue;
                            if (!string.IsNullOrEmpty(dr["工作年限"].ToString()))
                            {
                                if (!Int32.TryParse(dr["工作年限"].ToString(), out outintvalue))
                                {
                                    strErr.Append("第" + irowIndex + "行【工作年限】格式不正確,請輸入整數!\r\n");
                                    //continue;
                                }
                                if (outintvalue < 0)
                                {
                                    strErr.Append("第" + irowIndex + "行【工作年限】格式不正確,請輸入正整數!\r\n");
                                    //continue;
                                }
                            }

                            //curData.ComingDate = DateTime.Now;//進場時間默認賦值新增時間
                            //curData.Coming_date = dr["進場時間"] == DBNull.Value ? DBUtil.INVALID_DATE : StrHelper.ParseDate(dr["進場時間"].ToString(), DBUtil.INVALID_DATE);
                            //DateTime outdate;
                            //if (!string.IsNullOrEmpty(dr["進場時間"].ToString()))
                            //{
                            //    if (!DateTime.TryParse(dr["進場時間"].ToString(), out outdate))
                            //    {
                            //        strErr.Append("第" + irowIndex + "行【進場時間】格式不正確,請輸入時間格式!\r\n");
                            //        continue;
                            //    }
                            //}
                            //else
                            //{
                            //    strErr.Append("第" + irowIndex + "行【進場時間】未填寫!\r\n");
                            //    continue;
                            //}
                            if (payWaylist.Count(x => x.Text == dr["發放方式"].ToString()) > 0)
                            {
                                curData.PayType = Convert.ToInt32(payWaylist.FirstOrDefault(x => x.Text == dr["發放方式"].ToString()).Id);
                            }
                            //curData.BankAccount = dr["銀行卡號"] == DBNull.Value ? "" : dr["銀行卡號"].ToString().Trim();
                            if (string.IsNullOrEmpty(dr["銀行卡號"].ToString()))
                            {
                                strErr.Append("第" + irowIndex + "行【銀行卡號】未填寫!\r\n");
                                //continue;
                            }
                            else
                            {
                                if (CheckBankAccount(dr["銀行卡號"].ToString().Trim()))
                                {
                                    curData.BankAccount = dr["銀行卡號"].ToString().Trim();
                                }
                                else
                                {
                                    strErr.Append("第" + irowIndex + "行【銀行卡號】格式不正確,請輸入16位或19正整數!\r\n");
                                    //continue;
                                }
                            }

                            if (!string.IsNullOrEmpty(dr["是否貧困縣"].ToString()))
                            {
                                if (dr["是否貧困縣"].ToString() == "是" || dr["是否貧困縣"].ToString() == "否")
                                {
                                    curData.Ispoor = string.IsNullOrEmpty(dr["是否貧困縣"].ToString()) ? DBUtil.INVALID_ID : (int)Enum.Parse(typeof(InsSysLib.Core.是否狀態), dr["是否貧困縣"].ToString());
                                }
                                else
                                {
                                    strErr.Append("第" + irowIndex + "行【是否貧困縣】格式不正確,請選擇是和否!\r\n");
                                    //continue;
                                }
                            }

                            curData.Address = dr["家庭地址"] == DBNull.Value ? "" : dr["家庭地址"].ToString().Trim();
                            curData.EmergencyContact = dr["緊急聯繫人"] == DBNull.Value ? "" : dr["緊急聯繫人"].ToString().Trim();
                            if (string.IsNullOrEmpty(dr["緊急聯繫人電話"].ToString()))
                            {
                                strErr.Append("第" + irowIndex + "行【緊急聯繫人電話】未填寫!\r\n");
                                //continue;
                            }
                            else
                            {
                                if (CheckContactTel(dr["緊急聯繫人電話"].ToString().Trim()))
                                {
                                    curData.EmergencyContactTel = dr["緊急聯繫人電話"].ToString().Trim();
                                }
                                else
                                {
                                    strErr.Append("第" + irowIndex + "行【緊急聯繫人電話】格式不正確,請輸入正確格式的電話!\r\n");
                                    //continue;
                                }
                            }
                            curData.ContactRelationship = dr["關係"] == DBNull.Value ? "" : dr["關係"].ToString().Trim();
                            //curData.Occupational = dr["技能資格證"] == DBNull.Value ? "" : dr["技能資格證"].ToString().Trim();


                            #region 護照信息
                            curData.PassportNumber = dr["護照號碼"] == DBNull.Value ? "" : dr["護照號碼"].ToString().Trim();
                            curData.PassportType = dr["護照類型"] == DBNull.Value ? "" : dr["護照類型"].ToString().Trim();
                            curData.Visanumber = dr["簽證編號"] == DBNull.Value ? "" : dr["簽證編號"].ToString().Trim();
                            curData.HzPeriod = dr["護照有效期至"] == DBNull.Value ? DBUtil.INVALID_DATE : StrHelper.ParseDate(dr["護照有效期至"].ToString(), DBUtil.INVALID_DATE);
                            DateTime HzPeriod;
                            if (!string.IsNullOrEmpty(dr["護照有效期至"].ToString()))
                            {
                                if (!DateTime.TryParse(dr["護照有效期至"].ToString(), out HzPeriod))
                                {
                                    strErr.Append("第" + irowIndex + "行【護照有效期至】格式不正確,請輸入時間格式!\r\n");
                                }
                            }

                            curData.HandlingDate = dr["辦理日期"] == DBNull.Value ? DBUtil.INVALID_DATE : StrHelper.ParseDate(dr["辦理日期"].ToString(), DBUtil.INVALID_DATE);
                            DateTime HandlingDate;
                            if (!string.IsNullOrEmpty(dr["辦理日期"].ToString()))
                            {
                                if (!DateTime.TryParse(dr["辦理日期"].ToString(), out HandlingDate))
                                {
                                    strErr.Append("第" + irowIndex + "行【辦理日期】格式不正確,請輸入時間格式!\r\n");
                                }
                            }

                            curData.DueDate = dr["到期時間"] == DBNull.Value ? DBUtil.INVALID_DATE : StrHelper.ParseDate(dr["到期時間"].ToString(), DBUtil.INVALID_DATE);
                            DateTime DueDate;
                            if (!string.IsNullOrEmpty(dr["到期時間"].ToString()))
                            {
                                if (!DateTime.TryParse(dr["到期時間"].ToString(), out DueDate))
                                {
                                    strErr.Append("第" + irowIndex + "行【到期時間】格式不正確,請輸入時間格式!\r\n");
                                }
                            }
                            #endregion

                            #region 特殊證/保險
                            curData.SpecialCerCode = dr["特種作業證編號"] == DBNull.Value ? "" : dr["特種作業證編號"].ToString().Trim();
                            curData.SpecialCerTime = dr["證書有效期"] == DBNull.Value ? DBUtil.INVALID_DATE : StrHelper.ParseDate(dr["證書有效期"].ToString(), DBUtil.INVALID_DATE);
                            DateTime SpecialCerTime;
                            if (!string.IsNullOrEmpty(dr["證書有效期"].ToString()))
                            {
                                if (!DateTime.TryParse(dr["證書有效期"].ToString(), out SpecialCerTime))
                                {
                                    strErr.Append("第" + irowIndex + "行【證書有效期】格式不正確,請輸入時間格式!\r\n");
                                }
                            }
                            if (!string.IsNullOrEmpty(dr["特殊工種"].ToString()))
                            {
                                if (dr["特殊工種"].ToString() == "是" || dr["特殊工種"].ToString() == "否")
                                {
                                    curData.IsOperation = string.IsNullOrEmpty(dr["特殊工種"].ToString()) ? DBUtil.INVALID_ID : (int)Enum.Parse(typeof(InsSysLib.Core.是否狀態), dr["特殊工種"].ToString());
                                    if (dr["特殊工種"].ToString() == "是")
                                    {
                                        if (string.IsNullOrEmpty(dr["特種作業證編號"].ToString()))
                                        {

                                            strErr.Append("第" + irowIndex + "行【特種作業證編號】未填寫,特殊工種此項必填!\r\n");
                                        }
                                        if (string.IsNullOrEmpty(dr["證書有效期"].ToString()))
                                        {

                                            strErr.Append("第" + irowIndex + "行【證書有效期】未填寫,特殊工種此項必填!\r\n");
                                        }
                                    }
                                }
                                else
                                {
                                    strErr.Append("第" + irowIndex + "行【特殊工種】格式不正確,請選擇是和否!\r\n");
                                }
                            }

                            curData.InsuranceType = dr["保險類型"] == DBNull.Value ? "" : dr["保險類型"].ToString().Trim();
                            curData.InsuranceTime = dr["保險有效期"] == DBNull.Value ? DBUtil.INVALID_DATE : StrHelper.ParseDate(dr["保險有效期"].ToString(), DBUtil.INVALID_DATE);
                            DateTime InsuranceTime;
                            if (!string.IsNullOrEmpty(dr["保險有效期"].ToString()))
                            {
                                if (!DateTime.TryParse(dr["保險有效期"].ToString(), out InsuranceTime))
                                {
                                    strErr.Append("第" + irowIndex + "行【保險有效期】格式不正確,請輸入時間格式!\r\n");
                                }
                            }
                            if (!string.IsNullOrEmpty(dr["購買保險"].ToString()))
                            {
                                if (dr["購買保險"].ToString() == "是" || dr["購買保險"].ToString() == "否")
                                {
                                    curData.Insurance = string.IsNullOrEmpty(dr["購買保險"].ToString()) ? DBUtil.INVALID_ID : (int)Enum.Parse(typeof(InsSysLib.Core.是否狀態), dr["購買保險"].ToString());
                                    if (dr["購買保險"].ToString() == "是")
                                    {
                                        if (string.IsNullOrEmpty(dr["保險類型"].ToString()))
                                        {
                                            strErr.Append("第" + irowIndex + "行【保險類型】未填寫,購買保險此項必填!\r\n");
                                        }
                                        if (string.IsNullOrEmpty(dr["保險有效期"].ToString()))
                                        {
                                            strErr.Append("第" + irowIndex + "行【保險有效期】未填寫,購買保險此項必填!\r\n");
                                        }
                                    }
                                }
                                else
                                {
                                    strErr.Append("第" + irowIndex + "行【購買保險】格式不正確,請選擇是和否!\r\n");
                                }
                            }
                            #endregion


                            curData.DataState = InsSysLib.Core.DataState.Modify;
                            curData.CurState = (int)EPC人員狀態.待進場;
                        }
                        #endregion

                        if (!string.IsNullOrEmpty(strErr.ToString()))
                        {
                            continue;
                        }
                        HrStaffBaseManager.Save(curData);    //保存數據至db中
                        //if (!string.IsNullOrEmpty(curData.Id))
                        //{
                        //    HrStaffBaseManager.Service.Modify(curData.Id, curData, sqlTrans);//修改
                        //}
                        //else
                        //{
                        //    HrStaffBaseManager.Service.Save(curData, sqlTrans);//新增
                        //}
                        #endregion
                    }
                }
                File.Delete(strFullAddress);//刪除服務器中當前excel文件,防止佔用服務器磁盤存儲空間
                Session["FILE_UP_ERR_MGS"] = strErr.ToString();
                //sqlTrans.Commit();
            }
            catch (Exception ex)
            {
                //sqlTrans.Rollback();
                Session["FILE_UP_ERR_MGS"] = ex.Message;
            }
            finally
            {
                //sqlCon.Close();
            }
            #endregion
        }

        #region 校驗18位和15位身份證號方法
        /// <summary>
        /// 校驗18位位身份證號方法
        /// </summary>
        /// <param name="idNumber"></param>
        /// <returns></returns>
        private bool CheckIDCard18(string idNumber)
        {
            long n = 0;
            if (long.TryParse(idNumber.Remove(17), out n) == false
                || n < Math.Pow(10, 16) || long.TryParse(idNumber.Replace('x', '0').Replace('X', '0'), out n) == false)
            {
                return false;//數字驗證  
            }
            string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
            if (address.IndexOf(idNumber.Remove(2)) == -1)
            {
                return false;//省份驗證  
            }
            string birth = idNumber.Substring(6, 8).Insert(6, "-").Insert(4, "-");
            DateTime time = new DateTime();
            if (DateTime.TryParse(birth, out time) == false)
            {
                return false;//生日驗證  
            }
            string[] arrVarifyCode = ("1,0,x,9,8,7,6,5,4,3,2").Split(',');
            string[] Wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2").Split(',');
            char[] Ai = idNumber.Remove(17).ToCharArray();
            int sum = 0;
            for (int i = 0; i < 17; i++)
            {
                sum += int.Parse(Wi[i]) * int.Parse(Ai[i].ToString());
            }
            int y = -1;
            Math.DivRem(sum, 11, out y);
            if (arrVarifyCode[y] != idNumber.Substring(17, 1).ToLower())
            {
                return false;//校驗碼驗證  
            }
            return true;//符合GB11643-1999標準  
        }
        /// <summary>
        /// 校驗15位身份證號方法
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        private bool CheckIDCard15(string Id)
        {
            long n = 0; if (long.TryParse(Id, out n) == false || n < Math.Pow(10, 14))
            {
                return false;//數字驗證 
            }
            string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
            if (address.IndexOf(Id.Remove(2)) == -1)
            {
                return false;//省份驗證 
            }
            string birth = Id.Substring(6, 6).Insert(4, "-").Insert(2, "-"); DateTime time = new DateTime();
            if (DateTime.TryParse(birth, out time) == false)
            {
                return false;//生日驗證  
            }
            return true;//符合15位身份證標準 
        }

        #endregion

        #region 校驗16位或19位銀行卡號
        private bool CheckBankAccount(string BankAccount)
        {
            bool result = false;
            //string regex = @"^\d{16}|\d{19}$";//16至19位數字
            string regex = @"^([0-9]{16}|[0-9]{19})$";//16或19位數字
            Match m = Regex.Match(BankAccount, regex);
            if (m.Success)
            {
                result = true;
            }
            return result;
        }

        private bool CheckContactTel(string ContactTel)
        {
            bool result = false;
            bool result1 = false;
            bool result2 = false;
            //https://c.runoob.com/front-end/854
            string regex1 = @"^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$";//手機號碼
            string regex2 = @"\d{3}-\d{8}|\d{4}-\d{7}";//國內電話號碼(0511-4405222、021-87888822)
            Match m1 = Regex.Match(ContactTel, regex1);
            if (m1.Success)
            {
                result1 = true;
            }
            Match m2 = Regex.Match(ContactTel, regex2);
            if (m2.Success)
            {
                result2 = true;
            }
            if (result1 || result2)
            {
                result = true;
            }
            return result;
        }
        #endregion

        /// <summary>
        /// Excel轉換DataTable
        /// </summary>
        /// <param name="FilePath">文件的絕對路徑</param>
        /// <returns>DataTable</returns>
        public static DataSet ExcelInput(string FilePath)
        {
            #region xlsx文件
            //DataSet ds = new DataSet();
            ////根據路徑通過已存在的excel來創建XSSFWorkbook,即整個excel文檔
            //////xlsx文件
            //XSSFWorkbook workbook = new XSSFWorkbook(File.Open(FilePath, FileMode.Open));
            //XSSFSheet sheet = (XSSFSheet)workbook.GetSheetAt(0);
            ////xls文件
            ////HSSFWorkbook workbook = new HSSFWorkbook(File.Open(FilePath, FileMode.Open));
            ////HSSFSheet sheet = (HSSFSheet)workbook.GetSheetAt(0);

            //DataTable table = new DataTable();
            //table.TableName = sheet.SheetName;
            ////獲取excel的第一個sheet
            ////獲取Excel的最大行數
            //int rowsCount = sheet.PhysicalNumberOfRows;//獲取Excel文檔中數據不爲空行數
            ////爲保證Table佈局與Excel一樣,這裏應該取所有行中的最大列數(需要遍歷整個Sheet)。
            ////爲少一交全Excel遍歷,提高性能,我們可以人爲把第0行的列數調整至所有行中的最大列數。
            ////int colsCount = sheet.GetRow(1).PhysicalNumberOfCells;//獲取Excel文檔中數據不爲空列數
            //int colsCount = 17;//獲取Excel文檔導入列數
            //for (int i = 0; i < colsCount; i++)
            //{
            //    table.Columns.Add(sheet.GetRow(1).GetCell(i).ToString());
            //}
            //for (int x = 2; x < rowsCount; x++)
            //{
            //    DataRow dr = table.NewRow();
            //    if (colsCount >= 1)
            //    {
            //        for (int y = 0; y < colsCount; y++)
            //        {
            //            if (sheet.GetRow(x).GetCell(y) != null)
            //                dr[y] = sheet.GetRow(x).GetCell(y).ToString();
            //            else
            //                dr[y] = null;
            //        }
            //    }
            //    table.Rows.Add(dr);
            //}
            //ds.Tables.Add(table);
            //return ds;
            #endregion

            #region xls文件,導出xls文件只有一行標題,導出xlsx文件有兩行標題
            DataSet ds = new DataSet();
            //根據路徑通過已存在的excel來創建XSSFWorkbook,即整個excel文檔
            ////xlsx文件
            //XSSFWorkbook workbook = new XSSFWorkbook(File.Open(FilePath, FileMode.Open));
            //XSSFSheet sheet = (XSSFSheet)workbook.GetSheetAt(0);
            //xls文件
            HSSFWorkbook workbook = new HSSFWorkbook(File.Open(FilePath, FileMode.Open));
            HSSFSheet sheet = (HSSFSheet)workbook.GetSheetAt(0);

            DataTable table = new DataTable();
            table.TableName = sheet.SheetName;
            //獲取excel的第一個sheet
            //獲取Excel的最大行數
            int rowsCount = sheet.PhysicalNumberOfRows;//獲取Excel文檔中數據不爲空行數
            //爲保證Table佈局與Excel一樣,這裏應該取所有行中的最大列數(需要遍歷整個Sheet)。
            //爲少一交全Excel遍歷,提高性能,我們可以人爲把第0行的列數調整至所有行中的最大列數。
            //int colsCount = sheet.GetRow(1).PhysicalNumberOfCells;//獲取Excel文檔中數據不爲空列數
            int colsCount = 29;//獲取Excel文檔導入列數 17銀行卡號
            for (int i = 0; i < colsCount; i++)
            {
                //table.Columns.Add(sheet.GetRow(1).GetCell(i).ToString());
                table.Columns.Add(sheet.GetRow(0).GetCell(i).ToString());//構造列
            }
            //for (int x = 2; x < rowsCount; x++)
            for (int x = rowsCount - 1; x < rowsCount; x++)//遍歷行,構造行數據
            {
                DataRow dr = table.NewRow();
                if (colsCount >= 1)
                {
                    for (int y = 0; y < colsCount; y++)//構造列數據
                    {
                        //if (sheet.GetRow(x).GetCell(y) != null)
                        //    dr[y] = sheet.GetRow(x).GetCell(y).ToString();
                        //else
                        //    dr[y] = null;


                        if (sheet.GetRow(x).GetCell(y) != null)
                        {
                            ICell cellItem = sheet.GetRow(x).GetCell(y);//獲取當前單元格
                            if (cellItem.CellType == NPOI.SS.UserModel.CellType.Numeric && DateUtil.IsCellDateFormatted(cellItem))//當前單元格類型爲Numeric,且爲日期格式時轉換單元格內容格式,防止導入異常
                            {
                                //dr[y] = cellItem.DateCellValue.ToString("yyyy/MM/dd");
                                dr[y] = cellItem.DateCellValue.ToString("yyyy-MM-dd");
                            }
                            else
                            {
                                dr[y] = sheet.GetRow(x).GetCell(y).ToString();
                            }
                        }
                        else
                            dr[y] = null;
                    }
                }
                table.Rows.Add(dr);
            }
            ds.Tables.Add(table);
            return ds;
            #endregion
        }

        private XSSFWorkbook xssfworkbook;

        /// <summary>
        /// 下載excel模板
        /// </summary>
        public void DownloadExcel()
        {
            string fileName = "人員臺賬模板.xlsx";
            string sServerPath = Server.MapPath("TempFiles") + "\\" + fileName;//Server.MapPath(fileName);

            FileInfo file = new FileInfo(sServerPath);
            FileStream myFile = File.OpenRead(sServerPath);
            byte[] byteData = new byte[myFile.Length];
            myFile.Read(byteData, 0, (int)myFile.Length);
            // byte[] byteData = data.Data;
            HttpResponse response = HttpContext.Current.Response;
            response.Clear();
            response.ClearContent();
            response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file.Name));
            response.AddHeader("Content-Length", byteData.Length.ToString());
            response.AddHeader("Content-Transfer-Encoding", "binary");
            //response.ContentType = contentType;
            response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            response.BinaryWrite(byteData);
            response.Flush();
            response.End();
            //File.Delete(sServerPath);
        }

        /// <summary>
        /// 寫入Excel 設置數據源
        /// </summary>
        public void WriteToExcel()
        {
            if (!Directory.Exists(Server.MapPath("TempFiles")))
            {
                Directory.CreateDirectory(Server.MapPath("TempFiles"));
            }

            //生成的下載Excel
            string sDownLoadServerPath = Server.MapPath("TempFiles") + "\\" + "人員臺賬模板.xlsx";

            //原始Excel
            string fileName = "TempFiles/人員臺賬模板1.xlsx";
            string sServerPath = Server.MapPath(fileName);
            FileStream myFile = File.OpenRead(sServerPath);
            FileStream file = new FileStream(sServerPath, FileMode.Open, FileAccess.Read);
            xssfworkbook = new XSSFWorkbook(file);
            ISheet sheet = xssfworkbook.GetSheet("數據源");
            IRow row = null;
            //查詢list
            //人員分類
            //var personList = CommonTypeCache.ListCommonTypeByDefCode(ConstuctionCommonType.人員分類, true);
            //崗位
            //var gangweilist = new List<TreeListItem>();
            //List<CacheObject> entities = RangeCache.QueryProjectWorkerForCache(null, new OrderByParams("Inner_Code"));
            //foreach (CacheObject entity in entities)
            //{
            //    gangweilist.Add(new TreeListItem { Id = entity.Id, Text = "[" + entity.OuterCode + "]" + entity.Name });
            //}
            //人員種類
            var gongzhonglist = IdTextItem.ToItems(typeof(工種));
            ////人員狀態
            //var personStatelist = IdTextItem.ToItems(typeof(EPC人員狀態));
            //是否
            var Isfalselist = IdTextItem.ToItems(typeof(是否));
            //性別
            var Issexlist = IdTextItem.ToItems(typeof(性別));
            //學歷
            var studylist = IdTextItem.ToItems(typeof(學歷));

            //發放方式
            var payWaylist = IdTextItem.ToItems(typeof(EPC發放方式));

            //所屬單位
            //var deptlist = new List<TreeListItem>();
            //所屬分包商
            List<IdTextItem> ht = GetSupplierIdTextList();
            //string sCompanyId = UserContext.CurrentUser.CompanyId;
            //OrgQueryParams queryParam = new OrgQueryParams();
            //queryParam.OrgPartType = OrgPartEnum.內部單位;
            //queryParam.IsRecursive = true;
            //List<TreeListItem> _items = SystemServiceFactory.Service.GetOrgAncestors(sCompanyId);
            //foreach (TreeListItem item in _items)
            //{
            //    if (string.IsNullOrEmpty(item.ParentId))
            //        queryParam.RootOrgId = item.Id;
            //}
            //queryParam.OrgType = OrgTypeEnum.全部;
            //queryParam.AppendRootNode = true;
            //deptlist = SystemServiceFactory.Service.GetOrganizationList(UserContext.CurrentUser.CurrentAppID, queryParam);
            //List<TreeListItem> items1 = SystemServiceFactory.Service.GetAllUpperOutCompy(sCompanyId, true);
            //deptlist.AddRange(items1);

            var maxCountList = new List<int>{  //gangweilist.Count(),//personList.Count(),deptlist.Count, personStatelist.Count(),
                gongzhonglist.Count(),Isfalselist.Count(), studylist.Count(), ht.Count,payWaylist.Count() };
            var maxNum = Convert.ToInt32(maxCountList.OrderByDescending(x => x).FirstOrDefault().ToString());
            for (int i = 0; i < maxNum; i++)
            {
                row = sheet.CreateRow(i + 1);
                var countindex = i;
                row.CreateCell(0).SetCellValue(ht.Count > countindex ? (ht[countindex] == null ? "" : ht[countindex].Text) : "");
                row.CreateCell(1).SetCellValue(gongzhonglist.Count() > countindex ? (gongzhonglist[countindex] == null ? "" : gongzhonglist[countindex].Text) : "");
                row.CreateCell(2).SetCellValue(Issexlist.Count() > countindex ? (Issexlist[countindex] == null ? "" : Issexlist[countindex].Text) : "");
                row.CreateCell(3).SetCellValue(payWaylist.Count() > countindex ? (payWaylist[countindex] == null ? "" : payWaylist[countindex].Text) : "");
                row.CreateCell(4).SetCellValue(studylist.Count() > countindex ? (studylist[countindex] == null ? "" : studylist[countindex].Text) : "");
                //row.CreateCell(5).SetCellValue(studylist.Count() > countindex ? (studylist[countindex] == null ? "" : studylist[countindex].Text) : "");
                //row.CreateCell(6).SetCellValue(Issexlist.Count() > countindex ? (Issexlist[countindex] == null ? "" : Issexlist[countindex].Text) : "");
                //row.CreateCell(7).SetCellValue(deptlist.Count > countindex ? (deptlist[countindex] == null ? "" : deptlist[countindex].Text) : "");
                //rowCount++;
            }
            sheet.ForceFormulaRecalculation = true;
            file = new FileStream(sDownLoadServerPath, FileMode.Create);
            xssfworkbook.Write(file);
            file.Close();
            file.Dispose();
        }

        ///// <summary>
        ///// 初始化Excel
        ///// </summary>
        ///// <param name="stream"></param>
        //public void InitWorkbook(FileStream stream)
        //{
        //    xssfworkbook = new HSSFWorkbook(stream);

        //    DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
        //    dsi.Company = "Ins lnc";
        //    xssfworkbook.DocumentSummaryInformation = dsi;

        //    SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
        //    si.Subject = "人員臺帳";
        //    xssfworkbook.SummaryInformation = si;
        //}


        /// <summary>
        /// 設置選擇源區域
        /// </summary>
        /// <param name="sheet">數據區sheet</param>
        /// <param name="colIndex">數據區對應的選擇項列</param>
        /// <param name="sSheetName">源sheet</param>
        /// <param name="letter">源對應的列編號名</param>
        /// <param name="startRowIndex">源起始行</param>
        /// <param name="endRowIndex">源結束行</param>
        public void SetChongeSource(ref ISheet sheet, int colIndex, string sSheetName, string letter, int startRowIndex, int endRowIndex, string dicRange)
        {
            CellRangeAddressList rangeList = new CellRangeAddressList(1, 1000, colIndex, colIndex);

            HSSFName range = (HSSFName)xssfworkbook.CreateName();
            range.RefersToFormula = sSheetName + "!$" + letter + "$" + startRowIndex + ":$" + letter + "$" + endRowIndex;
            range.NameName = dicRange;

            DVConstraint dvconstraint = DVConstraint.CreateFormulaListConstraint(dicRange);
            HSSFDataValidation dataValidation = new HSSFDataValidation(rangeList, dvconstraint);
            ((HSSFSheet)sheet).AddValidationData(dataValidation);
        }


        /// <summary>
        /// 初始化源sheet
        /// </summary>
        /// <param name="currentSheet">當前sheet</param>
        /// <param name="sheetIndex">sheet編號</param>
        /// <param name="sSheetName">sheet名稱</param>
        public void InitSheet(ref ISheet currentSheet, int sheetIndex, string sSheetName)
        {
            try
            {
                currentSheet = xssfworkbook.GetSheetAt(sheetIndex);
            }
            catch { }
            if (currentSheet != null)
            {
                xssfworkbook.RemoveSheetAt(sheetIndex);
            }
            currentSheet = xssfworkbook.CreateSheet(sSheetName);
            xssfworkbook.SetSheetHidden(sheetIndex, true);
        }

        #region 導出樣表下拉數據源
        //所屬單位
        protected Hashtable GetDept()
        {
            string sCompanyId = UserContext.CurrentUser.CompanyId;
            List<TreeListItem> items = new List<TreeListItem>();
            OrgQueryParams queryParam = new OrgQueryParams();
            queryParam.OrgPartType = OrgPartEnum.內部單位;
            queryParam.IsRecursive = true;
            List<TreeListItem> _items = SystemServiceFactory.Service.GetOrgAncestors(sCompanyId);
            foreach (TreeListItem item in _items)
            {
                if (string.IsNullOrEmpty(item.ParentId))
                    queryParam.RootOrgId = item.Id;
            }

            queryParam.OrgType = OrgTypeEnum.全部;
            queryParam.AppendRootNode = true;
            items = SystemServiceFactory.Service.GetOrganizationList(UserContext.CurrentUser.CurrentAppID, queryParam);

            List<TreeListItem> items1 = SystemServiceFactory.Service.GetAllUpperOutCompy(sCompanyId, true);

            items.AddRange(items1);

            Hashtable ht = new Hashtable();
            int d = 0;
            foreach (TreeListItem t in items)
            {
                if (t.Text != null && !ht.ContainsKey(t.Text))
                {
                    ht.Add(t.Text, t.Id);
                }

            }
            return ht;
        }

        //人員分類
        private Hashtable GetCommonType()
        {
            TreeListItem[] listItems = CommonTypeCache.ListCommonTypeByDefCode(ConstuctionCommonType.人員分類, false); // (ConstuctionCommonType.人員分類);
            Hashtable ht = new Hashtable();
            foreach (TreeListItem t in listItems)
            {
                if (t.Text != null && !ht.ContainsKey(t.Text))
                {
                    ht.Add(t.Text, t.Id);
                }
            }
            return ht;
        }

        //崗位或工種
        //private Hashtable GetProjectWork()
        //{
        //    List<CacheObject> entities = RangeCache.QueryProjectWorkerForCache(null, new OrderByParams("Inner_Code"));
        //    Hashtable ht = new Hashtable();
        //    foreach (CacheObject entity in entities)
        //    {
        //        if (entity.Name != null && !ht.ContainsKey(entity.Name))
        //        {
        //            ht.Add("[" + entity.OuterCode + "]" + entity.Name, entity.Id);
        //        }
        //    }
        //    return ht;
        //}

        //id和身份證
        private List<Tuple<string, string>> GetIdCardHt()
        {
            //HrStaffBaseParams ps = new HrStaffBaseParams();
            //ps.Deleted = 0;
            //ps.Project_id = string.IsNullOrEmpty(curProjectId) ? "-1" : curProjectId;  不根據項目來了。包含已退場的其他項目的
            var idcardlist = new List<Tuple<string, string>>();
            var HrStaffBase = HrStaffBaseManager.Find(true);//(ps, null, null);
            foreach (HrStaffBase entity in HrStaffBase)
            {
                if (entity.IdentityCard != null)
                {
                    var item = new Tuple<string, string>(entity.Id, entity.IdentityCard);
                    idcardlist.Add(item);
                }
            }
            return idcardlist;
        }



        //其他枚舉
        private Hashtable GetEnumData(Type type)
        {
            Hashtable ht = new Hashtable();
            foreach (int myCode in Enum.GetValues(type))
            {
                string strName = Enum.GetName(type, myCode);//獲取名稱
                string strVaule = myCode.ToString();//獲取值
                if (!ht.ContainsKey(strName))
                {
                    ht.Add(strName, strVaule);
                }
            }
            return ht;
        }

        //其他枚舉(排序用)
        private Hashtable GetEnumData2(Type type)
        {
            Hashtable ht = new Hashtable();
            foreach (int myCode in Enum.GetValues(type))
            {
                string strName = Enum.GetName(type, myCode);//獲取名稱
                string strVaule = myCode.ToString();//獲取值
                if (!ht.ContainsKey(strName))
                {
                    ht.Add(strVaule, strName);
                }
            }
            return ht;
        }

        /// <summary>
        /// 獲取分包商信息
        /// </summary>
        /// <returns></returns>
        private List<Tuple<string, string, string>> GetSuppliers()
        {
            #region
            //List<Tuple<string, string, string>> ht = new List<Tuple<string, string, string>>();
            ////SupplierBaseInfoParams supplierPs = new SupplierBaseInfoParams();
            ////supplierPs.Sup_type = (int)是否狀態.是;
            ////string sProjectId = EntityIdSessionConfig.GetCurEntityIdSession(EntityIdSessionConfig.Project_Id);
            ////if (!AppConfigUtil.isEnterprise)
            ////    supplierPs.Project_id = sProjectId;
            ////else
            ////{
            ////    SqlComplexParam sql = new SqlComplexParam(" t.PROJECT_ID IS NULL");
            ////    supplierPs.AppendChild(sql);
            ////}
            //List<SupplierBaseInfo> baseInfos = SupplierBaseInfoManager.Find(true);// Service.QueryIDOsByParams(supplierPs, null, null);
            //if (baseInfos != null && baseInfos.Count() > 0)
            //{
            //    foreach (SupplierBaseInfo entity in baseInfos)
            //    {
            //        ht.Add(new Tuple<string, string, string>(entity.Id, entity.Supplier_name, entity.Isblacklist.ToString()));
            //    }
            //}
            //return ht;
            #endregion

            #region
            List<Tuple<string, string, string>> ht = new List<Tuple<string, string, string>>();
            List<SubcontractorBase> baseInfos = HrSubcontractorManager.Find(true);
            if (baseInfos != null && baseInfos.Count() > 0)
            {
                foreach (SubcontractorBase entity in baseInfos)
                {
                    ht.Add(new Tuple<string, string, string>(entity.Id, entity.SubcontractorName, entity.Isblacklist.ToString()));
                }
            }
            return ht;
            #endregion
        }

        /// <summary>
        /// 獲取分包商列表
        /// </summary>
        /// <returns></returns>
        private List<IdTextItem> GetSupplierIdTextList()
        {
            #region
            //List<IdTextItem> list = new List<IdTextItem>();
            ////SupplierBaseInfoParams supplierPs = new SupplierBaseInfoParams();
            ////supplierPs.Sup_type = (int)是否狀態.是;
            //string sProjectId = EntityIdSessionConfig.GetCurEntityIdSession(EntityIdSessionConfig.Project_Id);
            ////if (!AppConfigUtil.isEnterprise)
            ////    supplierPs.Project_id = sProjectId;
            ////else
            ////{
            ////    SqlComplexParam sql = new SqlComplexParam(" t.PROJECT_ID IS NULL");
            ////    supplierPs.AppendChild(sql);
            ////}
            //List<SupplierBaseInfo> baseInfos = SupplierBaseInfoManager.GetSuppliersByType(sProjectId, (int)InsSysLib.Core.是否狀態.是);//.Service.QueryIDOsByParams(supplierPs, null, null);
            //if (baseInfos != null && baseInfos.Count() > 0)
            //{
            //    foreach (SupplierBaseInfo entity in baseInfos)
            //    {
            //        list.Add(new IdTextItem { Id = entity.Id, Text = entity.Supplier_name });
            //    }
            //}
            //return list;
            #endregion

            #region
            List<IdTextItem> list = new List<IdTextItem>();
            string sProjectId = EntityIdSessionConfig.GetCurEntityIdSession(EntityIdSessionConfig.Project_Id);
            List<SubcontractorBase> baseInfos = HrSubcontractorManager.Find(true);
            if (baseInfos != null && baseInfos.Count() > 0)
            {
                foreach (SubcontractorBase entity in baseInfos)
                {
                    list.Add(new IdTextItem { Id = entity.Id, Text = entity.SubcontractorName });
                }
            }
            return list;
            #endregion
        }

        ///// <summary>
        ///// 設置數據源(按照值排序)
        ///// </summary>
        ///// <param name="datasourcename">源選項名稱。例如:所屬單位</param>
        ///// <param name="datasourcename">數據源</param>
        ///// <param name="colindex">填充到數據源sheet中的列號</param>
        //public int SetCellDataSource2Sort(string datasourcename, Hashtable ht, int colindex, string sheetname)
        //{
        //    //任務類型標題
        //    ISheet Sheet2 = xssfworkbook.GetSheet(sheetname);
        //    if (Sheet2 == null)
        //    {
        //        Sheet2 = xssfworkbook.CreateSheet();
        //    }
        //    //源選項名稱。例如:所屬單位
        //    IRow row = Sheet2.GetRow(0);
        //    if (row == null)
        //    {
        //        row = Sheet2.CreateRow(0);
        //    }
        //    row.CreateCell(colindex).SetCellValue(datasourcename);
        //    //添加空白項。
        //    IRow row2 = Sheet2.GetRow(1);
        //    if (row2 == null)
        //    {
        //        row2 = Sheet2.CreateRow(1);
        //    }
        //    row2.CreateCell(colindex).SetCellValue("");
        //    int i = 2;
        //    ArrayList alv = new ArrayList(ht.Keys);
        //    alv.Sort();
        //    foreach (object obj in alv)
        //    {
        //        IRow curRow = Sheet2.GetRow(i);
        //        if (curRow == null)
        //        {
        //            curRow = Sheet2.CreateRow(i);
        //        }
        //        curRow.CreateCell(colindex).SetCellValue(ht[obj].ToString());
        //        i++;
        //    }

        //    return ht.Count + 2;
        //}

        #endregion

        #endregion

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章