private void OpenTemplate(object templateType) { const string fnfMessage = "Das gesuchte Dokument konnte nicht gefunden werden."; const string title = "Ein Fehler ist aufgetreten"; try { switch ((TemplateType)templateType) { case TemplateType.Offer: FileAccess.Open(Properties.Settings.Default.OfferTemplatePath, FileType.Template); break; case TemplateType.Confirmation: FileAccess.Open(Properties.Settings.Default.ConfirmationTemplatePath, FileType.Template); break; case TemplateType.Invoice: FileAccess.Open(Properties.Settings.Default.InvoiceTemplatePath, FileType.Template); break; default: throw new ArgumentOutOfRangeException(nameof(templateType), templateType, null); } } catch (FileNotFoundException) { MessageBox.Show(fnfMessage, title); } catch (Win32Exception) { MessageBox.Show(fnfMessage, title); } }
private void NewInvoice() { if (Validator.ValidateAll().IsValid) { if (order.Id == 0) { order = UnitOfWork.Orders.Add(order); } var vm = new InvoiceCreationViewModel(new UnitOfWorkFactory()); vm.Init(); var windowView = new InvoiceCreationView(vm); if (windowView.ShowDialog() ?? false) { var invoiceNumber = vm.InvoiceNumber; var amount = double.Parse(vm.Amount); string fileName; try { fileName = FileAccess.CreateDocumentFromTemplate(order.Customer, invoiceNumber, Properties.Settings.Default.InvoiceTemplatePath); } catch (Win32Exception) { MessageBox.Show("Das Dokument konnte nicht erstellt werden. Eventuell haben Sie die Vorlage noch geöffnet.", "Ein Fehler ist aufgetreten"); return; } var document = new Document { IssueDate = DateTime.Now, Name = invoiceNumber, Tag = "Rechnung", RelativePath = fileName }; document = UnitOfWork.Documents.Add(document); var invoice = new Invoice { Amount = amount, InvoiceNumber = invoiceNumber, IsPaid = false, Order = order, Document = document }; invoice = UnitOfWork.Invoices.Add(invoice); UnitOfWork.Complete(); InvoiceList.Add(invoice); if (vm.OpenAfterSave ?? false) { Open(fileName); } } } }
private void Save(object window) { var validationResult = Validator.ValidateAll(); if (validationResult.IsValid) { document.Name = Name; document.Tag = Tag; document.IssueDate = IssueDate; if (document.RelativePath == null) { document.RelativePath = FileAccess.Add(RelativePath, FileType.Document); } else if (document.RelativePath != RelativePath) { FileAccess.Delete(document.RelativePath); document.RelativePath = FileAccess.Add(RelativePath, FileType.Document); } if (document.Id == 0) { document = UnitOfWork.Documents.Add(document); } if (UnitOfWork.Complete() > 0) { ((Window)window).DialogResult = true; } ((Window)window).Close(); } }
private void NewOrderConfirmation() { if (Validator.ValidateAll().IsValid) { if (order.Id == 0) { order = UnitOfWork.Orders.Add(order); } var vm = new OrderConfirmationCreationViewModel(new UnitOfWorkFactory()); vm.Init(); var windowView = new OrderConfirmationCreationView(vm); if (windowView.ShowDialog() ?? false) { var orderConfNumber = vm.OrderConfNumber; string fileName; try { fileName = FileAccess.CreateDocumentFromTemplate(order.Customer, orderConfNumber, Properties.Settings.Default.ConfirmationTemplatePath); } catch (Win32Exception) { MessageBox.Show("Das Dokument konnte nicht erstellt werden. Eventuell haben Sie die Vorlage noch geöffnet.", "Ein Fehler ist aufgetreten"); return; } var document = new Document { IssueDate = DateTime.Now, Name = orderConfNumber, Tag = "Auftragsbestätigung", RelativePath = fileName }; document = UnitOfWork.Documents.Add(document); var orderConfirmation = new OrderConfirmation { OrderConfNumber = orderConfNumber, Order = order, Document = document }; orderConfirmation = UnitOfWork.OrderConfirmations.Add(orderConfirmation); UnitOfWork.Complete(); OrderConfirmationList.Add(orderConfirmation); OnPropertyChanged(nameof(OrderConfToolTip)); if (vm.OpenAfterSave ?? false) { Open(fileName); } } } }
private void Open(object fileName) { const string fnfMessage = "Das gesuchte Dokument konnte nicht gefunden werden."; const string title = "Ein Fehler ist aufgetreten"; try { FileAccess.Open((string)fileName, FileType.Document); } catch (FileNotFoundException) { MessageBox.Show(fnfMessage, title); } catch (Win32Exception) { MessageBox.Show(fnfMessage, title); } }
private void OpenDocument() { const string fnfMessage = "Das gesuchte Dokument konnte nicht gefunden werden."; const string title = "Ein Fehler ist aufgetreten"; try { FileAccess.Open(SelectedDocument.RelativePath, FileType.Document); } catch (FileNotFoundException) { MessageBox.Show(fnfMessage, title); } catch (Win32Exception) { MessageBox.Show(fnfMessage, title); } }
private void UploadTemplate(object templateType) { try { switch ((TemplateType)templateType) { case TemplateType.Offer: Properties.Settings.Default.OfferTemplatePath = FileAccess.Add(Offer, FileType.Template); break; case TemplateType.Confirmation: Properties.Settings.Default.ConfirmationTemplatePath = FileAccess.Add(Confirmation, FileType.Template); break; case TemplateType.Invoice: Properties.Settings.Default.InvoiceTemplatePath = FileAccess.Add(Invoice, FileType.Template); break; default: throw new ArgumentOutOfRangeException(nameof(templateType), templateType, null); } Properties.Settings.Default.Save(); MessageBox.Show("Vorlage erfolgreich hochgeladen."); } catch (IOException) { MessageBox.Show( "Ein Fehler ist aufgetreten. Bitte vergewissern Sie sich, dass das Dokument " + "nicht von einem anderen Programm geöffnet ist und Sie die Leserechte dafür besitzen."); } catch (ArgumentNullException) { MessageBox.Show("Bitte wählen Sie eine Word-Datei aus."); } catch (ArgumentException e) { MessageBox.Show(e.Message); } }