Ejemplo n.º 1
0
        private void GetCityByRegionName(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            bool   flag  = false;
            string text  = context.Request["city"];
            string text2 = context.Request["address"];

            if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(text2) || text2.IndexOf(text) == -1)
            {
                context.Response.Write("{\"Status\":\"0\"}");
            }
            else
            {
                string text3 = "";
                if (text2.IndexOf(text) > -1 && text2.IndexOf(text) + text.Length < text2.Length)
                {
                    text3 = text2.Substring(text2.IndexOf(text) + text.Length);
                    if (text3.IndexOf("区") > -1 || text3.IndexOf("县") > -1 || text3.IndexOf("市") > -1 || text3.IndexOf("街道") > -1 || text3.IndexOf("镇") > -1 || text3.IndexOf("村") > -1)
                    {
                        char[] anyOf = new char[5]
                        {
                            '区',
                            '县',
                            '市',
                            '镇',
                            '村'
                        };
                        int  num   = text3.LastIndexOfAny(anyOf);
                        bool flag2 = false;
                        if (num <= -1)
                        {
                            flag2 = true;
                            num   = text3.LastIndexOf("街道");
                        }
                        if (num > -1)
                        {
                            text3 = text3.Substring(0, num + ((!flag2) ? 1 : 2));
                        }
                    }
                }
                Hidistro.Entities.Store.RegionInfo regionInfo = RegionHelper.GetCityByRegionName(text, text3);
                if (regionInfo == null)
                {
                    int regionIdByRegionName = RegionHelper.GetRegionIdByRegionName(text, 2);
                    regionInfo = RegionHelper.GetRegionByRegionId(regionIdByRegionName);
                }
                else
                {
                    flag = true;
                }
                if (regionInfo != null)
                {
                    string fullRegion = RegionHelper.GetFullRegion(regionInfo.RegionId, " ", true, 0);
                    string text4      = text2.Substring(0, text2.IndexOf(regionInfo.RegionName) + regionInfo.RegionName.Length);
                    string str        = text2.Substring(text2.IndexOf(regionInfo.RegionName) + regionInfo.RegionName.Length);
                    string str2       = "{";
                    str2 += "\"Status\":\"OK\",";
                    str2  = str2 + "\"RegionId\":\"" + regionInfo.RegionId.ToString(CultureInfo.InvariantCulture) + "\",";
                    str2  = str2 + "\"County\":\"" + fullRegion + "\",";
                    str2  = str2 + "\"Address\":\"" + str + "\",";
                    str2  = str2 + "\"IsLocateArea\":\"" + flag.ToString() + "\"";
                    str2 += "}";
                    context.Response.Write(str2);
                }
                else
                {
                    string str3 = "{";
                    str3 += "\"Status\":\"OK\",";
                    str3  = str3 + "\"RegionId\":\"" + 0 + "\",";
                    str3  = str3 + "\"County\":\"" + text + "\",";
                    str3  = str3 + "\"Address\":\"" + text2 + "\",";
                    str3  = str3 + "\"IsLocateArea\":\"" + flag.ToString() + "\"";
                    str3 += "}";
                    context.Response.Write(str3);
                }
            }
        }