From b61686e0d52c9a464d3cce2379e648dbedb193d7 Mon Sep 17 00:00:00 2001 From: DJh2o2 Date: Tue, 22 Mar 2022 09:55:42 +0100 Subject: [PATCH] show a summary of LineItems without CustomDescription --- .../ViewModels/CustomDescriptionViewModel.cs | 26 +++++++++----- Gremlin/MVVM/ViewModels/QuoteViewModel.cs | 35 +++++++++++++++++-- Gremlin/MVVM/Views/QuoteView.xaml | 8 +++-- Gremlin/MVVM/Views/ShellView.xaml | 2 +- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/Gremlin/MVVM/ViewModels/CustomDescriptionViewModel.cs b/Gremlin/MVVM/ViewModels/CustomDescriptionViewModel.cs index 5463cee..4eb0ad5 100644 --- a/Gremlin/MVVM/ViewModels/CustomDescriptionViewModel.cs +++ b/Gremlin/MVVM/ViewModels/CustomDescriptionViewModel.cs @@ -1,20 +1,28 @@ -using Gremlin.GremlinData.DBClasses; +using Caliburn.Micro; +using Gremlin.GremlinData.DBClasses; using Gremlin.GremlinData.EntityClasses; using System.Linq; using System.Windows; namespace Gremlin.MVVM { - public class CustomDescriptionViewModel + public class CustomDescriptionViewModel : PropertyChangedBase { - public string Heading { get; set; } - public string DescriptionText { get; set; } - public string CoverletterText { get; set; } - public string Notes { get; set; } //Hinweise, Tipps, Caveats, etc. für Konfiguration, Verwendung, Best Practice usw. + private string heading; + private string descriptionText; + private string coverletterText; + private string notes; + private bool isAvailable; + + public string Heading { get => heading; set { heading = value; NotifyOfPropertyChange(() => Heading); } } + public string DescriptionText { get => descriptionText; set { descriptionText = value; NotifyOfPropertyChange(() => Heading); }} + public string CoverletterText { get => coverletterText; set { coverletterText = value; NotifyOfPropertyChange(() => Heading); } } + public string Notes { get => notes; set { notes = value; NotifyOfPropertyChange(() => Heading); } } + public bool IsAvailable { get => isAvailable; set { isAvailable = value; NotifyOfPropertyChange(() => Heading); } } public override string ToString() { - return $"{Heading}"; + return $"{Heading}\n{DescriptionText}"; } public static CustomDescriptionViewModel GetCustomDescription(LineItemViewModel lineItemVM) @@ -34,12 +42,14 @@ namespace Gremlin.MVVM customDescriptionVM.DescriptionText = TexReplace(customDescription.DescriptionText); customDescriptionVM.CoverletterText = TexReplace(customDescription.CoverletterText); customDescriptionVM.Notes = TexReplace(customDescription.Notes); + customDescriptionVM.IsAvailable = true; } else { - MessageBox.Show($"CustomDescription für \"{lineItemVM.ProductNumber}#{lineItemVM.OptionNumber}\" nicht vorhanden! Verwende (vorläufig) Standardbeschreibung \"{lineItemVM.SapShortDescription}\"!"); + //MessageBox.Show($"CustomDescription für \"{lineItemVM.ProductNumber}#{lineItemVM.OptionNumber}\" nicht vorhanden! Verwende (vorläufig) Standardbeschreibung \"{lineItemVM.SapShortDescription}\"!"); customDescriptionVM.DescriptionText = TexReplace(lineItemVM.SapShortDescription); customDescriptionVM.Heading = TexReplace(lineItemVM.SapShortDescription); + customDescriptionVM.IsAvailable = false; } return customDescriptionVM; diff --git a/Gremlin/MVVM/ViewModels/QuoteViewModel.cs b/Gremlin/MVVM/ViewModels/QuoteViewModel.cs index 5d02e91..2e233dc 100644 --- a/Gremlin/MVVM/ViewModels/QuoteViewModel.cs +++ b/Gremlin/MVVM/ViewModels/QuoteViewModel.cs @@ -1,6 +1,7 @@ using Caliburn.Micro; using Microsoft.Win32; using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; @@ -12,7 +13,7 @@ namespace Gremlin.MVVM { private string quoteType = "ein Analysegerät"; private string quotePath = AppDomain.CurrentDomain.BaseDirectory; - private LineItemViewModel selectedLineItemVM = new(); + private LineItemViewModel selectedLineItem; private ObservableCollection lineItemsVM = new(); private ContactViewModel recipient = new(); private ContactViewModel salesRep = new(); @@ -36,7 +37,9 @@ namespace Gremlin.MVVM private decimal totalVAT; private decimal totalGross; - public LineItemViewModel SelectedLineItemVM { get => selectedLineItemVM; set { selectedLineItemVM = value; NotifyOfPropertyChange(() => SelectedLineItemVM); } } + private List lineItemsWithoutCustomDescription = new(); + + public LineItemViewModel SelectedLineItem { get => selectedLineItem; set { selectedLineItem = value; NotifyOfPropertyChange(() => SelectedLineItem); DebugSelectedLineItem(); } } public ObservableCollection LineItemsVM { get => lineItemsVM; set { lineItemsVM = value; NotifyOfPropertyChange(() => LineItemsVM); } } public ContactViewModel Recipient { get => recipient; set { recipient = value; NotifyOfPropertyChange(() => Recipient); } } public ContactViewModel SalesRep { get => salesRep; set { salesRep = value; NotifyOfPropertyChange(() => SalesRep); } } @@ -84,16 +87,25 @@ namespace Gremlin.MVVM }; } + private void DebugSelectedLineItem() + { + Debug.WriteLine($"{SelectedLineItem.ProductNumber}#{SelectedLineItem.OptionNumber}:\n{SelectedLineItem.CustomDescriptionVM.Heading}\n{SelectedLineItem.CustomDescriptionVM.DescriptionText}"); + } + public bool ReadLineItems() { ResetTotals(); LineItemsVM = LineItemViewModel.ReadLineItemsFromClipboard(); - + if (LineItemsVM == null) { return false; } + else + { + SelectedLineItem = LineItemsVM[0]; + } foreach (LineItemViewModel lineItemVM in LineItemsVM) { @@ -115,12 +127,29 @@ namespace Gremlin.MVVM Warranty = 36; } + //Checke auf fehlende CustomDescriptions + if (!lineItemVM.CustomDescriptionVM.IsAvailable) + { + lineItemsWithoutCustomDescription.Add(lineItemVM); + } + //AddToTotal TotalListprice += lineItemVM.ListPrice; TotalNet += lineItemVM.CalcTotalNet; } CalculateTotals(); + + if (lineItemsWithoutCustomDescription.Count != 0) + { + string fehlendeCustomDescriptions = "Folgende LineItems haben keine CustomDescription:\n"; + foreach (LineItemViewModel lineItemWithoutCustomDescription in lineItemsWithoutCustomDescription) + { + fehlendeCustomDescriptions += lineItemWithoutCustomDescription.ProductNumber + "#" + lineItemWithoutCustomDescription.OptionNumber + ": " + lineItemWithoutCustomDescription.CustomDescriptionVM.Heading + "\n"; + } + ErrorHandler.ShowErrorMessage(fehlendeCustomDescriptions); + } + return LineItemsVM.Count != 0 && Recipient.LastName != "lastName"; } diff --git a/Gremlin/MVVM/Views/QuoteView.xaml b/Gremlin/MVVM/Views/QuoteView.xaml index ffcbfac..6d4cffd 100644 --- a/Gremlin/MVVM/Views/QuoteView.xaml +++ b/Gremlin/MVVM/Views/QuoteView.xaml @@ -88,18 +88,20 @@ - + - + \ No newline at end of file diff --git a/Gremlin/MVVM/Views/ShellView.xaml b/Gremlin/MVVM/Views/ShellView.xaml index 918a2b3..37ffa99 100644 --- a/Gremlin/MVVM/Views/ShellView.xaml +++ b/Gremlin/MVVM/Views/ShellView.xaml @@ -13,7 +13,7 @@ - +