add PropertyChangedBase to all VMs and delete EventHandler

pull/1/head
Sascha Woitschetzki 2021-07-12 10:17:43 +07:00
parent 0f7f495975
commit 8fcaa06eab
10 changed files with 47 additions and 129 deletions

@ -4,17 +4,17 @@ namespace Gremlin.MVVM
{
public class AppBootstrapper : BootstrapperBase
{
private readonly SimpleContainer _container = new();
//private readonly SimpleContainer _container = new();
public AppBootstrapper()
{
Initialize();
}
protected override void Configure()
{
_container.Singleton<IEventAggregator, EventAggregator>();
}
//protected override void Configure()
//{
// _container.Singleton<IEventAggregator, EventAggregator>();
//}
protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
{

@ -1,4 +1,5 @@
using Gremlin.GremlinData.DBClasses;
using Caliburn.Micro;
using Gremlin.GremlinData.DBClasses;
using Gremlin.GremlinData.EntityClasses;
using Microsoft.EntityFrameworkCore;
using System;
@ -8,7 +9,7 @@ using System.Linq;
namespace Gremlin.MVVM
{
internal class AccountViewModel : BaseViewModel
internal class AccountViewModel : PropertyChangedBase
{
public uint SAPAccountNumber { get; set; }
public string AccountName { get; set; }

@ -7,38 +7,14 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Gremlin.MVVM
{
public class AllContactsViewModel : PropertyChangedBase, IHandle<ShellViewModel>
public class AllContactsViewModel : PropertyChangedBase
{
private ObservableCollection<ContactViewModel> _allContactsVM;
private IEventAggregator _eventAggregator;
public static ObservableCollection<ContactViewModel> ListOfContactsVM => GetAllContactsVM();
public ObservableCollection<ContactViewModel> AllContactsVM { get => _allContactsVM; internal set { _allContactsVM = value; NotifyOfPropertyChange(() => AllContactsVM); } }
//public AllContactsViewModel()
//{
// LoadContacts();
//}
public AllContactsViewModel(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
LoadContacts();
_eventAggregator.PublishOnUIThreadAsync($"{AllContactsVM.Count} Contacts loaded.");
}
public AllContactsViewModel()
{
}
public void LoadContacts()
{
AllContactsVM = GetAllContactsVM();
}
public AllContactsViewModel() { }
internal static ObservableCollection<ContactViewModel> GetAllContactsVM()
{
@ -65,10 +41,5 @@ namespace Gremlin.MVVM
throw;
}
}
public Task HandleAsync(ShellViewModel message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}

@ -1,17 +0,0 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Gremlin.MVVM
{
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
Debug.WriteLine(propName + " changed in INotifyPropertyChanged");
}
}
}

@ -18,7 +18,7 @@ namespace Gremlin.MVVM
private string _accountStreet;
private uint _accountZIP;
private string _accountCity;
private IEventAggregator _eventAggregator;
//private IEventAggregator _eventAggregator;
public byte Gender { get => _gender; internal set { _gender = value; NotifyOfPropertyChange(() => Gender); } }
public string FirstName { get => _firstName; internal set { _firstName = value; NotifyOfPropertyChange(() => FirstName); } }
@ -29,10 +29,10 @@ namespace Gremlin.MVVM
public uint AccountZIP { get => _accountZIP; internal set { _accountZIP = value; NotifyOfPropertyChange(() => AccountZIP); } }
public string AccountCity { get => _accountCity; internal set { _accountCity = value; NotifyOfPropertyChange(() => AccountCity); } }
public ContactViewModel(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
}
//public ContactViewModel(IEventAggregator eventAggregator)
//{
// _eventAggregator = eventAggregator;
//}
public ContactViewModel(byte gender, string firstName, string lastName, string eMail, string accountName, string accountStreet, uint accountZIP, string accountCity)
{

@ -1,23 +1,36 @@
using System;
using Caliburn.Micro;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
namespace Gremlin.MVVM
{
public class LineItemViewModel : BaseViewModel
public class LineItemViewModel : PropertyChangedBase
{
public ushort Position { get; private set; }
public ushort Amount { get; internal set; }
public string ProductNumber { get; private set; }
public string OptionNumber { get; private set; }
public string SapShortDescription { get; private set; }
public CustomDescriptionViewModel CustomDescriptionVM { get; private set; }
public string ProductLine { get; private set; }
public decimal TotalDiscount { get; internal set; }
public decimal CalcNetPrice { get; private set; }
public decimal CalcTotalNet { get; private set; }
public decimal ListPrice { get; private set; }
private ushort _position;
private ushort _amount;
private string _productNumber;
private string _optionNumber;
private string _sapShortDescription;
private CustomDescriptionViewModel _customDescriptionVM;
private string _productLine;
private decimal _totalDiscount;
private decimal _calcNetPrice;
private decimal _calcTotalNet;
private decimal _listPrice;
public ushort Position { get => _position; internal set { _position = value; NotifyOfPropertyChange(() => Position); } }
public ushort Amount { get => _amount; internal set { _amount = value; NotifyOfPropertyChange(() => Amount); } }
public string ProductNumber { get => _productNumber; internal set { _productNumber = value; NotifyOfPropertyChange(() => ProductNumber); }}
public string OptionNumber { get => _optionNumber; internal set { _optionNumber = value; NotifyOfPropertyChange(() => OptionNumber); }}
public string SapShortDescription { get => _sapShortDescription; internal set { _sapShortDescription = value; NotifyOfPropertyChange(() => SapShortDescription); }}
public CustomDescriptionViewModel CustomDescriptionVM { get => _customDescriptionVM; internal set { _customDescriptionVM = value; NotifyOfPropertyChange(() => CustomDescriptionVM); }}
public string ProductLine { get => _productLine; internal set { _productLine = value; NotifyOfPropertyChange(() => ProductLine); }}
public decimal TotalDiscount { get => _totalDiscount; internal set { _totalDiscount = value; NotifyOfPropertyChange(() => TotalDiscount); }}
public decimal CalcNetPrice { get => _calcNetPrice; internal set { _calcNetPrice = value; NotifyOfPropertyChange(() => CalcNetPrice); }}
public decimal CalcTotalNet { get => _calcTotalNet; internal set { _calcTotalNet = value; NotifyOfPropertyChange(() => CalcTotalNet); }}
public decimal ListPrice { get => _listPrice; internal set { _listPrice = value; NotifyOfPropertyChange(() => ListPrice); }}
internal static ObservableCollection<LineItemViewModel> ReadLineItemsFromClipboard()
{

@ -2,12 +2,10 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Gremlin.MVVM
{
public class QuoteViewModel : PropertyChangedBase, IHandle<ShellViewModel>
public class QuoteViewModel : PropertyChangedBase
{
private string _quoteType = "ein Analysegerät";
private string _quotePath;
@ -29,7 +27,6 @@ namespace Gremlin.MVVM
private bool _quoteContains3PP;
private bool _quoteContainsRB;
private bool? _showDiscounts = true;
private IEventAggregator _eventAggregator;
public string QuoteType { get => _quoteType; internal set { _quoteType = value; NotifyOfPropertyChange(() => QuoteType); } }
public string QuotePath { get => _quotePath; internal set { _quotePath = value; NotifyOfPropertyChange(() => QuotePath); } }
@ -65,7 +62,7 @@ namespace Gremlin.MVVM
};
}
//public QuoteViewModel() { }
public QuoteViewModel() { }
private QuoteViewModel(string quoteNumber, string quoteType, ContactViewModel recipient, ContactViewModel salesRep, bool? brutto, float vAT, int warranty, int validity, string quotePath, bool? singlePrices, bool? brochures, bool? dataSheets, bool? mailTemplate, bool? showDiscounts)
{
@ -85,15 +82,6 @@ namespace Gremlin.MVVM
ShowDiscounts = showDiscounts;
}
public QuoteViewModel(IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
}
public QuoteViewModel()
{
}
internal static QuoteViewModel CreateQuote(string quoteNumber, ContactViewModel recipient, ContactViewModel salesRep, float vAT = 19f, string quoteType = "ein Analysegerät", bool? brutto = true, int warranty = 12, bool? singlePrices = true, bool? brochures = true, bool? dataSheets = true, bool? mailTemplate = true, string quotePath = "", int validity = 60, bool? showDiscounts = true)
{
decimal totalListprice = 0, totalDiscount = 0, calcTotalNet = 0;
@ -156,15 +144,9 @@ namespace Gremlin.MVVM
};
}
public void ReadLineItems()
{
LineItemsViewModel = LineItemViewModel.ReadLineItemsFromClipboard();
}
public Task HandleAsync(ShellViewModel message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}

@ -1,43 +1,16 @@
using Caliburn.Micro;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Gremlin.MVVM
{
public class ShellViewModel : PropertyChangedBase, IHandle<QuoteViewModel> ,IHandle<AllContactsViewModel>
public class ShellViewModel : PropertyChangedBase
{
private AllContactsViewModel allContactsVM;
private QuoteViewModel quoteVM;
private readonly IEventAggregator _eventAggregator;
public QuoteViewModel QuoteVM { get => quoteVM; set => quoteVM = value; }
public AllContactsViewModel AllContactsVM { get => allContactsVM; set => allContactsVM = value; }
public QuoteViewModel QuoteVM { get; set; }
public AllContactsViewModel AllContactsVM { get; set; }
public ShellViewModel()
{
QuoteVM = new();
AllContactsVM = new();
}
public ShellViewModel(IEventAggregator eventAggregator)
{
QuoteVM = new QuoteViewModel(eventAggregator);
AllContactsVM = new AllContactsViewModel(eventAggregator);
_eventAggregator = eventAggregator;
_eventAggregator.PublishOnUIThreadAsync($"{AllContactsVM.AllContactsVM.Count} Contacts loaded.");
_eventAggregator.PublishOnUIThreadAsync(12);
}
public Task HandleAsync(AllContactsViewModel message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task HandleAsync(QuoteViewModel message, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}

@ -4,14 +4,10 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="0" Height="Auto">
<Button x:Name="LoadContacts" Content="Kontakte laden" Margin="10,5,10,5"/>
</Grid>
<Grid Grid.Row="1" Grid.Column="0" Height="Auto">
<DataGrid x:Name="AllContactsVM" AutoGenerateColumns="True" Height="200" Width ="600" Margin="10,5,10,5" />
</Grid>

@ -4,6 +4,5 @@ namespace Gremlin.MVVM
{
public partial class ShellView : UserControl
{
}
}