Esempio n. 1
0
        private void dataGridViewMap_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0)
            {
                return;
            }
            if (e.RowIndex < 0)
            {
                return;
            }

            if (isDataGridViewMaps_CellValueChanging)
            {
                return;                                       //Avoid requirng isues
            }
            if (GlobalData.IsApplicationClosing)
            {
                return;
            }

            DataGridView dataGridView = ((DataGridView)sender);

            if (!dataGridView.Enabled)
            {
                return;
            }
            if (GlobalData.IsPopulatingMapLocation)
            {
                return;
            }
            if (DataGridViewHandler.GetIsPopulatingFile(dataGridView))
            {
                return;
            }
            if (DataGridViewHandler.GetIsPopulating(dataGridView))
            {
                return;
            }


            DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, e.ColumnIndex);

            if (dataGridViewGenericColumn?.Metadata == null)
            {
                return;
            }
            DataGridViewGenericRow gridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, e.RowIndex);

            isDataGridViewMaps_CellValueChanging = true;
            ///////////////////////////////////////////////////////////////////////////
            /// Coordinate changes, updated Nomnatatim address
            ///////////////////////////////////////////////////////////////////////////
            if (gridViewGenericRow.HeaderName.Equals(DataGridViewHandlerMap.headerMedia) &&
                gridViewGenericRow.RowName.Equals(DataGridViewHandlerMap.tagMediaCoordinates))
            {
                string coordinate = DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridViewMap, e.ColumnIndex, e.RowIndex);
                UpdateBrowserMap(coordinate, GetMapProvider());

                DataGridViewGenericColumn dataGridViewGenericColumnLookup = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewMap, e.ColumnIndex);
                AddQueueLazyLoadingMapNomnatatimLock(dataGridViewGenericColumnLookup.FileEntryAttribute, forceReloadUsingReverseGeocoder: false);

                DataGridViewHandlerDate.PopulateTimeZone(dataGridViewDate, null, dataGridViewGenericColumn.FileEntryAttribute);
            }

            ///////////////////////////////////////////////////////////////////////////
            /// Camera make and model owner changed, upated all fields
            ///////////////////////////////////////////////////////////////////////////

            else if (gridViewGenericRow.HeaderName.Equals(DataGridViewHandlerMap.headerGoogleLocations) &&
                     gridViewGenericRow.RowName.Equals(DataGridViewHandlerMap.tagCameraOwner))
            {
                string selectedCameraOwner = DataGridViewHandlerMap.GetUserInputCameraOwner(dataGridView, e.ColumnIndex);

                DataGridViewHandlerMap.SetCameraOwner(dataGridView, e.ColumnIndex, selectedCameraOwner);
                if (!string.IsNullOrWhiteSpace(selectedCameraOwner))
                {
                    if (dataGridViewGenericColumn.Metadata != null)
                    {
                        CameraOwner cameraOwner = new CameraOwner(
                            dataGridViewGenericColumn.Metadata.CameraMake,
                            dataGridViewGenericColumn.Metadata.CameraModel,
                            selectedCameraOwner);

                        databaseAndCahceCameraOwner.SaveCameraMakeModelAndOwner(cameraOwner);
                        databaseAndCahceCameraOwner.CameraMakeModelAndOwnerMakeDirty();

                        for (int columnIndex = 0; columnIndex < DataGridViewHandler.GetColumnCount(dataGridViewMap); columnIndex++)
                        {
                            DataGridViewGenericColumn gridViewGenericColumnCheck = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex);

                            if (gridViewGenericColumnCheck?.Metadata == null)
                            {
                                //DEBUG
                            }
                            if (dataGridViewGenericColumn.Metadata == null)
                            {
                                //DEBUG
                            }
                            if (gridViewGenericColumnCheck?.Metadata?.CameraMake == dataGridViewGenericColumn.Metadata.CameraMake &&
                                gridViewGenericColumnCheck?.Metadata?.CameraModel == dataGridViewGenericColumn.Metadata.CameraModel)
                            {
                                DataGridViewHandlerMap.PopulateCameraOwner(dataGridView, columnIndex, gridViewGenericColumnCheck.ReadWriteAccess,
                                                                           gridViewGenericColumnCheck?.Metadata?.CameraMake, gridViewGenericColumnCheck?.Metadata?.CameraModel);
                                DataGridViewHandlerMap.PopulateGoogleHistoryCoordinateAndNearby(dataGridView, dataGridViewDate, columnIndex, GetTimeZoneShift(), GetAccepedIntervalSecound());
                            }
                        }
                    }
                }
            }

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

            if (gridViewGenericRow.HeaderName.Equals(DataGridViewHandlerMap.headerNominatim))
            {
                LocationCoordinate locationCoordinateNomnatatim = DataGridViewHandlerMap.GetUserInputLocationCoordinate(dataGridViewMap, e.ColumnIndex, null);
                bool createNewAccurateLocation = DataGridViewHandlerMap.GetUserInputIsCreateNewAccurateLocationUsingSearchLocation(dataGridViewMap, e.ColumnIndex, null);

                if (locationCoordinateNomnatatim != null)
                {
                    #region Get Coordinateds enter by user
                    LocationCoordinate locationCoordinateSearch = new LocationCoordinate(
                        (float)locationCoordinateNomnatatim.Latitude,
                        (float)locationCoordinateNomnatatim.Longitude);
                    #endregion

                    #region Get Coordinates use to store in database
                    LocationCoordinateAndDescription locationCoordinateAndDescriptionFromDatabase = databaseLocationNameAndLookUp.ReadLocationNameFromDatabaseOrCache(
                        locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude);
                    #endregion

                    #region Find nearby location in Datbase
                    LocationCoordinate locationCoordinateFromDatabase;
                    if (locationCoordinateAndDescriptionFromDatabase != null && !createNewAccurateLocation)
                    {
                        locationCoordinateFromDatabase = locationCoordinateAndDescriptionFromDatabase.Coordinate; //If exist, updated
                    }
                    else
                    {
                        locationCoordinateFromDatabase = locationCoordinateSearch; //If not, create new
                    }
                    LocationCoordinateAndDescription locationCoordinateAndDescriptionUpdated =
                        new LocationCoordinateAndDescription
                        (
                            locationCoordinateSearch,
                            new LocationDescription(
                                (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagLocationName), //Name
                                (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagCity),         //City
                                (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagProvince),     //State
                                (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagCountry))      //Country
                        );
                    #endregion

                    #region Updated the database
                    databaseLocationNameAndLookUp.AddressUpdate(locationCoordinateFromDatabase,
                                                                locationCoordinateAndDescriptionUpdated, locationAccuracyLatitude, locationAccuracyLongitude);
                    #endregion

                    #region Updated DataGridView with new data
                    for (int columnIndex = 0; columnIndex < dataGridViewMap.ColumnCount; columnIndex++)
                    {
                        DataGridViewGenericColumn dataGridViewGenericColumnLookup = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewMap, columnIndex);
                        AddQueueLazyLoadingMapNomnatatimLock(dataGridViewGenericColumnLookup.FileEntryAttribute, forceReloadUsingReverseGeocoder: false);
                    }
                    #endregion
                }
            }

            isDataGridViewMaps_CellValueChanging = false;
        }
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;
            }
        }