Exemple #1
0
        public void GenerateDataAccordingToLastButtonPressed()
        {
            int buttonPressed = GetLastButtonPressed();

            if (buttonPressed >= 10)
            {
                buttonPressed = buttonPressed - 10;

                ItemsToFetch itemsToFetch = (ItemsToFetch)buttonPressed;

                int orderId = GetSelectedOrderIdFromSession();

                var data = _factory.FetchOrderItemData(itemsToFetch, orderId);

                _dataTable = DataTableCreator.ToDataTable(data.Cast <ITEM>().ToList());
            }
            else
            {
                OrdersToFetch ordersToFetch = (OrdersToFetch)buttonPressed;

                var data = _factory.FetchDataForAdmin(ordersToFetch);

                _dataTable = DataTableCreator.ToDataTable(data.Cast <ORDERS>().ToList());
            }
        }
        private Attachment CreatePDF(List <ITEM> items)
        {
            DataTable table = DataTableCreator.ToDataTable(items);

            MemoryStream memoryStream = new MemoryStream();

            Document document = new Document(PageSize.A4, 10f, 10f, 10f, 10f);

            PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);

            //PdfWriter writer2 = PdfWriter.GetInstance(document, new FileStream(Path.GetTempPath() + "/myFile2.pdf", FileMode.OpenOrCreate));

            PdfPTable pdfTable = new PdfPTable(5);

            pdfTable = AddHeaders(pdfTable, table);

            pdfTable = AddRowData(pdfTable, table);

            int totalPrice = CalculateTotalPrice(table);

            document = FormatInvoice(document, pdfTable, totalPrice);

            //string path = Path.Combine(Path.GetTempPath(), "myFile.pdf");

            //StreamWriter sWriter = new StreamWriter(path);
            //sWriter.Write(memoryStream);
            //sWriter.Close();

            writer.CloseStream = false;
            //writer2.CloseStream = false;
            document.Close();
            memoryStream.Position = 0;

            Attachment attachment = new Attachment(memoryStream, "festo-invoice.pdf");

            return(attachment);
        }