Ejemplo n.º 1
0
        /// <summary>
        /// 根据用户传递的  省、市、区名称、级别(省1,市2,区3),转换为 国标码
        /// 例如:用户传的是 Name:北京市,Code:1,级别:1,调用该方法返回:Name:北京市,Code:110000,级别:1
        /// 在查询不到的情况下,返回null
        /// wc
        /// </summary>
        /// <param name="from"></param>
        /// <returns></returns>
        public AreaModelTranslate GetNationalAreaInfo(AreaModelTranslate from)
        {
            var redis = new ETS.NoSql.RedisCache.RedisCache();
            //List<AreaModel> list = new List<AreaModel>();
            string key        = ETS.Const.RedissCacheKey.Common_GetNationalAreaInfo;
            var    cacheValue = redis.Get <string>(key);
            List <AreaModelTranslate> cacheAreaModelList = null;

            if (!string.IsNullOrEmpty(cacheValue))
            {
                cacheAreaModelList = JsonHelper.ToObject <List <AreaModelTranslate> >(cacheValue);
            }
            else
            {
                cacheAreaModelList = dao.GetRegionInfo().ToList();
                redis.Add(key, JsonHelper.ToJson(cacheAreaModelList), DateTime.Now.AddDays(1));
            }
            //cacheAreaModelList = CacheFactory.Instance[key] as List<AreaModelTranslate>;
            //if (cacheAreaModelList == null) //为null的时候,取数据库
            //{
            //    cacheAreaModelList = dao.GetRegionInfo().ToList();
            //    redis.Add(key, Letao.Util.JsonHelper.ToJson(cacheAreaModelList));
            //    CacheFactory.Instance.AddObject(key, cacheAreaModelList);
            //}
            AreaModelTranslate areaModel       = new AreaModelTranslate();
            AreaModelTranslate resultAreaModel = new AreaModelTranslate();

            if (from.JiBie == 2)
            {
                if (from.Name.Contains("北京"))
                {
                    from.Name = "北京市";
                }
                if (from.Name.Contains("上海"))
                {
                    from.Name = "上海市";
                }
                if (from.Name.Contains("天津"))
                {
                    from.Name = "天津市";
                }
                if (from.Name.Contains("重庆"))
                {
                    from.Name = "重庆市";
                }
            }
            areaModel = cacheAreaModelList.FirstOrDefault(s => s.Name == from.Name.Trim() && s.JiBie == from.JiBie);

            if (areaModel != null)
            {
                resultAreaModel.NationalCode = areaModel.NationalCode;
                //resultAreaModel.Name = areaModel.Name;
                //resultAreaModel.JiBie = from.JiBie;
            }
            else
            {
                resultAreaModel = null;
            }
            return(resultAreaModel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 批量导入骑士验证excel内数据的合法性  add by caoheyang 20150706
        /// </summary>
        /// <param name="st"></param>
        /// <param name="rowCount"></param>
        /// <returns></returns>
        private List <BatchImportClienterExcelDM> ValatiteBatchImportClienterExcel(ISheet st, int rowCount)
        {
            List <BatchImportClienterExcelDM> list = new List <BatchImportClienterExcelDM>();

            for (int i = 1; i <= rowCount; i++)
            {
                string name = "", phone = "", city = "", idCard = "";
                if (st.GetRow(i) != null && st.GetRow(i).GetCell(0) != null) //用户名
                {
                    name = st.GetRow(i).GetCell(0).ToString();
                }
                if (st.GetRow(i) != null && st.GetRow(i).GetCell(1) != null) //手机号
                {
                    phone = st.GetRow(i).GetCell(1).ToString();
                }
                if (st.GetRow(i) != null && st.GetRow(i).GetCell(2) != null) //城市
                {
                    city = st.GetRow(i).GetCell(2).ToString();
                }
                if (st.GetRow(i) != null && st.GetRow(i).GetCell(3) != null) //身份证号
                {
                    idCard = st.GetRow(i).GetCell(3).ToString();
                }
                BatchImportClienterExcelDM model = new BatchImportClienterExcelDM();
                model.Phone  = phone;
                model.Name   = name;
                model.City   = city;
                model.IdCard = idCard;
                Regex phoneReg  = new Regex("^1\\d{10}$"); //手机号验证正则表达式
                Regex idcardReg = new Regex(@"^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$");
                model.Remark = "";
                if (string.IsNullOrWhiteSpace(phone) || string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(city) ||
                    string.IsNullOrWhiteSpace(idCard))
                {
                    model.Remark = model.Remark + "信息不全。";
                    list.Add(model);
                    continue;
                }
                if (!phoneReg.IsMatch(phone))//验证骑士手机号
                {
                    model.Remark = model.Remark + "手机号不合法。";
                }
                if (!idcardReg.IsMatch(idCard))//身份证号验证
                {
                    model.Remark = model.Remark + "身份证号不合法。";
                }
                // 市编码
                IAreaProvider      iAreaProvider = new AreaProvider();
                AreaModelTranslate areaModel     =
                    iAreaProvider.GetNationalAreaInfo(new AreaModelTranslate()
                {
                    Name  = city.Trim(),
                    JiBie = 2
                });
                if (areaModel == null)
                {
                    model.Remark = model.Remark + "城市信息不合法。";
                }
                else
                {
                    model.CityCode = areaModel.NationalCode.ToString();
                }

                if (string.IsNullOrWhiteSpace(model.Remark) &&
                    (list.Count(item => item.Phone == phone) > 0))   //验证xls中手机号是否重复
                {
                    model.Remark = model.Remark + "信息重复。";
                }
                list.Add(model);
            }
            return(list);
        }