private static void ErrorHanding(string errorMsg, WhiteListcs whlist)
 {
     if (errorMsg == "Missing/Incorrect mbrship no under Orig Scheme")
     {
         whlist.ErrorCode.Append("3,");
     }
     if (errorMsg == "Missing/Incorrect Orig Scheme Reg No (Scheme name)")
     {
         whlist.ErrorCode.Append("4,");
     }
     if (errorMsg == "Missing/Incorrect Original Scheme ID no (ERID)")
     {
         whlist.ErrorCode.Append("5,");
     }
     if (errorMsg == "No such member record in Original Scheme")
     {
         whlist.ErrorCode.Append("8,");
     }
     if (errorMsg == "There are MemebershipNo with multiple data is the same")
     {
         whlist.ErrorCode.Append("13,");
     }
     if (errorMsg == "Duplicate request in the NEWD file.")
     {
         whlist.ErrorCode.Append("99,");
     }
     if (errorMsg == "Please Check Value Choice")
     {
         throw new AccountException("Please Check Value Choice");
     }
     whlist.Clean_Case = "N";
     whlist.Unclean_Reason.Append(errorMsg + "\r\n");
 }
        public void TestSaveExcel()
        {
            string             ExcelPath   = @"D:\ConceptFlower Test\Epass Stage 1 & 2 automation tool.xlsx";
            ExcelEditor        excelHandel = new ExcelEditor();
            List <WhiteListcs> wlist       = new List <WhiteListcs>();
            WhiteListcs        model       = new WhiteListcs {
                PM_AC            = "PC", Membership_No = "12345678-123456789", ERID = "21456789", Case_Number = "5454579859"
                , Name_in_AS400  = "test", Name_in_XML = "test", Name_Pass = "******", Clean_Case = "Y", Unclean_Reason = new StringBuilder("sdfasdfsfds"), Signature_Pass = "******"
                , Withdraw_NT_PM = "NT", Process_result = "Process"
            };

            wlist.Add(model);
            var       excel = excelHandel.Open(ExcelPath);
            DataTable dt    = ListToDatatableHelper.ToDataTable <WhiteListcs>(wlist);

            excel.SaveDataTableToExcel(dt, ExcelPath, "White List");
        }
        /// <summary>
        /// 利用反射和泛型
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static List <WhiteListcs> ConvertToList(DataTable dt)
        {
            // 定义集合
            List <WhiteListcs> ts = new List <WhiteListcs>();

            // 获得此模型的类型
            Type type = typeof(WhiteListcs);
            //定义一个临时变量
            string tempName = string.Empty;

            //遍历DataTable中所有的数据行
            foreach (DataRow dr in dt.Rows)
            {
                WhiteListcs t = new WhiteListcs();
                // 获得此模型的公共属性
                PropertyInfo[] propertys = t.GetType().GetProperties();
                //遍历该对象的所有属性
                foreach (PropertyInfo pi in propertys)
                {
                    tempName = pi.Name;//将属性名称赋值给临时变量
                    //检查DataTable是否包含此列(列名==对象的属性名)
                    if (dt.Columns.Contains(tempName))
                    {
                        // 判断此属性是否有Setter
                        if (!pi.CanWrite)
                        {
                            continue;              //该属性不可写,直接跳出
                        }
                        //取值
                        object value = dr[tempName];
                        //如果非空,则赋给对象的属性
                        if (value != DBNull.Value)
                        {
                            pi.SetValue(t, value, null);
                        }
                    }
                }
                //对象添加到泛型集合中
                ts.Add(t);
            }
            return(ts);
        }
        public static SH795AccoutModel Getcase(TransferCase cs, List <SH795AccoutModel> entityList, WhiteListcs whlist, TrusteInfoModel tsinfo, List <UserInfoSchemeInfo> schemeInfoList)
        {
            SH795AccoutModel model = null;
            Regex            reg1  = new Regex(@"^(\d{8})(\D)(\d{9})$");
            Regex            reg2  = new Regex(@"^(\d{8})(\D)(\d{8})$");
            Regex            reg3  = new Regex(@"^\d{9}$");
            Regex            reg4  = new Regex(@"^\d{8}$");
            Regex            reg5  = new Regex(@"^\d{17}$");
            Regex            reg6  = new Regex(@"^(\d{9})(\D)(\d{8})$");
            Regex            reg7  = new Regex(@"^\d{16}$");

            #region first select logic
            try
            {
                if (reg1.IsMatch(cs.OriSchAcctMemNo))
                {
                    model = GetAccountByReg1(cs, entityList, reg1);
                }
                else if (reg2.IsMatch(cs.OriSchAcctMemNo))
                {
                    model = GetAccountByReg2(cs, entityList, reg2);
                }
                else if (reg3.IsMatch(cs.OriSchAcctMemNo))
                {
                    model = GetAccountByReg3(cs, entityList, schemeInfoList, reg3);
                }
                else if (reg4.IsMatch(cs.OriSchAcctMemNo))
                {
                    model = GetAccountByReg4(cs, entityList, tsinfo, schemeInfoList, reg4);
                }
                else if (reg5.IsMatch(cs.OriSchAcctMemNo))
                {
                    model = GetAccountByReg5(cs, entityList, reg5);
                }
                else if (reg6.IsMatch(cs.OriSchAcctMemNo))
                {
                    model = GetAccountByReg6(cs, entityList, reg6);
                }
                else if (reg7.IsMatch(cs.OriSchAcctMemNo))
                {
                    model = GetAccountByReg7(cs, entityList, tsinfo, reg7);
                }
                else
                {
                    //whlist.Clean_Case = "N";
                    //whlist.Unclean_Reason.Append("Member Account or ERID is Error, pls input correct whitelsit \r\n");
                    //if (cs.RequestFormType == "PM")
                    //{
                    //    whlist.ErrorCode.Append("3,5,");
                    //}
                    //else if (cs.RequestFormType == "PC")
                    //{
                    //    whlist.ErrorCode.Append("3,");
                    //}
                }

                if (model != null)
                {
                    string schemeName = schemeInfoList.Where(t => t.SchemeID == model.SchemeID).FirstOrDefault().CaseNO;
                    if (!string.IsNullOrEmpty(schemeName) && schemeName != cs.OriSchRegNo)
                    {
                        throw new AccountException("Missing/Incorrect Orig Scheme Reg No (Scheme name)");
                    }
                }
            }
            catch (AccountException ex)
            {
                ErrorHanding(ex.Message, whlist);
            }
            #endregion
            #region The second select logic

            #endregion
            return(model);
        }