binding of all text boxes to the VM class

pull/1/head
Sascha Woitschetzki 2021-06-22 22:38:11 +07:00
parent 2314883319
commit 54ab613f85
4 changed files with 47 additions and 38 deletions

@ -7,6 +7,9 @@
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Title="Gremlin QuoteUI" Height="1024" Width="1280">
<Window.Resources>
<viewmodels:QuoteVM x:Key="m" ></viewmodels:QuoteVM>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
@ -70,11 +73,11 @@
<Grid Grid.Column="1" Height="Auto">
<StackPanel>
<TextBox x:Name="tbQuoteType" Text="ein Analysegerät" Margin="10,4,10,4" TextChanged="TbQuoteType_TextChanged" />
<TextBox x:Name="tbQuoteNumber" Text="DE-83PE89-421-6000" Margin="10,4,10,4" TextChanged="TbQuoteNumber_TextChanged" />
<TextBox x:Name="tbQuotePath" Text="D:\Coding\Gremlin\Gremlin\bin\Debug\net5.0-windows" Margin="10,4,10,4" TextChanged="TbQuotePath" />
<TextBox x:Name="tbWarranty" Text="12" Margin="10,4,10,4" TextChanged="TbWarranty_TextChanged" />
<TextBox x:Name="tbValidity" Text="60" Margin="10,5,10,5" TextChanged="TbValidity_TextChanged" />
<TextBox x:Name="tbQuoteType" Text="{Binding Path=QuoteType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="10,4,10,4" TextChanged="TbQuoteType_TextChanged" />
<TextBox x:Name="tbQuoteNumber" Text="{Binding Path=QuoteNumber, UpdateSourceTrigger=PropertyChanged}" Margin="10,4,10,4" TextChanged="TbQuoteNumber_TextChanged" />
<TextBox x:Name="tbQuotePath" Text="{Binding Path=QuotePath, UpdateSourceTrigger=PropertyChanged}" Margin="10,4,10,4" TextChanged="TbQuotePath" />
<TextBox x:Name="tbWarranty" Text="{Binding Path=Warranty, UpdateSourceTrigger=PropertyChanged}" Margin="10,4,10,4" TextChanged="TbWarranty_TextChanged" />
<TextBox x:Name="tbValidity" Text="{Binding Path=Validity, UpdateSourceTrigger=PropertyChanged}" Margin="10,5,10,5" TextChanged="TbValidity_TextChanged" />
<TextBox x:Name="tbOppID" Text="3003541659" Margin="10,4,10,4" />
</StackPanel>
</Grid>
@ -83,11 +86,11 @@
<StackPanel x:Name="Opp" Grid.Row="0" Grid.Column="2" Orientation="Vertical">
<CheckBox d:DataContext="{d:DesignInstance Type=viewmodels:QuoteVM}" x:Name="cbBrutto" Content="Brutto anzeigen" Margin="10,5,10,5" IsChecked="{Binding Path=Brutto, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Click="CbBrutto_Click"/>
<CheckBox x:Name="cbSinglePrices" Content="Einzelpreise ausweisen" Margin="10,5,10,5" IsChecked="True" Click="CbSinglePrices_Click" />
<CheckBox x:Name="cbShowDiscounts" Content="Discounts ausweisen" Margin="10,5,10,5" IsChecked="True" Click="CbShowDiscounts_Click"/>
<CheckBox x:Name="cbBrochure" Content="Broschüren anhängen" Margin="10,5,10,5" Click="CbBrochure_Click" />
<CheckBox x:Name="cbDataSheets" Content="Datenblätter anhängen" Margin="10,5,10,5" Click="CbDataSheets_Click" />
<CheckBox x:Name="cbMailTemplate" Content="Mail aus Template erstellen" Margin="10,5,10,5" Click="CbMailTemplate_Click" />
<CheckBox x:Name="cbSinglePrices" Content="Einzelpreise ausweisen" Margin="10,5,10,5" IsChecked="{Binding Path=SinglePrices, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Click="CbSinglePrices_Click" />
<CheckBox x:Name="cbShowDiscounts" Content="Discounts ausweisen" Margin="10,5,10,5" IsChecked="{Binding Path=ShowDiscounts, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Click="CbShowDiscounts_Click"/>
<CheckBox x:Name="cbBrochure" Content="Broschüren anhängen" Margin="10,5,10,5" IsChecked="{Binding Path=Brochures, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Click="CbBrochure_Click" />
<CheckBox x:Name="cbDataSheets" Content="Datenblätter anhängen" Margin="10,5,10,5" IsChecked="{Binding Path=DataSheets, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Click="CbDataSheets_Click" />
<CheckBox x:Name="cbMailTemplate" Content="Mail aus Template erstellen" Margin="10,5,10,5" IsChecked="{Binding Path=MailTemplate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Click="CbMailTemplate_Click" />
</StackPanel>
</Grid>

@ -4,6 +4,7 @@ using Gremlin.Operations;
using Gremlin.ViewModels;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Data;
@ -13,19 +14,11 @@ namespace Gremlin.GremlinUI
{
private static ListCollectionView listCollectionContacts = new(new ObservableCollection<Contact>());
private static ListCollectionView lineItems = new(new ObservableCollection<LineItemVM>());
private QuoteVM quoteVM = new();
private readonly int salesRepCode = 1;
private QuoteVM quoteVM = new(ContactVM.GetSalesRepAsContact(1));
public QuoteUI()
{
Random random = new();
InitializeComponent();
if (salesRepCode == 1)
tbQuoteNumber.Text = $"DE-83PE89-{DateTime.Now:My}-{random.Next(999999)}";
else if (salesRepCode == 2)
tbQuoteNumber.Text = $"DE-83RE32-{DateTime.Now:My}-{random.Next(999999)}";
LoadContacts();
}
@ -49,7 +42,6 @@ namespace Gremlin.GremlinUI
private void DgFoundContacts_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
quoteVM.NotifyPropertyChanged("Recipient");
quoteVM.Recipient = ContactVM.ConvertObjectToContactVM(dgFoundContacts.SelectedItem);
}
@ -61,7 +53,7 @@ namespace Gremlin.GremlinUI
quoteVM = QuoteVM.CreateQuote(tbQuoteNumber.Text,
ContactVM.ConvertObjectToContactVM(dgFoundContacts.SelectedItem),
ContactVM.GetSalesRepAsContact(salesRepCode),
quoteVM.SalesRep,
vat,
tbQuoteType.Text,
cbBrutto.IsChecked,
@ -112,8 +104,7 @@ namespace Gremlin.GremlinUI
private void TbQuoteType_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
quoteVM.NotifyPropertyChanged("QuoteType");
quoteVM.QuoteType = tbQuoteType.Text;
quoteVM.OnPropertyChanged("QuoteType");
}
private void TbQuotePath(object sender, System.Windows.Controls.TextChangedEventArgs e)

@ -1,4 +1,6 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Gremlin.GremlinUI.ViewModels
{
@ -6,9 +8,10 @@ namespace Gremlin.GremlinUI.ViewModels
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propName)
public void OnPropertyChanged([CallerMemberName] string propName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
Debug.WriteLine(propName + " changed in INotifyPropertyChanged");
}
}
}

@ -8,26 +8,26 @@ namespace Gremlin.GremlinUI.ViewModels
{
internal class QuoteVM : BaseVM
{
private string quoteType;
private string quoteType = "ein Analysegerät";
private string quotePath;
private List<LineItemVM> lineItemsVM;
private ContactVM recipient;
private ContactVM salesRep;
private string quoteNumber;
private int warranty;
private int validity;
private int warranty = 12;
private int validity = 60;
private decimal totalListprice;
private decimal averageDiscount;
private decimal totalNet;
private float vAT;
private bool? brutto;
private bool? singlePrices;
private bool? brochures;
private bool? dataSheets;
private bool? mailTemplate;
private bool quoteContains3PP;
private bool quoteContainsRB;
private bool? showDiscounts;
private float vAT = 19f;
private bool? brutto = true;
private bool? singlePrices = true;
private bool? brochures = false;
private bool? dataSheets = false;
private bool? mailTemplate = false;
private bool quoteContains3PP = false;
private bool quoteContainsRB = false;
private bool? showDiscounts = true;
public string QuoteType
{
@ -36,7 +36,7 @@ namespace Gremlin.GremlinUI.ViewModels
internal set
{
quoteType = value;
NotifyPropertyChanged("QuoteType");
OnPropertyChanged("QuoteType");
}
}
@ -46,7 +46,7 @@ namespace Gremlin.GremlinUI.ViewModels
internal set
{
quotePath = value;
NotifyPropertyChanged("QuotePath");
OnPropertyChanged("QuotePath");
}
}
@ -69,6 +69,18 @@ namespace Gremlin.GremlinUI.ViewModels
public bool QuoteContainsRB { get => quoteContainsRB; private set => quoteContainsRB = value; }
public bool? ShowDiscounts { get => showDiscounts; internal set => showDiscounts = value; }
internal QuoteVM(ContactVM salesRep)
{
Random random = new();
SalesRep = salesRep;
QuoteNumber = SalesRep.LastName switch
{
"Woitschetzki" => $"DE-83PE89-{DateTime.Now:My}-{random.Next(999999)}",
"Welsch" => $"DE-83RE32-{DateTime.Now:My}-{random.Next(999999)}",
_ => $"DE-XXYYXX-{DateTime.Now:My}-{random.Next(999999)}",
};
}
internal QuoteVM() { }
private QuoteVM(string quoteNumber, string quoteType, ContactVM recipient, ContactVM salesRep, bool? brutto, float vAT, int warranty, int validity, string quotePath, bool? singlePrices, bool? brochures, bool? dataSheets, bool? mailTemplate, bool? showDiscounts)