From 0e5be04b02e83c6bb5ef8b599b13597310360e63 Mon Sep 17 00:00:00 2001 From: lvas463 Date: Mon, 9 Oct 2023 14:56:06 -0400 Subject: [PATCH] Added the NewControl as a content replacement for the MainWindow. --- PcgsInvUi/Models/Coin.cs | 147 +++++++++++++++--- PcgsInvUi/ViewModels/EditViewModel.cs | 30 ++++ PcgsInvUi/ViewModels/MainWindowViewModel.cs | 37 ++++- PcgsInvUi/ViewModels/NewViewModel.cs | 52 ++++++- PcgsInvUi/Views/CoinListView.axaml | 11 +- PcgsInvUi/Views/MainWindow.axaml | 10 +- PcgsInvUi/Views/NewControl.axaml | 24 --- PcgsInvUi/Views/NewControl.axaml.cs | 64 -------- PcgsInvUi/Views/NewView.axaml | 2 +- PcgsInvUi/bin/Debug/net6.0/PcgsInvUi.dll | Bin 237056 -> 235520 bytes PcgsInvUi/bin/Debug/net6.0/PcgsInvUi.pdb | Bin 22784 -> 22180 bytes .../net6.0/Avalonia/Resources.Inputs.cache | 2 +- .../obj/Debug/net6.0/Avalonia/original.dll | Bin 209920 -> 208896 bytes .../obj/Debug/net6.0/Avalonia/original.pdb | Bin 20224 -> 20020 bytes .../Debug/net6.0/Avalonia/original.ref.dll | Bin 11776 -> 11776 bytes PcgsInvUi/obj/Debug/net6.0/Avalonia/resources | Bin 188380 -> 186978 bytes .../Debug/net6.0/PcgsInvUi.AssemblyInfo.cs | 1 - ....GeneratedMSBuildEditorConfig.editorconfig | 3 - .../obj/Debug/net6.0/PcgsInvUi.assets.cache | Bin 54964 -> 54888 bytes .../PcgsInvUi.csproj.CoreCompileInputs.cache | 2 +- PcgsInvUi/obj/Debug/net6.0/PcgsInvUi.dll | Bin 237056 -> 235520 bytes PcgsInvUi/obj/Debug/net6.0/PcgsInvUi.pdb | Bin 22784 -> 22180 bytes PcgsInvUi/obj/Debug/net6.0/ref/PcgsInvUi.dll | Bin 11264 -> 11264 bytes .../obj/Debug/net6.0/refint/PcgsInvUi.dll | Bin 11264 -> 11264 bytes .../obj/PcgsInvUi.csproj.nuget.dgspec.json | 8 +- PcgsInvUi/obj/PcgsInvUi.csproj.nuget.g.props | 3 +- PcgsInvUi/obj/project.assets.json | 11 +- PcgsInvUi/obj/project.nuget.cache | 2 +- PcgsInvUi/obj/project.packagespec.json | 2 +- PcgsInvUi/obj/rider.project.model.nuget.info | 2 +- PcgsInvUi/obj/rider.project.restore.info | 2 +- 31 files changed, 262 insertions(+), 153 deletions(-) create mode 100644 PcgsInvUi/ViewModels/EditViewModel.cs delete mode 100644 PcgsInvUi/Views/NewControl.axaml delete mode 100644 PcgsInvUi/Views/NewControl.axaml.cs diff --git a/PcgsInvUi/Models/Coin.cs b/PcgsInvUi/Models/Coin.cs index bb9e9ad..fb045a9 100644 --- a/PcgsInvUi/Models/Coin.cs +++ b/PcgsInvUi/Models/Coin.cs @@ -1,26 +1,135 @@ using System; +using ReactiveUI; namespace PcgsInvUi.Models; -public class Coin +public class Coin : ReactiveObject { - public int PcgsNumber { get; set; } - public string Name { get; set; } - public int Year { get; set; } - public string Denomination { get; set; } - public string MintMark { get; set; } - public string Grade { get; set; } - public double PriceGuideValue { get; set; } - public string CoinFactsLink { get; set; } - public string MajorVariety { get; set; } - public string MinorVariety { get; set; } - public string DieVariety { get; set; } - public string Series { get; set; } - public string Category { get; set; } - public string Designation { get; set; } - public int CertificateNumber { get; set; } - public int Quantity { get; set; } + public int PcgsNumber + { + get => _pcgsNumber; + set => this.RaiseAndSetIfChanged(ref _pcgsNumber, value); + } + private int _pcgsNumber; + + public string Name + { + get => _name; + set => this.RaiseAndSetIfChanged(ref _name, value); + } + private string _name; + + public int Year + { + get => _year; + set => this.RaiseAndSetIfChanged(ref _year, value); + } + private int _year; + + public string Denomination + { + get => _denomination; + set => this.RaiseAndSetIfChanged(ref _denomination, value); + } + private string _denomination; + + public string MintMark + { + get => _mintMark; + set => this.RaiseAndSetIfChanged(ref _mintMark, value); + } + private string _mintMark; + + public string Grade + { + get => _grade; + set => this.RaiseAndSetIfChanged(ref _grade, value); + } + private string _grade; + + public double PriceGuideValue + { + get => _priceGuideValue; + set => this.RaiseAndSetIfChanged(ref _priceGuideValue, value); + } + private double _priceGuideValue; + + public string CoinFactsLink + { + get => _coinFactsLink; + set => this.RaiseAndSetIfChanged(ref _coinFactsLink, value); + } + private string _coinFactsLink; + + public string MajorVariety + { + get => _majorVariety; + set => this.RaiseAndSetIfChanged(ref _majorVariety, value); + } + private string _majorVariety; + + public string MinorVariety + { + get => _minorVariety; + set => this.RaiseAndSetIfChanged(ref _minorVariety, value); + } + private string _minorVariety; + + public string DieVariety + { + get => _dieVariety; + set => this.RaiseAndSetIfChanged(ref _dieVariety, value); + } + private string _dieVariety; + + public string Series + { + get => _series; + set => this.RaiseAndSetIfChanged(ref _series, value); + } + private string _series; + + public string Category + { + get => _category; + set => this.RaiseAndSetIfChanged(ref _category, value); + } + private string _category; + + public string Designation + { + get => _designation; + set => this.RaiseAndSetIfChanged(ref _designation, value); + } + private string _designation; + + public int CertificateNumber + { + get => _certificateNumber; + set => this.RaiseAndSetIfChanged(ref _certificateNumber, value); + } + private int _certificateNumber; + + public int Quantity + { + get => _quantity; + set => this.RaiseAndSetIfChanged(ref _quantity, value); + } + private int _quantity; + public double TotalPrice => Quantity * PriceGuideValue; - public double PaidFor { get; set; } - public String Notes { get; set; } + + public double PaidFor + { + get => _paidFor; + set => this.RaiseAndSetIfChanged(ref _paidFor, value); + } + private double _paidFor; + + public String Notes + { + get => _notes; + set => this.RaiseAndSetIfChanged(ref _notes, value); + } + private string _notes; } \ No newline at end of file diff --git a/PcgsInvUi/ViewModels/EditViewModel.cs b/PcgsInvUi/ViewModels/EditViewModel.cs new file mode 100644 index 0000000..a8b1fd5 --- /dev/null +++ b/PcgsInvUi/ViewModels/EditViewModel.cs @@ -0,0 +1,30 @@ +using System; +using System.Reactive; +using PcgsInvUi.Models; +using ReactiveUI; + +namespace PcgsInvUi.ViewModels; + +public class EditViewModel : ViewModelBase +{ + public Coin CurrentCoin { get; set; } + + public ReactiveCommand OkCommand { get; } + + public EditViewModel(Coin coin) + { + CurrentCoin = coin; + + var okEnabled = this.WhenAnyValue( + x => x.CurrentCoin.PcgsNumber, + x => x.CurrentCoin.Grade, + x => x.CurrentCoin.Quantity, + (id, grade, quantity) => (id != 0) && + !string.IsNullOrWhiteSpace(grade) && + (quantity != 0) + ); + + // Setup OkCommand - all Coin-related properties must be non-whitespace. + OkCommand = ReactiveCommand.Create(() => { }); + } +} \ No newline at end of file diff --git a/PcgsInvUi/ViewModels/MainWindowViewModel.cs b/PcgsInvUi/ViewModels/MainWindowViewModel.cs index 1611313..292aeaf 100644 --- a/PcgsInvUi/ViewModels/MainWindowViewModel.cs +++ b/PcgsInvUi/ViewModels/MainWindowViewModel.cs @@ -9,23 +9,29 @@ namespace PcgsInvUi.ViewModels; public class MainWindowViewModel : ViewModelBase { public CoinListViewModel List { get; } - private ViewModelBase _content; + private ViewModelBase _mainContent; + private ViewModelBase _sideContent; public MainWindowViewModel(CoinCollection coins) { List = new CoinListViewModel(coins.GetItems()); - Content = List; + MainContent = List; } - public ViewModelBase Content + public ViewModelBase MainContent { - get => _content; - private set => this.RaiseAndSetIfChanged(ref _content, value); + get => _mainContent; + private set => this.RaiseAndSetIfChanged(ref _mainContent, value); + } + + public ViewModelBase SidebarContent + { + get => _sideContent; + private set => this.RaiseAndSetIfChanged(ref _sideContent, value); } public void AddItem() { - Console.WriteLine("You hit the button!"); var newViewModel = new NewViewModel(); Observable.Merge( @@ -37,9 +43,24 @@ public class MainWindowViewModel : ViewModelBase if (model != null) List.CoinCollection.Add(model); - Content = List; + MainContent = List; }); - Content = newViewModel; + MainContent = newViewModel; + } + + public void EditItem() + { + var editViewModel = new EditViewModel(List.SelectedCoin); + } + + public void DeleteItem() + { + + } + + public void FindItem() + { + } } diff --git a/PcgsInvUi/ViewModels/NewViewModel.cs b/PcgsInvUi/ViewModels/NewViewModel.cs index 95c3f29..5d4ed54 100644 --- a/PcgsInvUi/ViewModels/NewViewModel.cs +++ b/PcgsInvUi/ViewModels/NewViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Reactive; +using System.Collections.Generic; using PcgsInvUi.Models; using ReactiveUI; @@ -26,17 +27,62 @@ public class NewViewModel : ViewModelBase get => _quantity; set => this.RaiseAndSetIfChanged(ref _quantity, value); } - + public List GradesList { get; } + public NewViewModel() { var okEnabled = this.WhenAnyValue( x => x.PcgsNumber, - x => !string.IsNullOrWhiteSpace(x)); + x => x.Grade, + x => x.Quantity, + (id, grade, quantity) => !string.IsNullOrWhiteSpace(id) && + !string.IsNullOrWhiteSpace(grade) && + !string.IsNullOrWhiteSpace(quantity)); + // This will eventually send our request to the public API, then construct our coin. OkCommand = ReactiveCommand.Create( - () => new Coin { PcgsNumber = Int32.Parse(PcgsNumber) }, + () => new Coin { PcgsNumber = Int32.Parse(PcgsNumber), + Grade = Grade, + Quantity = Int32.Parse(Quantity) }, okEnabled); + CancelCommand = ReactiveCommand.Create(() => { }); + + // Initialize grade values for use in the view. + // This must be typed out manually, as there is no way to get a list of grades from the API. + GradesList = new List() + { + "P-01", + "FR-02", + "AG-03", + "G-04", + "G-06", + "VG-08", + "VG-10", + "F-12", + "F-15", + "VF-20", + "VF-25", + "VF-30", + "VF-35", + "EF-40", + "EF-45", + "AU-50", + "AU-53", + "AU-55", + "AU-58", + "MS-60", + "MS-61", + "MS-62", + "MS-63", + "MS-64", + "MS-65", + "MS-66", + "MS-67", + "MS-68", + "MS-69", + "MS-70" + }; } public ReactiveCommand OkCommand { get; } diff --git a/PcgsInvUi/Views/CoinListView.axaml b/PcgsInvUi/Views/CoinListView.axaml index 6315898..243a50b 100644 --- a/PcgsInvUi/Views/CoinListView.axaml +++ b/PcgsInvUi/Views/CoinListView.axaml @@ -55,11 +55,14 @@ -