Esempio n. 1
0
        private void PopulateDataGridViewMapWithBrowserCoordinate(DataGridView dataGridView, string text)
        {
            if (dataGridView.CurrentCell == null && dataGridView.SelectedCells.Count < 1)
            {
                return;
            }

            LocationCoordinate locationCoordinate = ParseCoordinateFromURL(text);

            if (locationCoordinate != null)
            {
                List <int> selectedColumns = DataGridViewHandler.GetColumnSelected(dataGridView);

                foreach (int columnIndex in selectedColumns)
                {
                    DataGridViewHandler.SetCellValue(dataGridView, columnIndex,
                                                     DataGridViewHandlerMap.headerBrowser, DataGridViewHandlerMap.tagMediaCoordinates, locationCoordinate.ToString());
                }
            }
        }
Esempio n. 2
0
        public static void PopulateGrivViewMapNomnatatim(DataGridView dataGridView, int columnIndex, LocationCoordinate locationCoordinateSearch,
                                                         bool onlyFromCache, bool canReverseGeocoder, bool forceReloadUsingReverseGeocoder, bool createNewAccurateLocationUsingSearchLocation)
        {
            GlobalData.IsPopulatingMapLocation = true;
            try
            {
                LocationCoordinateAndDescription locationCoordinateAndDescriptionInDatabase = null;

                float locationAccuracyLatitude  = Properties.Settings.Default.LocationAccuracyLatitude;
                float locationAccuracyLongitude = Properties.Settings.Default.LocationAccuracyLongitude;

                //LocationDescription locationDescription = null;
                LocationDescription locationDescription = null;

                #region Get Location Info from User when allowed
                DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex);
                if (!forceReloadUsingReverseGeocoder && dataGridViewGenericColumn?.Metadata != null)
                {
                    #region Get UserInput Location data
                    Metadata metadataUser = new Metadata(MetadataBrokerType.Empty);
                    GetUserInputChanges(dataGridView, ref metadataUser, null, columnIndex);
                    #endregion

                    if (!string.IsNullOrEmpty(metadataUser.LocationName) || !string.IsNullOrEmpty(metadataUser.LocationCity) ||
                        !string.IsNullOrEmpty(metadataUser.LocationState) || !string.IsNullOrEmpty(metadataUser.LocationCountry))
                    {
                        locationDescription = new LocationDescription(metadataUser.LocationName, metadataUser.LocationCity, metadataUser.LocationState, metadataUser.LocationCountry);

                        #region createNewAccurateLocationUsingSearchLocation
                        if (createNewAccurateLocationUsingSearchLocation)
                        {
                            try
                            {
                                LocationCoordinateAndDescription locationCoordinateAndDescriptionFromUserInput = new LocationCoordinateAndDescription(
                                    locationCoordinateSearch, locationDescription);
                                DatabaseAndCacheLocationAddress.WriteLocationName(locationCoordinateSearch, locationCoordinateAndDescriptionFromUserInput);

                                dataGridView.EndEdit();
                                //Remove + sign
                                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagMediaCoordinates,
                                                                                             ReadWriteAccess.AllowCellReadAndWrite), locationCoordinateSearch.ToString(), false);
                            }
                            catch
                            {
                                //DEBUG
                            }
                        }
                        #endregion
                    }
                }
                #endregion

                if (locationCoordinateSearch != null)
                {
                    #region Get Nearby Location Coordinate and Info in Database
                    locationCoordinateAndDescriptionInDatabase = DatabaseAndCacheLocationAddress.AddressLookupAndReverseGeocoder(
                        locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude, onlyFromCache: onlyFromCache,
                        canReverseGeocoder: canReverseGeocoder, metadataLocationDescription: locationDescription, forceReloadUsingReverseGeocoder: false);
                    #endregion



                    #region If Asked to Reload, reload from UsingReverseGeocoder
                    if (forceReloadUsingReverseGeocoder && locationCoordinateAndDescriptionInDatabase != null)
                    {
                        locationCoordinateAndDescriptionInDatabase = DatabaseAndCacheLocationAddress.AddressLookupAndReverseGeocoder(
                            locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude, onlyFromCache: false,
                            canReverseGeocoder: true, metadataLocationDescription: null, forceReloadUsingReverseGeocoder: true);
                    }
                    #endregion
                }
                else
                {
                    #region No coordinates found
                    AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagMediaCoordinates,
                                                                                 ReadWriteAccess.AllowCellReadAndWrite), null, false);
                    #endregion
                }
                #region Show Tooltip when Use need Nearby coordinate
                int rowIndex = DataGridViewHandler.GetRowIndex(dataGridView, headerMedia, tagMediaCoordinates);
                if (locationCoordinateAndDescriptionInDatabase != null && locationCoordinateSearch != locationCoordinateAndDescriptionInDatabase.Coordinate)
                {
                    DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Near by location used: " + locationCoordinateAndDescriptionInDatabase.Coordinate.ToString());
                }
                else
                {
                    DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "");
                }
                #endregion

                #region No data location data loaded, set as readonly
                bool isReadOnly = (locationCoordinateAndDescriptionInDatabase == null);
                #endregion

                #region Updated DataGridView with new data
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagLocationName, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.Name, isReadOnly);
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagCity, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.City, isReadOnly);
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagProvince, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.Region, isReadOnly);
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagCountry, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.Country, isReadOnly);
                #endregion
            }
            catch (Exception ex)
            {
                KryptonMessageBox.Show("Unexpected error occur.\r\nException message:" + ex.Message + "\r\n",
                                       "Unexpected error occur", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true);
            }
            finally
            {
                GlobalData.IsPopulatingMapLocation = false;
            }
        }