Reformatted and cleaned up code across whole project.

This commit is contained in:
alphafetus committed 2023-10-24 09:04:04 -04:00
1 parent 42a7871ed4
commit 99cb9268dd
21 files changed
+124 -171

No files matched your search

+5 -10
View File
@@ -7,23 +7,18 @@ using PcgsInvUi.Views;
namespace PcgsInvUi; namespace PcgsInvUi;
public partial class App : Application public partial class App : Application {
{ public override void Initialize() {
public override void Initialize()
{
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }
public override void OnFrameworkInitializationCompleted() public override void OnFrameworkInitializationCompleted() {
{
base.OnFrameworkInitializationCompleted(); base.OnFrameworkInitializationCompleted();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
{
var coins = new Services.CoinCollection(); var coins = new Services.CoinCollection();
desktop.MainWindow = new MainWindow desktop.MainWindow = new MainWindow {
{
DataContext = new MainWindowViewModel(coins), DataContext = new MainWindowViewModel(coins),
}; };
} }
+40 -48
View File
@@ -3,55 +3,52 @@ using ReactiveUI;
namespace PcgsInvUi.Models; namespace PcgsInvUi.Models;
public class Coin : ReactiveObject public class Coin : ReactiveObject {
{ public string PCGSNo {
public string PCGSNo
{
get => _pcgsNo; get => _pcgsNo;
set => this.RaiseAndSetIfChanged(ref _pcgsNo, value); set => this.RaiseAndSetIfChanged(ref _pcgsNo, value);
} }
private string _pcgsNo; private string _pcgsNo;
public string Name public string Name {
{
get => _name; get => _name;
set => this.RaiseAndSetIfChanged(ref _name, value); set => this.RaiseAndSetIfChanged(ref _name, value);
} }
private string _name; private string _name;
public int Year public int Year {
{
get => _year; get => _year;
set => this.RaiseAndSetIfChanged(ref _year, value); set => this.RaiseAndSetIfChanged(ref _year, value);
} }
private int _year; private int _year;
public string Denomination public string Denomination {
{
get => _denomination; get => _denomination;
set => this.RaiseAndSetIfChanged(ref _denomination, value); set => this.RaiseAndSetIfChanged(ref _denomination, value);
} }
private string _denomination; private string _denomination;
public string MintMark public string MintMark {
{
get => _mintMark; get => _mintMark;
set => this.RaiseAndSetIfChanged(ref _mintMark, value); set => this.RaiseAndSetIfChanged(ref _mintMark, value);
} }
private string _mintMark; private string _mintMark;
public string Grade public string Grade {
{
get => _grade; get => _grade;
set => this.RaiseAndSetIfChanged(ref _grade, value); set => this.RaiseAndSetIfChanged(ref _grade, value);
} }
private string _grade; private string _grade;
public double PriceGuideValue public double PriceGuideValue {
{
get => _priceGuideValue; get => _priceGuideValue;
set set {
{
TotalPrice = value * Quantity; TotalPrice = value * Quantity;
this.RaiseAndSetIfChanged(ref _priceGuideValue, value); this.RaiseAndSetIfChanged(ref _priceGuideValue, value);
} }
@@ -59,67 +56,65 @@ public class Coin : ReactiveObject
private double _priceGuideValue; private double _priceGuideValue;
public string CoinFactsLink public string CoinFactsLink {
{
get => _coinFactsLink; get => _coinFactsLink;
set => this.RaiseAndSetIfChanged(ref _coinFactsLink, value); set => this.RaiseAndSetIfChanged(ref _coinFactsLink, value);
} }
private string _coinFactsLink; private string _coinFactsLink;
public string MajorVariety public string MajorVariety {
{
get => _majorVariety; get => _majorVariety;
set => this.RaiseAndSetIfChanged(ref _majorVariety, value); set => this.RaiseAndSetIfChanged(ref _majorVariety, value);
} }
private string _majorVariety; private string _majorVariety;
public string MinorVariety public string MinorVariety {
{
get => _minorVariety; get => _minorVariety;
set => this.RaiseAndSetIfChanged(ref _minorVariety, value); set => this.RaiseAndSetIfChanged(ref _minorVariety, value);
} }
private string _minorVariety; private string _minorVariety;
public string DieVariety public string DieVariety {
{
get => _dieVariety; get => _dieVariety;
set => this.RaiseAndSetIfChanged(ref _dieVariety, value); set => this.RaiseAndSetIfChanged(ref _dieVariety, value);
} }
private string _dieVariety; private string _dieVariety;
public string SeriesName public string SeriesName {
{
get => _seriesName; get => _seriesName;
set => this.RaiseAndSetIfChanged(ref _seriesName, value); set => this.RaiseAndSetIfChanged(ref _seriesName, value);
} }
private string _seriesName; private string _seriesName;
public string Category public string Category {
{
get => _category; get => _category;
set => this.RaiseAndSetIfChanged(ref _category, value); set => this.RaiseAndSetIfChanged(ref _category, value);
} }
private string _category; private string _category;
public string Designation public string Designation {
{
get => _designation; get => _designation;
set => this.RaiseAndSetIfChanged(ref _designation, value); set => this.RaiseAndSetIfChanged(ref _designation, value);
} }
private string _designation; private string _designation;
public int CertificateNumber public int CertificateNumber {
{
get => _certificateNumber; get => _certificateNumber;
set => this.RaiseAndSetIfChanged(ref _certificateNumber, value); set => this.RaiseAndSetIfChanged(ref _certificateNumber, value);
} }
private int _certificateNumber; private int _certificateNumber;
public int Quantity public int Quantity {
{
get => _quantity; get => _quantity;
set set {
{
TotalPrice = value * PriceGuideValue; TotalPrice = value * PriceGuideValue;
this.RaiseAndSetIfChanged(ref _quantity, value); this.RaiseAndSetIfChanged(ref _quantity, value);
} }
@@ -127,29 +122,28 @@ public class Coin : ReactiveObject
private int _quantity; private int _quantity;
public double TotalPrice public double TotalPrice {
{
get => _totalPrice; get => _totalPrice;
set => this.RaiseAndSetIfChanged(ref _totalPrice, value); set => this.RaiseAndSetIfChanged(ref _totalPrice, value);
} }
private double _totalPrice; private double _totalPrice;
public double PaidFor public double PaidFor {
{
get => _paidFor; get => _paidFor;
set => this.RaiseAndSetIfChanged(ref _paidFor, value); set => this.RaiseAndSetIfChanged(ref _paidFor, value);
} }
private double _paidFor; private double _paidFor;
public string Notes public string Notes {
{
get => _notes; get => _notes;
set => this.RaiseAndSetIfChanged(ref _notes, value); set => this.RaiseAndSetIfChanged(ref _notes, value);
} }
private string _notes; private string _notes;
public Coin() public Coin() {
{
PCGSNo = ""; PCGSNo = "";
Name = ""; Name = "";
Year = 0; Year = 0;
@@ -168,7 +162,5 @@ public class Coin : ReactiveObject
Quantity = 0; Quantity = 0;
PaidFor = 0; PaidFor = 0;
Notes = ""; Notes = "";
} }
} }
+1
View File
@@ -23,6 +23,7 @@
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.2"/> <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.2"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.2"/> <PackageReference Include="Avalonia.ReactiveUI" Version="11.0.2"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/> <PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageReference Include="System.Data.SQLite" Version="1.0.118"/>
</ItemGroup> </ItemGroup>
+1 -2
View File
@@ -4,8 +4,7 @@ using System;
namespace PcgsInvUi; namespace PcgsInvUi;
class Program class Program {
{
// Initialization code. Don't use any Avalonia, third-party APIs or any // Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break. // yet and stuff might break.
+2 -4
View File
@@ -3,10 +3,8 @@ using PcgsInvUi.Models;
namespace PcgsInvUi.Services; namespace PcgsInvUi.Services;
public class CoinCollection public class CoinCollection {
{ public IEnumerable<Coin> GetItems() => new[] {
public IEnumerable<Coin> GetItems() => new[]
{
new Coin(), new Coin(),
new Coin(), new Coin(),
new Coin(), new Coin(),
+2 -3
View File
@@ -1,6 +1,5 @@
namespace PcgsInvUi.Services; namespace PcgsInvUi.Services;
public class Database public class Database {
{ public Database() { }
// TODO Create a database using SQLite.
} }
+8 -17
View File
@@ -4,29 +4,24 @@ using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;
// using Newtonsoft.Json; // using Newtonsoft.Json;
using PcgsInvUi.Models; using PcgsInvUi.Models;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace PcgsInvUi.Services; namespace PcgsInvUi.Services;
public class PcgsClient public class PcgsClient {
{
private string _apiUri = "https://api.pcgs.com/publicapi"; private string _apiUri = "https://api.pcgs.com/publicapi";
private readonly string _apiKey; private readonly string _apiKey;
public PcgsClient(string apiKey) public PcgsClient(string apiKey) {
{
// _apiKey = apiKey; // _apiKey = apiKey;
_apiKey = _apiKey =
"E8xivTVN_k4Q8ubk8Xv_uU11U91WX0wDht4S4m4BAf2HPmKnGrZ0J2f9nccM7Ns1VkGoT1SXYR74I7aNaMKqXlJGEy3oobseKV0nGiqu1IKvFkOTVjhV37SWUVExSDFMC6FLzs7xJQIHwkcxr5JFOQNmc4ZytEh_-hmCN3NL-z0fEk98tzBmPJ_F7bq_xNru86QMD2A9yalu_dWe-lCysfyE2bCA2EDqwvWenRYf-0XnNtp6qlxxCMlCd-TDqqRKLC3qefCwpXSemwBiNSP5gbC9pwcKrZugkruuJ0nyxxThZymm"; "E8xivTVN_k4Q8ubk8Xv_uU11U91WX0wDht4S4m4BAf2HPmKnGrZ0J2f9nccM7Ns1VkGoT1SXYR74I7aNaMKqXlJGEy3oobseKV0nGiqu1IKvFkOTVjhV37SWUVExSDFMC6FLzs7xJQIHwkcxr5JFOQNmc4ZytEh_-hmCN3NL-z0fEk98tzBmPJ_F7bq_xNru86QMD2A9yalu_dWe-lCysfyE2bCA2EDqwvWenRYf-0XnNtp6qlxxCMlCd-TDqqRKLC3qefCwpXSemwBiNSP5gbC9pwcKrZugkruuJ0nyxxThZymm";
} }
public async Task<Coin> GetCoinFactsByGrade(int pcgsNumber, string grade, bool plusGrade = false) public async Task<Coin> GetCoinFactsByGrade(int pcgsNumber, string grade, bool plusGrade = false) {
{
Coin newCoin = null; Coin newCoin = null;
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient()) {
{
var gradeParam = GetGradeFromString(grade); var gradeParam = GetGradeFromString(grade);
string requestUri = string requestUri =
@@ -36,14 +31,12 @@ public class PcgsClient
HttpResponseMessage response = await client.GetAsync(requestUri); HttpResponseMessage response = await client.GetAsync(requestUri);
Console.WriteLine("Got response."); Console.WriteLine("Got response.");
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode) {
{
string jsonResponse = await response.Content.ReadAsStringAsync(); string jsonResponse = await response.Content.ReadAsStringAsync();
newCoin = ParseJsonResponse(jsonResponse); newCoin = ParseJsonResponse(jsonResponse);
Console.WriteLine("Coin created."); Console.WriteLine("Coin created.");
} }
else else {
{
Console.WriteLine($"Error: {response.StatusCode} - {response.ReasonPhrase}"); Console.WriteLine($"Error: {response.StatusCode} - {response.ReasonPhrase}");
} }
} }
@@ -51,8 +44,7 @@ public class PcgsClient
return newCoin; return newCoin;
} }
private int GetGradeFromString(string grade) private int GetGradeFromString(string grade) {
{
var actualGrade = int.Parse(grade.Substring(grade.Length - 2)); var actualGrade = int.Parse(grade.Substring(grade.Length - 2));
Console.WriteLine($"Grade is {actualGrade}"); Console.WriteLine($"Grade is {actualGrade}");
return actualGrade; return actualGrade;
@@ -60,8 +52,7 @@ public class PcgsClient
// TODO Will eventually create the other methods that are included in the Public API. // TODO Will eventually create the other methods that are included in the Public API.
private Coin ParseJsonResponse(string json) private Coin ParseJsonResponse(string json) {
{
Console.WriteLine(json); Console.WriteLine(json);
Coin newCoin = JsonSerializer.Deserialize<Coin>(json); Coin newCoin = JsonSerializer.Deserialize<Coin>(json);
Console.WriteLine($"New Coin has pcgs number {newCoin.PCGSNo}"); Console.WriteLine($"New Coin has pcgs number {newCoin.PCGSNo}");
+4 -8
View File
@@ -5,23 +5,19 @@ using PcgsInvUi.ViewModels;
namespace PcgsInvUi; namespace PcgsInvUi;
public class ViewLocator : IDataTemplate public class ViewLocator : IDataTemplate {
{ public Control Build(object data) {
public Control Build(object data)
{
var name = data.GetType().FullName!.Replace("ViewModel", "View"); var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name); var type = Type.GetType(name);
if (type != null) if (type != null) {
{
return (Control)Activator.CreateInstance(type)!; return (Control)Activator.CreateInstance(type)!;
} }
return new TextBlock { Text = "Not Found: " + name }; return new TextBlock { Text = "Not Found: " + name };
} }
public bool Match(object data) public bool Match(object data) {
{
return data is ViewModelBase; return data is ViewModelBase;
} }
} }
+5 -6
View File
@@ -5,19 +5,18 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels; namespace PcgsInvUi.ViewModels;
public class CoinListViewModel : ViewModelBase public class CoinListViewModel : ViewModelBase {
{
public ObservableCollection<Coin> CoinCollection { get; set; } public ObservableCollection<Coin> CoinCollection { get; set; }
private float _totalValue; private float _totalValue;
public float TotalValue
{ public float TotalValue {
get => _totalValue; get => _totalValue;
set => this.RaiseAndSetIfChanged(ref _totalValue, value); set => this.RaiseAndSetIfChanged(ref _totalValue, value);
} }
public Coin? SelectedCoin { get; set; } public Coin? SelectedCoin { get; set; }
public CoinListViewModel(IEnumerable<Coin> items) public CoinListViewModel(IEnumerable<Coin> items) {
{
CoinCollection = new ObservableCollection<Coin>(items); CoinCollection = new ObservableCollection<Coin>(items);
TotalValue = 0; TotalValue = 0;
} }
@@ -4,13 +4,11 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels; namespace PcgsInvUi.ViewModels;
public class DeleteWindowViewModel : ViewModelBase public class DeleteWindowViewModel : ViewModelBase {
{
public ReactiveCommand<Unit, object> OkCommand { get; } public ReactiveCommand<Unit, object> OkCommand { get; }
public ReactiveCommand<DeleteWindow, Unit> CancelCommand { get; } public ReactiveCommand<DeleteWindow, Unit> CancelCommand { get; }
public DeleteWindowViewModel() public DeleteWindowViewModel() {
{
OkCommand = ReactiveCommand.Create(() => (object)true); OkCommand = ReactiveCommand.Create(() => (object)true);
CancelCommand = ReactiveCommand.Create<DeleteWindow>(window => window.Close()); CancelCommand = ReactiveCommand.Create<DeleteWindow>(window => window.Close());
} }
+2 -4
View File
@@ -5,14 +5,12 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels; namespace PcgsInvUi.ViewModels;
public class EditViewModel : ViewModelBase public class EditViewModel : ViewModelBase {
{
public Coin CurrentCoin { get; set; } public Coin CurrentCoin { get; set; }
public ReactiveCommand<Unit, Unit> OkCommand { get; } public ReactiveCommand<Unit, Unit> OkCommand { get; }
public EditViewModel(Coin coin) public EditViewModel(Coin coin) {
{
CurrentCoin = coin; CurrentCoin = coin;
var okEnabled = this.WhenAnyValue( var okEnabled = this.WhenAnyValue(
+1 -2
View File
@@ -3,7 +3,6 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels; namespace PcgsInvUi.ViewModels;
public class FindWindowViewModel : ViewModelBase public class FindWindowViewModel : ViewModelBase {
{
public ReactiveCommand<Unit, object> OkCommand { get; } = ReactiveCommand.Create(() => (object)1); public ReactiveCommand<Unit, object> OkCommand { get; } = ReactiveCommand.Create(() => (object)1);
} }
+16 -18
View File
@@ -19,25 +19,25 @@ namespace PcgsInvUi.ViewModels;
// TODO API request tracker (1000 per day) // TODO API request tracker (1000 per day)
// TODO API update schedules (per month? manual override? needs to store a date of last update in the coin object) // TODO API update schedules (per month? manual override? needs to store a date of last update in the coin object)
public class MainWindowViewModel : ViewModelBase public class MainWindowViewModel : ViewModelBase {
{ public ViewModelBase SidebarContent {
public ViewModelBase SidebarContent
{
get => _sideContent; get => _sideContent;
private set => this.RaiseAndSetIfChanged(ref _sideContent, value); private set => this.RaiseAndSetIfChanged(ref _sideContent, value);
} }
public ObservableCollection<Coin> CoinCollection { get; set; } public ObservableCollection<Coin> CoinCollection { get; set; }
public ObservableCollection<Coin> DisplayedList { get; set; } public ObservableCollection<Coin> DisplayedList { get; set; }
public Coin? SelectedCoin
{ public Coin? SelectedCoin {
get => _selectedCoin; get => _selectedCoin;
set => this.RaiseAndSetIfChanged(ref _selectedCoin, value); set => this.RaiseAndSetIfChanged(ref _selectedCoin, value);
} }
public double TotalValue
{ public double TotalValue {
get => _totalValue; get => _totalValue;
set => this.RaiseAndSetIfChanged(ref _totalValue, value); set => this.RaiseAndSetIfChanged(ref _totalValue, value);
} }
public ReactiveCommand<Unit, Unit> DeleteCommand { get; } public ReactiveCommand<Unit, Unit> DeleteCommand { get; }
public Interaction<DeleteWindowViewModel, Boolean> ShowDeleteWindow { get; } public Interaction<DeleteWindowViewModel, Boolean> ShowDeleteWindow { get; }
public ReactiveCommand<Unit, Coin> FindCommand { get; } public ReactiveCommand<Unit, Coin> FindCommand { get; }
@@ -48,30 +48,29 @@ public class MainWindowViewModel : ViewModelBase
private double _totalValue; private double _totalValue;
private PcgsClient _pcgsClient; private PcgsClient _pcgsClient;
public MainWindowViewModel(CoinCollection coins) public MainWindowViewModel(CoinCollection coins) {
{
var newViewModel = new NewViewModel(); var newViewModel = new NewViewModel();
_sideContent = newViewModel; _sideContent = newViewModel;
DisplayedList = CoinCollection = new ObservableCollection<Coin>(coins.GetItems()); DisplayedList = CoinCollection = new ObservableCollection<Coin>(coins.GetItems());
_pcgsClient = new PcgsClient("eAb8gS0I2XAvT_5gJeiGJaglMia1Tk-oB4kJUK6kuafyrny_S61vIJY-Ikl4nCQM67wrdxzUqLVWTV2kBSxD3d5XNBHxHnYBhcSS6dOPug0hZaF3qAv56df3gYSzOGh9Tif5y0eP3Iw0LrqKDr1Hj-dk6SV6GKog2IIqCPQhhHH8FMTWBTYO-_O8cx7qLdM5GM8KlTsic6g3VRUhM8EA_4OO04dCfmNLGhqINRl3jGZ0Q4ziI8fng2bVWsIyteqiPzUn10rIQ3-OPpqVZG_DxeOmOejj4GzbUNyqUOajy-nr5rYY"); _pcgsClient = new PcgsClient(
"eAb8gS0I2XAvT_5gJeiGJaglMia1Tk-oB4kJUK6kuafyrny_S61vIJY-Ikl4nCQM67wrdxzUqLVWTV2kBSxD3d5XNBHxHnYBhcSS6dOPug0hZaF3qAv56df3gYSzOGh9Tif5y0eP3Iw0LrqKDr1Hj-dk6SV6GKog2IIqCPQhhHH8FMTWBTYO-_O8cx7qLdM5GM8KlTsic6g3VRUhM8EA_4OO04dCfmNLGhqINRl3jGZ0Q4ziI8fng2bVWsIyteqiPzUn10rIQ3-OPpqVZG_DxeOmOejj4GzbUNyqUOajy-nr5rYY");
// Set up the ability to open the delete window. // Set up the ability to open the delete window.
ShowDeleteWindow = new Interaction<DeleteWindowViewModel, bool>(); ShowDeleteWindow = new Interaction<DeleteWindowViewModel, bool>();
var deleteEnabled = this.WhenAnyValue(x => x.SelectedCoin) var deleteEnabled = this.WhenAnyValue(x => x.SelectedCoin)
.Select(x => x != null); .Select(x => x != null);
DeleteCommand = ReactiveCommand.CreateFromTask(async () => DeleteCommand = ReactiveCommand.CreateFromTask(async () => {
{
var deleteViewModel = new DeleteWindowViewModel(); var deleteViewModel = new DeleteWindowViewModel();
var result = await ShowDeleteWindow.Handle(deleteViewModel); var result = await ShowDeleteWindow.Handle(deleteViewModel);
if (result) CoinCollection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled. if (result)
CoinCollection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled.
}, deleteEnabled); }, deleteEnabled);
// Set up the ability to open the find window. // Set up the ability to open the find window.
ShowFindWindow = new Interaction<FindWindowViewModel, int>(); ShowFindWindow = new Interaction<FindWindowViewModel, int>();
var findEnabled = this.WhenAnyValue(x => x.CoinCollection.Count, var findEnabled = this.WhenAnyValue(x => x.CoinCollection.Count,
x => x > 0); x => x > 0);
FindCommand = ReactiveCommand.CreateFromTask(async () => FindCommand = ReactiveCommand.CreateFromTask(async () => {
{
var findViewModel = new FindWindowViewModel(); var findViewModel = new FindWindowViewModel();
var result = await ShowFindWindow.Handle(findViewModel); var result = await ShowFindWindow.Handle(findViewModel);
// Find the coin with the matching ID. The issue is that there could be multiple - so we need to return a list. // Find the coin with the matching ID. The issue is that there could be multiple - so we need to return a list.
@@ -82,8 +81,7 @@ public class MainWindowViewModel : ViewModelBase
// Subscribe to SidebarContent.OkCommand, which is an IObservable<(int, string, int)> // Subscribe to SidebarContent.OkCommand, which is an IObservable<(int, string, int)>
// This is the same as the above, but with a different syntax. // This is the same as the above, but with a different syntax.
newViewModel.OkCommand newViewModel.OkCommand
.Subscribe(async requestStructure => .Subscribe(async requestStructure => {
{
var newCoin = await _pcgsClient.GetCoinFactsByGrade(requestStructure.Item1, requestStructure.Item2); var newCoin = await _pcgsClient.GetCoinFactsByGrade(requestStructure.Item1, requestStructure.Item2);
newCoin.Quantity = requestStructure.Item3; newCoin.Quantity = requestStructure.Item3;
CoinCollection.Add(newCoin); CoinCollection.Add(newCoin);
+10 -15
View File
@@ -4,31 +4,29 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels; namespace PcgsInvUi.ViewModels;
public class NewViewModel : ViewModelBase public class NewViewModel : ViewModelBase {
{
private string _pcgsNumber = ""; private string _pcgsNumber = "";
private string _grade = ""; private string _grade = "";
private string _quantity = ""; private string _quantity = "";
public string PcgsNumber public string PcgsNumber {
{
get => _pcgsNumber; get => _pcgsNumber;
set => this.RaiseAndSetIfChanged(ref _pcgsNumber, value); set => this.RaiseAndSetIfChanged(ref _pcgsNumber, value);
} }
public string Grade
{ public string Grade {
get => _grade; get => _grade;
set => this.RaiseAndSetIfChanged(ref _grade, value); set => this.RaiseAndSetIfChanged(ref _grade, value);
} }
public string Quantity
{ public string Quantity {
get => _quantity; get => _quantity;
set => this.RaiseAndSetIfChanged(ref _quantity, value); set => this.RaiseAndSetIfChanged(ref _quantity, value);
} }
public List<string> GradesList { get; } public List<string> GradesList { get; }
public NewViewModel() public NewViewModel() {
{
var okEnabled = this.WhenAnyValue( var okEnabled = this.WhenAnyValue(
x => x.PcgsNumber, x => x.PcgsNumber,
x => x.Grade, x => x.Grade,
@@ -41,8 +39,7 @@ public class NewViewModel : ViewModelBase
() => (int.Parse(PcgsNumber), Grade, int.Parse(Quantity)), () => (int.Parse(PcgsNumber), Grade, int.Parse(Quantity)),
okEnabled); okEnabled);
ClearCommand = ReactiveCommand.Create(() => ClearCommand = ReactiveCommand.Create(() => {
{
PcgsNumber = ""; PcgsNumber = "";
Grade = ""; Grade = "";
Quantity = ""; Quantity = "";
@@ -50,8 +47,7 @@ public class NewViewModel : ViewModelBase
// Initialize grade values for use in the view. // 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. // This must be typed out manually, as there is no way to get a list of grades from the API.
GradesList = new List<string> GradesList = new List<string> {
{
"P-01", "P-01",
"FR-02", "FR-02",
"AG-03", "AG-03",
@@ -87,5 +83,4 @@ public class NewViewModel : ViewModelBase
public ReactiveCommand<Unit, (int, string, int)> OkCommand { get; } public ReactiveCommand<Unit, (int, string, int)> OkCommand { get; }
public ReactiveCommand<Unit, Unit> ClearCommand { get; } public ReactiveCommand<Unit, Unit> ClearCommand { get; }
} }
+1 -3
View File
@@ -2,6 +2,4 @@
namespace PcgsInvUi.ViewModels; namespace PcgsInvUi.ViewModels;
public class ViewModelBase : ReactiveObject public class ViewModelBase : ReactiveObject { }
{
}
+2 -4
View File
@@ -5,10 +5,8 @@ using System;
namespace PcgsInvUi.Views; namespace PcgsInvUi.Views;
public partial class DeleteWindow : ReactiveWindow<DeleteWindowViewModel> public partial class DeleteWindow : ReactiveWindow<DeleteWindowViewModel> {
{ public DeleteWindow() {
public DeleteWindow()
{
InitializeComponent(); InitializeComponent();
this.WhenActivated(d => d(ViewModel!.OkCommand.Subscribe(Close))); this.WhenActivated(d => d(ViewModel!.OkCommand.Subscribe(Close)));
} }
+2 -4
View File
@@ -5,10 +5,8 @@ using System;
namespace PcgsInvUi.Views; namespace PcgsInvUi.Views;
public partial class FindWindow : ReactiveWindow<FindWindowViewModel> public partial class FindWindow : ReactiveWindow<FindWindowViewModel> {
{ public FindWindow() {
public FindWindow()
{
InitializeComponent(); InitializeComponent();
this.WhenActivated(d => d(ViewModel!.OkCommand.Subscribe(Close))); this.WhenActivated(d => d(ViewModel!.OkCommand.Subscribe(Close)));
} }
+12 -6
View File
@@ -12,7 +12,8 @@
PanePlacement="Right"> PanePlacement="Right">
<SplitView.Pane> <SplitView.Pane>
<Grid RowDefinitions="Auto, *"> <Grid RowDefinitions="Auto, *">
<UserControl Grid.Row="0" Margin="10, 20, 10, 10" VerticalAlignment="Center" Content="{Binding SidebarContent}"/> <UserControl Grid.Row="0" Margin="10, 20, 10, 10" VerticalAlignment="Center"
Content="{Binding SidebarContent}" />
<TextBox Grid.Row="1" Margin="5" Watermark="Notes..." /> <TextBox Grid.Row="1" Margin="5" Watermark="Notes..." />
</Grid> </Grid>
</SplitView.Pane> </SplitView.Pane>
@@ -60,15 +61,20 @@
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<DockPanel Grid.Row="1"> <DockPanel Grid.Row="1">
<Grid HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" ColumnDefinitions="Auto, Auto" DockPanel.Dock="Left"> <Grid HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" ColumnDefinitions="Auto, Auto"
DockPanel.Dock="Left">
<Button Grid.Column="0" Margin="5" Width="100" HorizontalContentAlignment="Center" Content="Delete" <Button Grid.Column="0" Margin="5" Width="100" HorizontalContentAlignment="Center" Content="Delete"
Command="{Binding DeleteCommand}" /> Command="{Binding DeleteCommand}" />
<Button Grid.Column="1" Margin="5" Width="100" HorizontalContentAlignment="Center" Content="Find..." <Button Grid.Column="1" Margin="5" Width="100" HorizontalContentAlignment="Center"
Content="Find..."
Command="{Binding FindCommand}" /> Command="{Binding FindCommand}" />
</Grid> </Grid>
<Grid HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="5" ColumnDefinitions="Auto, Auto" DockPanel.Dock="Right"> <Grid HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="5" ColumnDefinitions="Auto, Auto"
<Label Grid.Column="0" Margin="5" VerticalAlignment="Center" Content="{Binding TotalValue, StringFormat='Total Value: ${0:0.00}'}" /> DockPanel.Dock="Right">
<Button Grid.Column="1" Margin="5" Width="150" HorizontalContentAlignment="Center" Content="Export to CSV..." /> <Label Grid.Column="0" Margin="5" VerticalAlignment="Center"
Content="{Binding TotalValue, StringFormat='Total Value: ${0:0.00}'}" />
<Button Grid.Column="1" Margin="5" Width="150" HorizontalContentAlignment="Center"
Content="Export to CSV..." />
</Grid> </Grid>
</DockPanel> </DockPanel>
</Grid> </Grid>
+4 -8
View File
@@ -6,17 +6,14 @@ using ReactiveUI;
namespace PcgsInvUi.Views; namespace PcgsInvUi.Views;
public partial class MainWindow : ReactiveWindow<MainWindowViewModel> public partial class MainWindow : ReactiveWindow<MainWindowViewModel> {
{ public MainWindow() {
public MainWindow()
{
InitializeComponent(); InitializeComponent();
this.WhenActivated(d => d(ViewModel!.ShowDeleteWindow.RegisterHandler(ShowDeleteWindowAsync))); this.WhenActivated(d => d(ViewModel!.ShowDeleteWindow.RegisterHandler(ShowDeleteWindowAsync)));
this.WhenActivated(d => d(ViewModel!.ShowFindWindow.RegisterHandler(ShowFindWindowAsync))); this.WhenActivated(d => d(ViewModel!.ShowFindWindow.RegisterHandler(ShowFindWindowAsync)));
} }
public async Task ShowDeleteWindowAsync(InteractionContext<DeleteWindowViewModel, Boolean> interaction) public async Task ShowDeleteWindowAsync(InteractionContext<DeleteWindowViewModel, Boolean> interaction) {
{
var window = new DeleteWindow(); var window = new DeleteWindow();
window.DataContext = interaction.Input; window.DataContext = interaction.Input;
@@ -24,8 +21,7 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
interaction.SetOutput(result); interaction.SetOutput(result);
} }
public async Task ShowFindWindowAsync(InteractionContext<FindWindowViewModel, int> interaction) public async Task ShowFindWindowAsync(InteractionContext<FindWindowViewModel, int> interaction) {
{
var window = new FindWindow(); var window = new FindWindow();
window.DataContext = interaction.Input; window.DataContext = interaction.Input;
+2 -1
View File
@@ -10,7 +10,8 @@
<Label Grid.Column="0" Grid.Row="0" Margin="5, 5, 20, 5" VerticalAlignment="Center" Content="PCGS #:" /> <Label Grid.Column="0" Grid.Row="0" Margin="5, 5, 20, 5" VerticalAlignment="Center" Content="PCGS #:" />
<TextBox Grid.Column="1" Grid.Row="0" Margin="5, 5, 10, 5" Text="{Binding PcgsNumber}" /> <TextBox Grid.Column="1" Grid.Row="0" Margin="5, 5, 10, 5" Text="{Binding PcgsNumber}" />
<Label Grid.Column="0" Grid.Row="1" Margin="5, 5, 20, 5" VerticalAlignment="Center" Content="Grade:" /> <Label Grid.Column="0" Grid.Row="1" Margin="5, 5, 20, 5" VerticalAlignment="Center" Content="Grade:" />
<ComboBox Name="GradeChoices" Grid.Column="1" Grid.Row="1" SelectedIndex="0" Margin="5, 5, 10, 5" Width="150" <ComboBox Name="GradeChoices" Grid.Column="1" Grid.Row="1" SelectedIndex="0" Margin="5, 5, 10, 5"
Width="150"
ItemsSource="{Binding GradesList}" SelectedItem="{Binding Grade}" /> ItemsSource="{Binding GradesList}" SelectedItem="{Binding Grade}" />
<Label Grid.Column="0" Grid.Row="2" Margin="5, 5, 20, 5" VerticalAlignment="Center" Content="Quantity:" /> <Label Grid.Column="0" Grid.Row="2" Margin="5, 5, 20, 5" VerticalAlignment="Center" Content="Quantity:" />
<TextBox Grid.Column="1" Grid.Row="2" Margin="5, 5, 10, 5" Text="{Binding Quantity}" /> <TextBox Grid.Column="1" Grid.Row="2" Margin="5, 5, 10, 5" Text="{Binding Quantity}" />
+2 -4
View File
@@ -4,10 +4,8 @@ using Avalonia.Markup.Xaml;
namespace PcgsInvUi.Views; namespace PcgsInvUi.Views;
public partial class NewView : UserControl public partial class NewView : UserControl {
{ public NewView() {
public NewView()
{
InitializeComponent(); InitializeComponent();
} }
} }