Esempio n. 1
0
        private void CreateListOfLocations(Taxi_AppMain.PlaceSearchResponse places)
        {
            dgvLocations.Rows.Clear();

            if (places != null && places.Status == "OK")
            {
                //if (places.Result.Count <= 3)
                //{
                //    string[] arrV = places.Result.Select(c => c.Name + ", " + c.Formatted_address).Distinct().ToList().ToArray<string>();
                //    for (int i = 0; i < arrV.Count(); i++)
                //    {

                //        //Add items in the listview
                //        string[] arr1 = new string[1];


                //        arr1[0] = arrV[i];


                //        arr1[0] = (arr1[0].LastIndexOf(',') > 0 && (arr1[0].ToStr().ToUpper().EndsWith(", UNITED KINGDOM") || arr1[0].ToStr().ToUpper().EndsWith(", UNITED KINGDOM")) ? arr1[0].Substring(0, arr1[0].LastIndexOf(',')) : arr1[0]).ToUpper().Replace(",", "");


                //        dgvLocations.Rows.Add(arr1);


                //    }

                //    dgvLocations.Columns[0].HeaderText = string.Format("{0} Record(s) found", dgvLocations.Rows.Count);
                //}
                //else
                //{

                dgvLocations.Columns[0].HeaderText = string.Format("{0} Record(s) found", places.Result.Count());

                bool isvisible = true;
                for (int i = 0; i < places.Result.Count(); i++)
                {
                    isvisible = true;
                    string locationName = places.Result[i].Formatted_address;


                    if (places.Result[i].Name.ToStr().Trim().Length > 0 && (locationName.ToLower().StartsWith(places.Result[i].Name.ToStr().ToLower() + ", ") == false))
                    {
                        if (locationName.ToStr().Trim().ToLower() != places.Result[i].Name.ToStr().Trim().ToLower())
                        {
                            locationName = places.Result[i].Name + ", " + places.Result[i].Formatted_address;
                        }
                    }
                    locationName = (locationName.LastIndexOf(',') > 0 && (LocationName.ToStr().ToUpper().EndsWith(", UNITED KINGDOM") || LocationName.ToStr().ToUpper().EndsWith(", UNITED KINGDOM")) ? locationName.Substring(0, locationName.LastIndexOf(',')) : locationName).ToUpper().Replace(",", "");


                    string[] arr = new string[1];
                    arr[0] = locationName;


                    if (dgvLocations.Rows.Count > 0 && dgvLocations.Rows.Cast <DataGridViewRow>().Count(c => c.Cells[0].Value.ToStr().ToUpper() == locationName) > 0)
                    {
                        isvisible = false;
                    }


                    dgvLocations.Rows.Add(arr);


                    dgvLocations.Rows[i].Visible = isvisible;
                }
                //   }
            }
            if (dgvLocations.Rows.Count > 0)
            {
                dgvLocations.Rows[0].Selected = true;
                dgvLocations.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders);
            }
        }
Esempio n. 2
0
        private void SearchLocation()
        {
            try
            {
                string postCode = txtAddress.Text.Trim();
                string radius   = txtRadius.Text.Trim();
                double doubleRadius;

                if (string.IsNullOrEmpty(postCode))
                {
                    //MessageBox.Show("Please enter a PostCode");
                    ENUtils.ShowMessage("Please enter a Address");
                    return;
                }
                else if (string.IsNullOrEmpty(radius))
                {
                    ENUtils.ShowMessage("Please enter Radius.");
                    return;
                }
                else if (!double.TryParse(radius, out doubleRadius))
                {
                    ENUtils.ShowMessage("Radius must be in number.");
                    return;
                }



                stp_getCoordinatesByAddressResult baseCoordinates = null;

                if (chkWithinRadius.Checked)
                {
                    baseCoordinates = new TaxiDataContext().stp_getCoordinatesByAddress(AppVars.objPolicyConfiguration.BaseAddress.ToStr(), General.GetPostCodeMatch(AppVars.objPolicyConfiguration.BaseAddress.ToStr())).FirstOrDefault();
                }

                if (baseCoordinates != null && baseCoordinates.Latitude.HasValue && baseCoordinates.Longtiude.HasValue)
                {
                    SearchPlaces = GetDistance.SearchPlaces(postCode, new GetDistance.Coords()
                    {
                        Latitude = baseCoordinates.Latitude.Value, Longitude = baseCoordinates.Longtiude.Value
                    }, doubleRadius);

                    if (SearchPlaces != null && SearchPlaces.Status == "OK")
                    {
                        if (SearchPlaces.Result.Count > 0)
                        {
                            var result = SearchPlaces.Result[0];
                            var latLng = new PointLatLng(Convert.ToDouble(result.Geometry.Location.Lat), Convert.ToDouble(result.Geometry.Location.Lng));
                            DrawPoint(latLng);

                            dgvLocations.Visible = true;
                            CreateListOfLocations(SearchPlaces);

                            BringToFront();
                            dgvLocations.Focus();
                        }
                        else
                        {
                            dgvLocations.Columns[0].HeaderText = string.Format("{0} Record(s) found", 0);
                            dgvLocations.Rows.Clear();


                            if (gMapControl1.Overlays.Count > 0 && gMapControl1.Overlays[0].Markers.Count > 0)
                            {
                                gMapControl1.Overlays[0].Markers.Clear();
                            }
                        }
                    }
                    else
                    {
                        dgvLocations.Visible = false;
                        SearchLocation_old();
                        BringToFront();
                        txtAddress.Focus();
                    }
                }
                else
                {
                    dgvLocations.Visible = false;
                    SearchLocation_old();
                    BringToFront();
                    txtAddress.Focus();
                }
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }