private void LocationDialog_Unloaded(object sender, RoutedEventArgs e)
        {
            //Detect manual entry, if it's the case pop station dialog
            if (locationVM.entryType == Dictionaries.DatabaseLiterals.locationEntryTypeManual && locationVM.doLocationUpdate == false && !isBackButtonPressed)
            {
                //Create a field note report to act like a parent
                FieldNotes stationParent = new FieldNotes();
                stationParent.location         = locationVM.locationModel;
                stationParent.GenericAliasName = locationVM.LocationAlias;
                stationParent.GenericID        = locationVM.LocationID;
                stationParent.GenericID        = Dictionaries.DatabaseLiterals.TableLocation;

                //Create a map point
                var modal = Window.Current.Content as ModalDialog;
                var view  = modal.ModalContent as Views.StationDataPart;
                modal.ModalContent             = view = new Views.StationDataPart(stationParent, false);
                view.mapPosition               = locationVM.locationModel;
                view.ViewModel.newStationEdit += locationVM.NavigateToReportAsync; //Detect when the add/edit request has finished.
                modal.IsModal = true;

                DataLocalSettings dLocalSettings = new DataLocalSettings();
                dLocalSettings.SetSettingValue("forceNoteRefresh", true);
            }
            else
            {
                locationVM.newLocationEdit += locationVM.NavigateToReportAsync;
            }
        }
        /// <summary>
        /// Will close the modal dialog.
        /// </summary>
        public void CloseControl()
        {
            //Get the current window and cast it to a UserInfoPart ModalDialog and shut it down.
            WindowWrapper.Current().Dispatcher.Dispatch(() =>
            {
                var modal          = Window.Current.Content as ModalDialog;
                var view           = modal.ModalContent as FieldBookDialog;
                modal.ModalContent = view;
                modal.IsModal      = false;
            });

            //Set header visibility init
            Services.DatabaseServices.DataLocalSettings localSetting = new DataLocalSettings();
            localSetting.InitializeHeaderVisibility();
        }
        /// <summary>
        /// Will erase the initial fieldbook from local state.
        /// </summary>
        /// <returns></returns>
        public async Task DeleteInitBook()
        {
            //Get folder
            DataAccess    da = new DataAccess();
            StorageFolder currentCreatedFieldBookFolder = await StorageFolder.GetFolderFromPathAsync(da.ProjectPath);

            //Initiate a task with a timeout of a minute, in case field book is still in use in some other windows
            //this is true when a user creates a field book, add tpks, goes back to field book page, deletes it, then recreate one
            //then closes the field book dialog without saving, for some reason there is a lock that happen which prevent the folder being
            //deleted. We only need all the code to have finished and closed the database connection.
            int  timeout = 60000;
            Task t       = DeleteABook(currentCreatedFieldBookFolder); //delete a field book

            if (await Task.WhenAny(t, Task.Delay(timeout)) == t)
            {
                //Delete local settings
                Services.DatabaseServices.DataLocalSettings localSettings = new DataLocalSettings();
                localSettings.WipeUserInfoSettings();
            }
        }
        /// <summary>
        /// An option to reset the application and start a clean slate version
        /// </summary>
        public async void ResetAppAsync()
        {
            var           loadLocalization = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
            ContentDialog deleteBookDialog = new ContentDialog()
            {
                Title               = loadLocalization.GetString("SettingPageButtonResetTitle"),
                Content             = loadLocalization.GetString("SettingPageButtonResetMessage/Text"),
                PrimaryButtonText   = loadLocalization.GetString("Generic_ButtonYes/Content"),
                SecondaryButtonText = loadLocalization.GetString("Generic_ButtonNo/Content")
            };

            deleteBookDialog.Style = (Style)Application.Current.Resources["DeleteDialog"];
            ContentDialogResult cdr = await deleteBookDialog.ShowAsync();

            if (cdr == ContentDialogResult.Primary)
            {
                //Clear map page of any layers before deleting them, else they won't be.
                EventHandler settingDeleteLayerRequest = settingDeleteAllLayers;
                if (settingDeleteLayerRequest != null)
                {
                    settingDeleteLayerRequest(this, null);
                }

                //Make a copy of database
                FileServices fileService = new FileServices();
                string       newFilePath = await fileService.SaveDBCopy();

                if (newFilePath != null && newFilePath != string.Empty)
                {
                    Services.FileServices.FileServices deleteService = new Services.FileServices.FileServices();
                    Task  deleteTask = deleteService.DeleteLocalStateFileAll();
                    await deleteTask;

                    //Delete local settings
                    Services.DatabaseServices.DataLocalSettings localSettings = new DataLocalSettings();
                    localSettings.WipeUserInfoSettings();

                    Application.Current.Exit();
                }
            }
        }