public static bool CheckAddress(string city, string street, string house)
        {
            if (city == "" || city == null)
            {
                return(false);
            }
            if (street == "" || street == null)
            {
                return(false);
            }
            if (house == "" || house == null)
            {
                return(false);
            }

            var response = api.SuggestAddress($"{city} {street} {house}");

            if (response.suggestions.Count != 0)
            {
                var suggestion = response.suggestions[0];
                return(suggestion.data.city == city && suggestion.data.street.Contains(street) && suggestion.data.house == house);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        private void txtBx_Address_TextChanged(object sender, EventArgs e)
        {
            if (EditMode)
            {
                SelectedFromListBox = false;

                if (txtBx_Address.Text != "")
                {
                    foreach (ListBox Listbox in groupBox1.Controls.OfType <ListBox>())
                    {
                        Listbox.Visible = true;
                    }
                }
                else
                {
                    foreach (ListBox Listbox in groupBox1.Controls.OfType <ListBox>())
                    {
                        Listbox.Visible = false;
                    }
                }


                listBox1.Items.Clear();

                SuggestClient api      = new SuggestClient(DaDataToken);
                var           query    = txtBx_Address.Text;
                var           response = api.SuggestAddress(query);

                foreach (var item in response.suggestions)
                {
                    listBox1.Items.Add(item.unrestricted_value);
                }
            }
        }
Пример #3
0
        public IEnumerable <Dadata.Model.Suggestion <Dadata.Model.Address> > SuggestAddress(string data)
        {
            var token = "518f96d435704b748e40b3f6a0aa18efea327334";

            this.api = new SuggestClient(token);
            var query = new SuggestAddressRequest(data);

            query.locations = new[] {
                new Address()
                {
                    kladr_id = "7200000000000"
                },
            };
            query.restrict_value = true;
            var response = api.SuggestAddress(query).suggestions;

            return(response);
        }
Пример #4
0
        public static ArrayList Fulldata(ArrayList data, bool light = false)
        {
            if (data.Count == 0)
            {
                Console.WriteLine("Список для отправки в Dadata пуст!");
                System.Environment.Exit(0);
            }
            var       client     = new SuggestClient("b717e3a82d3e964d4e2f37ffe9777d9cad101217");
            ArrayList clearsheet = new ArrayList();
            ArrayList errorsheet = new ArrayList();

            foreach (ArrayList datarow in data)
            {
                try
                {
                    var response = client.SuggestAddress(datarow[0].ToString(), 1);
                    if (response.suggestions[0].data.house_fias_id != null)
                    {
                        datarow.Add(response.suggestions[0].data.house_fias_id);
                    }
                    else if (response.suggestions[0].data.street_fias_id != null)
                    {
                        datarow.Add(response.suggestions[0].data.street_fias_id);
                    }
                    else if (response.suggestions[0].data.settlement_fias_id != null)
                    {
                        datarow.Add(response.suggestions[0].data.settlement_fias_id);
                    }
                    else
                    {
                        datarow.Add(response.suggestions[0].data.city_fias_id);
                    }

                    double           lat;
                    double           lon;
                    NumberFormatInfo nfi = new NumberFormatInfo();
                    nfi.NumberDecimalSeparator = ".";
                    lat = Convert.ToDouble(response.suggestions[0].data.geo_lat, nfi);
                    lon = Convert.ToDouble(response.suggestions[0].data.geo_lon, nfi);
                    datarow.Add(lat);
                    datarow.Add(lon);
                    var routeBuilder = SqlGeography.Point(lat, lon, 4326);
                    datarow.Add(routeBuilder);
                    clearsheet.Add(datarow);
                }
                catch
                {
                    Console.WriteLine("Ошибка с: {0}", datarow[0]);
                    errorsheet.Add(datarow);
                }
            }
            if (light == true)
            {
                return(clearsheet);
            }
            if (errorsheet.Count > 1)
            {
                Console.WriteLine("Записи приведённый выше не распарсились, возможно в них есть ошибка или недопустимые знаки.");
                Console.WriteLine("Отправить их на стандартизацию, каждая стандартизация стоит 10 копеек: (Ввести y-Y)");
                Console.WriteLine("Или хотите исправить ошибки в исходном документе вручную: (Ввести n-N или другой символ)");

                string input = Console.ReadLine();
                if (input == "y" ^ input == "Y")
                {
                    clearsheet.AddRange(Fulldata(DaDatacon(errorsheet)));
                }
                else
                {
                    Console.ReadLine();
                    System.Environment.Exit(0);
                }
            }
            return(clearsheet);
        }