Beispiel #1
0
        private void btnInvoice_Click(object sender, EventArgs e)
        {
            if(lvItems.Items.Count <= 0)
                return;

            if (_order.Customer == null)
                SelectCustomer();

            if (_order.Customer == null)
                return;

            var items = lvItems.Items.OfType<ListViewItem>()
                               .Select(lvi => lvi.Tag as OrderItem)
                               .ToList();

            var invoice = InvoiceBuilder.Create(FinancialHandler.GenerateInvoiceNumber(),
                                                CreateInvoice(items),
                                                _order.Customer);
            invoice.Total = items.Select(oi => oi.CalculateTotal())
                                 .DefaultIfEmpty(0)
                                 .Sum();

            var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var path = Path.Combine(desktopPath, $"Factura-{invoice.Number}.pdf");
            var pdfWriter = new PdfWriter(path);

            pdfWriter.Write(invoice.ToString());
            pdfWriter.Save();

            Process.Start(path);
        }