Merge vas-working to master (attempt 2) #2
No files matched your search
@@ -17,7 +17,7 @@ public partial class App : Application {
|
|||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
|
|
||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
|
||||||
var coins = new Database();
|
var coins = new CoinDatabase();
|
||||||
|
|
||||||
desktop.MainWindow = new MainWindow {
|
desktop.MainWindow = new MainWindow {
|
||||||
DataContext = new MainWindowViewModel(coins),
|
DataContext = new MainWindowViewModel(coins),
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ using PcgsInvUi.Models;
|
|||||||
|
|
||||||
namespace PcgsInvUi.Services;
|
namespace PcgsInvUi.Services;
|
||||||
|
|
||||||
public class Database {
|
public class CoinDatabase {
|
||||||
public SQLiteConnection Connection { get; set; }
|
public SQLiteConnection Connection { get; set; }
|
||||||
private Boolean IsConnected { get; set; }
|
private Boolean IsConnected { get; set; }
|
||||||
|
|
||||||
public Database() {
|
public CoinDatabase() {
|
||||||
// Create a connection to SQLite
|
// Create a connection to SQLite
|
||||||
Connection = CreateConnection();
|
Connection = CreateConnection();
|
||||||
// Create a base table.
|
// Create a base table.
|
||||||
@@ -13,7 +13,7 @@ namespace PcgsInvUi.ViewModels;
|
|||||||
// TODO Error handling.
|
// TODO Error handling.
|
||||||
// TODO Manual handling of API key.
|
// TODO Manual handling of API key.
|
||||||
// TODO Use CoinFacts link.
|
// TODO Use CoinFacts link.
|
||||||
// TODO Splash screen that loads.
|
// TODO Splash screen during startup.
|
||||||
// TODO Take giant sheet of coins to integrate into the application.
|
// TODO Take giant sheet of coins to integrate into the application.
|
||||||
// TODO Update all coins. Choose those that are older first.
|
// TODO Update all coins. Choose those that are older first.
|
||||||
// TODO API request tracker (1000 per day)
|
// TODO API request tracker (1000 per day)
|
||||||
@@ -28,7 +28,7 @@ public class MainWindowViewModel : ViewModelBase {
|
|||||||
}
|
}
|
||||||
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 Database ConnectedDatabase { get; set; }
|
public CoinDatabase ConnectedCoinDatabase { get; set; }
|
||||||
public Coin? SelectedCoin {
|
public Coin? SelectedCoin {
|
||||||
get => _selectedCoin;
|
get => _selectedCoin;
|
||||||
set => this.RaiseAndSetIfChanged(ref _selectedCoin, value);
|
set => this.RaiseAndSetIfChanged(ref _selectedCoin, value);
|
||||||
@@ -43,21 +43,21 @@ public class MainWindowViewModel : ViewModelBase {
|
|||||||
public ReactiveCommand<Unit, Coin> FindCommand { get; }
|
public ReactiveCommand<Unit, Coin> FindCommand { get; }
|
||||||
public Interaction<FindWindowViewModel, int> ShowFindWindow { get; }
|
public Interaction<FindWindowViewModel, int> ShowFindWindow { get; }
|
||||||
public ReactiveCommand<Unit, Unit> ExportCommand { get; }
|
public ReactiveCommand<Unit, Unit> ExportCommand { get; }
|
||||||
public Interaction<Unit, Stream> ShowExportWindow { get; }
|
public Interaction<Unit, Uri> ShowExportWindow { get; }
|
||||||
|
|
||||||
private ViewModelBase _sideContent;
|
private ViewModelBase _sideContent;
|
||||||
private Coin? _selectedCoin;
|
private Coin? _selectedCoin;
|
||||||
private double _totalValue;
|
private double _totalValue;
|
||||||
private PcgsClient _pcgsClient;
|
private PcgsClient _pcgsClient;
|
||||||
|
|
||||||
// public MainWindowViewModel(CoinCollection coins) {
|
public MainWindowViewModel(CoinDatabase coins) {
|
||||||
public MainWindowViewModel(Database coins) {
|
ConnectedCoinDatabase = coins;
|
||||||
ConnectedDatabase = 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());
|
||||||
DisplayedList = CoinCollection =
|
DisplayedList = CoinCollection =
|
||||||
new ObservableCollection<Coin>(coins.GetCollection("CollectionTable"));
|
new ObservableCollection<Coin>(coins.GetCollection("CollectionTable"));
|
||||||
|
TotalValue = DisplayedList.Sum(x => x.TotalPrice);
|
||||||
_pcgsClient = new PcgsClient(
|
_pcgsClient = new PcgsClient(
|
||||||
"eAb8gS0I2XAvT_5gJeiGJaglMia1Tk-oB4kJUK6kuafyrny_S61vIJY-Ikl4nCQM67wrdxzUqLVWTV2kBSxD3d5XNBHxHnYBhcSS6dOPug0hZaF3qAv56df3gYSzOGh9Tif5y0eP3Iw0LrqKDr1Hj-dk6SV6GKog2IIqCPQhhHH8FMTWBTYO-_O8cx7qLdM5GM8KlTsic6g3VRUhM8EA_4OO04dCfmNLGhqINRl3jGZ0Q4ziI8fng2bVWsIyteqiPzUn10rIQ3-OPpqVZG_DxeOmOejj4GzbUNyqUOajy-nr5rYY");
|
"eAb8gS0I2XAvT_5gJeiGJaglMia1Tk-oB4kJUK6kuafyrny_S61vIJY-Ikl4nCQM67wrdxzUqLVWTV2kBSxD3d5XNBHxHnYBhcSS6dOPug0hZaF3qAv56df3gYSzOGh9Tif5y0eP3Iw0LrqKDr1Hj-dk6SV6GKog2IIqCPQhhHH8FMTWBTYO-_O8cx7qLdM5GM8KlTsic6g3VRUhM8EA_4OO04dCfmNLGhqINRl3jGZ0Q4ziI8fng2bVWsIyteqiPzUn10rIQ3-OPpqVZG_DxeOmOejj4GzbUNyqUOajy-nr5rYY");
|
||||||
|
|
||||||
@@ -69,26 +69,26 @@ public class MainWindowViewModel : ViewModelBase {
|
|||||||
var deleteViewModel = new DeleteWindowViewModel();
|
var deleteViewModel = new DeleteWindowViewModel();
|
||||||
var result = await ShowDeleteWindow.Handle(deleteViewModel);
|
var result = await ShowDeleteWindow.Handle(deleteViewModel);
|
||||||
if (result && SelectedCoin is not null) {
|
if (result && SelectedCoin is not null) {
|
||||||
ConnectedDatabase.DeleteCoin(SelectedCoin);
|
ConnectedCoinDatabase.DeleteCoin(SelectedCoin);
|
||||||
CoinCollection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled.
|
CoinCollection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled.
|
||||||
}
|
}
|
||||||
}, deleteEnabled);
|
}, deleteEnabled);
|
||||||
|
|
||||||
ShowExportWindow = new Interaction<Unit, Stream>();
|
ShowExportWindow = new Interaction<Unit, Uri>();
|
||||||
ExportCommand = ReactiveCommand.CreateFromTask(async () => {
|
ExportCommand = ReactiveCommand.CreateFromTask(async () => {
|
||||||
var stream = await ShowExportWindow.Handle(Unit.Default);
|
|
||||||
var writer = new StreamWriter(stream);
|
|
||||||
try {
|
try {
|
||||||
await writer.WriteAsync(ConnectedDatabase.CollectionToCSV("CollectionTable"));
|
var filePath = await ShowExportWindow.Handle(Unit.Default);
|
||||||
|
var stream = File.Open(filePath.AbsolutePath, FileMode.OpenOrCreate);
|
||||||
|
var writer = new StreamWriter(stream);
|
||||||
|
await writer.WriteAsync(ConnectedCoinDatabase.CollectionToCSV("CollectionTable"));
|
||||||
await writer.FlushAsync();
|
await writer.FlushAsync();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
// Something is wrong with the file after it's been created.
|
// Something is wrong with the file after it's been created.
|
||||||
Console.WriteLine(e.Message);
|
Console.WriteLine(e.Message);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.Close();
|
|
||||||
stream.Close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set up the ability to open the find window.
|
// Set up the ability to open the find window.
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel> {
|
|||||||
interaction.SetOutput(result);
|
interaction.SetOutput(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ShowFilePickerAsync(InteractionContext<Unit, Stream> interationContext) {
|
public async Task ShowFilePickerAsync(InteractionContext<Unit, Uri> interationContext) {
|
||||||
var topLevel = GetTopLevel(this);
|
var topLevel = GetTopLevel(this);
|
||||||
var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions {
|
var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions {
|
||||||
Title = "Save CSV...",
|
Title = "Save CSV...",
|
||||||
@@ -44,10 +44,13 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Stream stream;
|
Stream stream;
|
||||||
|
|
||||||
if (file is not null) {
|
if (file is not null) {
|
||||||
stream = await file.OpenWriteAsync();
|
interationContext.SetOutput(file.Path);
|
||||||
interationContext.SetOutput(stream);
|
}
|
||||||
|
else {
|
||||||
|
// TODO Handle user closing the dialog.
|
||||||
|
throw new Exception("User cancelled the file picker.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user