recreate fundamental functionality of PDF creation

pull/1/head
Sascha Woitschetzki 2021-07-12 10:51:58 +07:00
parent 8fcaa06eab
commit 660188a748
7 changed files with 60 additions and 25 deletions

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

@ -12,9 +12,10 @@ namespace Gremlin.MVVM
{
public class AllContactsViewModel : PropertyChangedBase
{
public static ObservableCollection<ContactViewModel> ListOfContactsVM => GetAllContactsVM();
private ObservableCollection<ContactViewModel> _listOfContactsVM;
public ObservableCollection<ContactViewModel> ListOfContactsVM { set => _listOfContactsVM = value; get => _listOfContactsVM; }
public AllContactsViewModel() { }
public AllContactsViewModel() => ListOfContactsVM = GetAllContactsVM();
internal static ObservableCollection<ContactViewModel> GetAllContactsVM()
{

@ -8,17 +8,16 @@ using System.Threading;
namespace Gremlin.MVVM
{
public class ContactViewModel : PropertyChangedBase, IHandle<ShellViewModel>
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();

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

@ -9,7 +9,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="1" Grid.Column="0" Height="Auto">
<DataGrid x:Name="AllContactsVM" AutoGenerateColumns="True" Height="200" Width ="600" Margin="10,5,10,5" />
<DataGrid x:Name="ListOfContactsVM" AutoGenerateColumns="True" Height="300" Width ="1280" Margin="10,5,10,5" />
</Grid>
</Grid>
</UserControl>

@ -59,7 +59,7 @@
<!--LineItems-->
<Grid Grid.Row="2" Grid.ColumnSpan="4" Height="Auto">
<DataGrid x:Name="LineItemsViewModel" AutoGenerateColumns="True" Height="Auto" Margin="10,5,10,5" />
<DataGrid x:Name="LineItemsViewModel" AutoGenerateColumns="True" Height="300" Width ="1280" Margin="10,5,10,5" />
</Grid>
</Grid>
</UserControl>

@ -6,5 +6,9 @@
<StackPanel Orientation="Vertical">
<local:AllContactsView cal:Bind.Model="{Binding AllContactsVM}" />
<local:QuoteView cal:Bind.Model="{Binding QuoteVM}" />
<StackPanel Orientation="Horizontal">
<Button x:Name="CreateTex" Content="TexFile erzeugen" Margin="10,5,10,5"/>
<Button x:Name="CreatePDF" Content="PDF erzeugen" Margin="10,5,10,5"/>
</StackPanel>
</StackPanel>
</UserControl>