IsEnabled of Button is binded to bool which should be notified automatically

pull/1/head
DJh2o2 2022-03-17 14:51:38 +07:00
parent 5c2687a387
commit 05b45f9887
8 changed files with 107 additions and 93 deletions

@ -21,9 +21,14 @@ namespace Gremlin
Debug.WriteLine(ex.Message); Debug.WriteLine(ex.Message);
} }
internal static void ShowMessageBox(string message) public static void ShowErrorMessage(string message)
{ {
_ = MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); _ = MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
} }
public static void ShowInfoMessage(string message)
{
_ = MessageBox.Show(message, "Info", MessageBoxButton.OK, MessageBoxImage.Information);
}
} }
} }

@ -6,7 +6,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;

@ -7,23 +7,32 @@ namespace Gremlin.Operations
{ {
internal class PDFHandler internal class PDFHandler
{ {
public static void CreatePDF(QuoteViewModel quoteVM) public static bool CreatePDF(QuoteViewModel quoteVM)
{ {
//Copy images to quotePath //Copy images to quotePath
if (quoteVM.QuotePath is "" or null) try
{ {
File.WriteAllBytes("agilentLogo.png", Properties.Resources.agilentLogo); if (quoteVM.QuotePath is "" or null)
File.WriteAllBytes("signWoitschetzki.png", Properties.Resources.signWoitschetzki); {
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); ErrorHandler.ShowErrorInMessageBox(ex);
File.WriteAllBytes($"{quoteVM.QuotePath}signWoitschetzki.png", Properties.Resources.signWoitschetzki); return false;
} }
//Create PDF twice
RunningPDFLaTeX(quoteVM, 2);
RemoveTempFiles(quoteVM.QuotePath);
} }
public static void RemoveTempFiles(string quotePath) public static void RemoveTempFiles(string quotePath)

@ -10,7 +10,7 @@ namespace Gremlin.MVVM
{ {
internal class TexHandler internal class TexHandler
{ {
internal static void CreateTexAndOpen(QuoteViewModel quoteVM) internal static int CreateTexAndOpen(QuoteViewModel quoteVM)
{ {
StringBuilder texStringBuilder = CreateTexFile(quoteVM); StringBuilder texStringBuilder = CreateTexFile(quoteVM);
@ -22,6 +22,8 @@ namespace Gremlin.MVVM
{ {
WriteTextToFile(texStringBuilder, $"{quoteVM.QuotePath}{quoteVM.QuoteNumber}.tex"); WriteTextToFile(texStringBuilder, $"{quoteVM.QuotePath}{quoteVM.QuoteNumber}.tex");
} }
return texStringBuilder.Length;
} }
private static void WriteTextToFile(StringBuilder texFile, string datei) private static void WriteTextToFile(StringBuilder texFile, string datei)

@ -11,23 +11,23 @@ namespace Gremlin.MVVM
{ {
public class ContactViewModel : PropertyChangedBase public class ContactViewModel : PropertyChangedBase
{ {
private Enums.Gender _gender = Enums.Gender.Male; private Enums.Gender gender = Enums.Gender.Male;
private string _firstName = "firstName"; private string firstName = "firstName";
private string _lastName = "lastName"; private string lastName = "lastName";
private string _eMail = "email@email.de"; private string eMail = "email@email.de";
private string _accountName = "accountName"; private string accountName = "accountName";
private string _accountStreet = "accountStreet"; private string accountStreet = "accountStreet";
private uint _accountZIP; private uint accountZIP;
private string _accountCity = "accountCity"; private string accountCity = "accountCity";
public Enums.Gender Gender { get => _gender; set { _gender = value; NotifyOfPropertyChange(() => Gender); } } public Enums.Gender Gender { get => gender; set { gender = value; NotifyOfPropertyChange(() => Gender); } }
public string FirstName { get => _firstName; set { _firstName = value; NotifyOfPropertyChange(() => FirstName); } } public string FirstName { get => firstName; set { firstName = value; NotifyOfPropertyChange(() => FirstName); } }
public string LastName { get => _lastName; set { _lastName = value; NotifyOfPropertyChange(() => LastName); } } public string LastName { get => lastName; set { lastName = value; NotifyOfPropertyChange(() => LastName); } }
public string EMail { get => _eMail; set { _eMail = value; NotifyOfPropertyChange(() => EMail); } } public string EMail { get => eMail; set { eMail = value; NotifyOfPropertyChange(() => EMail); } }
public string AccountName { get => _accountName; set { _accountName = value; NotifyOfPropertyChange(() => AccountName); } } public string AccountName { get => accountName; set { accountName = value; NotifyOfPropertyChange(() => AccountName); } }
public string AccountStreet { get => _accountStreet; set { _accountStreet = value; NotifyOfPropertyChange(() => AccountStreet); } } public string AccountStreet { get => accountStreet; set { accountStreet = value; NotifyOfPropertyChange(() => AccountStreet); } }
public uint AccountZIP { get => _accountZIP; set { _accountZIP = value; NotifyOfPropertyChange(() => AccountZIP); } } public uint AccountZIP { get => accountZIP; set { accountZIP = value; NotifyOfPropertyChange(() => AccountZIP); } }
public string AccountCity { get => _accountCity; set { _accountCity = value; NotifyOfPropertyChange(() => AccountCity); } } public string AccountCity { get => accountCity; set { accountCity = value; NotifyOfPropertyChange(() => AccountCity); } }
public ContactViewModel() { } public ContactViewModel() { }

@ -8,29 +8,29 @@ namespace Gremlin.MVVM
{ {
public class LineItemViewModel : PropertyChangedBase public class LineItemViewModel : PropertyChangedBase
{ {
private ushort _position; private ushort position;
private ushort _amount; private ushort amount;
private string _productNumber; private string productNumber;
private string _optionNumber; private string optionNumber;
private string _sapShortDescription; private string sapShortDescription;
private CustomDescriptionViewModel _customDescriptionVM; private CustomDescriptionViewModel customDescriptionVM;
private string _productLine; private string productLine;
private decimal _totalDiscount; private decimal totalDiscount;
private decimal _calcNetPrice; private decimal calcNetPrice;
private decimal _calcTotalNet; private decimal calcTotalNet;
private decimal _listPrice; private decimal listPrice;
public ushort Position { get => _position; set { _position = value; NotifyOfPropertyChange(() => Position); } } public ushort Position { get => position; set { position = value; NotifyOfPropertyChange(() => Position); } }
public ushort Amount { get => _amount; set { _amount = value; NotifyOfPropertyChange(() => Amount); } } public ushort Amount { get => amount; set { amount = value; NotifyOfPropertyChange(() => Amount); } }
public string ProductNumber { get => _productNumber; set { _productNumber = value; NotifyOfPropertyChange(() => ProductNumber); } } public string ProductNumber { get => productNumber; set { productNumber = value; NotifyOfPropertyChange(() => ProductNumber); } }
public string OptionNumber { get => _optionNumber; set { _optionNumber = value; NotifyOfPropertyChange(() => OptionNumber); } } public string OptionNumber { get => optionNumber; set { optionNumber = value; NotifyOfPropertyChange(() => OptionNumber); } }
public string SapShortDescription { get => _sapShortDescription; set { _sapShortDescription = value; NotifyOfPropertyChange(() => SapShortDescription); } } public string SapShortDescription { get => sapShortDescription; set { sapShortDescription = value; NotifyOfPropertyChange(() => SapShortDescription); } }
public CustomDescriptionViewModel CustomDescriptionVM { get => _customDescriptionVM; set { _customDescriptionVM = value; NotifyOfPropertyChange(() => CustomDescriptionVM); } } public CustomDescriptionViewModel CustomDescriptionVM { get => customDescriptionVM; set { customDescriptionVM = value; NotifyOfPropertyChange(() => CustomDescriptionVM); } }
public string ProductLine { get => _productLine; set { _productLine = value; NotifyOfPropertyChange(() => ProductLine); } } public string ProductLine { get => productLine; set { productLine = value; NotifyOfPropertyChange(() => ProductLine); } }
public decimal TotalDiscount { get => _totalDiscount; set { _totalDiscount = value; NotifyOfPropertyChange(() => TotalDiscount); } } public decimal TotalDiscount { get => totalDiscount; set { totalDiscount = value; NotifyOfPropertyChange(() => TotalDiscount); } }
public decimal CalcNetPrice { get => _calcNetPrice; set { _calcNetPrice = value; NotifyOfPropertyChange(() => CalcNetPrice); } } public decimal CalcNetPrice { get => calcNetPrice; set { calcNetPrice = value; NotifyOfPropertyChange(() => CalcNetPrice); } }
public decimal CalcTotalNet { get => _calcTotalNet; set { _calcTotalNet = value; NotifyOfPropertyChange(() => CalcTotalNet); } } public decimal CalcTotalNet { get => calcTotalNet; set { calcTotalNet = value; NotifyOfPropertyChange(() => CalcTotalNet); } }
public decimal ListPrice { get => _listPrice; set { _listPrice = value; NotifyOfPropertyChange(() => ListPrice); } } public decimal ListPrice { get => listPrice; set { listPrice = value; NotifyOfPropertyChange(() => ListPrice); } }
internal static ObservableCollection<LineItemViewModel> ReadLineItemsFromClipboard() internal static ObservableCollection<LineItemViewModel> ReadLineItemsFromClipboard()
{ {

@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq; using System.Linq;
namespace Gremlin.MVVM namespace Gremlin.MVVM
@ -18,6 +17,9 @@ namespace Gremlin.MVVM
private ObservableCollection<ContactViewModel> contacts; private ObservableCollection<ContactViewModel> contacts;
private QuoteViewModel quoteVM; private QuoteViewModel quoteVM;
private string searchContact; private string searchContact;
private bool quoteReady;
private bool texCreated;
private bool pdfCreated;
public string SearchContact { public string SearchContact {
get => searchContact; get => searchContact;
@ -25,42 +27,18 @@ namespace Gremlin.MVVM
searchContact = value; searchContact = value;
NotifyOfPropertyChange(() => SearchContact); NotifyOfPropertyChange(() => SearchContact);
Contacts = GetContactsVM(searchContact); Contacts = GetContactsVM(searchContact);
QuoteReady = CheckQuoteReady();
} }
} }
public ContactViewModel ContactVM { public ContactViewModel ContactVM { get => contactVM; set { contactVM = value; NotifyOfPropertyChange(() => ContactVM); } }
get => contactVM; public QuoteViewModel QuoteVM { get => quoteVM; set { quoteVM = value; NotifyOfPropertyChange(() => QuoteVM); QuoteReady = CheckQuoteReady(); } }
set {
contactVM = value;
NotifyOfPropertyChange(() => ContactVM);
}
}
public QuoteViewModel QuoteVM {
get => quoteVM;
set {
quoteVM = value;
NotifyOfPropertyChange(() => QuoteVM);
}
}
public ContactViewModel SelectedContact { public ContactViewModel SelectedContact { get => selectedContact; set { selectedContact = value; NotifyOfPropertyChange(() => SelectedContact); QuoteVM.Recipient = value; NotifyOfPropertyChange(() => QuoteVM.Recipient); } }
get => selectedContact; public ObservableCollection<ContactViewModel> Contacts { get => contacts; set { contacts = value; NotifyOfPropertyChange(() => Contacts); } }
set { public bool QuoteReady { get => quoteReady; set { quoteReady = value; NotifyOfPropertyChange(() => QuoteReady); } }
selectedContact = value; public bool TexCreated { get => texCreated; set { texCreated = value; NotifyOfPropertyChange(() => TexCreated); } }
NotifyOfPropertyChange(() => SelectedContact); public bool PDFCreated { get => pdfCreated; set { pdfCreated = value; NotifyOfPropertyChange(() => PDFCreated); } }
QuoteVM.Recipient = value;
NotifyOfPropertyChange(() => QuoteVM.Recipient);
}
}
public ObservableCollection<ContactViewModel> Contacts {
get => contacts;
set {
contacts = value;
NotifyOfPropertyChange(() => Contacts);
}
}
public ShellViewModel() public ShellViewModel()
{ {
@ -97,15 +75,36 @@ namespace Gremlin.MVVM
} }
} }
private bool CheckQuoteReady()
{
return QuoteVM.LineItemsVM.Count != 0 && QuoteVM.Recipient.LastName != "lastName";
}
public void CreateTex() public void CreateTex()
{ {
TexHandler.CreateTexAndOpen(QuoteVM); if (QuoteVM.LineItemsVM.Count == 0)
Debug.WriteLine(quoteVM.TotalListprice); {
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() public void CreatePDF()
{ {
PDFHandler.CreatePDF(QuoteVM); PDFCreated = PDFHandler.CreatePDF(QuoteVM);
} }
public void OpenPDF() public void OpenPDF()

@ -16,9 +16,9 @@
<!--<local1:ContactView cal:Bind.Model="{Binding ContactsVM}"/>--> <!--<local1:ContactView cal:Bind.Model="{Binding ContactsVM}"/>-->
<local:QuoteView cal:Bind.Model="{Binding QuoteVM}"/> <local:QuoteView cal:Bind.Model="{Binding QuoteVM}"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<Button x:Name="CreateTex" Content="TexFile erzeugen" Margin="10,5,10,5"/> <Button x:Name="CreateTex" Content="TexFile erzeugen" Margin="10,5,10,5" IsEnabled="{Binding Path=QuoteReady}"/>
<Button x:Name="CreatePDF" Content="PDF erzeugen" Margin="10,5,10,5"/> <Button x:Name="CreatePDF" Content="PDF erzeugen" Margin="10,5,10,5" IsEnabled="{Binding Path=TexCreated}"/>
<Button x:Name="OpenPDF" Content="PDF öffnen" Margin="10,5,10,5"/> <Button x:Name="OpenPDF" Content="PDF öffnen" Margin="10,5,10,5" IsEnabled="{Binding Path=PDFCreated}"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</UserControl> </UserControl>