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);
}
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);
}
}
}

@ -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;

@ -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)

@ -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)

@ -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() { }

@ -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<LineItemViewModel> ReadLineItemsFromClipboard()
{

@ -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<ContactViewModel> 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<ContactViewModel> 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<ContactViewModel> 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()

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