diff --git a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs index 04f0d519..53afc9bc 100644 --- a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs +++ b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs @@ -810,11 +810,6 @@ public async void ProjectRestore_Tapped(object sender, Windows.UI.Xaml.Input.Tap isRestoreFromZip = true; } - //if (inFile.FileType.Contains("SQLite")) - //{ - // ConvertSQLiteToGeoPackage(inFile.Name, fieldProjectPath + "/" + inFile.Name + ".gpkg"); - //} - //Connect to the new database IReadOnlyList storageFiles = await newFieldBookFolder.GetFilesAsync(); StorageFile wantedDB = null; @@ -861,32 +856,49 @@ public async void ProjectRestore_Tapped(object sender, Windows.UI.Xaml.Input.Tap //Fill in current setting and change field book. IEnumerable metadata_raw = accessData.ReadTableFromDBConnection(metadataModel.GetType(), string.Empty, loadedDBConnection); IEnumerable metadataTable = metadata_raw.Cast(); - Metadata metItem = metadataTable.First() as Metadata; - //Display a warning for version validation - if (metItem.VersionSchema != DatabaseLiterals.DBVersion.ToString()) + if (metadataTable != null && metadataTable.Count() > 0) { - // Language localization using Resource.resw - var local = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); + Metadata metItem = metadataTable.First() as Metadata; - await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => + //Display a warning for version validation + if (metItem.VersionSchema != DatabaseLiterals.DBVersion.ToString()) { - ContentDialog outDatedVersionDialog = new ContentDialog() + // Language localization using Resource.resw + var local = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); + + await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { - Title = local.GetString("WarningBadVersionTitle"), - Content = local.GetString("WarningBadVersionContent"), - PrimaryButtonText = local.GetString("GenericDialog_ButtonOK") - }; - outDatedVersionDialog.Style = (Style)Application.Current.Resources["WarningDialog"]; - await Services.ContentDialogMaker.CreateContentDialogAsync(outDatedVersionDialog, false); + ContentDialog outDatedVersionDialog = new ContentDialog() + { + Title = local.GetString("WarningBadVersionTitle"), + Content = local.GetString("WarningBadVersionContent"), + PrimaryButtonText = local.GetString("GenericDialog_ButtonOK") + }; + outDatedVersionDialog.Style = (Style)Application.Current.Resources["WarningDialog"]; + await Services.ContentDialogMaker.CreateContentDialogAsync(outDatedVersionDialog, false); + + }).AsTask(); - }).AsTask(); + } + + OpenFieldBook(fieldProjectPath, metItem.FieldworkType, metItem.UserCode, + metItem.MetaID, wantedDB.Path, metItem.VersionSchema, metItem.ProjectName, metItem.MetadataActivity, false); + FillProjectCollectionAsync(); + } + else + { + ContentDialog missingMetadataDialog = new ContentDialog() + { + Title = loadLocalization.GetString("Generic_MessageErrorTitle"), + Content = loadLocalization.GetString("UpgradeErrorMetadataContent"), + CloseButtonText = loadLocalization.GetString("GenericCloseLabel/Label"), + }; + missingMetadataDialog.Style = (Style)Application.Current.Resources["DeleteDialog"]; + ContentDialogResult cdr = await missingMetadataDialog.ShowAsync(); } - OpenFieldBook(fieldProjectPath, metItem.FieldworkType, metItem.UserCode, - metItem.MetaID, wantedDB.Path, metItem.VersionSchema, metItem.ProjectName, metItem.MetadataActivity, false); - FillProjectCollectionAsync(); }