diff --git a/Gremlin/ErrorHandler.cs b/Gremlin/ErrorHandler.cs index 03a2054..85ddb8e 100644 --- a/Gremlin/ErrorHandler.cs +++ b/Gremlin/ErrorHandler.cs @@ -21,9 +21,14 @@ namespace Gremlin Debug.WriteLine(ex.Message); } - internal static void ShowMessageBox(string message) + public static void ShowErrorMessage(string message) { _ = MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } + + public static void ShowInfoMessage(string message) + { + _ = MessageBox.Show(message, "Info", MessageBoxButton.OK, MessageBoxImage.Information); + } } } diff --git a/Gremlin/GremlinData/DBClasses/GenericImporter.cs b/Gremlin/GremlinData/DBClasses/GenericImporter.cs index a7669fb..e3fe2ad 100644 --- a/Gremlin/GremlinData/DBClasses/GenericImporter.cs +++ b/Gremlin/GremlinData/DBClasses/GenericImporter.cs @@ -6,7 +6,6 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; diff --git a/Gremlin/MVVM/Operations/PDFHandler.cs b/Gremlin/MVVM/Operations/PDFHandler.cs index 4dea234..ba06152 100644 --- a/Gremlin/MVVM/Operations/PDFHandler.cs +++ b/Gremlin/MVVM/Operations/PDFHandler.cs @@ -7,23 +7,32 @@ namespace Gremlin.Operations { internal class PDFHandler { - public static void CreatePDF(QuoteViewModel quoteVM) + public static bool CreatePDF(QuoteViewModel quoteVM) { //Copy images to quotePath - if (quoteVM.QuotePath is "" or null) + try { - File.WriteAllBytes("agilentLogo.png", Properties.Resources.agilentLogo); - File.WriteAllBytes("signWoitschetzki.png", Properties.Resources.signWoitschetzki); + if (quoteVM.QuotePath is "" or null) + { + File.WriteAllBytes("agilentLogo.png", Properties.Resources.agilentLogo); + File.WriteAllBytes("signWoitschetzki.png", Properties.Resources.signWoitschetzki); + } + else + { + File.WriteAllBytes($"{quoteVM.QuotePath}agilentLogo.png", Properties.Resources.agilentLogo); + File.WriteAllBytes($"{quoteVM.QuotePath}signWoitschetzki.png", Properties.Resources.signWoitschetzki); + } + + //Create PDF twice + RunningPDFLaTeX(quoteVM, 2); + RemoveTempFiles(quoteVM.QuotePath); + return true; } - else + catch (Exception ex) { - File.WriteAllBytes($"{quoteVM.QuotePath}agilentLogo.png", Properties.Resources.agilentLogo); - File.WriteAllBytes($"{quoteVM.QuotePath}signWoitschetzki.png", Properties.Resources.signWoitschetzki); + ErrorHandler.ShowErrorInMessageBox(ex); + return false; } - - //Create PDF twice - RunningPDFLaTeX(quoteVM, 2); - RemoveTempFiles(quoteVM.QuotePath); } public static void RemoveTempFiles(string quotePath) diff --git a/Gremlin/MVVM/Operations/TexHandler.cs b/Gremlin/MVVM/Operations/TexHandler.cs index 91b51d2..b17819e 100644 --- a/Gremlin/MVVM/Operations/TexHandler.cs +++ b/Gremlin/MVVM/Operations/TexHandler.cs @@ -10,7 +10,7 @@ namespace Gremlin.MVVM { internal class TexHandler { - internal static void CreateTexAndOpen(QuoteViewModel quoteVM) + internal static int CreateTexAndOpen(QuoteViewModel quoteVM) { StringBuilder texStringBuilder = CreateTexFile(quoteVM); @@ -22,6 +22,8 @@ namespace Gremlin.MVVM { WriteTextToFile(texStringBuilder, $"{quoteVM.QuotePath}{quoteVM.QuoteNumber}.tex"); } + + return texStringBuilder.Length; } private static void WriteTextToFile(StringBuilder texFile, string datei) diff --git a/Gremlin/MVVM/ViewModels/ContactViewModel.cs b/Gremlin/MVVM/ViewModels/ContactViewModel.cs index 595ad89..c030ffd 100644 --- a/Gremlin/MVVM/ViewModels/ContactViewModel.cs +++ b/Gremlin/MVVM/ViewModels/ContactViewModel.cs @@ -11,23 +11,23 @@ namespace Gremlin.MVVM { public class ContactViewModel : PropertyChangedBase { - private Enums.Gender _gender = Enums.Gender.Male; - private string _firstName = "firstName"; - private string _lastName = "lastName"; - private string _eMail = "email@email.de"; - private string _accountName = "accountName"; - private string _accountStreet = "accountStreet"; - private uint _accountZIP; - private string _accountCity = "accountCity"; - - public Enums.Gender Gender { get => _gender; set { _gender = value; NotifyOfPropertyChange(() => Gender); } } - public string FirstName { get => _firstName; set { _firstName = value; NotifyOfPropertyChange(() => FirstName); } } - public string LastName { get => _lastName; set { _lastName = value; NotifyOfPropertyChange(() => LastName); } } - public string EMail { get => _eMail; set { _eMail = value; NotifyOfPropertyChange(() => EMail); } } - public string AccountName { get => _accountName; set { _accountName = value; NotifyOfPropertyChange(() => AccountName); } } - public string AccountStreet { get => _accountStreet; set { _accountStreet = value; NotifyOfPropertyChange(() => AccountStreet); } } - public uint AccountZIP { get => _accountZIP; set { _accountZIP = value; NotifyOfPropertyChange(() => AccountZIP); } } - public string AccountCity { get => _accountCity; set { _accountCity = value; NotifyOfPropertyChange(() => AccountCity); } } + private Enums.Gender gender = Enums.Gender.Male; + private string firstName = "firstName"; + private string lastName = "lastName"; + private string eMail = "email@email.de"; + private string accountName = "accountName"; + private string accountStreet = "accountStreet"; + private uint accountZIP; + private string accountCity = "accountCity"; + + public Enums.Gender Gender { get => gender; set { gender = value; NotifyOfPropertyChange(() => Gender); } } + public string FirstName { get => firstName; set { firstName = value; NotifyOfPropertyChange(() => FirstName); } } + public string LastName { get => lastName; set { lastName = value; NotifyOfPropertyChange(() => LastName); } } + public string EMail { get => eMail; set { eMail = value; NotifyOfPropertyChange(() => EMail); } } + public string AccountName { get => accountName; set { accountName = value; NotifyOfPropertyChange(() => AccountName); } } + public string AccountStreet { get => accountStreet; set { accountStreet = value; NotifyOfPropertyChange(() => AccountStreet); } } + public uint AccountZIP { get => accountZIP; set { accountZIP = value; NotifyOfPropertyChange(() => AccountZIP); } } + public string AccountCity { get => accountCity; set { accountCity = value; NotifyOfPropertyChange(() => AccountCity); } } public ContactViewModel() { } diff --git a/Gremlin/MVVM/ViewModels/LineItemViewModel.cs b/Gremlin/MVVM/ViewModels/LineItemViewModel.cs index 885408b..a881c8d 100644 --- a/Gremlin/MVVM/ViewModels/LineItemViewModel.cs +++ b/Gremlin/MVVM/ViewModels/LineItemViewModel.cs @@ -8,29 +8,29 @@ namespace Gremlin.MVVM { public class LineItemViewModel : PropertyChangedBase { - 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; set { _position = value; NotifyOfPropertyChange(() => Position); } } - public ushort Amount { get => _amount; set { _amount = value; NotifyOfPropertyChange(() => Amount); } } - public string ProductNumber { get => _productNumber; set { _productNumber = value; NotifyOfPropertyChange(() => ProductNumber); } } - public string OptionNumber { get => _optionNumber; set { _optionNumber = value; NotifyOfPropertyChange(() => OptionNumber); } } - public string SapShortDescription { get => _sapShortDescription; set { _sapShortDescription = value; NotifyOfPropertyChange(() => SapShortDescription); } } - public CustomDescriptionViewModel CustomDescriptionVM { get => _customDescriptionVM; set { _customDescriptionVM = value; NotifyOfPropertyChange(() => CustomDescriptionVM); } } - public string ProductLine { get => _productLine; set { _productLine = value; NotifyOfPropertyChange(() => ProductLine); } } - public decimal TotalDiscount { get => _totalDiscount; set { _totalDiscount = value; NotifyOfPropertyChange(() => TotalDiscount); } } - public decimal CalcNetPrice { get => _calcNetPrice; set { _calcNetPrice = value; NotifyOfPropertyChange(() => CalcNetPrice); } } - public decimal CalcTotalNet { get => _calcTotalNet; set { _calcTotalNet = value; NotifyOfPropertyChange(() => CalcTotalNet); } } - public decimal ListPrice { get => _listPrice; set { _listPrice = value; NotifyOfPropertyChange(() => ListPrice); } } + 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; set { position = value; NotifyOfPropertyChange(() => Position); } } + public ushort Amount { get => amount; set { amount = value; NotifyOfPropertyChange(() => Amount); } } + public string ProductNumber { get => productNumber; set { productNumber = value; NotifyOfPropertyChange(() => ProductNumber); } } + public string OptionNumber { get => optionNumber; set { optionNumber = value; NotifyOfPropertyChange(() => OptionNumber); } } + public string SapShortDescription { get => sapShortDescription; set { sapShortDescription = value; NotifyOfPropertyChange(() => SapShortDescription); } } + public CustomDescriptionViewModel CustomDescriptionVM { get => customDescriptionVM; set { customDescriptionVM = value; NotifyOfPropertyChange(() => CustomDescriptionVM); } } + public string ProductLine { get => productLine; set { productLine = value; NotifyOfPropertyChange(() => ProductLine); } } + public decimal TotalDiscount { get => totalDiscount; set { totalDiscount = value; NotifyOfPropertyChange(() => TotalDiscount); } } + public decimal CalcNetPrice { get => calcNetPrice; set { calcNetPrice = value; NotifyOfPropertyChange(() => CalcNetPrice); } } + public decimal CalcTotalNet { get => calcTotalNet; set { calcTotalNet = value; NotifyOfPropertyChange(() => CalcTotalNet); } } + public decimal ListPrice { get => listPrice; set { listPrice = value; NotifyOfPropertyChange(() => ListPrice); } } internal static ObservableCollection ReadLineItemsFromClipboard() { diff --git a/Gremlin/MVVM/ViewModels/ShellViewModel.cs b/Gremlin/MVVM/ViewModels/ShellViewModel.cs index 20ff2b5..c4f3c21 100644 --- a/Gremlin/MVVM/ViewModels/ShellViewModel.cs +++ b/Gremlin/MVVM/ViewModels/ShellViewModel.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Diagnostics; using System.Linq; namespace Gremlin.MVVM @@ -18,6 +17,9 @@ namespace Gremlin.MVVM private ObservableCollection contacts; private QuoteViewModel quoteVM; private string searchContact; + private bool quoteReady; + private bool texCreated; + private bool pdfCreated; public string SearchContact { get => searchContact; @@ -25,42 +27,18 @@ namespace Gremlin.MVVM searchContact = value; NotifyOfPropertyChange(() => SearchContact); Contacts = GetContactsVM(searchContact); + QuoteReady = CheckQuoteReady(); } } - public ContactViewModel ContactVM { - get => contactVM; - set { - contactVM = value; - NotifyOfPropertyChange(() => ContactVM); - } - } - - public QuoteViewModel QuoteVM { - get => quoteVM; - set { - quoteVM = value; - NotifyOfPropertyChange(() => QuoteVM); - } - } + public ContactViewModel ContactVM { get => contactVM; set { contactVM = value; NotifyOfPropertyChange(() => ContactVM); } } + public QuoteViewModel QuoteVM { get => quoteVM; set { quoteVM = value; NotifyOfPropertyChange(() => QuoteVM); QuoteReady = CheckQuoteReady(); } } - public ContactViewModel SelectedContact { - get => selectedContact; - set { - selectedContact = value; - NotifyOfPropertyChange(() => SelectedContact); - QuoteVM.Recipient = value; - NotifyOfPropertyChange(() => QuoteVM.Recipient); - } - } - - public ObservableCollection Contacts { - get => contacts; - set { - contacts = value; - NotifyOfPropertyChange(() => Contacts); - } - } + public ContactViewModel SelectedContact { get => selectedContact; set { selectedContact = value; NotifyOfPropertyChange(() => SelectedContact); QuoteVM.Recipient = value; NotifyOfPropertyChange(() => QuoteVM.Recipient); } } + public ObservableCollection Contacts { get => contacts; set { contacts = value; NotifyOfPropertyChange(() => Contacts); } } + public bool QuoteReady { get => quoteReady; set { quoteReady = value; NotifyOfPropertyChange(() => QuoteReady); } } + public bool TexCreated { get => texCreated; set { texCreated = value; NotifyOfPropertyChange(() => TexCreated); } } + public bool PDFCreated { get => pdfCreated; set { pdfCreated = value; NotifyOfPropertyChange(() => PDFCreated); } } public ShellViewModel() { @@ -97,15 +75,36 @@ namespace Gremlin.MVVM } } + private bool CheckQuoteReady() + { + return QuoteVM.LineItemsVM.Count != 0 && QuoteVM.Recipient.LastName != "lastName"; + } + public void CreateTex() { - TexHandler.CreateTexAndOpen(QuoteVM); - Debug.WriteLine(quoteVM.TotalListprice); + if (QuoteVM.LineItemsVM.Count == 0) + { + ErrorHandler.ShowErrorMessage("Das Angebot enthält keine LineItems.\nBitte zuerst ein Angebot einfügen."); + } + else + { + if (QuoteVM.Recipient.LastName != "lastName") + { + int texFileLength = TexHandler.CreateTexAndOpen(QuoteVM); + ErrorHandler.ShowInfoMessage($"Es wurde ein texFile mit {texFileLength} Zeichen erstellt."); + TexCreated = true; + } + else + { + ErrorHandler.ShowErrorMessage("Bitte wähle zuerst einen Kunden aus!"); + } + } + } public void CreatePDF() { - PDFHandler.CreatePDF(QuoteVM); + PDFCreated = PDFHandler.CreatePDF(QuoteVM); } public void OpenPDF() diff --git a/Gremlin/MVVM/Views/ShellView.xaml b/Gremlin/MVVM/Views/ShellView.xaml index a9765ae..1ebf8eb 100644 --- a/Gremlin/MVVM/Views/ShellView.xaml +++ b/Gremlin/MVVM/Views/ShellView.xaml @@ -16,9 +16,9 @@ -