From 1277a0e982e5c9f6aca7379d70c4d719ff77ab20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gabriel=2Ehuot-v=C3=A9zina?= Date: Thu, 20 Jun 2024 13:36:41 -0400 Subject: [PATCH 1/5] #354 fixed not updatable project type in field book. --- GSCFieldApp/ViewModels/FieldBookDialogViewModel.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/GSCFieldApp/ViewModels/FieldBookDialogViewModel.cs b/GSCFieldApp/ViewModels/FieldBookDialogViewModel.cs index 79b5839c..0325ef82 100644 --- a/GSCFieldApp/ViewModels/FieldBookDialogViewModel.cs +++ b/GSCFieldApp/ViewModels/FieldBookDialogViewModel.cs @@ -4,6 +4,7 @@ using SQLite; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Threading.Tasks; using Template10.Common; using Template10.Mvvm; @@ -22,7 +23,7 @@ public class FieldBookDialogViewModel : ViewModelBase public FieldBooks existingUserDetail; //UI - private List _projectType = new List(); + private ObservableCollection _projectType = new ObservableCollection(); private string _selectedProjectType = string.Empty; private string _startStationNumber = "1"; private string _projectName = string.Empty; @@ -119,7 +120,7 @@ public string StartStationNumber public string ActivityName { get { return _activityName; } set { _activityName = value; } } public string Notes { get { return _notes; } set { _notes = value; } } - public List ProjectType { get { return _projectType; } set { _projectType = value; } } + public ObservableCollection ProjectType { get { return _projectType; } set { _projectType = value; } } public string SelectedProjectType { get { return _selectedProjectType; } set { _selectedProjectType = value; } } public bool Enability { get { return _enability; } set { _enability = value; } } @@ -141,7 +142,10 @@ private void FillProjectType() //Init. string fieldName = Dictionaries.DatabaseLiterals.FieldUserInfoFWorkType; - _projectType = accessData.GetComboboxListWithVocab(userTable, fieldName, out _selectedProjectType); + foreach (var pType in accessData.GetComboboxListWithVocab(userTable, fieldName, out _selectedProjectType)) + { + _projectType.Add(pType); + } //Update UI RaisePropertyChanged("ProjectType"); @@ -259,6 +263,7 @@ public void AutoFillDialog(FieldBooks incomingData) RaisePropertyChanged("GeologistLN"); RaisePropertyChanged("Notes"); RaisePropertyChanged("ActivityName"); + RaisePropertyChanged("SelectedProjectType"); } From 4d91395456776d66d5b73ce746070f3eee0d1504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gabriel=2Ehuot-v=C3=A9zina?= Date: Thu, 20 Jun 2024 20:25:09 -0400 Subject: [PATCH 2/5] #345 testing code to fix issue in field books. Without luck. --- .../ViewModels/FieldBooksPageViewModel.cs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs index e44b115c..60c693fb 100644 --- a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs +++ b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs @@ -38,7 +38,7 @@ public class FieldBooksPageViewModel : ViewModelBase #region INITIALIZATION //UI - public ObservableCollection _projectCollection = new ObservableCollection(); + private ObservableCollection _projectCollection = new ObservableCollection(); public int _selectedProjectIndex = -1; private bool _noFieldBookWatermark = false; @@ -71,6 +71,7 @@ public class FieldBooksPageViewModel : ViewModelBase public ObservableCollection ProjectCollection { get { return _projectCollection; } + set { _projectCollection = value; } } public bool ProgressRingActive @@ -90,11 +91,8 @@ public bool ProgressRingVisibility public FieldBooksPageViewModel() { - _projectCollection = new ObservableCollection(); - RaisePropertyChanged("ProjectCollection"); - //Fill list view of projects - FillProjectCollectionAsync(); + _ = FillProjectCollectionAsync(); //Detect new field book save GSCFieldApp.Views.FieldBookDialog.newFieldBookSaved -= FieldBookDialog_newFieldBookSaved; @@ -119,9 +117,9 @@ private void FieldBookDialog_newFieldBookSaved(object sender, EventArgs e) /// /// Will fill the project collection with information related to it /// - private async void FillProjectCollectionAsync() + private async Task> FillProjectCollectionAsync() { - _projectCollection.Clear(); + _projectCollection = new ObservableCollection(); RaisePropertyChanged("ProjectCollection"); List invalidFieldBookToDelete = new List(); @@ -189,16 +187,15 @@ private async void FillProjectCollectionAsync() { currentDB.StationNumber = 0.ToString(); } - + #endregion - _projectCollection.Add(currentDB); + if (!_projectCollection.Contains(currentDB)) + { + _projectCollection.Add(currentDB); + } currentConnection.Close(); - GC.Collect(); - GC.WaitForPendingFinalizers(); - - System.Runtime.InteropServices.Marshal.ReleaseComObject(sfi); break; //Forget about other files } @@ -207,7 +204,7 @@ private async void FillProjectCollectionAsync() } //Refresh UI - RaisePropertyChanged("ProjectCollection"); + //RaisePropertyChanged("ProjectCollection"); //Select the current active project, so it's highlighted in the list view ResourceLoader loadLocal = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); @@ -231,6 +228,7 @@ private async void FillProjectCollectionAsync() fieldBooksUpdate?.Invoke(this, true); } + return _projectCollection; } /// @@ -396,7 +394,7 @@ public async void DeleteFieldBook() } //Refresh page - FillProjectCollectionAsync(); + _ =FillProjectCollectionAsync(); } @@ -713,8 +711,9 @@ public async void ProjectDeleteButton_TappedAsync(object sender, Windows.UI.Xaml private void ViewModel_projectEdit(object sender) { //Refresh page - FillProjectCollectionAsync(); + _ =FillProjectCollectionAsync(); + RaisePropertyChanged("ProjectCollection"); } /// @@ -868,7 +867,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch SetFieldBook(restFieldBook); - FillProjectCollectionAsync(); + _ = FillProjectCollectionAsync(); } else { @@ -1149,7 +1148,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch private void upgradedDBDialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args) { //Send call to refresh other pages - FillProjectCollectionAsync(); + _ = FillProjectCollectionAsync(); EventHandler newFieldBookRequest = newFieldBookSelected; if (newFieldBookRequest != null) { From ee837376cf8f85e23363fe4c557e368e68d7e0a0 Mon Sep 17 00:00:00 2001 From: "gabriel.huot-vezina" Date: Thu, 20 Jun 2024 21:48:45 -0400 Subject: [PATCH 3/5] #345 fixed duplicate fb, had to remove event trigger. --- GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs index 60c693fb..57256ff6 100644 --- a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs +++ b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs @@ -664,6 +664,7 @@ public void ProjectEditButton_Tapped(object sender, Windows.UI.Xaml.Input.Tapped var modal = Window.Current.Content as ModalDialog; var view = modal.ModalContent as Views.FieldBookDialog; modal.ModalContent = view = new Views.FieldBookDialog(selectedProject); + view.ViewModel.projectEdit -= ViewModel_projectEdit; view.ViewModel.projectEdit += ViewModel_projectEdit; modal.IsModal = true; }); From 71d20e9af83fc6dff271971a70ec5ca1007047b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gabriel=2Ehuot-v=C3=A9zina?= Date: Fri, 21 Jun 2024 10:56:36 -0400 Subject: [PATCH 4/5] Yet another fix for #345, it was still duplicating fbs. --- .../ViewModels/FieldBooksPageViewModel.cs | 196 ++++++++++-------- 1 file changed, 107 insertions(+), 89 deletions(-) diff --git a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs index 57256ff6..623b140b 100644 --- a/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs +++ b/GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs @@ -19,7 +19,6 @@ using Windows.Storage.Pickers; using Windows.UI.Core; using Template10.Utils; -using System.Diagnostics; using Esri.ArcGISRuntime.Geometry; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -92,7 +91,7 @@ public bool ProgressRingVisibility public FieldBooksPageViewModel() { //Fill list view of projects - _ = FillProjectCollectionAsync(); + FillProjectCollectionAsync(); //Detect new field book save GSCFieldApp.Views.FieldBookDialog.newFieldBookSaved -= FieldBookDialog_newFieldBookSaved; @@ -117,118 +116,137 @@ private void FieldBookDialog_newFieldBookSaved(object sender, EventArgs e) /// /// Will fill the project collection with information related to it /// - private async Task> FillProjectCollectionAsync() + private async Task FillProjectCollectionAsync() { _projectCollection = new ObservableCollection(); + ProjectCollection = _projectCollection; RaisePropertyChanged("ProjectCollection"); List invalidFieldBookToDelete = new List(); - //Iterate through local state folder - IReadOnlyList localStateFolders = await ApplicationData.Current.LocalFolder.GetFoldersAsync(); - IEnumerable reverseStateList = localStateFolders.Reverse(); - - foreach (StorageFolder sf in reverseStateList) + if (_projectCollection.Count() == 0) { - //Get files - IReadOnlyList localFiles = await sf.GetFilesAsync(); - foreach (StorageFile sfi in localFiles) + //Iterate through local state folder + IReadOnlyList localStateFolders = await ApplicationData.Current.LocalFolder.GetFoldersAsync(); + IEnumerable reverseStateList = localStateFolders.Reverse(); + + foreach (StorageFolder sf in reverseStateList) { - //Get the database - if ((sfi.FileType.Contains(DatabaseLiterals.DBTypeSqlite) || sfi.FileType.Contains(DatabaseLiterals.DBTypeSqliteDeprecated)) - && sfi.DisplayName == DatabaseLiterals.DBName) + //Get files + IReadOnlyList localFiles = await sf.GetFilesAsync(); + foreach (StorageFile sfi in localFiles) { - FieldBooks currentDB = new FieldBooks(); - - using (SQLiteConnection currentConnection = accessData.GetConnectionFromPath(sfi.Path)) + //Get the database + if ((sfi.FileType.Contains(DatabaseLiterals.DBTypeSqlite) || sfi.FileType.Contains(DatabaseLiterals.DBTypeSqliteDeprecated)) + && sfi.DisplayName == DatabaseLiterals.DBName) { - List metadataTableRows = accessData.ReadTableFromDBConnectionWithoutClosingConnection(metadataModel.GetType(), string.Empty, currentConnection); - foreach (object m in metadataTableRows) + FieldBooks currentDB = new FieldBooks(); + + using (SQLiteConnection currentConnection = accessData.GetConnectionFromPath(sfi.Path)) { - //For metadata - Metadata met = m as Metadata; - currentDB.CreateDate = met.StartDate; - currentDB.GeologistGeolcode = met.Geologist + "[" + met.UserCode + "]"; - //currentDB.metadataForProject.FieldworkType = met.FieldworkType; - //currentDB.metadataForProject.MetaID = met.MetaID; - currentDB.ProjectPath = Path.GetDirectoryName(sfi.Path); - currentDB.ProjectDBPath = sfi.Path; - currentDB.metadataForProject = m as Metadata; - } + List metadataTableRows = accessData.ReadTableFromDBConnectionWithoutClosingConnection(metadataModel.GetType(), string.Empty, currentConnection); + foreach (object m in metadataTableRows) + { + //For metadata + Metadata met = m as Metadata; + currentDB.CreateDate = met.StartDate; + currentDB.GeologistGeolcode = met.Geologist + "[" + met.UserCode + "]"; + //currentDB.metadataForProject.FieldworkType = met.FieldworkType; + //currentDB.metadataForProject.MetaID = met.MetaID; + currentDB.ProjectPath = Path.GetDirectoryName(sfi.Path); + currentDB.ProjectDBPath = sfi.Path; + currentDB.metadataForProject = m as Metadata; + } - #region For stations - string stationQuerySelect = "SELECT *"; - string stationQueryFrom = " FROM " + DatabaseLiterals.TableStation; - string stationQueryWhere = " WHERE " + DatabaseLiterals.TableStation + "." + DatabaseLiterals.FieldStationAlias + " NOT LIKE '%" + DatabaseLiterals.KeywordStationWaypoint + "%'"; - string stationQueryFinal = stationQuerySelect + stationQueryFrom + stationQueryWhere; - List stationCountResult = accessData.ReadTableFromDBConnectionWithoutClosingConnection(stationModel.GetType(), stationQueryFinal, currentConnection); + #region For stations + string stationQuerySelect = "SELECT *"; + string stationQueryFrom = " FROM " + DatabaseLiterals.TableStation; + string stationQueryWhere = " WHERE " + DatabaseLiterals.TableStation + "." + DatabaseLiterals.FieldStationAlias + " NOT LIKE '%" + DatabaseLiterals.KeywordStationWaypoint + "%'"; + string stationQueryFinal = stationQuerySelect + stationQueryFrom + stationQueryWhere; + List stationCountResult = accessData.ReadTableFromDBConnectionWithoutClosingConnection(stationModel.GetType(), stationQueryFinal, currentConnection); - if (stationCountResult.Count != 0) - { - Station lastStation = (Station)stationCountResult[stationCountResult.Count - 1]; - currentDB.StationLastEntered = lastStation.StationAlias; - } + if (stationCountResult.Count != 0) + { + Station lastStation = (Station)stationCountResult[stationCountResult.Count - 1]; + currentDB.StationLastEntered = lastStation.StationAlias; + } - //If field book is invalid keep parent folder path at least user will be able to delete it. - if (metadataTableRows.Count == 0 && stationCountResult.Count == 0) - { - StorageFolder parentFolder = await sfi.GetParentAsync(); - currentDB.ProjectPath = parentFolder.Path; - } - #endregion + //If field book is invalid keep parent folder path at least user will be able to delete it. + if (metadataTableRows.Count == 0 && stationCountResult.Count == 0) + { + StorageFolder parentFolder = await sfi.GetParentAsync(); + currentDB.ProjectPath = parentFolder.Path; + } + #endregion - #region For locations - string queryLocation = "select count(*) from " + DatabaseLiterals.TableLocation; - List locationCountResult = accessData.ReadScalarFromDBConnectionWithoutClosingConnection(queryLocation, currentConnection); - if (locationCountResult != null && locationCountResult.Count() > 0) - { - currentDB.StationNumber = locationCountResult[0].ToString(); - } - else - { - currentDB.StationNumber = 0.ToString(); - } + #region For locations + string queryLocation = "select count(*) from " + DatabaseLiterals.TableLocation; + List locationCountResult = accessData.ReadScalarFromDBConnectionWithoutClosingConnection(queryLocation, currentConnection); + if (locationCountResult != null && locationCountResult.Count() > 0) + { + currentDB.StationNumber = locationCountResult[0].ToString(); + } + else + { + currentDB.StationNumber = 0.ToString(); + } - #endregion - if (!_projectCollection.Contains(currentDB)) - { - _projectCollection.Add(currentDB); - } + #endregion - currentConnection.Close(); + currentConnection.Close(); - break; //Forget about other files + if (!_projectCollection.Contains(currentDB)) + { + //Detect duplicates + bool foundDup = false; + foreach (FieldBooks fbs in _projectCollection) + { + if (fbs.ProjectDBPath == currentDB.ProjectDBPath) + { + foundDup = true; break; + } + } + + if (!foundDup) + { + _projectCollection.Add(currentDB); + } + + } + + break; //Forget about other files + + } } } } - } - //Refresh UI - //RaisePropertyChanged("ProjectCollection"); + //Refresh UI + RaisePropertyChanged("ProjectCollection"); - //Select the current active project, so it's highlighted in the list view - ResourceLoader loadLocal = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); - if (_projectCollection.Count == 0) - { + //Select the current active project, so it's highlighted in the list view + ResourceLoader loadLocal = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); + if (_projectCollection.Count == 0) + { - _noFieldBookWatermark = true; - RaisePropertyChanged("NoFieldBookWatermark"); + _noFieldBookWatermark = true; + RaisePropertyChanged("NoFieldBookWatermark"); - //Send event about missing field books. - fieldBooksUpdate?.Invoke(this, false); + //Send event about missing field books. + fieldBooksUpdate?.Invoke(this, false); - } - else - { - SelectActiveProject(); - _noFieldBookWatermark = false; - RaisePropertyChanged("NoFieldBookWatermark"); + } + else + { + SelectActiveProject(); + _noFieldBookWatermark = false; + RaisePropertyChanged("NoFieldBookWatermark"); - //Send event about missing field books. - fieldBooksUpdate?.Invoke(this, true); + //Send event about missing field books. + fieldBooksUpdate?.Invoke(this, true); + } } - return _projectCollection; } /// @@ -394,7 +412,7 @@ public async void DeleteFieldBook() } //Refresh page - _ =FillProjectCollectionAsync(); + FillProjectCollectionAsync(); } @@ -712,7 +730,7 @@ public async void ProjectDeleteButton_TappedAsync(object sender, Windows.UI.Xaml private void ViewModel_projectEdit(object sender) { //Refresh page - _ =FillProjectCollectionAsync(); + FillProjectCollectionAsync(); RaisePropertyChanged("ProjectCollection"); } @@ -868,7 +886,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch SetFieldBook(restFieldBook); - _ = FillProjectCollectionAsync(); + FillProjectCollectionAsync(); } else { @@ -1149,7 +1167,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch private void upgradedDBDialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args) { //Send call to refresh other pages - _ = FillProjectCollectionAsync(); + FillProjectCollectionAsync(); EventHandler newFieldBookRequest = newFieldBookSelected; if (newFieldBookRequest != null) { From 870a1f4b81f35e6a46516193b8254c913dc1a5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gabriel=2Ehuot-v=C3=A9zina?= Date: Fri, 21 Jun 2024 10:57:00 -0400 Subject: [PATCH 5/5] version 2.4.2 --- GSCFieldApp/GSCFieldApp.csproj | 1 - GSCFieldApp/Package.appxmanifest | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/GSCFieldApp/GSCFieldApp.csproj b/GSCFieldApp/GSCFieldApp.csproj index 4fc4265e..10a46cd0 100644 --- a/GSCFieldApp/GSCFieldApp.csproj +++ b/GSCFieldApp/GSCFieldApp.csproj @@ -147,7 +147,6 @@ Always - Always diff --git a/GSCFieldApp/Package.appxmanifest b/GSCFieldApp/Package.appxmanifest index 29dfdc75..454c4355 100644 --- a/GSCFieldApp/Package.appxmanifest +++ b/GSCFieldApp/Package.appxmanifest @@ -1,7 +1,7 @@  - - + + Geological Survey Canada Field Application Natural Resources Canada