optimize ShellViewModel

pull/1/head
Sascha Woitschetzki 2021-07-09 11:05:59 +07:00
parent 46adcf0087
commit 27702728d6
8 changed files with 31 additions and 44 deletions

@ -1,18 +1,7 @@
using Gremlin.GremlinData.DBClasses; using Gremlin.GremlinData.DBClasses;
using Gremlin.GremlinUtilities; using Gremlin.GremlinUtilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Gremlin.MVVM namespace Gremlin.MVVM
{ {

@ -1,5 +1,4 @@
using Gremlin.GremlinUtilities; using System;
using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;

@ -84,7 +84,7 @@ namespace Gremlin.MVVM
_ = texFile.AppendLine(@"\textbf{\#} & \textbf{Produktbeschreibung} (Produktnummer) & \textbf{Menge}\\ \hline \endhead"); _ = texFile.AppendLine(@"\textbf{\#} & \textbf{Produktbeschreibung} (Produktnummer) & \textbf{Menge}\\ \hline \endhead");
} }
foreach (LineItemViewModel lI in quoteVM.LineItemsVM) foreach (LineItemViewModel lI in quoteVM.LineItemsViewModel)
{ {
string lineItemTex = ""; string lineItemTex = "";
@ -156,7 +156,7 @@ namespace Gremlin.MVVM
string rbDisclaimer = "\\textbf{Wichtiger Hinweis zur Bestellung von überholten Geräten}\\\\\n"; string rbDisclaimer = "\\textbf{Wichtiger Hinweis zur Bestellung von überholten Geräten}\\\\\n";
rbDisclaimer += "Bitte beachten Sie, dass in der Regel nur wenige gebrauchte Geräte auf Lager sind und diese ohne die Möglichkeit einer Reservierung auf „first come, first serve“-Basis verkauft werden. Um lange Lieferzeiten zu vermeiden, sollte daher bei konkretem Interesse zunächst der Lagerstand überprüft werden. Die aktuellen Lagerbestände sind:\n"; rbDisclaimer += "Bitte beachten Sie, dass in der Regel nur wenige gebrauchte Geräte auf Lager sind und diese ohne die Möglichkeit einer Reservierung auf „first come, first serve“-Basis verkauft werden. Um lange Lieferzeiten zu vermeiden, sollte daher bei konkretem Interesse zunächst der Lagerstand überprüft werden. Die aktuellen Lagerbestände sind:\n";
List<LineItemViewModel> lineItemsWithRB = quoteVM.LineItemsVM.Where(lI => lI.ProductLine == "RB").ToList(); List<LineItemViewModel> lineItemsWithRB = quoteVM.LineItemsViewModel.Where(lI => lI.ProductLine == "RB").ToList();
rbDisclaimer += "\\begin{center}\n\\begin{tabular}{clc}\n"; rbDisclaimer += "\\begin{center}\n\\begin{tabular}{clc}\n";
rbDisclaimer += "\\textbf{Modul} & \\textbf{Beschreibung} &\\textbf{Bestand}\\\\ \\hline \n"; rbDisclaimer += "\\textbf{Modul} & \\textbf{Beschreibung} &\\textbf{Bestand}\\\\ \\hline \n";
@ -176,7 +176,7 @@ namespace Gremlin.MVVM
+ $"Bitte beachten Sie, dass das/die o.g. Produkt/e "; + $"Bitte beachten Sie, dass das/die o.g. Produkt/e ";
//List all 3PP product numbers //List all 3PP product numbers
List<LineItemViewModel> lineItemsWith3PP = quoteVM.LineItemsVM.Where(lI => lI.ProductLine == "3PP").ToList(); List<LineItemViewModel> lineItemsWith3PP = quoteVM.LineItemsViewModel.Where(lI => lI.ProductLine == "3PP").ToList();
for (int i = 0; i < lineItemsWith3PP.Count; i++) for (int i = 0; i < lineItemsWith3PP.Count; i++)
{ {
_ = i < lineItemsWith3PP.Count - 1 _ = i < lineItemsWith3PP.Count - 1
@ -211,7 +211,7 @@ namespace Gremlin.MVVM
+ "Es umfasst im Einzelnen:\n" + "Es umfasst im Einzelnen:\n"
+ "\\begin{itemize}\n"; + "\\begin{itemize}\n";
foreach (LineItemViewModel lineItemVM in quoteVM.LineItemsVM) foreach (LineItemViewModel lineItemVM in quoteVM.LineItemsViewModel)
{ {
if (lineItemVM.OptionNumber == "") if (lineItemVM.OptionNumber == "")
{ {

@ -65,14 +65,14 @@ namespace Gremlin.MVVM
if (quoteVM == null) return; if (quoteVM == null) return;
ObservableCollection<LineItemViewModel> lineItemsViewModel = new(quoteVM.LineItemsVM); ObservableCollection<LineItemViewModel> lineItemsViewModel = new(quoteVM.LineItemsViewModel);
lineItems = new(lineItemsViewModel); lineItems = new(lineItemsViewModel);
UpdateUI(); UpdateUI();
} }
private void BtnCreateTex_Click(object sender, RoutedEventArgs e) private void BtnCreateTex_Click(object sender, RoutedEventArgs e)
{ {
if (quoteVM.LineItemsVM == null || quoteVM.LineItemsVM.Count == 0) if (quoteVM.LineItemsViewModel == null || quoteVM.LineItemsViewModel.Count == 0)
{ {
ErrorHandler.ShowMessageBox("Bitte zuerst ein Angebot einfügen"); ErrorHandler.ShowMessageBox("Bitte zuerst ein Angebot einfügen");
} }

@ -22,11 +22,11 @@ namespace Gremlin.MVVM
private float _vAT = 19f; private float _vAT = 19f;
private bool? _showBrutto = true; private bool? _showBrutto = true;
private bool? _singlePrices = true; private bool? _singlePrices = true;
private bool? _attachBrochures = false; private bool? _attachBrochures;
private bool? _attachDataSheets = false; private bool? _attachDataSheets;
private bool? _useMailTemplate = false; private bool? _useMailTemplate;
private bool _quoteContains3PP = false; private bool _quoteContains3PP;
private bool _quoteContainsRB = false; private bool _quoteContainsRB;
private bool? _showDiscounts = true; private bool? _showDiscounts = true;
public string QuoteType { get => _quoteType; internal set { _quoteType = value; NotifyOfPropertyChange(() => QuoteType); } } public string QuoteType { get => _quoteType; internal set { _quoteType = value; NotifyOfPropertyChange(() => QuoteType); } }
@ -41,15 +41,15 @@ namespace Gremlin.MVVM
public bool? UseMailTemplate { get => _useMailTemplate; internal set { _useMailTemplate = value; NotifyOfPropertyChange(() => UseMailTemplate); } } public bool? UseMailTemplate { get => _useMailTemplate; internal set { _useMailTemplate = value; NotifyOfPropertyChange(() => UseMailTemplate); } }
public bool? ShowDiscounts { get => _showDiscounts; internal set { _showDiscounts = value; NotifyOfPropertyChange(() => ShowDiscounts); } } public bool? ShowDiscounts { get => _showDiscounts; internal set { _showDiscounts = value; NotifyOfPropertyChange(() => ShowDiscounts); } }
public List<LineItemViewModel> LineItemsVM { get => _lineItemsVM; private set => _lineItemsVM = value; } public List<LineItemViewModel> LineItemsViewModel { get => _lineItemsVM; internal set { _lineItemsVM = value; NotifyOfPropertyChange(() => LineItemsViewModel); } }
public ContactViewModel Recipient { get => _recipient; internal set => _recipient = value; } public ContactViewModel Recipient { get => _recipient; internal set { _recipient = value; NotifyOfPropertyChange(() => Recipient); } }
public ContactViewModel SalesRep { get => _salesRep; private set => _salesRep = value; } public ContactViewModel SalesRep { get => _salesRep; internal set { _salesRep = value; NotifyOfPropertyChange(() => SalesRep); } }
public decimal TotalListprice { get => _totalListprice; private set => _totalListprice = value; } public decimal TotalListprice { get => _totalListprice; internal set { _totalListprice = value; NotifyOfPropertyChange(() => TotalListprice); } }
public decimal AverageDiscount { get => _averageDiscount; private set => _averageDiscount = value; } public decimal AverageDiscount { get => _averageDiscount; internal set { _averageDiscount = value; NotifyOfPropertyChange(() => AverageDiscount); } }
public decimal TotalNet { get => _totalNet; private set => _totalNet = value; } public decimal TotalNet { get => _totalNet; internal set { _totalNet = value; NotifyOfPropertyChange(() => TotalNet); } }
public float VAT { get => _vAT; private set => _vAT = value; } public float VAT { get => _vAT; internal set { _vAT = value; NotifyOfPropertyChange(() => VAT); } }
public bool QuoteContains3PP { get => _quoteContains3PP; private set => _quoteContains3PP = value; } public bool QuoteContains3PP { get => _quoteContains3PP; internal set { _quoteContains3PP = value; NotifyOfPropertyChange(() => QuoteContains3PP); } }
public bool QuoteContainsRB { get => _quoteContainsRB; private set => _quoteContainsRB = value; } public bool QuoteContainsRB { get => _quoteContainsRB; internal set { _quoteContainsRB = value; NotifyOfPropertyChange(() => QuoteContainsRB); } }
internal QuoteViewModel(ContactViewModel salesRep) internal QuoteViewModel(ContactViewModel salesRep)
{ {
@ -89,7 +89,7 @@ namespace Gremlin.MVVM
bool quoteContains3PP = false, quoteContainsRB = false; bool quoteContains3PP = false, quoteContainsRB = false;
QuoteViewModel quoteVM = new(quoteNumber, quoteType, recipient, salesRep, brutto, vAT, warranty, validity, quotePath, singlePrices, brochures, dataSheets, mailTemplate, showDiscounts); QuoteViewModel quoteVM = new(quoteNumber, quoteType, recipient, salesRep, brutto, vAT, warranty, validity, quotePath, singlePrices, brochures, dataSheets, mailTemplate, showDiscounts);
quoteVM.LineItemsVM = new(); quoteVM.LineItemsViewModel = new();
ObservableCollection<LineItemViewModel> lineItemsVM = LineItemViewModel.ReadLineItemsFromClipboard(); ObservableCollection<LineItemViewModel> lineItemsVM = LineItemViewModel.ReadLineItemsFromClipboard();
@ -119,7 +119,7 @@ namespace Gremlin.MVVM
quoteVM.Warranty = int.Parse(lineItemVM.OptionNumber.Last().ToString()) * 12; quoteVM.Warranty = int.Parse(lineItemVM.OptionNumber.Last().ToString()) * 12;
} }
quoteVM.LineItemsVM.Add(lineItemVM); quoteVM.LineItemsViewModel.Add(lineItemVM);
} }
quoteVM.TotalListprice = totalListprice; quoteVM.TotalListprice = totalListprice;

@ -1,14 +1,16 @@
namespace Gremlin.MVVM using System.Collections.Generic;
namespace Gremlin.MVVM
{ {
public class ShellViewModel public class ShellViewModel
{ {
public QuoteViewModel QuoteVM { get; set; } public QuoteViewModel QuoteVM { get; set; }
public LineItemViewModel LineVM { get; set; } public List<LineItemViewModel> LineVMs { get; set; }
public ShellViewModel() public ShellViewModel()
{ {
QuoteVM = new QuoteViewModel(); QuoteVM = new QuoteViewModel();
LineVM = new LineItemViewModel(); LineVMs = QuoteVM.LineItemsViewModel;
} }
} }
} }

@ -1,13 +1,10 @@
<UserControl x:Class="Gremlin.MVVM.ShellView" <UserControl x:Class="Gremlin.MVVM.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cal="http://www.caliburnproject.org" xmlns:cal="http://www.caliburnproject.org"
xmlns:local="clr-namespace:Gremlin.MVVM" xmlns:local="clr-namespace:Gremlin.MVVM">
mc:Ignorable="d" >
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<local:QuoteView cal:Bind.Model="{Binding QuoteVM}" /> <local:QuoteView cal:Bind.Model="{Binding QuoteVM}" />
<!--<local:LineItemView cal:Bind.Model="{Binding LineItemVM}" />--> <local:LineItemView cal:Bind.Model="{Binding LineItemVM}" />
</StackPanel> </StackPanel>
</UserControl> </UserControl>

@ -1,6 +1,6 @@
using System.Windows.Controls; using System.Windows.Controls;
namespace Gremlin.MVVM namespace Gremlin.MVVM.Views
{ {
public partial class ShellView : UserControl public partial class ShellView : UserControl
{ {