Skip to content

Commit

Permalink
testing because of merge in progress issue on my end
Browse files Browse the repository at this point in the history
  • Loading branch information
jameljoseph committed Sep 6, 2024
2 parents 824aece + 870a1f4 commit 065ea1d
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 94 deletions.
1 change: 0 additions & 1 deletion GSCFieldApp/GSCFieldApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
<Content Include="ModelResources\GSCFieldwork_v160.sqlite">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="GSCFieldApp_TemporaryKey.pfx" />
<Content Include="ModelResources\GSCFieldwork_v170.gpkg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
2 changes: 1 addition & 1 deletion GSCFieldApp/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" IgnorableNamespaces="uap mp uap3 iot">
<Identity Name="NaturalResourcesCanada.GeologicalSurveyCanadaField" Publisher="CN=jjoseph" Version="2.4.16.0" />
<Identity Name="NaturalResourcesCanada.GeologicalSurveyCanadaField" Publisher="CN=Geological Survey of Canada, O=Natural Resources Canada, C=CA" Version="2.4.1.0" />
<mp:PhoneIdentity PhoneProductId="06e90cbe-1a34-4205-8fe6-3ce0ad4467db" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>Geological Survey Canada Field Application</DisplayName>
Expand Down
11 changes: 8 additions & 3 deletions GSCFieldApp/ViewModels/FieldBookDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +23,7 @@ public class FieldBookDialogViewModel : ViewModelBase
public FieldBooks existingUserDetail;

//UI
private List<Themes.ComboBoxItem> _projectType = new List<Themes.ComboBoxItem>();
private ObservableCollection<Themes.ComboBoxItem> _projectType = new ObservableCollection<Themes.ComboBoxItem>();
private string _selectedProjectType = string.Empty;
private string _startStationNumber = "1";
private string _projectName = string.Empty;
Expand Down Expand Up @@ -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<Themes.ComboBoxItem> ProjectType { get { return _projectType; } set { _projectType = value; } }
public ObservableCollection<Themes.ComboBoxItem> 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; } }

Expand All @@ -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");
Expand Down Expand Up @@ -259,6 +263,7 @@ public void AutoFillDialog(FieldBooks incomingData)
RaisePropertyChanged("GeologistLN");
RaisePropertyChanged("Notes");
RaisePropertyChanged("ActivityName");
RaisePropertyChanged("SelectedProjectType");

}

Expand Down
196 changes: 107 additions & 89 deletions GSCFieldApp/ViewModels/FieldBooksPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +37,7 @@ public class FieldBooksPageViewModel : ViewModelBase
#region INITIALIZATION

//UI
public ObservableCollection<FieldBooks> _projectCollection = new ObservableCollection<FieldBooks>();
private ObservableCollection<FieldBooks> _projectCollection = new ObservableCollection<FieldBooks>();
public int _selectedProjectIndex = -1;
private bool _noFieldBookWatermark = false;

Expand Down Expand Up @@ -71,6 +70,7 @@ public class FieldBooksPageViewModel : ViewModelBase
public ObservableCollection<FieldBooks> ProjectCollection
{
get { return _projectCollection; }
set { _projectCollection = value; }
}

public bool ProgressRingActive
Expand All @@ -90,9 +90,6 @@ public bool ProgressRingVisibility

public FieldBooksPageViewModel()
{
_projectCollection = new ObservableCollection<FieldBooks>();
RaisePropertyChanged("ProjectCollection");

//Fill list view of projects
FillProjectCollectionAsync();

Expand All @@ -119,116 +116,135 @@ private void FieldBookDialog_newFieldBookSaved(object sender, EventArgs e)
/// <summary>
/// Will fill the project collection with information related to it
/// </summary>
private async void FillProjectCollectionAsync()
private async Task FillProjectCollectionAsync()
{
_projectCollection.Clear();
_projectCollection = new ObservableCollection<FieldBooks>();
ProjectCollection = _projectCollection;
RaisePropertyChanged("ProjectCollection");
List<string> invalidFieldBookToDelete = new List<string>();

//Iterate through local state folder
IReadOnlyList<StorageFolder> localStateFolders = await ApplicationData.Current.LocalFolder.GetFoldersAsync();
IEnumerable<StorageFolder> reverseStateList = localStateFolders.Reverse();

foreach (StorageFolder sf in reverseStateList)
if (_projectCollection.Count() == 0)
{
//Get files
IReadOnlyList<StorageFile> localFiles = await sf.GetFilesAsync();
foreach (StorageFile sfi in localFiles)
//Iterate through local state folder
IReadOnlyList<StorageFolder> localStateFolders = await ApplicationData.Current.LocalFolder.GetFoldersAsync();
IEnumerable<StorageFolder> 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<StorageFile> 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<object> 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<object> 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<object> 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<object> 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<int> 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<int> locationCountResult = accessData.ReadScalarFromDBConnectionWithoutClosingConnection(queryLocation, currentConnection);
if (locationCountResult != null && locationCountResult.Count() > 0)
{
currentDB.StationNumber = locationCountResult[0].ToString();
}
else
{
currentDB.StationNumber = 0.ToString();
}

#endregion
_projectCollection.Add(currentDB);

currentConnection.Close();
GC.Collect();
GC.WaitForPendingFinalizers();
#endregion

System.Runtime.InteropServices.Marshal.ReleaseComObject(sfi);
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);
}
}

}
Expand Down Expand Up @@ -666,6 +682,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;
});
Expand Down Expand Up @@ -715,6 +732,7 @@ private void ViewModel_projectEdit(object sender)
//Refresh page
FillProjectCollectionAsync();

RaisePropertyChanged("ProjectCollection");
}

/// <summary>
Expand Down

0 comments on commit 065ea1d

Please sign in to comment.