Exemplo n.º 1
0
        /// <summary>
        /// 添加城市
        /// </summary>
        /// <returns></returns>
        public bool AddCityCode(CityCodeModel model)
        {
            redisoperate.model = model;
            bool redisResult = redisoperate.SaveToRedis();

            return(redisResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 查询城市信息
        /// </summary>
        /// <param name="readStr"></param>
        /// <returns></returns>
        public static IList <CityInfo> GetCityInfos(string readStr)
        {
            try
            {
                if (_cityCodeModel == null)
                {
                    _cityCodeModel = GetCityCodeModel();
                }

                IList <CityInfo> cityInfos = new List <CityInfo>();

                foreach (var provinceValue in _cityCodeModel.ProvinceList)
                {
                    foreach (var cityValue in provinceValue.City)
                    {
                        if (cityValue.CityName == readStr || cityValue.CityCode == readStr)
                        {
                            CityInfo cityInfo = new CityInfo()
                            {
                                CityName = cityValue.CityName,
                                CityCode = cityValue.CityCode
                            };
                            cityInfos.Add(cityInfo);
                            //break; //这里决定不break,因为担心有同一个省下面可能有相同的城市名?
                        }
                    }
                }

                return(cityInfos);
            }
            catch (Exception ex)
            {
                throw new Exception("获取与输入匹配城市时发生错误!\n" + ex.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 将新增城市区号信息发送至MQ
        /// </summary>
        /// <param name="cityCode"></param>
        /// <returns></returns>
        private bool AddCityCodeToMq(CityCodeModel model)
        {
            CommandEntity <CityCodeModel> entity = new CommandEntity <CityCodeModel>()
            {
                command = BussineCommand.NewCityCode,
                idMsg   = Convert.ToBase64String(Guid.NewGuid().ToByteArray()),
                message = model
            };

            return(m_rabbitMQ.SendMessageForRabbitMQ("发送新增城市区号命令", m_serializer.Serialize(entity), entity.idMsg, "", "NewCityCode4007004008", "FuJiCaDynamicAddNewCityCode.direct"));
        }
Exemplo n.º 4
0
        private List <ProvinceCodeModel> GetProvinceCodeModel(string txt)
        {
            List <ProvinceCodeModel> ProvinceCodeModelList = new List <ProvinceCodeModel>();  // ProvinceCodeModel();

            Regex eg = new Regex(@"<p class=""MsoNormal""><b><span lang=""EN-US"">([\s\S]+?)<span>&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b><span style=""font-family: 宋体"">([\s\S]+?)</span></b></p>([\s\S]+?)(?=<p class=""MsoNormal""><b>)");
            //return eg.Match(redirctUrl).Groups[1].Value;
            var list = eg.Matches(txt);

            foreach (Match item in list)
            {
                ProvinceCodeModel proModel = new ProvinceCodeModel()
                {
                    Province = item.Groups[2].Value,
                    CityList = new List <CityCodeModel>()
                };

                string cityTxt = item.Groups[3].Value;
                Regex  egCity  = new Regex(@"<p class=""MsoNormal""><span style=""font-family: 宋体""> </span><span lang=""EN-US"">(.+?)<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style=""font-family: 宋体""> (.+?)</span></p>([\s\S]+?)(?=<p class=""MsoNormal""><span style=""font-family: 宋体""> </span><span lang=""EN-US"">(.+?)<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>|$)");

                var listCity = egCity.Matches(cityTxt);
                foreach (Match itemCity in listCity)
                {
                    CityCodeModel cityModel = new CityCodeModel()
                    {
                        CityName = itemCity.Groups[2].Value,
                        AreaList = new List <AreaCodeModel>()
                    };
                    string AreaTxt  = itemCity.Groups[3].Value;
                    Regex  egArea   = new Regex(@"<p class=""MsoNormal""><span style=""font-family: 宋体"">  </span><span lang=""EN-US"">([\s\S]+?)<span>&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style=""font-family: 宋体"">  ([\s\S]+?)</span></p>");
                    var    listArea = egArea.Matches(AreaTxt);
                    foreach (Match itemArea in listArea)
                    {
                        AreaCodeModel AreaModel = new AreaCodeModel()
                        {
                            AreaName = itemArea.Groups[2].Value
                        };
                        cityModel.AreaList.Add(AreaModel);
                    }

                    proModel.CityList.Add(cityModel);
                }

                ProvinceCodeModelList.Add(proModel);
            }

            return(ProvinceCodeModelList);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 添加城市
        /// </summary>
        /// <returns></returns>
        public bool AddCityCode(string cityID)
        {
            CityCodeModel model = new CityCodeModel();

            model.CodeID = cityID;

            bool redisResult = _iCityCodeContext.AddCityCode(model);

            //redis执行不成功,直接返回false
            if (!redisResult)
            {
                return(false);
            }

            AddCityCodeToMq(model);

            return(redisResult);
        }