diff --git a/.gitignore b/.gitignore index 548f21c..0a199e1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,12 @@ /PcgsInvUi/[Oo]bj/ [Oo]bj/ [Bb]in/ +ALL_BUILD.vcxproj +ALL_BUILD.vcxproj.filters +ZERO_CHECK.vcxproj +ZERO_CHECK.vcxproj.filters +CMakeCache.txt +CMakeFiles/ +.idea/ +cmake_install.cmake +coin_collection diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..74dab4e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.25) + +project("PcgsInvUi" CSharp) + +add_subdirectory(PcgsInvUi) diff --git a/PcgsInvUi/CMakeLists.txt b/PcgsInvUi/CMakeLists.txt new file mode 100644 index 0000000..7c894f7 --- /dev/null +++ b/PcgsInvUi/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.25) + +project(PcgsInvUi LANGUAGES CSharp) + +include(CSharpUtilities) + +add_executable(PcgsInvUi + App.axaml.cs + Program.cs + ViewLocator.cs + App.axaml + app.manifest + Models/Coin.cs + Services/CoinCollection.cs + Services/CoinDatabase.cs + Services/PcgsClient.cs + ViewModels/CoinListViewModel.cs + ViewModels/DeleteWindowViewModel.cs + ViewModels/EditViewModel.cs + ViewModels/ErrorWindowViewModel.cs + ViewModels/FindWindowViewModel.cs + ViewModels/MainWindowViewModel.cs + ViewModels/NewViewModel.cs + ViewModels/ViewModelBase.cs + Views/DeleteWindow.axaml + Views/DeleteWindow.axaml.cs + Views/ErrorWindow.axaml + Views/ErrorWindow.axaml.cs + Views/FindWindow.axaml + Views/FindWindow.axaml.cs + Views/MainWindow.axaml + Views/MainWindow.axaml.cs + Views/NewView.axaml + Views/NewView.axaml.cs +) + +# Set the .NET Framework version for the executable. +set_property(TARGET PcgsInvUi PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2") +# Set the executable to be 64-bit. +set_property(TARGET PcgsInvUi PROPERTY WIN64_EXECUTABLE TRUE) +# Set the C# language version (defaults to 3.0) +set(CMAKE_CSharp_FLAGS "/langversion:latest") + +# Add the .NET reference libraries as dependencies. +set_property(TARGET PcgsInvUi PROPERTY VS_DOTNET_REFERENCES + "Microsoft.CSharp" +) diff --git a/PcgsInvUi/Services/CoinDatabase.cs b/PcgsInvUi/Services/CoinDatabase.cs index b954ef3..221d845 100644 --- a/PcgsInvUi/Services/CoinDatabase.cs +++ b/PcgsInvUi/Services/CoinDatabase.cs @@ -37,14 +37,16 @@ public class CoinDatabase { private SQLiteConnection CreateConnection() { // Check if database exists. - if (!System.IO.File.Exists("%USERPROFILE%\\coin_collection")) { + if (!System.IO.File.Exists("coin_collection")) { // Create the database. - SQLiteConnection.CreateFile("%USERPROFILE%\\coin_collection"); + Console.Write("Creating database... "); + SQLiteConnection.CreateFile("coin_collection"); + Console.WriteLine("Done."); } // Create a connection to the database. SQLiteConnection connection = - new SQLiteConnection("DataSource=%USERPROFILE%\\coin_collection"); + new SQLiteConnection("DataSource=coin_collection"); // Open the connection. try { diff --git a/PcgsInvUi/ViewModels/DeleteWindowViewModel.cs b/PcgsInvUi/ViewModels/DeleteWindowViewModel.cs index 54623cf..db4b132 100644 --- a/PcgsInvUi/ViewModels/DeleteWindowViewModel.cs +++ b/PcgsInvUi/ViewModels/DeleteWindowViewModel.cs @@ -1,15 +1,14 @@ using System.Reactive; -using PcgsInvUi.Views; using ReactiveUI; namespace PcgsInvUi.ViewModels; public class DeleteWindowViewModel : ViewModelBase { public ReactiveCommand OkCommand { get; } - public ReactiveCommand CancelCommand { get; } + public ReactiveCommand CancelCommand { get; } public DeleteWindowViewModel() { OkCommand = ReactiveCommand.Create(() => (object)true); - CancelCommand = ReactiveCommand.Create(window => window.Close()); + CancelCommand = ReactiveCommand.Create(() => (object)false); } -} \ No newline at end of file +} diff --git a/PcgsInvUi/ViewModels/EditViewModel.cs b/PcgsInvUi/ViewModels/EditViewModel.cs index 3572169..cf64977 100644 --- a/PcgsInvUi/ViewModels/EditViewModel.cs +++ b/PcgsInvUi/ViewModels/EditViewModel.cs @@ -1,5 +1,4 @@ -using System; -using System.Reactive; +using System.Reactive; using PcgsInvUi.Models; using ReactiveUI; @@ -25,4 +24,4 @@ public class EditViewModel : ViewModelBase { // Setup OkCommand - all Coin-related properties must be non-whitespace. OkCommand = ReactiveCommand.Create(() => { }); } -} \ No newline at end of file +} diff --git a/PcgsInvUi/ViewModels/ErrorWindowViewModel.cs b/PcgsInvUi/ViewModels/ErrorWindowViewModel.cs index 6d93ac2..68ed391 100644 --- a/PcgsInvUi/ViewModels/ErrorWindowViewModel.cs +++ b/PcgsInvUi/ViewModels/ErrorWindowViewModel.cs @@ -1,6 +1,4 @@ using System.Reactive; -using System.Security.Principal; -using PcgsInvUi.Views; using ReactiveUI; namespace PcgsInvUi.ViewModels; @@ -11,16 +9,15 @@ public class ErrorWindowViewModel : ViewModelBase { get => _message; set => this.RaiseAndSetIfChanged(ref _message, value); } - private string _message; - public ReactiveCommand CloseCommand { get; } + public ReactiveCommand CloseCommand { get; } public ErrorWindowViewModel(string message) { - DisplayedMessage = message; + _message = message; - CloseCommand = ReactiveCommand.Create(window => window.Close()); + CloseCommand = ReactiveCommand.Create(() => (object)false); } -} \ No newline at end of file +} diff --git a/PcgsInvUi/ViewModels/MainWindowViewModel.cs b/PcgsInvUi/ViewModels/MainWindowViewModel.cs index 05d3433..af680ba 100644 --- a/PcgsInvUi/ViewModels/MainWindowViewModel.cs +++ b/PcgsInvUi/ViewModels/MainWindowViewModel.cs @@ -10,6 +10,7 @@ using ReactiveUI; namespace PcgsInvUi.ViewModels; +// TODO Create proper sums for total value. // TODO Error handling for API calls. // TODO Manual handling of API key. // TODO Use CoinFacts link. @@ -41,7 +42,7 @@ public class MainWindowViewModel : ViewModelBase { public Interaction ShowDeleteWindow { get; } public ReactiveCommand ExportCommand { get; } public Interaction ShowExportWindow { get; } - public Interaction ShowErrorWindow { get; } + public Interaction ShowErrorWindow { get; } private ViewModelBase _sideContent; private Coin? _selectedCoin; @@ -56,7 +57,7 @@ public class MainWindowViewModel : ViewModelBase { TotalValue = DisplayedList.Sum(x => x.TotalPrice); // Set up the ability to show the error window. - ShowErrorWindow = new Interaction(); + ShowErrorWindow = new Interaction(); // Set up the ability to open the delete window. ShowDeleteWindow = new Interaction(); @@ -67,7 +68,7 @@ public class MainWindowViewModel : ViewModelBase { var result = await ShowDeleteWindow.Handle(deleteViewModel); if (result && SelectedCoin is not null) { ConnectedCoinDatabase.DeleteCoin(SelectedCoin); - ConnectedCoinDatabase.Collection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled. + ConnectedCoinDatabase.Collection.Remove(SelectedCoin); } }, deleteEnabled); @@ -83,10 +84,10 @@ public class MainWindowViewModel : ViewModelBase { catch (IOException e) { // Something is wrong with the file after it's been created. Console.WriteLine(e.Message); - ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message)); + await ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message)); } catch (Exception e) { Console.WriteLine(e.Message); - ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message)); + await ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message)); } }); @@ -114,10 +115,15 @@ public class MainWindowViewModel : ViewModelBase { // TODO Clear the text boxes. }); - - // Change TotalValue anytime SelectedCoin.TotalPrice changes. - // Possible null deref - how do you remove this? + + // Update TotalValue anytime a coin's quantity changes. + // Possible null reference is currently ignored - SelectedCoin will never be null. this.WhenAnyValue(x => x.SelectedCoin.TotalPrice) .Subscribe(_ => TotalValue = ConnectedCoinDatabase.Collection.Sum(x => x.TotalPrice)); + + // Update TotalValue anytime a coin is added or removed. + ConnectedCoinDatabase.Collection.CollectionChanged += (sender, args) => { + TotalValue = ConnectedCoinDatabase.Collection.Sum(x => x.TotalPrice); + }; } -} \ No newline at end of file +} diff --git a/PcgsInvUi/Views/DeleteWindow.axaml b/PcgsInvUi/Views/DeleteWindow.axaml index a967024..b9dabdf 100644 --- a/PcgsInvUi/Views/DeleteWindow.axaml +++ b/PcgsInvUi/Views/DeleteWindow.axaml @@ -18,7 +18,7 @@