Exemple #1
0
        private void readInvoiceHead()
        {
            dateOfSale.Format = DateTimePickerFormat.Long;
            String displayDate = dateOfSale.Text;

            //Titles and Image of invoice:
            invoiceTitle     = ConfigurationDAL.GetShopName(); // "International Food Company";
            invoiceSubTitle1 = "Address:" + ConfigurationDAL.GetCurrentAddress() + "\nDated :" + displayDate.ToString();
            invoiceImage     = Application.StartupPath + @"\Images\" + "Header.jpg";
        }
Exemple #2
0
        private void frmSettings_Load(object sender, EventArgs e)
        {
            txtCurrencySybmol.Text = ConfigurationDAL.GetCurrentCurrency();
            txtShopName.Text       = ConfigurationDAL.GetShopName();
            txtAddress.Text        = ConfigurationDAL.GetCurrentAddress();

            try
            {
                string defaultFileName = System.Reflection.Assembly.GetExecutingAssembly().Location;
                string directory       = System.IO.Path.GetDirectoryName(defaultFileName);
                string path            = directory + "\\Images\\Header.JPG";

                picHeaderImage.Image = ImageUtilities.ResizeImage(new Bitmap(path), 280, 70);
                txtFileImage.Text    = path;
            }
            catch (Exception ex)
            {
                DebugUtil.genericShow(ex.Message.ToString());
            }
        }
Exemple #3
0
        private void btnSaveAsPDF_Click(object sender, EventArgs e)
        {
            try
            {
                List <Sale> saleItems = this.getListofItemsToBeAdded();
                if (saleItems.Count >= 1)
                {
                    string path = "";

                    FileDialog dialog = new SaveFileDialog();
                    dialog.Title = "Save file as...";
                    long nextInvoiceId = DBUtil.GetNextID("Sale_ID", "Sales");
                    dialog.FileName         = "Sale_No_" + nextInvoiceId.ToString() + "_Dated_" + System.DateTime.Now.Day.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Year.ToString();
                    dialog.RestoreDirectory = true;
                    dialog.Filter           = "Adobe Acrobat Reader PDF (*.pdf)|*.*";
                    DialogResult result = dialog.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        String saleDate  = dateOfSale.Text;
                        long   invoiceID = ShopDAL.SaleItems(saleDate, saleItems);

                        path = dialog.FileName;
                        Document myDocument = new Document(PageSize.A4.Rotate());


                        // step 2:
                        // Now create a writer that listens to this doucment and writes the document to desired Stream.

                        PdfWriter.GetInstance(myDocument, new FileStream(path + ".pdf", FileMode.Create));

                        // step 3:  Open the document now using
                        myDocument.Open();

                        // step 4: Now add some contents to the document
                        PdfPTable table = new PdfPTable(6);
                        table.WidthPercentage = 50;

                        dateOfSale.Format = DateTimePickerFormat.Long;
                        String displayDate = dateOfSale.Text;

                        //String displayDate = System.DateTime.Now.ToLongDateString() + " " + System.DateTime.Now.ToLongTimeString();

                        // Printing Header
                        PdfPCell cellShopName = new PdfPCell(new Paragraph(ConfigurationDAL.GetShopName(), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 14)));
                        table.HorizontalAlignment        = Element.ALIGN_LEFT;
                        cellShopName.Colspan             = 6;
                        cellShopName.BackgroundColor     = new BaseColor(204, 204, 204);
                        cellShopName.BorderColor         = new BaseColor(204, 204, 204);
                        cellShopName.HorizontalAlignment = Element.ALIGN_CENTER;
                        table.AddCell(cellShopName);


                        PdfPCell cellAddress = new PdfPCell(new Paragraph("Address: " + ConfigurationDAL.GetCurrentAddress()));
                        cellAddress.Colspan             = 6;
                        cellAddress.BackgroundColor     = new BaseColor(204, 204, 204);
                        cellAddress.BorderColor         = new BaseColor(204, 204, 204);
                        cellAddress.HorizontalAlignment = Element.ALIGN_CENTER;
                        table.AddCell(cellAddress);

                        PdfPCell cellCurrentDate = new PdfPCell(new Paragraph("Dated: " + displayDate));
                        cellCurrentDate.Colspan             = 6;
                        cellCurrentDate.BackgroundColor     = new BaseColor(204, 204, 204);
                        cellCurrentDate.BorderColor         = new BaseColor(204, 204, 204);
                        cellCurrentDate.HorizontalAlignment = Element.ALIGN_CENTER;
                        table.AddCell(cellCurrentDate);

                        PdfPCell cellInvoiceID = new PdfPCell(new Paragraph("Invoice ID: " + invoiceID.ToString()));
                        cellInvoiceID.Colspan             = 6;
                        cellInvoiceID.BackgroundColor     = new BaseColor(204, 204, 204);
                        cellInvoiceID.BorderColor         = new BaseColor(204, 204, 204);
                        cellInvoiceID.HorizontalAlignment = Element.ALIGN_LEFT;
                        table.AddCell(cellInvoiceID);



                        // Printing Items

                        PdfPCell cellItemHeader = new PdfPCell(new Paragraph("Item"));
                        cellItemHeader.Colspan = 2;
                        table.AddCell(cellItemHeader);

                        PdfPCell cellQuantityHeader = new PdfPCell(new Paragraph("Quantity"));
                        cellQuantityHeader.Colspan = 2;
                        table.AddCell(cellQuantityHeader);

                        PdfPCell cellPriceHeader = new PdfPCell(new Paragraph("Unit Price"));
                        cellPriceHeader.Colspan = 2;
                        table.AddCell(cellPriceHeader);

                        foreach (Sale item in saleItems)
                        {
                            PdfPCell cellItemName = new PdfPCell(new Paragraph(item.ItemName));
                            cellItemName.Colspan = 2;
                            table.AddCell(cellItemName);

                            PdfPCell cellQuantity = new PdfPCell(new Paragraph(item.Quantity.ToString() + "  " + item.UomName));
                            cellQuantity.Colspan = 2;
                            table.AddCell(cellQuantity);

                            string   pricewithUnit = ConfigurationDAL.GetCurrentCurrency() + " " + string.Format("{0:N2}", item.SalePrice);
                            PdfPCell cellPrice     = new PdfPCell(new Paragraph(pricewithUnit));
                            cellPrice.Colspan = 2;
                            table.AddCell(cellPrice);
                        }

                        // Printing Total Quantity and Price
                        PdfPCell cellTotalQtyHeader = new PdfPCell(new Paragraph("Total Quantity "));
                        cellTotalQtyHeader.Colspan             = 2;
                        cellTotalQtyHeader.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cellTotalQtyHeader.BackgroundColor     = new BaseColor(200, 200, 200);
                        table.AddCell(cellTotalQtyHeader);

                        PdfPCell cellTotalQtyValue = new PdfPCell(new Paragraph(this.saleCounter.ToString()));
                        cellTotalQtyValue.BackgroundColor = new BaseColor(200, 200, 200);
                        table.AddCell(cellTotalQtyValue);


                        PdfPCell cellTotalPriceHeader = new PdfPCell(new Paragraph("Total Price"));
                        cellTotalPriceHeader.BackgroundColor = new BaseColor(200, 200, 200);
                        table.AddCell(cellTotalPriceHeader);

                        PdfPCell cellTotalPriceValue = new PdfPCell(new Paragraph(ConfigurationDAL.GetCurrentCurrency() + " " + this.saleTotalPrice.ToString()));
                        cellTotalPriceValue.Colspan         = 2;
                        cellTotalPriceValue.BackgroundColor = new BaseColor(200, 200, 200);
                        table.AddCell(cellTotalPriceValue);

                        // Printing XtraWebApps Footer
                        PdfPCell cellFooter = new PdfPCell(new Paragraph("Shop Management Solution by www.DeluxeWebApps.com", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10)));
                        cellFooter.Colspan             = 6;
                        cellFooter.HorizontalAlignment = Element.ALIGN_CENTER;
                        table.AddCell(cellFooter);

                        // Add cells to table and close it.
                        myDocument.Add(table);
                        myDocument.Close();

                        //Launch the PDF Generated.
                        System.Diagnostics.Process.Start(path + ".pdf");

                        this.Close();
                        MessageBox.Show(this, "Item sold successfully.", "Sale Item(s)", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    throw new Exception("Please add some item(s) in list");
                }
            }
            catch (DocumentException de)
            {
                MessageBox.Show(de.Message);
            }
            catch (IOException ioe)
            {
                MessageBox.Show(ioe.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message.ToString(), "Error: Sale Item(s)", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }