From 660188a748f15bea9357f2b374a0d678f55905fa Mon Sep 17 00:00:00 2001 From: Sascha Woitschetzki Date: Mon, 12 Jul 2021 10:51:58 +0200 Subject: [PATCH] recreate fundamental functionality of PDF creation --- Gremlin/MVVM/Operations/PDFHandler.cs | 29 ++++++++++++++++++- .../MVVM/ViewModels/AllContactsViewModel.cs | 5 ++-- Gremlin/MVVM/ViewModels/ContactViewModel.cs | 28 +++++++----------- Gremlin/MVVM/ViewModels/ShellViewModel.cs | 15 ++++++++-- Gremlin/MVVM/Views/AllContactsView.xaml | 2 +- Gremlin/MVVM/Views/QuoteView.xaml | 2 +- Gremlin/MVVM/Views/ShellView.xaml | 4 +++ 7 files changed, 60 insertions(+), 25 deletions(-) diff --git a/Gremlin/MVVM/Operations/PDFHandler.cs b/Gremlin/MVVM/Operations/PDFHandler.cs index 35a1666..6843f05 100644 --- a/Gremlin/MVVM/Operations/PDFHandler.cs +++ b/Gremlin/MVVM/Operations/PDFHandler.cs @@ -1,4 +1,5 @@ -using System; +using Gremlin.MVVM; +using System; using System.Diagnostics; using System.IO; @@ -6,6 +7,16 @@ namespace Gremlin.Operations { internal class PDFHandler { + public static void CreatePDF(QuoteViewModel quoteVM) + { + //Copy images to quotePath + File.WriteAllBytes($"{quoteVM.QuotePath}\\agilentLogo.png", Properties.Resources.agilentLogo); + File.WriteAllBytes($"{quoteVM.QuotePath}\\signWoitschetzki.png", Properties.Resources.signWoitschetzki); + + //Create PDF twice + RunningPDFLaTeX(quoteVM, 2); + } + public static void CreatePDF(string fileName, string quotePath) { //Copy images to quotePath @@ -52,6 +63,22 @@ namespace Gremlin.Operations } } + private static void RunningPDFLaTeX(QuoteViewModel quoteVM, int runs) + { + for (int i = 0; i < runs; i++) + { + using (Process process = new()) + { + process.StartInfo.FileName = "pdflatex"; + process.StartInfo.Arguments = quoteVM.QuotePath == "" || quoteVM.QuotePath == null ? $"{quoteVM.QuoteNumber}.tex" : $"{quoteVM.QuotePath}\\{quoteVM.QuoteNumber}.tex"; + process.StartInfo.UseShellExecute = false; + try { _ = process.Start(); } + catch (Exception ex) { ErrorHandler.ShowErrorInMessageBox(ex); } + process.WaitForExit(); + } + } + } + private static void RunningPDFLaTeX(string quotePath, string fileName, int runs) { for (int i = 0; i < runs; i++) diff --git a/Gremlin/MVVM/ViewModels/AllContactsViewModel.cs b/Gremlin/MVVM/ViewModels/AllContactsViewModel.cs index 809b109..87ec260 100644 --- a/Gremlin/MVVM/ViewModels/AllContactsViewModel.cs +++ b/Gremlin/MVVM/ViewModels/AllContactsViewModel.cs @@ -12,9 +12,10 @@ namespace Gremlin.MVVM { public class AllContactsViewModel : PropertyChangedBase { - public static ObservableCollection ListOfContactsVM => GetAllContactsVM(); + private ObservableCollection _listOfContactsVM; + public ObservableCollection ListOfContactsVM { set => _listOfContactsVM = value; get => _listOfContactsVM; } - public AllContactsViewModel() { } + public AllContactsViewModel() => ListOfContactsVM = GetAllContactsVM(); internal static ObservableCollection GetAllContactsVM() { diff --git a/Gremlin/MVVM/ViewModels/ContactViewModel.cs b/Gremlin/MVVM/ViewModels/ContactViewModel.cs index b5849e2..5086d98 100644 --- a/Gremlin/MVVM/ViewModels/ContactViewModel.cs +++ b/Gremlin/MVVM/ViewModels/ContactViewModel.cs @@ -8,17 +8,16 @@ using System.Threading; namespace Gremlin.MVVM { - public class ContactViewModel : PropertyChangedBase, IHandle + public class ContactViewModel : PropertyChangedBase { - private byte _gender; - private string _firstName; - private string _lastName; - private string _eMail; - private string _accountName; - private string _accountStreet; - private uint _accountZIP; - private string _accountCity; - //private IEventAggregator _eventAggregator; + private byte _gender = 1; + 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 = 0; + private string _accountCity = "accountCity"; public byte Gender { get => _gender; internal set { _gender = value; NotifyOfPropertyChange(() => Gender); } } public string FirstName { get => _firstName; internal set { _firstName = value; NotifyOfPropertyChange(() => FirstName); } } @@ -29,10 +28,7 @@ namespace Gremlin.MVVM public uint AccountZIP { get => _accountZIP; internal set { _accountZIP = value; NotifyOfPropertyChange(() => AccountZIP); } } public string AccountCity { get => _accountCity; internal set { _accountCity = value; NotifyOfPropertyChange(() => AccountCity); } } - //public ContactViewModel(IEventAggregator eventAggregator) - //{ - // _eventAggregator = eventAggregator; - //} + public ContactViewModel() { } public ContactViewModel(byte gender, string firstName, string lastName, string eMail, string accountName, string accountStreet, uint accountZIP, string accountCity) { @@ -46,10 +42,6 @@ namespace Gremlin.MVVM AccountCity = accountCity ?? throw new ArgumentNullException(nameof(accountCity)); } - public ContactViewModel() - { - } - internal static ContactViewModel ConvertObjectToContactVM(object selectedItem) { ContactViewModel selectedContact = new(); diff --git a/Gremlin/MVVM/ViewModels/ShellViewModel.cs b/Gremlin/MVVM/ViewModels/ShellViewModel.cs index 9e1207f..36e1b34 100644 --- a/Gremlin/MVVM/ViewModels/ShellViewModel.cs +++ b/Gremlin/MVVM/ViewModels/ShellViewModel.cs @@ -1,16 +1,27 @@ using Caliburn.Micro; +using Gremlin.Operations; namespace Gremlin.MVVM { public class ShellViewModel : PropertyChangedBase { - public QuoteViewModel QuoteVM { get; set; } public AllContactsViewModel AllContactsVM { get; set; } + public QuoteViewModel QuoteVM { get; set; } public ShellViewModel() { - QuoteVM = new(); AllContactsVM = new(); + QuoteVM = new(); + } + + public void CreateTex() + { + TexHandler.CreateTexAndOpen(QuoteVM); + } + + public void CreatePDF() + { + PDFHandler.CreatePDF(QuoteVM); } } } diff --git a/Gremlin/MVVM/Views/AllContactsView.xaml b/Gremlin/MVVM/Views/AllContactsView.xaml index 757739f..3c870f9 100644 --- a/Gremlin/MVVM/Views/AllContactsView.xaml +++ b/Gremlin/MVVM/Views/AllContactsView.xaml @@ -9,7 +9,7 @@ - + \ No newline at end of file diff --git a/Gremlin/MVVM/Views/QuoteView.xaml b/Gremlin/MVVM/Views/QuoteView.xaml index 322e249..4720848 100644 --- a/Gremlin/MVVM/Views/QuoteView.xaml +++ b/Gremlin/MVVM/Views/QuoteView.xaml @@ -59,7 +59,7 @@ - + \ No newline at end of file diff --git a/Gremlin/MVVM/Views/ShellView.xaml b/Gremlin/MVVM/Views/ShellView.xaml index 659f415..ca6ef4d 100644 --- a/Gremlin/MVVM/Views/ShellView.xaml +++ b/Gremlin/MVVM/Views/ShellView.xaml @@ -6,5 +6,9 @@ + +