public void Verify_TableHeight_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            PdfWriter.GetInstance(document, stream);
            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            PdfPTable table = createFirstTable();

            document.Add(new Paragraph(string.Format(
                                           "Table height before document.Add(): {0}",
                                           table.TotalHeight)
                                       ));
            document.Add(new Paragraph(
                             string.Format("Height of the first row: {0}",
                                           table.GetRowHeight(0))
                             ));
            document.Add(table);
            document.Add(new Paragraph(string.Format(
                                           "Table height after document.Add(): {0}",
                                           table.TotalHeight
                                           )));
            document.Add(new Paragraph(string.Format(
                                           "Height of the first row: {0}",
                                           table.GetRowHeight(0)
                                           )));
            table = createFirstTable();
            document.Add(new Paragraph(string.Format(
                                           "Table height before setTotalWidth(): {0}",
                                           table.TotalHeight
                                           )));
            document.Add(new Paragraph(string.Format(
                                           "Height of the first row: {0}",
                                           table.GetRowHeight(0)
                                           )));
            table.TotalWidth  = 50;
            table.LockedWidth = true;
            document.Add(new Paragraph(string.Format(
                                           "Table height after setTotalWidth(): {0}",
                                           table.TotalHeight
                                           )));
            document.Add(new Paragraph(string.Format(
                                           "Height of the first row: {0}",
                                           table.GetRowHeight(0)
                                           )));
            document.Add(table);

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
Esempio n. 2
0
 // ===========================================================================
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         PdfPTable table = CreateFirstTable();
         document.Add(new Paragraph(string.Format(
                                        "Table height before document.Add(): {0}",
                                        table.TotalHeight
                                        )));
         document.Add(new Paragraph(string.Format(
                                        "Height of the first row: {0}",
                                        table.GetRowHeight(0)
                                        )));
         document.Add(table);
         document.Add(new Paragraph(string.Format(
                                        "Table height after document.Add(): {0}",
                                        table.TotalHeight
                                        )));
         document.Add(new Paragraph(string.Format(
                                        "Height of the first row: {0}",
                                        table.GetRowHeight(0)
                                        )));
         table = CreateFirstTable();
         document.Add(new Paragraph(string.Format(
                                        "Table height before setTotalWidth(): {0}",
                                        table.TotalHeight
                                        )));
         document.Add(new Paragraph(string.Format(
                                        "Height of the first row: {0}",
                                        table.GetRowHeight(0)
                                        )));
         table.TotalWidth  = 50;
         table.LockedWidth = true;
         document.Add(new Paragraph(string.Format(
                                        "Table height after setTotalWidth(): {0}",
                                        table.TotalHeight
                                        )));
         document.Add(new Paragraph(string.Format(
                                        "Height of the first row: {0}",
                                        table.GetRowHeight(0)
                                        )));
         document.Add(table);
     }
 }
Esempio n. 3
0
        public float Soma(PdfPTable tabela)
        {
            float soma = 0;

            for (int i = 0; i < tabela.HeaderRows; i++)
            {
                soma += tabela.GetRowHeight(i);
            }

            return(soma);
        }
Esempio n. 4
0
        public float AlturaDaTabela(PdfPTable tabela)
        {
            float altura = 0;

            for (int i = 0; i < tabela.Rows.Count; i++)
            {
                altura += tabela.GetRowHeight(i);
            }

            return(altura);
        }
Esempio n. 5
0
        public bool EhParaPularParaProximaPagina(PdfPTable tabelaTerciaria)
        {
            int qntdHeaderRows               = tabelaTerciaria.HeaderRows;
            var alturaAtualDoCursor          = writer.GetVerticalPosition(false);
            var espacoRestanteDaUltimaPagina = alturaAtualDoCursor - doc.BottomMargin;
            var somaDaAlturaDosHeadersDaTabelaTerciariaMaisUmRegistro = 0.0;

            for (int i = 0; i < qntdHeaderRows + 1; i++)
            {
                somaDaAlturaDosHeadersDaTabelaTerciariaMaisUmRegistro += tabelaTerciaria.GetRowHeight(i);
            }
            return(somaDaAlturaDosHeadersDaTabelaTerciariaMaisUmRegistro
                   > espacoRestanteDaUltimaPagina);
        }
        // Render the table to the Pdf document.
        public void RenderTable(Document document, PdfWriter writer)
        {
            float left = (document.PageSize.Width - headerTable.TotalWidth) / 2;

            var   pageCount    = pageSplitter.Count;
            float headerHeight = headerTable.GetRowHeight(0);

            for (int i = 0; i < pageCount; i++)
            {
                var rownumbers = pageSplitter[i];
                headerTable.WriteSelectedRows(0, 1, left, top, writer.DirectContent);
                dataTable.WriteSelectedRows(rownumbers.Item1, rownumbers.Item2,
                                            left, top - headerHeight, writer.DirectContent);

                if (i != pageCount - 1)
                {
                    document.NewPage();
                }
            }
        }
Esempio n. 7
0
        public void Printledger(string Header, List <ledger> ledgerList, string balance)
        {
            //MemoryStream ms = new MemoryStream();
            //////string fileName = "";
            //////string payMode = "";
            string[] str         = Header.Split(';');
            string   HeaderSring = "Party: " + str[0] +
                                   ";From Date:" + str[1] + ";To Date:" + str[2];
            string ColHeader = "SI No.;Document ID;Voucher No;Voucher Date;Transaction Acc Name; Narration; Debit Amount; Credit Amount";
            //string footer3 = "Receiver's Signature;Authorised Signatory";
            int    n = 1;
            string ColDetailString = "";
            var    count           = ledgerList.Count();

            foreach (ledger ldg in ledgerList)
            {
                if (n == count)
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + ldg.DocumentID + Main.delimiter1 + ldg.VoucherNo + Main.delimiter1 + ldg.VoucherDate.ToString("dd-MM-yyyy") + Main.delimiter1 + ldg.TransactionACName + Main.delimiter1
                                      + ldg.Narration + Main.delimiter1 + ldg.DebitAmnt + Main.delimiter1 + ldg.CreditAmnt;
                }
                else
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + ldg.DocumentID + Main.delimiter1 + ldg.VoucherNo + Main.delimiter1 + ldg.VoucherDate.ToString("dd-MM-yyyy") + Main.delimiter1 + ldg.TransactionACName + Main.delimiter1
                                      + ldg.Narration + Main.delimiter1 + ldg.DebitAmnt + Main.delimiter1 + ldg.CreditAmnt + Main.delimiter2;
                }
                //totQuant = totQuant + pod.Quantity;
                //totAmnt = totAmnt + (pod.Quantity * pod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = "ledger" + " - " + str[0];

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName + ".pdf", FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                //String imageURL = @"D:\Smrutiranjan\PurchaseOrder\index.jpg";
                //iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
                String URL = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;
                Paragraph paragraph1 = new Paragraph(new Phrase("CELLCOMM SOLUTIONS Ltd.", font2));
                paragraph1.Alignment = Element.ALIGN_CENTER;
                Paragraph paragraph2 = new Paragraph(new Phrase("Ledger", font2));
                paragraph2.Alignment = Element.ALIGN_CENTER;

                //PrintPurchaseOrder prog = new PrintPurchaseOrder();
                string[] HeaderStr = HeaderSring.Split(';');

                Paragraph para = new Paragraph();
                para.Add(new Chunk(HeaderStr[0] + "\n", font1));
                para.Add(new Chunk(HeaderStr[1] + "\n", font1));
                para.Add(new Chunk(HeaderStr[2] + "\n", font1));
                ////para.Add(new Chunk(HeaderStr[3] + "\n", font1));
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(8);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                table1.SpacingBefore   = 20;
                float[] width = new float[] { 0.5f, 2f, 1.5f, 1.5f, 2f, 4f, 1.5f, 1.5f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 8;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    string st = DetailStr[i];
                    hg = table1.GetRowHeight(i + 1);
                    string[] detail = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < detail.Length; j++)
                    {
                        PdfPCell pcell;
                        pcell = new PdfPCell(new Phrase(detail[j], font1));
                        pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(pcell);
                        string stt = detail[j];
                    }
                }
                if (table1.Rows.Count > 10)
                {
                    table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);
                }
                PdfPTable table2 = new PdfPTable(8);
                table2.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table2.WidthPercentage = 100;
                table2.SetWidths(width);
                //table2.SpacingBefore = 20;
                PdfPCell cel = new PdfPCell(new Phrase(""));
                cel.Colspan = 5;
                cel.Rowspan = 2;
                table2.AddCell(cel);
                table2.AddCell(new Phrase("Balance", font2));
                string[] bal = balance.Split(';');
                if (bal[0].Contains("Credit"))
                {
                    string str4 = bal[0].Substring(bal[0].IndexOf(':') + 1);
                    table2.AddCell(new Phrase(""));
                    table2.AddCell(new Phrase(bal[0].Substring(bal[0].IndexOf(':') + 1), font2));
                }
                else if (bal[0].Contains("Debit"))
                {
                    string str4 = bal[0].Substring(bal[0].IndexOf(':') + 1);
                    table2.AddCell(new Phrase(bal[0].Substring(bal[0].IndexOf(':') + 1), font2));
                    table2.AddCell(new Phrase(""));
                }
                table2.AddCell(new Phrase("Total", font2));
                table2.AddCell(new Phrase(bal[1], font2));
                table2.AddCell(new Phrase(bal[1], font2));
                doc.Add(img);
                doc.Add(paragraph1);
                doc.Add(paragraph2);
                doc.Add(para);
                doc.Add(table1);
                doc.Add(table2);
                doc.Close();
                MessageBox.Show("Saved sucessfully");
            }
            catch (Exception ie)
            {
                MessageBox.Show("error");
            }
            //return fileName;
            //byte[] pdfByte = ms.ToArray();
            //string path = Path.GetTempPath();
            //fileDir = path + "Test.pdf";
            //File.Delete(fileDir);
            //using (FileStream fs = File.Create(path+"Test.pdf"))
            //{
            //    fs.Write(pdfByte, 0, (int)pdfByte.Length);
            //}
            //File.SetAttributes(fileDir,FileAttributes.Hidden);
            //System.Diagnostics.Process process = System.Diagnostics.Process.Start(path + "Test.pdf");
            //process.EnableRaisingEvents = true;
            //process.Exited += new EventHandler(myProcess_Exited);
            //process.WaitForExit();
            ////if (process.HasExited)
            ////{
            ////    MessageBox.Show("Exited");
            ////}
            ////System.Diagnostics.Process.Start(path + "Test.pdf");
            //return ms.ToArray();
        }
Esempio n. 8
0
        public void PrintIO(invoiceoutheader ioh, List <invoiceoutdetail> IODetails, string taxStr, string podocID)
        {
            try
            {
                Dictionary <string, string> companyInfo = getCompanyInformation();
                string[] pos        = ioh.TrackingNos.Split(';');
                int      b          = 0;
                int[]    a          = (from s in pos where int.TryParse(s, out b) select b).ToArray();
                int      min        = a.Min();
                string[] dates      = ioh.TrackingDates.Split(';');
                string   poStr      = "";
                string   billingAdd = "";
                string   othRef     = "";
                for (int i = 0; i < pos.Length - 1; i++)
                {
                    string   custPOStr = POPIHeaderDB.getCustomerPOAndDateForInvoiceOut(Convert.ToInt32(pos[i]), Convert.ToDateTime(dates[i]), podocID);
                    string[] custPO    = custPOStr.Split(Main.delimiter1);
                    ////if (Convert.ToInt32(pos[i]) == min)
                    ////billingAdd = custPO[2];
                    poStr  = poStr + custPO[0] + ", Date: " + String.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(custPO[1])) + "\n";
                    othRef = othRef + pos[i] + ",";
                }
                companybank cb         = CompanyBankDB.getCompBankDetailForIOPrint(ioh.BankAcReference);
                customer    custDetail = CustomerDB.getCustomerDetailForPO(ioh.ConsigneeID);

                string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
                string   ConsgAdd          = "Consignee:\n" + custDetail.name + Main.delimiter2 + "\n" + ioh.DeliveryAddress + "\n";
                string   buyer             = "Buyer:\n" + custDetail.name + Main.delimiter2 + "\n" + custDetail.BillingAddress + "\n";
                if (custDetail.StateName.ToString().Length != 0)
                {
                    ConsgAdd = ConsgAdd + "Sate Name:" + custDetail.StateName;
                    buyer    = buyer + "Sate Name:" + custDetail.StateName;
                    if (custDetail.StateCode.ToString().Length != 0)
                    {
                        ConsgAdd = ConsgAdd + " ,\nState Code:" + custDetail.StateCode;
                        buyer    = buyer + " ,\nState Code:" + custDetail.StateCode;
                    }
                }
                else
                {
                    if (custDetail.StateCode.ToString().Length != 0)
                    {
                        ConsgAdd = ConsgAdd + "\nState Code:" + custDetail.StateCode;
                        buyer    = buyer + "\nState Code:" + custDetail.StateCode;
                    }
                }
                if (custDetail.OfficeName.ToString().Length != 0)
                {
                    ConsgAdd = ConsgAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
                    buyer    = buyer + "\nGST:" + custDetail.OfficeName;    // For GST Code
                }
                if (CustomerDB.getCustomerPANForInvoicePrint(ioh.ConsigneeID).Length != 0)
                {
                    ConsgAdd = ConsgAdd + "\nPAN:" + custDetail.OfficeName; // For PAN Code
                    buyer    = buyer + "\nPAN:" + custDetail.OfficeName;    // For PAN Code
                }

                string HeaderString = buyer +

                                      Main.delimiter1 + "Invoice No : " + ioh.InvoiceNo + " , Date: " + String.Format("{0:dd MMMM, yyyy}", ioh.InvoiceDate) +
                                      Main.delimiter1 + "Buyer's Reference : " + poStr.Trim() +
                                      Main.delimiter1 + "Mode of Dispatch : " + ioh.TransportationModeName +
                                      Main.delimiter1 + "Terms of Payment : " + ioh.TermsOfPayment + Main.delimiter1 + //Description : Name of terms of payment

                                      ConsgAdd +

                                      Main.delimiter1 + "Supplier's Reference : " + othRef.Trim().Substring(0, othRef.Length - 1) +
                                      Main.delimiter1 + "Reverse Charge : " + ioh.ReverseCharge +
                                      Main.delimiter1 + ioh.SpecialNote;

                string footer1   = "Amount in words\n\n";
                string ColHeader = "";
                if (ioh.DocumentID == "PRODUCTINVOICEOUT" || ioh.DocumentID == "PRODUCTEXPORTINVOICEOUT")
                {
                    ColHeader = "SI No.;Description of Goods;HSN;Quantity;Unit;Unit Rate;Amount";
                }
                else
                {
                    ColHeader = "SI No.;Description of Goods;SAC;Quantity;Unit;Unit Rate;Amount";
                }
                CompanyDetailDB compDB   = new CompanyDetailDB();
                cmpnydetails    det      = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                string          compName = "";
                if (det != null)
                {
                    compName = det.companyname;
                }
                string footer2 = "\n\nAccount Name : " + compName + "\nAccount No : " + cb.AccountCode + "\nAccount Type : " + cb.AccountType + "\nBank : " + cb.BankName + "\nBranch : " + cb.BranchName + "\nIFSC : " + cb.CreateUser;
                //"\nSWIFT Code : " + cb.CompanyID +
                string footer3         = "For Cellcomm Solutions Limited;Authorised Signatory";
                double totQuant        = 0.00;
                double totAmnt         = 0.00;
                int    n               = 1;
                string ColDetailString = "";
                var    count           = IODetails.Count();

                foreach (invoiceoutdetail iod in IODetails)
                {
                    if (ioh.DocumentID == "PRODUCTINVOICEOUT")
                    {
                        iod.HSNCode = iod.HSNCode.Substring(0, 4);
                    }
                    else if (ioh.DocumentID == "SERVICEINVOICEOUT")
                    {
                        iod.HSNCode = iod.HSNCode.Substring(0, 6);
                    }
                    if (n == count)
                    {
                        //if (ioh.DocumentID == "PRODUCTINVOICEOUT")
                        ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + iod.HSNCode + Main.delimiter1 + iod.Quantity + Main.delimiter1
                                          + iod.Unit + Main.delimiter1 + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price);
                        //else
                        //    ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + iod.HSNCode.Substring(0, 4) + Main.delimiter1 + iod.Quantity + Main.delimiter1
                        //                   + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price);
                    }
                    else
                    {
                        //if (ioh.DocumentID == "PRODUCTINVOICEOUT")
                        ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + iod.HSNCode + Main.delimiter1 + iod.Quantity + Main.delimiter1
                                          + iod.Unit + Main.delimiter1 + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price) + Main.delimiter2;
                        //else
                        //    ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + iod.HSNCode.Substring(0, 4) + Main.delimiter1 + iod.Quantity + Main.delimiter1
                        //                   + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price) + Main.delimiter2;
                    }
                    totQuant = totQuant + iod.Quantity;
                    totAmnt  = totAmnt + (iod.Quantity * iod.Price);
                    n++;
                }

                try
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Title            = "Save As PDF";
                    sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                    sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    if (ioh.status == 0 && ioh.DocumentStatus < 99)
                    {
                        sfd.FileName = ioh.DocumentID + "-Temp-" + ioh.TemporaryNo;
                    }
                    else
                    {
                        sfd.FileName = ioh.DocumentID + "-" + ioh.InvoiceNo;
                    }

                    if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                    {
                        return;
                    }
                    FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                    Rectangle  rec = new Rectangle(PageSize.A4);
                    rec.Bottom = 10;
                    iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                    PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                    MyEvent   evnt = new MyEvent();
                    writer.PageEvent = evnt;

                    doc.Open();
                    Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                    Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                    Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                    Font font4 = FontFactory.GetFont("Arial", 5, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);

                    String URL = "Cellcomm2.JPG";
                    iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                    img.Alignment = Element.ALIGN_LEFT;

                    PdfPTable tableHeader = new PdfPTable(2);

                    tableHeader.WidthPercentage = 100;
                    PdfPCell  cellImg = new PdfPCell();
                    Paragraph pp      = new Paragraph();
                    pp.Add(new Chunk(img, 0, 0));
                    cellImg.AddElement(pp);
                    cellImg.Border = 0;
                    tableHeader.AddCell(cellImg);

                    PdfPCell  cellAdd = new PdfPCell();
                    Paragraph ourAddr = new Paragraph("");

                    if (det != null)
                    {
                        ourAddr.Add(new Chunk(det.companyname + "\n", font2));
                        ourAddr.Add(new Chunk(det.companyAddress.Replace("\r\n", "\n"), font4));
                        StringBuilder sb = new StringBuilder();
                        sb.Append("\nGST : " + companyInfo["GST"] + "\nState Code for GST : " + companyInfo["StateCode"] + "\nCIN : " + companyInfo["CIN"] + "\nPAN : " + companyInfo["PAN"]);
                        ourAddr.Add(new Chunk(sb.ToString(), font4));
                        ourAddr.Alignment = Element.ALIGN_RIGHT;
                        ourAddr.SetLeading(0.0f, 1.5f);
                    }
                    cellAdd.AddElement(ourAddr);
                    cellAdd.Border = 0;
                    tableHeader.AddCell(cellAdd);

                    Paragraph ParagraphDocumentName = new Paragraph(new Phrase("Tax Invoice", font2));
                    ParagraphDocumentName.Alignment = Element.ALIGN_CENTER;

                    PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                    string[]           HeaderStr = HeaderString.Split(Main.delimiter1);

                    PdfPTable TableAddress = new PdfPTable(7);

                    TableAddress.SpacingBefore   = 20f;
                    TableAddress.WidthPercentage = 100;
                    float[] HWidths = new float[] { 1f, 8f, 1.5f, 2f, 1.5f, 2f, 3f };
                    TableAddress.SetWidths(HWidths);
                    PdfPCell cell;
                    int[]    arr = { 3, 7, 9, 10 };
                    float    wid = 0;
                    for (int i = 0; i < HeaderStr.Length; i++)
                    {
                        if (i == 0 || i == 5)
                        {
                            string[] format = HeaderStr[i].Split(Main.delimiter2);
                            Phrase   phr    = new Phrase();
                            phr.Add(new Chunk(format[0], font2));
                            phr.Add(new Chunk(format[1], font1));
                            cell = new PdfPCell(phr);
                            if (i == 0)
                            {
                                cell.Rowspan = 4;
                            }
                            else
                            {
                                cell.Rowspan = 3;
                            }
                            cell.Colspan             = 2;
                            cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                            TableAddress.AddCell(cell);
                        }
                        else
                        {
                            cell               = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                            cell.Colspan       = 5;
                            cell.MinimumHeight = wid;
                            TableAddress.AddCell(cell);
                        }
                    }
                    string[] ColHeaderStr = ColHeader.Split(';');

                    PdfPTable TableItemDetail = new PdfPTable(7);
                    TableItemDetail.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetail.WidthPercentage = 100;
                    float[] widthProd = new float[] { 1f, 8f, 1.5f, 2f, 1.5f, 2f, 3f };
                    float[] widthServ = new float[] { 1f, 8f, 1.5f, 2f, 0f, 2f, 3f };
                    if (ioh.DocumentID == "PRODUCTINVOICEOUT" || ioh.DocumentID == "PRODUCTEXPORTINVOICEOUT")
                    {
                        TableItemDetail.SetWidths(widthProd);
                    }
                    else
                    {
                        TableItemDetail.SetWidths(widthServ);
                    }


                    //Table Row No : 1 (Header Column)
                    for (int i = 0; i < ColHeaderStr.Length; i++)
                    {
                        if (i == (ColHeaderStr.Length - 1) || i == (ColHeaderStr.Length - 2))
                        {
                            PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim() + "\n(" + ioh.CurrencyID + ")", font2));
                            hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            TableItemDetail.AddCell(hcell);
                        }
                        else
                        {
                            PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                            hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            TableItemDetail.AddCell(hcell);
                        }
                    }
                    //---
                    //Table Row No : 2 (Footer Column)
                    PdfPCell foot = new PdfPCell(new Phrase(""));
                    foot.Colspan        = 7;
                    foot.BorderWidthTop = 0;
                    foot.MinimumHeight  = 0.5f;
                    TableItemDetail.AddCell(foot);

                    TableItemDetail.HeaderRows = 2;
                    TableItemDetail.FooterRows = 1;

                    TableItemDetail.SkipFirstHeader = false;
                    TableItemDetail.SkipLastFooter  = true;
                    //---
                    int     track = 0;
                    decimal dc1   = 0;
                    decimal dc2   = 0;

                    //Table Row No : 3 (Header Column)
                    string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                    float    hg        = 0f;
                    for (int i = 0; i < DetailStr.Length; i++)
                    {
                        track = 0;
                        hg    = TableItemDetail.GetRowHeight(i + 1);
                        string[] str = DetailStr[i].Split(Main.delimiter1);
                        for (int j = 0; j < str.Length; j++)
                        {
                            PdfPCell pcell;
                            if (j == 3 || j == 5 || j == 6)
                            {
                                decimal p = 1;
                                if (Decimal.TryParse(str[j], out p))
                                {
                                    pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(""));
                                }
                                pcell.Border = 0;
                                if (j == 6)
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                            else
                            {
                                if (j == 2)
                                {
                                    if (str[j].Trim().Length == 0)
                                    {
                                        pcell = new PdfPCell(new Phrase("", font1));
                                    }
                                    else
                                    {
                                        pcell = new PdfPCell(new Phrase(str[j], font1));
                                    }
                                }
                                else if (j == 4)
                                {
                                    int m = 1;
                                    if (Int32.TryParse(str[j], out m) == true)
                                    {
                                        if (Convert.ToInt32(str[j]) == 0)
                                        {
                                            pcell = new PdfPCell(new Phrase("", font1));
                                        }
                                        else
                                        {
                                            pcell = new PdfPCell(new Phrase(str[j], font1));
                                        }
                                    }
                                    else
                                    {
                                        pcell = new PdfPCell(new Phrase(str[j], font1));
                                    }
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                                pcell.Border = 0;
                            }

                            pcell.MinimumHeight = 10;
                            if (j == 1)
                            {
                                pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            }
                            else
                            {
                                pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            }
                            pcell.BorderWidthLeft  = 0.01f;
                            pcell.BorderWidthRight = 0.01f;

                            TableItemDetail.AddCell(pcell);
                        }
                    }
                    PdfPCell Temp = new PdfPCell(new Phrase(""));
                    Temp.Border           = 0;
                    Temp.BorderWidthLeft  = 0.01f;
                    Temp.BorderWidthRight = 0.01f;

                    int dd = 0;
                    if (ioh.TaxAmount != 0)
                    {
                        ////Table Row No : 4 (Total Amount)
                        PdfPCell Temp1 = new PdfPCell(new Phrase(""));
                        Temp1.Border           = 0;
                        Temp1.BorderWidthTop   = 0.01f;
                        Temp1.BorderWidthLeft  = 0.01f;
                        Temp1.BorderWidthRight = 0.01f;
                        TableItemDetail.AddCell(Temp1); //blank cell
                        TableItemDetail.AddCell(Temp1);
                        PdfPCell cellCom = new PdfPCell(new Phrase("", font1));
                        cellCom.Colspan             = 4;
                        cellCom.Border              = 0;
                        cellCom.BorderWidthLeft     = 0.01f;
                        cellCom.BorderWidthRight    = 0.01f;
                        cellCom.BorderWidthTop      = 0.01f;
                        cellCom.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        TableItemDetail.AddCell(cellCom);

                        PdfPCell cellTot = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(totAmnt)), font2));
                        cellTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        TableItemDetail.AddCell(cellTot);
                        dd++;

                        string[] tax = taxStr.Split(Main.delimiter2);
                        for (int i = 0; i < tax.Length - 1; i++)
                        {
                            TableItemDetail.AddCell(Temp); //blank cell
                            TableItemDetail.AddCell(Temp);

                            string[] subtax     = tax[i].Split(Main.delimiter1);
                            PdfPCell cellinrtax = new PdfPCell(new Phrase(subtax[0], font1));
                            cellinrtax.Colspan             = 4;
                            cellinrtax.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            TableItemDetail.AddCell(cellinrtax);

                            PdfPCell pcell2;
                            pcell2 = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(subtax[1])), font1));
                            pcell2.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            TableItemDetail.AddCell(pcell2);
                            dd++;
                        }
                        double taxAmRnd = Math.Round(ioh.TaxAmount, 0);
                        if (taxAmRnd != ioh.TaxAmount)
                        {
                            TableItemDetail.AddCell(Temp); //blank cell
                            TableItemDetail.AddCell(Temp);
                            PdfPCell cellTotTax = new PdfPCell(new Phrase("", font1));
                            cellTotTax.Colspan          = 4;
                            cellTotTax.Border           = 0;
                            cellTotTax.BorderWidthLeft  = 0.01f;
                            cellTotTax.BorderWidthRight = 0.01f;
                            //cellCom.BorderWidthTop = 0.01f;
                            cellTotTax.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            TableItemDetail.AddCell(cellTotTax);

                            PdfPCell cellTotTaxValue = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(totAmnt + ioh.TaxAmount)), font2));
                            cellTotTaxValue.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            TableItemDetail.AddCell(cellTotTaxValue);
                            dd++;
                        }
                    }



                    double roundedAmt = Math.Round(ioh.InvoiceAmount, 0);
                    double diffAmount = roundedAmt - ioh.InvoiceAmount;

                    if (diffAmount != 0)
                    {
                        TableItemDetail.AddCell("");
                        TableItemDetail.AddCell("");
                        PdfPCell cellRound = new PdfPCell(new Phrase("Rounding off", font1));
                        cellRound.Colspan             = 4;
                        cellRound.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        TableItemDetail.AddCell(cellRound);
                        TableItemDetail.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                        //table1.AddCell("");
                        dd++;
                    }

                    TableItemDetail.AddCell("");
                    TableItemDetail.AddCell("");
                    PdfPCell cellRoundTot = new PdfPCell(new Phrase("Total", font1));
                    cellRoundTot.Colspan             = 4;
                    cellRoundTot.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    TableItemDetail.AddCell(cellRoundTot);

                    PdfPCell roundTot = new PdfPCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font2));
                    roundTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetail.AddCell(roundTot);

                    //table1.AddCell("");
                    string   total  = footer1 + NumberToString.convert(roundedAmt.ToString()).Replace("INR", ioh.CurrencyID) + "\n\n";
                    PdfPCell fcell1 = new PdfPCell(new Phrase((total), font1));
                    fcell1.Border              = 0;
                    fcell1.Colspan             = 6;
                    fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                    fcell1.BorderWidthLeft     = 0.5f;
                    fcell1.BorderWidthBottom   = 0.5f;
                    fcell1.BorderWidthRight    = 0;
                    fcell1.BorderWidthTop      = 0;
                    TableItemDetail.AddCell(fcell1);

                    PdfPCell fcell4 = new PdfPCell(new Phrase("E. & O.E", font1));
                    fcell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    fcell4.Border            = 0;
                    fcell4.BorderWidthBottom = 0.5f;
                    fcell4.BorderWidthRight  = 0.5f;
                    fcell4.BorderWidthLeft   = 0;
                    fcell4.BorderWidthTop    = 0;
                    TableItemDetail.AddCell(fcell4);
                    TableItemDetail.KeepRowsTogether(TableItemDetail.Rows.Count - (dd + 4), TableItemDetail.Rows.Count);
                    //int HSNMappCount = TaxDataTable.Rows.Count + 6;
                    //int itemCount = DetailStr.Length;
                    //int tableCount = table1.Rows.Count;

                    //=================================================
                    //DataTable TaxDataTable = new DataTable("TaxDetails");
                    //DataColumn[] colArr = { new DataColumn("HSN Code"), new DataColumn("Taxable Value"), new DataColumn("CGST %"),
                    //    new DataColumn("CGST Amt"), new DataColumn("SGST %"), new DataColumn("SGST Amt"), new DataColumn("IGST %"),
                    //    new DataColumn("IGST Amt"), new DataColumn("Total Amt") };
                    //TaxDataTable.Columns.AddRange(colArr);

                    //DataRow myDataRow = TaxDataTable.NewRow();
                    //myDataRow[colArr[0]] = "1111";
                    //myDataRow[colArr[1]] = "1000";
                    //myDataRow[colArr[2]] = "9";
                    //myDataRow[colArr[3]] = "200";
                    //myDataRow[colArr[4]] = "9";
                    //myDataRow[colArr[5]] = "200";
                    //myDataRow[colArr[6]] = "14";
                    //myDataRow[colArr[7]] = "600";
                    //myDataRow[colArr[8]] = "2000";
                    //TaxDataTable.Rows.Add(myDataRow);
                    //DataRow myDataRow1 = TaxDataTable.NewRow();
                    //myDataRow1[colArr[0]] = "2222";
                    //myDataRow1[colArr[1]] = "2000";
                    //myDataRow1[colArr[2]] = "9";
                    //myDataRow1[colArr[3]] = "300";
                    //myDataRow1[colArr[4]] = "9";
                    //myDataRow1[colArr[5]] = "400";
                    //myDataRow1[colArr[6]] = "14";
                    //myDataRow1[colArr[7]] = "1300";
                    //myDataRow1[colArr[8]] = "4000";
                    //TaxDataTable.Rows.Add(myDataRow1);
                    //==============================================
                    InvoiceOutHeaderDB iohDB        = new InvoiceOutHeaderDB();
                    DataTable          TaxDataTable = iohDB.taxDetails4Print(IODetails, ioh.DocumentID);


                    PdfPTable TabTaxDetail = new PdfPTable(TaxDataTable.Columns.Count);
                    TabTaxDetail.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TabTaxDetail.WidthPercentage = 100;
                    //TabTaxDetail.SpacingBefore = 10;
                    PdfPCell cellTax = new PdfPCell();
                    //Adding columns in table
                    List <string>            colListStr    = new List <string>();
                    List <string>            colListSubStr = new List <string>();
                    double                   amtTot        = 0;
                    double                   TaxTot1       = 0;
                    double                   TaxTot2       = 0;
                    double                   TaxTot3       = 0;
                    double                   TaxTot        = 0;
                    Dictionary <int, string> dictTot       = new Dictionary <int, string>();
                    for (int p = 0; p < TaxDataTable.Columns.Count; p++)
                    {
                        if (p != 0 && p != 1 && p != TaxDataTable.Columns.Count - 1)
                        {
                            TaxTot1 = 0;
                            string substr = TaxDataTable.Columns[p].ColumnName;
                            colListStr.Add(substr.Trim());                             //CGST
                            colListSubStr.Add(TaxDataTable.Columns[p].ColumnName);     //CGST% in subList
                            colListSubStr.Add(TaxDataTable.Columns[p + 1].ColumnName); //CGST amount in subList
                            p++;
                            if (p % 2 != 0)
                            {
                                TaxTot1 = TaxDataTable.AsEnumerable().Sum(c => c.Field <double>(TaxDataTable.Columns[p].ColumnName));
                                dictTot.Add(p, String.Format("{0:0.00}", Convert.ToDecimal(TaxTot1)));
                            }
                        }
                        else
                        {
                            colListStr.Add(TaxDataTable.Columns[p].ColumnName);
                            if (p == 1)
                            {
                                amtTot = TaxDataTable.AsEnumerable().Sum(c => c.Field <double>(TaxDataTable.Columns[p].ColumnName));
                                dictTot.Add(p, String.Format("{0:0.00}", Convert.ToDecimal(amtTot)));
                            }
                            if (p == TaxDataTable.Columns.Count - 1)
                            {
                                TaxTot = TaxDataTable.AsEnumerable().Sum(c => c.Field <double>(TaxDataTable.Columns[p].ColumnName));
                                dictTot.Add(p, String.Format("{0:0.00}", Convert.ToDecimal(TaxTot)));
                            }
                        }
                    }
                    foreach (string str in colListStr)
                    {
                        int index = colListStr.FindIndex(x => x == str);
                        if (index == 0 || index == 1 || index == colListStr.Count - 1)
                        {
                            cellTax         = new PdfPCell();
                            cellTax.Rowspan = 2;
                            Paragraph p = new Paragraph(str, font2);
                            p.Alignment = Element.ALIGN_CENTER;
                            cellTax.AddElement(p);
                            TabTaxDetail.AddCell(cellTax);
                        }
                        else
                        {
                            cellTax         = new PdfPCell();
                            cellTax.Colspan = 2;
                            Paragraph p = new Paragraph(str, font2);
                            p.Alignment = Element.ALIGN_CENTER;
                            cellTax.AddElement(p);
                            TabTaxDetail.AddCell(cellTax);
                        }
                    }
                    foreach (string str in colListSubStr)
                    {
                        cellTax = new PdfPCell();
                        Paragraph p = new Paragraph(str, font2);
                        p.Alignment = Element.ALIGN_CENTER;
                        cellTax.AddElement(p);
                        TabTaxDetail.AddCell(cellTax);
                    }
                    int t = 0;
                    foreach (DataRow row in TaxDataTable.Rows)
                    {
                        int l = 0;
                        foreach (DataColumn col in TaxDataTable.Columns)
                        {
                            cellTax = new PdfPCell();
                            if (l == 1 || l % 2 != 0 || l == TaxDataTable.Columns.Count - 1)
                            {
                                Paragraph p = new Paragraph(String.Format("{0:0.00}", Convert.ToDecimal(row[col].ToString())), font1);
                                p.Alignment = Element.ALIGN_CENTER;
                                cellTax.AddElement(p);
                                TabTaxDetail.AddCell(cellTax);
                            }
                            else
                            {
                                Paragraph p = new Paragraph(row[col].ToString(), font1);
                                p.Alignment = Element.ALIGN_CENTER;
                                cellTax.AddElement(p);
                                TabTaxDetail.AddCell(cellTax);
                            }
                            t++;
                            l++;
                        }
                    }
                    for (int k = 0; k < TaxDataTable.Columns.Count; k++)
                    {
                        if (k == 0)
                        {
                            cellTax = new PdfPCell();
                            Paragraph p = new Paragraph("Total", font2);
                            p.Alignment = Element.ALIGN_CENTER;
                            cellTax.AddElement(p);
                            TabTaxDetail.AddCell(cellTax);
                        }
                        else if (dictTot.ContainsKey(k))
                        {
                            cellTax = new PdfPCell();
                            Paragraph p = new Paragraph(dictTot[k], font2);
                            p.Alignment = Element.ALIGN_CENTER;
                            cellTax.AddElement(p);
                            TabTaxDetail.AddCell(cellTax);
                        }
                        else
                        {
                            cellTax = new PdfPCell();
                            Paragraph p = new Paragraph("", font1);
                            p.Alignment = Element.ALIGN_CENTER;
                            cellTax.AddElement(p);
                            TabTaxDetail.AddCell(cellTax);
                        }
                    }
                    //TabTaxDetail.KeepRowsTogether(TabTaxDetail.Rows.Count - 10, TabTaxDetail.Rows.Count);
                    TabTaxDetail.KeepTogether = true;

                    //Bank dtails and authorised Signature
                    PdfPTable tableFooter = new PdfPTable(2);
                    tableFooter.WidthPercentage = 100;
                    Phrase phrs = new Phrase();
                    phrs.Add(new Chunk("\nBank Details for Payment", font2));

                    phrs.Add(new Chunk(footer2, font1));

                    PdfPCell fcell2 = new PdfPCell(phrs);
                    fcell2.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                    fcell2.BorderWidthRight    = 0;
                    tableFooter.AddCell(fcell2);

                    string[] ft = footer3.Split(';');

                    PdfPCell fcell3 = new PdfPCell();
                    Chunk    ch1    = new Chunk(ft[0], font1);
                    Chunk    ch2    = new Chunk(ft[1], font1);
                    Phrase   phrase = new Phrase();
                    phrase.Add(ch1);
                    for (int i = 0; i < 3; i++)
                    {
                        phrase.Add(Chunk.NEWLINE);
                    }
                    phrase.Add(ch2);

                    Paragraph para = new Paragraph();
                    para.Add(phrase);
                    para.Alignment = Element.ALIGN_RIGHT;
                    fcell3.AddElement(para);
                    fcell3.Border            = 0;
                    fcell3.BorderWidthRight  = 0.5f;
                    fcell3.BorderWidthBottom = 0.5f;
                    fcell3.MinimumHeight     = 50;
                    tableFooter.AddCell(fcell3);

                    PdfPTable tableSub = new PdfPTable(1);
                    tableSub.DefaultCell.Border = 0;
                    tableSub.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    tableSub.AddCell(new Phrase("Subject To Bangalore Jurisdiction", font2));

                    PdfPCell celSub = new PdfPCell(tableSub);
                    celSub.Border  = 0;
                    celSub.Colspan = 2;
                    tableFooter.AddCell(celSub);

                    //=======


                    doc.Add(tableHeader);
                    doc.Add(ParagraphDocumentName);
                    doc.Add(TableAddress);
                    doc.Add(TableItemDetail);
                    doc.Add(TabTaxDetail);
                    doc.Add(tableFooter);


                    doc.Close();

                    if (ioh.status == 0 && ioh.DocumentStatus < 99)
                    {
                        String wmurl = "";
                        wmurl = "004.png";
                        PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
                    }
                    if (ioh.status == 98)
                    {
                        String wmurl = "";
                        wmurl = "003.png";
                        PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
                    }
                    MessageBox.Show("Document Saved");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                    MessageBox.Show("Failed TO Save");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception : " + ex.ToString());
                MessageBox.Show("Failed TO Save");
            }
        }
Esempio n. 9
0
        public bool EhParaPularParaProximaPagina(PdfPTable tabelaPrimaria, PdfPTable tabelaSecundaria)
        {
            int qntdHeaderRows               = tabelaSecundaria.HeaderRows;
            var alturaAtualDoCursor          = writer.GetVerticalPosition(false);
            var espacoRestanteDaUltimaPagina = alturaAtualDoCursor - doc.BottomMargin;
            var somaDaAlturaDaTabelaPrimariaComHeadersMaisUmRegistroDaTabelaSecundaria
                = tabelaPrimaria.TotalHeight;

            //var espacoJaOcupadoNaUltimaPagina = alturaMaximaDeUmaPagina - espacoRestanteDaUltimaPagina;
            for (int i = 0; i < qntdHeaderRows + 1; i++)
            {
                somaDaAlturaDaTabelaPrimariaComHeadersMaisUmRegistroDaTabelaSecundaria += tabelaSecundaria.GetRowHeight(i);
            }

            return(somaDaAlturaDaTabelaPrimariaComHeadersMaisUmRegistroDaTabelaSecundaria
                   > espacoRestanteDaUltimaPagina);
        }
Esempio n. 10
0
        public void PrintPO(poheader poh, List <podetail> PODetail, string taxStr)
        {
            Dictionary <string, string> companyInfo = getCompanyInformation();
            //string stateDetail =
            customer custDetail = CustomerDB.getCustomerDetailForPO(poh.CustomerID);

            string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
            string   poNoSuffix        = "";
            string   supplAdd          = "";
            string   stype             = "";

            if (poh.DocumentID == "POGENERAL")
            {
                poNoSuffix = "G-"; supplAdd = "Contractor:\n" + custDetail.name + Main.delimiter1 + "\n" + custDetail.BillingAddress + "\n";
                stype      = "Contractor";
            }
            else if (poh.DocumentID == "PURCHASEORDER")
            {
                poNoSuffix = "P-";
                stype      = "Supplier";
            }

            supplAdd = stype + ":\n" + custDetail.name + Main.delimiter1 + "\n" + custDetail.BillingAddress + "\n";
            if (custDetail.StateName.ToString().Length != 0)
            {
                supplAdd = supplAdd + "Sate Name:" + custDetail.StateName;
            }
            if (custDetail.StateCode.ToString().Length != 0)
            {
                supplAdd = supplAdd + "\nState Code:" + custDetail.StateCode;
            }
            if (custDetail.OfficeName.ToString().Length != 0)
            {
                supplAdd = supplAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
            }
            //; : main.delimiter2
            //$ : main.delimiter1
            string InvoiceTo    = "Invoice To: \n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + companyBillingAdd[1] + "\nGST:" + companyInfo["GST"] + "\nCIN:" + companyInfo["CIN"] + "\nPAN:" + companyInfo["PAN"];
            string DespatchTo   = "Dispatch To:\n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + poh.DeliveryAddress + "\nGST:" + companyInfo["GST"];
            string HeaderString = supplAdd +
                                  Main.delimiter2 + "PO No : " + poNoSuffix + poh.PONo + " , Date: " + String.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(poh.PODate)) +
                                  Main.delimiter2 + stype + " Reference : " + poh.ReferenceQuotation.Replace(";", ",\n") +
                                  Main.delimiter2 + "Mode Of Dispatch:" + CatalogueValueDB.getParamValue("TransportationMode", poh.TransportationMode) +
                                  Main.delimiter2 + "Delivery Period : " + poh.DeliveryPeriod + " Days" + Main.delimiter2 +

                                  InvoiceTo +

                                  Main.delimiter2 + "Price basis : " + CatalogueValueDB.getParamValue("PriceBasis", poh.PriceBasis) +
                                  Main.delimiter2 + "Delivery at : " + poh.DeliveryAt +
                                  Main.delimiter2 + "Terms of Payment : " + PTDefinitionDB.getPaymentTermString(poh.PaymentTerms) +
                                  Main.delimiter2 + "Tax : " + CatalogueValueDB.getParamValue("TaxStatus", poh.TaxTerms) + Main.delimiter2 +

                                  DespatchTo +

                                  Main.delimiter2 + "Partial Shipment : " + poh.PartialShipment +
                                  Main.delimiter2 + "Transhipment : " + poh.Transhipment +
                                  Main.delimiter2 + "Packaging Specification : " + poh.PackingSpec +
                                  Main.delimiter2 + poh.SpecialNote;
            string footer1     = "Amount In Words\n\n";
            string ColHeader   = "SI No.;Description of Goods;Quantity;Unit;Unit Rate;Amount;Warranty\nIn Days";
            string footer2     = "This Purchase Order, being computer generated, does not require physical signature.";
            string declaration = "We, Cellcomm Solutions Limited (also referred to as “CSL”), are pleased to place" +
                                 " this Purchase Order (also referred to as 'PO') with the " + stype + " addressed below.In accepting this Purchase Order, the " + stype +
                                 " undertakes to supply the Goods described herein as per the details and instructions shown below" +
                                 " (such details and instructions being the Specific Terms and Conditions agreed between the Parties) " +
                                 "and also subject to the General Terms & Conditions contained herein.";
            string termsAndCond    = getTCString(poh.TermsAndCondition, poh.DocumentID);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = PODetail.Count();

            foreach (podetail pod in PODetail)
            {
                if (n == count)
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + pod.Description + Main.delimiter1 + pod.Quantity + Main.delimiter1
                                      + pod.Unit + Main.delimiter1 + pod.Price + Main.delimiter1 + (pod.Quantity * pod.Price) + Main.delimiter1 + pod.WarrantyDays;
                }
                else
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + pod.Description + Main.delimiter1 + pod.Quantity + Main.delimiter1
                                      + pod.Unit + Main.delimiter1 + pod.Price + Main.delimiter1 + (pod.Quantity * pod.Price) + Main.delimiter1 + pod.WarrantyDays + Main.delimiter2;
                }
                totQuant = totQuant + pod.Quantity;
                totAmnt  = totAmnt + (pod.Quantity * pod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                if (poh.Status == 0 && poh.DocumentStatus < 99)
                {
                    sfd.FileName = poh.DocumentID + "-Temp-" + poh.TemporaryNo;
                }
                else
                {
                    sfd.FileName = poh.DocumentID + "-" + poh.PONo;
                }
                ///sfd.FileName = poh.DocumentID + "-" + poh.PONo;

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();

                Font   font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font   font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font   font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                Font   font4 = FontFactory.GetFont("Arial", 5, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                String URL   = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;


                PdfPTable tableHeader = new PdfPTable(2);

                tableHeader.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableHeader.AddCell(cellImg);

                PdfPCell        cellAdd = new PdfPCell();
                Paragraph       ourAddr = new Paragraph("");
                CompanyDetailDB compDB  = new CompanyDetailDB();
                cmpnydetails    det     = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                if (det != null)
                {
                    ourAddr.Add(new Chunk(det.companyname + "\n", font2));
                    ourAddr.Add(new Chunk(det.companyAddress.Replace("\r\n", "\n"), font4));
                    StringBuilder sb = new StringBuilder();
                    sb.Append("\nGST : " + companyInfo["GST"] + "\nState Code for GST : " + companyInfo["StateCode"] + "\nCIN : " + companyInfo["CIN"] + "\nPAN : " + companyInfo["PAN"]);
                    ourAddr.Add(new Chunk(sb.ToString(), font4));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                    ourAddr.SetLeading(0.0f, 1.5f);
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableHeader.AddCell(cellAdd);

                PdfPTable tableDocName = new PdfPTable(1);
                tableDocName.WidthPercentage = 100;
                PdfPCell cellHdr = new PdfPCell(new Phrase("PURCHASE ORDER", font2));
                cellHdr.Border = 0;
                cellHdr.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableDocName.AddCell(cellHdr);
                if (poh.CountryID != null && poh.CountryID != "India")
                {
                    PdfPCell cellHdrInr = new PdfPCell(new Phrase("(Import)", font2));
                    cellHdrInr.Border = 0;
                    cellHdrInr.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    tableDocName.AddCell(cellHdrInr);
                }

                Paragraph paragraphOpenCluse = new Paragraph(new Phrase(declaration, font1));
                paragraphOpenCluse.Alignment     = Element.ALIGN_JUSTIFIED;
                paragraphOpenCluse.SpacingBefore = 10;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(Main.delimiter2);

                PdfPTable TableAddress = new PdfPTable(7);

                TableAddress.SpacingBefore   = 20f;
                TableAddress.WidthPercentage = 100;
                float[] HWidths = new float[] { 1f, 8f, 2f, 1.5f, 1.5f, 3f, 1.5f };
                TableAddress.SetWidths(HWidths);
                PdfPCell cell;
                int[]    arr = { 6, 7, 9, 10 };
                float    wid = 0;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 0 || i == 5 || i == 10)
                    {
                        string[] format = HeaderStr[i].Split(Main.delimiter1);
                        Phrase   phr    = new Phrase();
                        phr.Add(new Chunk(format[0], font2));
                        phr.Add(new Chunk(format[1], font1));
                        cell                     = new PdfPCell(phr);
                        cell.Colspan             = 2;
                        cell.Rowspan             = 4;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        TableAddress.AddCell(cell);
                    }
                    else
                    {
                        cell               = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan       = 5;
                        cell.MinimumHeight = wid;
                        TableAddress.AddCell(cell);
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable TableItemDetails = new PdfPTable(7);
                TableItemDetails.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                TableItemDetails.WidthPercentage = 100;
                float[] width = new float[] { 1f, 8f, 2f, 1.5f, 2f, 2.5f, 1.5f };
                TableItemDetails.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    if (i == 4 || i == 5)
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim() + "\n(" + poh.CurrencyID + ")", font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        TableItemDetails.AddCell(hcell);
                    }
                    else
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        TableItemDetails.AddCell(hcell);
                    }
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 7;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                TableItemDetails.AddCell(foot);

                TableItemDetails.HeaderRows = 2;
                TableItemDetails.FooterRows = 1;

                TableItemDetails.SkipFirstHeader = false;
                TableItemDetails.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = TableItemDetails.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;

                        if (j == 2 || j == 4 || j == 5)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                            if (j == 5)
                            {
                                if (str[0].Length == 0)
                                {
                                    pcell.BorderWidthBottom = 0.01f;
                                    track = 1;
                                    dc2   = Convert.ToDecimal(str[j]);
                                }
                                else
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                        }
                        else
                        {
                            if (j == 6)
                            {
                                if ((str[j].Trim().Length == 0 || Convert.ToInt32(str[j]) == 0) && (track != 1))
                                {
                                    pcell = new PdfPCell(new Phrase("NA", font1));
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else if (j == 3)
                            {
                                int m = 1;
                                if (Int32.TryParse(str[j], out m) == true)
                                {
                                    if (Convert.ToInt32(str[j]) == 0)
                                    {
                                        pcell = new PdfPCell(new Phrase("", font1));
                                    }
                                    else
                                    {
                                        pcell = new PdfPCell(new Phrase(str[j], font1));
                                    }
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(str[j], font1));
                            }

                            pcell.Border = 0;
                        }

                        pcell.MinimumHeight = 10;
                        //pcell.MinimumHeight = 20;
                        if (j == 1)
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        }
                        else
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        }
                        pcell.BorderWidthLeft  = 0.01f;
                        pcell.BorderWidthRight = 0.01f;

                        TableItemDetails.AddCell(pcell);
                    }
                }
                double roundedAmt = Math.Round(totAmnt, 0);
                double diffAmount = roundedAmt - totAmnt;

                if (diffAmount != 0)
                {
                    TableItemDetails.AddCell("");
                    TableItemDetails.AddCell("");
                    PdfPCell cellTot = new PdfPCell(new Phrase("", font1));
                    cellTot.Colspan             = 3;
                    cellTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(cellTot);
                    TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", totAmnt), font1));
                    TableItemDetails.AddCell("");

                    TableItemDetails.AddCell("");
                    TableItemDetails.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Rounding off", font1));
                    cellRound.Colspan             = 3;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(cellRound);
                    TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                    TableItemDetails.AddCell("");
                }

                TableItemDetails.AddCell("");
                TableItemDetails.AddCell("");
                PdfPCell cellTotal = new PdfPCell(new Phrase("Total", font1));
                cellTotal.Colspan             = 3;
                cellTotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                TableItemDetails.AddCell(cellTotal);
                TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font1));
                TableItemDetails.AddCell("");

                string   total  = footer1 + NumberToString.convert(roundedAmt.ToString()).Replace("INR", poh.CurrencyID) + "\n\n";
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font1));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthRight    = 0;
                fcell1.BorderWidthTop      = 0;
                TableItemDetails.AddCell(fcell1);

                PdfPCell fcell4 = new PdfPCell(new Phrase("E. & O.E", font1));
                fcell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                fcell4.BorderWidthLeft     = 0;
                fcell4.BorderWidthTop      = 0;
                TableItemDetails.AddCell(fcell4);

                PdfPTable tableSub = new PdfPTable(1);
                tableSub.DefaultCell.Border = 0;
                tableSub.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableSub.AddCell(new Phrase("Subject To Bangalore Jurisdiction", font2));
                PdfPCell celSub = new PdfPCell(tableSub);
                celSub.Border  = 0;
                celSub.Colspan = 7;
                TableItemDetails.AddCell(celSub);

                TableItemDetails.KeepRowsTogether(TableItemDetails.Rows.Count - 6, TableItemDetails.Rows.Count);

                Paragraph footer = new Paragraph(new Phrase("Note : " + footer2, font3));
                footer.Alignment = Element.ALIGN_LEFT;

                PdfPTable TCTab = new PdfPTable(2);
                if (poh.TermsAndCondition.Trim().Length != 0)
                {
                    Chunk TCchunk = new Chunk("General Terms & Conditions\n", font2);
                    TCchunk.SetUnderline(0.2f, -2f);
                    TCTab = new PdfPTable(2);
                    TCTab.WidthPercentage = 100;
                    PdfPCell TCCell = new PdfPCell();
                    TCCell.Colspan = 2;
                    TCCell.Border  = 0;
                    TCCell.AddElement(TCchunk);
                    TCTab.AddCell(TCCell);
                    try
                    {
                        string[] ParaTC = termsAndCond.Split(Main.delimiter2);
                        for (int i = 0; i < ParaTC.Length - 1; i++)
                        {
                            TCCell         = new PdfPCell();
                            TCCell.Colspan = 2;
                            TCCell.Border  = 0;
                            Paragraph header  = new Paragraph();
                            Paragraph details = new Paragraph();
                            details.IndentationLeft  = 12f;
                            details.IndentationRight = 12f;
                            details.Alignment        = Element.ALIGN_JUSTIFIED;
                            string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf(Main.delimiter1)) + ":";
                            string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf(Main.delimiter1) + 1);
                            header.Add(new Phrase(paraHeaderStr, font2));
                            details.Add(new Phrase(paraFooterStr, font1));
                            TCCell.AddElement(header);
                            TCCell.AddElement(details);
                            TCTab.AddCell(TCCell);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                    }
                    try
                    {
                        if (TCTab.Rows.Count >= 3)
                        {
                            TCTab.KeepRowsTogether(0, 3);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                    }
                }

                doc.Add(tableHeader);
                doc.Add(tableDocName);
                doc.Add(paragraphOpenCluse);
                doc.Add(TableAddress);
                doc.Add(TableItemDetails);
                doc.Add(footer);
                if (poh.TermsAndCondition.Trim().Length != 0)
                {
                    doc.Add(TCTab);
                }
                doc.Close();

                if (poh.Status == 0 && poh.DocumentStatus < 99)
                {
                    String wmurl = "";
                    wmurl = "004.png";
                    PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
                }
                MessageBox.Show("Document Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to Save Document");
            }
        }
Esempio n. 11
0
        public void PrintIndent(indentheader ioh, List <indentdetail> IODetails)
        {
            string[] Purchasesrce = ioh.PurchaseSource.Split(';');
            string   ColHeader    = "SI No.;Item Code;Item Name;Last\nPurcahse\nPrice;Quoted\nPrice;Expected\nPurchase\nPrice" +
                                    ";Quotation\nNo;Quantity;Buffer\nQuantity;Warranty\nDays ";
            int    n = 1;
            string ColDetailString = "";
            var    count           = IODetails.Count();

            foreach (indentdetail iod in IODetails)
            {
                if (n == count)
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + iod.StockItemID + Main.delimiter1 + iod.StockItemName + Main.delimiter1 + iod.LastPurchasedPrice + Main.delimiter1
                                      + iod.QuotedPrice + Main.delimiter1 + iod.ExpectedPurchasePrice + Main.delimiter1 + iod.QuotationNo + Main.delimiter1 + iod.Quantity + Main.delimiter1 + iod.BufferQuantity + Main.delimiter1 + iod.WarrantyDays + "\n";
                }
                else
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + iod.StockItemID + Main.delimiter1 + iod.StockItemName + Main.delimiter1 + iod.LastPurchasedPrice + Main.delimiter1
                                      + iod.QuotedPrice + Main.delimiter1 + iod.ExpectedPurchasePrice + Main.delimiter1 + iod.QuotationNo + Main.delimiter1 + iod.Quantity + Main.delimiter1 + iod.BufferQuantity + Main.delimiter1 + iod.WarrantyDays + "\n" + Main.delimiter2;
                }
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = ioh.DocumentID + "-" + ioh.TemporaryNo;

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font   font1        = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font   font2        = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font   font3        = FontFactory.GetFont("Arial", 8, Font.BOLD | Font.UNDERLINE);
                Font   font4        = FontFactory.GetFont("Arial", 7, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                string HeaderString = "Temporary No : " + ioh.TemporaryNo +
                                      "    Temporary Date : " + String.Format("{0:dd MMMM, yyyy}", ioh.TemporaryDate) + Main.delimiter2 +
                                      "Target Date : " + String.Format("{0:dd MMMM, yyyy}", ioh.TargetDate) + Main.delimiter2 +
                                      "Purchase Source : " + getPurchaseSoursestring(ioh.PurchaseSource);

                Paragraph paragraph = new Paragraph(new Phrase("" + ioh.DocumentName + "", FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.BOLD, BaseColor.BLACK)));
                paragraph.Alignment    = Element.ALIGN_CENTER;
                paragraph.SpacingAfter = 10;

                PdfPTable tableMain = new PdfPTable(1);
                tableMain.WidthPercentage = 100;

                string[] header = HeaderString.Split(Main.delimiter2);
                foreach (string str in header)
                {
                    PdfPCell cell = new PdfPCell(new Phrase(str, font1));
                    cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                    cell.Border = 0;
                    tableMain.AddCell(cell);
                }

                if (ioh.DocumentID == "INDENT")
                {
                    System.Data.DataTable dt         = IndentHeaderDB.getPODetailsInDatatable(ioh);
                    PdfPTable             tablePODet = new PdfPTable(7);

                    tablePODet.SpacingBefore   = 10;
                    tablePODet.WidthPercentage = 100;
                    float[] widthmain = new float[] { 2f, 2f, 2f, 2f, 2f, 2f, 5f };
                    tablePODet.SetWidths(widthmain);
                    tablePODet.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;

                    PdfPCell cellHEad = new PdfPCell(new Phrase("Internal Order Detail", font3));
                    cellHEad.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    cellHEad.Border        = 0;
                    cellHEad.Colspan       = 7;
                    cellHEad.MinimumHeight = 20;
                    tablePODet.AddCell(cellHEad);

                    foreach (DataColumn c in dt.Columns)
                    {
                        tablePODet.AddCell(new Phrase(c.ColumnName, font2));
                    }

                    foreach (DataRow r in dt.Rows)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            tablePODet.AddCell(new Phrase(r[0].ToString(), font1));
                            tablePODet.AddCell(new Phrase(r[1].ToString(), font1));
                            tablePODet.AddCell(new Phrase(r[2].ToString(), font1));
                            tablePODet.AddCell(new Phrase(r[3].ToString(), font1));
                            tablePODet.AddCell(new Phrase(r[4].ToString(), font1));
                            tablePODet.AddCell(new Phrase(r[5].ToString(), font1));
                            tablePODet.AddCell(new Phrase(r[6].ToString(), font1));
                        }
                    }
                    PdfPCell cellPODet = new PdfPCell(tablePODet);
                    cellPODet.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    cellPODet.Border = 0;
                    tableMain.AddCell(cellPODet);

                    //tableMain.AddCell(cellAdd);
                }
                Paragraph subHeadPara = new Paragraph(new Phrase("Indent Detail", font3));
                subHeadPara.Alignment = Element.ALIGN_CENTER;

                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(10);
                table1.SpacingBefore = 10f;
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 1f, 2f, 4f, 1.2f, 1f, 1.2f, 1.3f, 1.2f, 1.2f, 1.2f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }

                int      track     = 0;
                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j > 2)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                        }
                        else
                        {
                            pcell        = new PdfPCell(new Phrase(str[j], font1));
                            pcell.Border = 0;
                        }
                        pcell.MinimumHeight = 10;
                        if (j == 0 || j > 2)
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        }
                        else
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        }
                        pcell.BorderWidthLeft   = 0.01f;
                        pcell.BorderWidthRight  = 0.01f;
                        pcell.BorderWidthBottom = 0.5f;
                        table1.AddCell(pcell);
                    }
                }


                ///
                PdfPCell pcelNo = new PdfPCell(new Phrase("", font1));
                pcelNo.BorderWidthTop   = 0;
                pcelNo.BorderWidthRight = 0;
                table1.AddCell(pcelNo);

                PdfPCell pcelMid = new PdfPCell(new Phrase("", font1));
                pcelMid.Colspan          = 3;
                pcelMid.Border           = 0;
                pcelMid.BorderWidthTop   = 0;
                pcelMid.BorderWidthLeft  = 0;
                pcelMid.BorderWidthRight = 0;
                table1.AddCell(pcelMid);

                doc.Add(paragraph);
                doc.Add(tableMain);
                doc.Add(subHeadPara);
                doc.Add(table1);
                doc.Close();
                MessageBox.Show("Document Saved");

                String wmurl = "";
                wmurl = "004.png";
                PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                MessageBox.Show("Failed TO Save");
            }
        }
Esempio n. 12
0
        public void PrintIO(invoiceoutheader ioh, List <invoiceoutdetail> IODetails)
        {
            string[] pos = ioh.TrackingNos.Split(';');
            int      b   = 0;

            int[] a   = (from s in pos where int.TryParse(s, out b) select b).ToArray();
            int   min = a.Min();

            string[] dates           = ioh.TrackingDates.Split(';');
            string   ColHeader       = "SI No.;Item Code;Item Name;Customer Description;Quantity;Details";
            int      n               = 1;
            string   ColDetailString = "";
            var      count           = IODetails.Count();

            foreach (invoiceoutdetail iod in IODetails)
            {
                if (n == count)
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + iod.StockItemID + Main.delimiter1 + iod.StockItemName + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1
                                      + iod.Quantity + Main.delimiter1 + "MRN No    : " + iod.MRNNo + "\n" + "MRN Date : " + iod.MRNDate.ToString("dd-MM-yyyy") + "\n" + "Supplier     : " + iod.SupplierName + "\n";
                }
                else
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + iod.StockItemID + Main.delimiter1 + iod.StockItemName + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1
                                      + iod.Quantity + Main.delimiter1 + "MRN No    : " + iod.MRNNo + "\n" + "MRN Date : " + iod.MRNDate.ToString("dd-MM-yyyy") + "\n" + "Supplier     : " + iod.SupplierName + "\n" + Main.delimiter2;
                }
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = ioh.DocumentID + "-" + ioh.TemporaryNo;

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }



                FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;


                doc.Open();
                Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                Font font4 = FontFactory.GetFont("Arial", 7, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);


                PdfPTable tableMain = new PdfPTable(1);
                tableMain.WidthPercentage = 100;

                PdfPCell  cellAdd = new PdfPCell();
                Paragraph ourAddr = new Paragraph("");
                DateTime  dt      = Convert.ToDateTime(dates[0]);
                ourAddr.Add(new Chunk("Tracking No     :" + a[0] + "           ", font2));
                ourAddr.Add(new Chunk("                    Tracking Date  :" + dt.ToString("dd-MM-yyyy") + "" + "\n", font2));
                ourAddr.Add(new Chunk("Customer        :" + ioh.ConsigneeName + "" + "\n", font2));
                ourAddr.Add(new Chunk("Temporary No: " + ioh.TemporaryNo + "               ", font2));
                ourAddr.Add(new Chunk("                 Temporary Date :" + ioh.TemporaryDate.ToString("dd-MM-yyyy") + "" + "\n", font2));
                ourAddr.Alignment = Element.ALIGN_LEFT;
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableMain.AddCell(cellAdd);

                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(6);
                table1.SpacingBefore = 20f;
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 1f, 3f, 8f, 5f, 2f, 5f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }
                ////---
                //PdfPCell foot = new PdfPCell(new Phrase(""));
                //foot.Colspan = 7;
                //foot.BorderWidthTop = 0;
                //foot.MinimumHeight = 0.5f;
                //table1.AddCell(foot);

                //table1.HeaderRows = 2;
                //table1.FooterRows = 1;

                //table1.SkipFirstHeader = false;
                //table1.SkipLastFooter = true;
                ////---
                int track = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 4)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                        }
                        else
                        {
                            pcell        = new PdfPCell(new Phrase(str[j], font1));
                            pcell.Border = 0;
                        }
                        pcell.MinimumHeight = 10;
                        if (j == 0 || j == 4)
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        }
                        else
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        }
                        pcell.BorderWidthLeft   = 0.01f;
                        pcell.BorderWidthRight  = 0.01f;
                        pcell.BorderWidthBottom = 0.5f;
                        table1.AddCell(pcell);
                    }
                }



                ///
                PdfPCell pcelNo = new PdfPCell(new Phrase("", font1));
                pcelNo.BorderWidthTop   = 0;
                pcelNo.BorderWidthRight = 0;
                table1.AddCell(pcelNo);

                PdfPCell pcelMid = new PdfPCell(new Phrase("", font1));
                pcelMid.Colspan          = 3;
                pcelMid.Border           = 0;
                pcelMid.BorderWidthTop   = 0;
                pcelMid.BorderWidthLeft  = 0;
                pcelMid.BorderWidthRight = 0;
                table1.AddCell(pcelMid);

                doc.Add(tableMain);
                doc.Add(table1);
                doc.Close();
                MessageBox.Show("Document Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                MessageBox.Show("Failed TO Save");
            }
        }
Esempio n. 13
0
        public string PrintVoucher(paymentvoucher pvh, List <paymentvoucherdetail> pvDetails)
        {
            string fileName = "";

            try
            {
                string payMode = "";
                if (pvh.BookType.Equals("BANKBOOK"))
                {
                    payMode = "Bank";
                }
                else
                {
                    payMode = "Cash";
                }
                string HeaderString = "No : " + pvh.VoucherNo + Main.delimiter1 + "Date : " + pvh.VoucherDate.ToString("dd-MM-yyyy") +
                                      Main.delimiter1 + "Payment Mode" + Main.delimiter1 + payMode + Main.delimiter1 + "Paied To" + Main.delimiter1 +
                                      pvh.SLName + Main.delimiter1 + "Amount(INR)" + Main.delimiter1 + pvh.VoucherAmountINR +
                                      Main.delimiter1 + "Amount In Words" + Main.delimiter1 +
                                      NumberToString.convert(pvh.VoucherAmountINR.ToString()).Trim() +
                                      Main.delimiter1 + "Narration" + Main.delimiter1 + pvh.Narration;
                string   ColHeader       = "SI No.;Bill No;Date;Amount(INR);Account Name";
                string   footer3         = "Receiver's Signature;Authorised Signatory";
                int      n               = 1;
                string   ColDetailString = "";
                var      count           = pvDetails.Count();
                string[] billdetail      = pvh.BillDetails.Split(Main.delimiter1); // 0: doctype, 1: billno, 2 : billdate
                foreach (paymentvoucherdetail pvd in pvDetails)
                {
                    if (pvd.AmountDebit != 0)
                    {
                        if (pvh.BillDetails.Trim().Length != 0)
                        {
                            ColDetailString = ColDetailString + n + Main.delimiter1 + billdetail[1] + Main.delimiter1 +
                                              Convert.ToDateTime(billdetail[2].Replace(Main.delimiter2.ToString(), "")).ToString("dd-MM-yyyy") +
                                              Main.delimiter1 + pvd.AmountDebitINR + Main.delimiter1
                                              + pvd.AccountName + Main.delimiter2;
                        }
                        else
                        {
                            ColDetailString = ColDetailString + n + Main.delimiter1 + "" + Main.delimiter1 +
                                              "" +
                                              Main.delimiter1 + pvd.AmountDebitINR + Main.delimiter1
                                              + pvd.AccountName + Main.delimiter2;
                        }
                        n++;
                    }
                }

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = pvh.DocumentID + "-" + pvh.VoucherNo;
                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return("");
                }
                FileStream fs = new FileStream(sfd.FileName + ".pdf", FileMode.Create, FileAccess.Write);
                fileName = sfd.FileName + ".pdf";
                Rectangle rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                //String imageURL = @"D:\Smrutiranjan\PurchaseOrder\index.jpg";
                //iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
                String URL = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;

                PdfPTable tableMain = new PdfPTable(2);

                tableMain.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableMain.AddCell(cellImg);

                PdfPCell        cellAdd = new PdfPCell();
                Paragraph       ourAddr = new Paragraph("");
                CompanyDetailDB compDB  = new CompanyDetailDB();
                cmpnydetails    det     = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                if (det != null)
                {
                    string addr = det.companyname + "\n" + det.companyAddress;
                    ourAddr           = new Paragraph(new Phrase(addr, font2));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableMain.AddCell(cellAdd);


                Paragraph paragraph2 = new Paragraph(new Phrase("Payment Voucher", font2));
                paragraph2.Alignment = Element.ALIGN_CENTER;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(Main.delimiter1);

                PdfPTable table = new PdfPTable(4);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 2f, 1f, 1f, 2f };
                table.SetWidths(HWidths);
                PdfPCell cell = null;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if ((i % 2) != 0)
                    {
                        cell                     = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan             = 3;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);
                    }
                    else
                    {
                        table.AddCell(new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1)));
                    }
                }
                Paragraph paragraph3 = new Paragraph(new Phrase("Bill Details", font2));
                paragraph3.Alignment     = Element.ALIGN_CENTER;
                paragraph3.SpacingBefore = 10;
                paragraph3.SpacingAfter  = 10;
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(5);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 2f, 2f, 3f, 7f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 5;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    if (DetailStr[i].Length != 0)
                    {
                        hg = table1.GetRowHeight(i + 1);
                        string[] str = DetailStr[i].Split(Main.delimiter1);
                        for (int j = 0; j < str.Length; j++)
                        {
                            PdfPCell pcell;
                            //if (j == 1 || j == 3 || j == 4)
                            //{
                            //    pcell = new PdfPCell(new Phrase(str[j], font2));
                            //}
                            //else
                            pcell = new PdfPCell(new Phrase(str[j], font1));
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            table1.AddCell(pcell);
                        }
                    }
                }
                string[] ft = footer3.Split(';');

                PdfPTable tableFooter = new PdfPTable(3);
                tableFooter.SpacingBefore = 50;
                tableFooter.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableFooter.WidthPercentage = 100;
                PdfPCell fcell1 = new PdfPCell(new Phrase(ft[0], font2));
                fcell1.Border = 0;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;

                PdfPCell fcell2 = new PdfPCell(new Phrase(ft[1], font2));
                fcell2.Border = 0;
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_CENTER;

                PdfPCell fcell3 = new PdfPCell();
                fcell3.Border = 0;

                tableFooter.AddCell(fcell1);
                tableFooter.AddCell(fcell3);
                tableFooter.AddCell(fcell2);
                if (table1.Rows.Count > 10)
                {
                    table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);
                }
                doc.Add(tableMain);
                //doc.Add(img);
                doc.Add(paragraph2);
                doc.Add(table);
                doc.Add(paragraph3);
                doc.Add(table1);
                doc.Add(tableFooter);
                doc.Close();
                MessageBox.Show("Saved Sucessfully");
            }
            catch (Exception ie)
            {
                MessageBox.Show("Failed to save.");
            }
            return(fileName);
        }
Esempio n. 14
0
        public void PrintPO(poheader poh, List <podetail> PODetail)
        {
            string HeaderString = "Dispatch To " + poh.DeliveryAddress +
                                  ";Voucher No:\n" + poh.PONo + ";Dated:\n" + poh.PODate + ";Supplier Ref./Order No.\n" + poh.PONo + ";Despatch Through\n***;Freight:\n" + poh.FreightTerms + ";Delivery Date:\n" + poh.DeliveryPeriod + ";Mode/Terms of Payment:\n" + poh.ModeOfPayment +
                                  ";Supplier \nCellcomm Solution Limited\n#52/44, 8th Main, II Cross,\nMahalaxmi layout,\nBangalore-560 096(INDIA)\n\n;" +
                                  "Tax And Duties:\n" + poh.TaxTerms + ";Warrenty:\n1 Year;Price Basis:\nCSL-BANGALORE";
            string footer1         = "Amount Chargeable(In Words)\n\n";
            string ColHeader       = "SI No.;Model No;Description of Goods;Quantity;Rate;Amount";
            string footer2         = "test";
            string footer3         = "for CELLCOMM SOLUTION LIMITED;Authorised Signatory";
            string termsAndCond    = getTCString(poh.TermsAndCondition);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = PODetail.Count();

            foreach (podetail pod in PODetail)
            {
                if (n == count)
                {
                    ColDetailString = ColDetailString + n + "+" + pod.StockItemID + "+" + pod.StockItemName + "+" + pod.Quantity + "+"
                                      + pod.Price + "+" + (pod.Quantity * pod.Price);
                }
                else
                {
                    ColDetailString = ColDetailString + n + "+" + pod.StockItemID + "+" + pod.StockItemName + "+" + pod.Quantity + "+"
                                      + pod.Price + "+" + (pod.Quantity * pod.Price) + ";";
                }
                totQuant = totQuant + pod.Quantity;
                totAmnt  = totAmnt + (pod.Quantity * pod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = @"C:\";
                sfd.FileName         = poh.DocumentID + "-" + poh.PONo;
                sfd.ShowDialog();

                FileStream fs  = new FileStream(sfd.FileName + ".pdf", FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                //String imageURL = @"D:\Smrutiranjan\PurchaseOrder\index.jpg";
                //iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
                String URL = @"..\\..\\Pictures\\Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;
                Paragraph paragraph = new Paragraph(new Phrase("PURCHASE ORDER", font2));
                paragraph.Alignment = Element.ALIGN_CENTER;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(';');

                PdfPTable table = new PdfPTable(3);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 3f, 2f, 2f };
                table.SetWidths(HWidths);
                PdfPCell cell;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 0)
                    {
                        cell                     = new PdfPCell(new Phrase(HeaderStr[0].Trim(), font1));
                        cell.Rowspan             = 4;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);
                    }
                    else if ((i == 7) || ((i > 8) && (i <= 11)))
                    {
                        cell         = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan = 2;
                        table.AddCell(cell);
                    }
                    else if (i == 8)
                    {
                        cell         = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Rowspan = 3;
                        table.AddCell(cell);
                    }
                    else
                    {
                        table.AddCell(new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1)));
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(6);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 2.5f, 5f, 2f, 2f, 2f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 6;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                string[] DetailStr = ColDetailString.Split(';');
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    hg = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split('+');
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 1 || j == 3 || j == 5)
                        {
                            pcell = new PdfPCell(new Phrase(str[j], font2));
                        }
                        else
                        {
                            pcell = new PdfPCell(new Phrase(str[j], font1));
                        }
                        pcell.Border = 0;
                        if (i == (DetailStr.Length - 1))
                        {
                            pcell.MinimumHeight = 100;
                        }
                        else
                        {
                            pcell.MinimumHeight = 20;
                        }
                        pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        pcell.BorderWidthLeft     = 0.01f;
                        pcell.BorderWidthRight    = 0.01f;
                        table1.AddCell(pcell);
                    }
                }
                //if()
                table1.AddCell("");
                table1.AddCell("");
                table1.AddCell(new Phrase("Total", font2));
                table1.AddCell(new Phrase(totQuant.ToString(), font2));
                table1.AddCell("");
                table1.AddCell(new Phrase(Math.Round(totAmnt, 2).ToString(), font2));
                string   total  = footer1 + NumberToString.convert(totAmnt.ToString()) + "\n\n P.S:";
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font3));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthBottom   = 0;
                table1.AddCell(fcell1);

                PdfPCell fcell2 = new PdfPCell(new Phrase(footer2, font1));
                fcell2.Colspan             = 3;
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell2.BorderWidthTop      = 0;
                table1.AddCell(fcell2);
                string[] ft = footer3.Split(';');

                PdfPCell fcell3 = new PdfPCell();
                Chunk    ch1    = new Chunk(ft[0], font1);
                Chunk    ch2    = new Chunk(ft[1], font1);
                Phrase   phrase = new Phrase();
                phrase.Add(ch1);
                for (int i = 0; i < 3; i++)
                {
                    phrase.Add(Chunk.NEWLINE);
                }
                phrase.Add(ch2);

                Paragraph para = new Paragraph();
                para.Add(phrase);
                para.Alignment = Element.ALIGN_RIGHT;
                fcell3.AddElement(para);
                fcell3.Border  = 0;
                fcell3.Colspan = 3;
                //fcell3.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                fcell3.BorderWidthTop    = 0.5f;
                fcell3.BorderWidthRight  = 0.5f;
                fcell3.BorderWidthBottom = 0.5f;
                fcell3.MinimumHeight     = 50;
                table1.AddCell(fcell3);
                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);
                Chunk TCchunk = new Chunk("Terms And Conditoins:\n", font2);
                TCchunk.SetUnderline(0.2f, -2f);
                PdfPTable TCTab = new PdfPTable(2);
                TCTab.WidthPercentage = 100;
                PdfPCell TCCell = new PdfPCell();
                TCCell.Colspan = 2;
                TCCell.Border  = 0;
                TCCell.AddElement(TCchunk);
                TCTab.AddCell(TCCell);
                try
                {
                    string[] ParaTC = termsAndCond.Split(';');
                    for (int i = 0; i < ParaTC.Length + 1; i++)
                    {
                        TCCell         = new PdfPCell();
                        TCCell.Colspan = 2;
                        TCCell.Border  = 0;
                        Paragraph header  = new Paragraph();
                        Paragraph details = new Paragraph();
                        details.IndentationLeft  = 12f;
                        details.IndentationRight = 12f;
                        string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf('+')) + ":";
                        string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf('+') + 1);
                        header.Add(new Phrase(paraHeaderStr, font2));
                        details.Add(new Phrase(paraFooterStr, font1));
                        TCCell.AddElement(header);
                        TCCell.AddElement(details);
                        TCTab.AddCell(TCCell);
                    }
                }
                catch (Exception ex)
                {
                }
                try
                {
                    TCTab.KeepRowsTogether(0, 3);
                }
                catch (Exception ex)
                {
                }

                //doc.Add(jpg);
                doc.Add(img);
                doc.Add(paragraph);
                doc.Add(table);
                doc.Add(table1);
                doc.Add(TCTab);
                doc.Close();
            }
            catch (Exception ie)
            {
            }
        }
Esempio n. 15
0
        public void PrintWO(workorderheader woh, List <workorderdetail> WODetail, string totalTaxDetail)
        {
            Dictionary <string, string> companyInfo = getCompanyInformation();

            customer custDetail = CustomerDB.getCustomerDetailForPO(woh.CustomerID);

            string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
            string   contractorAdd     = "Contractor:\n" + custDetail.name + Main.delimiter1 + "\n" + woh.POAddress + "\n";

            if (custDetail.StateName.ToString().Length != 0)
            {
                contractorAdd = contractorAdd + "Sate Name:" + custDetail.StateName;
            }
            if (custDetail.StateCode.ToString().Length != 0)
            {
                contractorAdd = contractorAdd + "\nState Code:" + custDetail.StateCode;
            }
            if (custDetail.OfficeName.ToString().Length != 0)
            {
                contractorAdd = contractorAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
            }
            string InvoiceTo   = "Invoice To: \n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + companyBillingAdd[1] + "\nGST:" + companyInfo["GST"] + "\nCIN:" + companyInfo["CIN"] + "\nPAN:" + companyInfo["PAN"];
            string declaration = "We, Cellcomm Solutions Limited (also referred to as “CSL”), are pleased to place" +
                                 " this Purchase Order (also referred to as 'PO') with the Contractor addressed below.In accepting this Purchase Order, the Contractor" +
                                 " undertakes to execute the work described herein as per the details and instructions shown below" +
                                 " (such details and instructions being the Specific Terms and Conditions agreed between the Parties) " +
                                 "and also subject to the General Terms & Conditions contained herein.";

            string HeaderString = contractorAdd +
                                  Main.delimiter2 + "PO No : S-" + woh.WONo + " , Date : " + String.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(woh.WODate)) +
                                  Main.delimiter2 + "Contractor Reference : " + woh.ContractorReference +
                                  Main.delimiter2 + "Target Date : " + String.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(woh.TargetDate)) + Main.delimiter2 +

                                  InvoiceTo +

                                  Main.delimiter2 + "Payment Terms : " + PTDefinitionDB.getPaymentTermString(woh.PaymentTerms) +
                                  Main.delimiter2 + woh.SpecialNote;


            string footer1         = "Amount in words\n\n";
            string ColHeader       = "SI No.;Description of Work;Location;Quantity;Rate;Amount";
            string footer2         = "This Purchase Order, being computer generated, does not require physical signature.";
            string footer3         = "for Cellcomm Solutions Limited;Authorised Signatory";
            string termsAndCond    = getTCString(woh.TermsAndCond, woh.DocumentID);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = WODetail.Count();

            //+ : main.delimeter1
            //; : main.delimiter2

            try
            {
                foreach (workorderdetail wod in WODetail)
                {
                    if (n == count)
                    {
                        ColDetailString = ColDetailString + n + Main.delimiter1 + wod.Description + Main.delimiter1 + wod.WorkLocation + Main.delimiter1 + wod.Quantity + Main.delimiter1
                                          + wod.Price + Main.delimiter1 + (wod.Quantity * wod.Price);
                    }
                    else
                    {
                        ColDetailString = ColDetailString + n + Main.delimiter1 + wod.Description + Main.delimiter1 + wod.WorkLocation + Main.delimiter1 + wod.Quantity + Main.delimiter1
                                          + wod.Price + Main.delimiter1 + (wod.Quantity * wod.Price) + Main.delimiter2;
                    }
                    totQuant = totQuant + wod.Quantity;
                    totAmnt  = totAmnt + (wod.Quantity * wod.Price);
                    n++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to Save 1 : " + ex.ToString());
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                if (woh.Status == 0 && woh.DocumentStatus < 99)
                {
                    sfd.FileName = woh.DocumentID + "-Temp-" + woh.TemporaryNo;
                }
                else
                {
                    sfd.FileName = woh.DocumentID + "-" + woh.WONo;
                }

                //sfd.ShowDialog();
                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }

                FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                //rec.Bottom = 10;
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                Font font4 = FontFactory.GetFont("Arial", 5, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                //String imageURL = @"D:\Smrutiranjan\PurchaseOrder\index.jpg";
                //iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
                String URL = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;
                //--

                PdfPTable tableHeader = new PdfPTable(2);

                tableHeader.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableHeader.AddCell(cellImg);

                PdfPCell        cellAdd = new PdfPCell();
                Paragraph       ourAddr = new Paragraph("");
                CompanyDetailDB compDB  = new CompanyDetailDB();
                cmpnydetails    det     = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                if (det != null)
                {
                    ourAddr.Add(new Chunk(det.companyname + "\n", font2));
                    ourAddr.Add(new Chunk(det.companyAddress.Replace("\r\n", "\n"), font4));
                    StringBuilder sb = new StringBuilder();
                    sb.Append("\nGST : " + companyInfo["GST"] + "\nState Code for GST : " + companyInfo["StateCode"] + "\nCIN : " + companyInfo["CIN"] + "\nPAN : " + companyInfo["PAN"]);
                    ourAddr.Add(new Chunk(sb.ToString(), font4));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                    ourAddr.SetLeading(0.0f, 1.5f);
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableHeader.AddCell(cellAdd);
                //----
                Paragraph paragraphDocumentName = new Paragraph(new Phrase("PURCHASE ORDER", font2));
                paragraphDocumentName.Alignment = Element.ALIGN_CENTER;
                Paragraph paragraphOpenCluse = new Paragraph(new Phrase(declaration, font1));
                paragraphOpenCluse.Alignment       = Element.ALIGN_JUSTIFIED;
                paragraphDocumentName.SpacingAfter = 15;
                //PrintPurchaseOrder prog = new PrintPurchaseOrder();
                string[] HeaderStr = HeaderString.Split(Main.delimiter2);

                PdfPTable TableAddress = new PdfPTable(6);

                TableAddress.SpacingBefore   = 20f;
                TableAddress.WidthPercentage = 100;
                float[] HWidths = new float[] { 0.5f, 4.5f, 2f, 2f, 2f, 3f };
                TableAddress.SetWidths(HWidths);
                PdfPCell cell;
                float    wid = 0;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 0 || i == 4)
                    {
                        string[] format = HeaderStr[i].Split(Main.delimiter1);
                        Phrase   phr    = new Phrase();
                        phr.Add(new Chunk(format[0], font2));
                        phr.Add(new Chunk(format[1], font1));
                        cell         = new PdfPCell(phr);
                        cell.Colspan = 3;
                        if (i == 0)
                        {
                            cell.Rowspan = 3;
                        }
                        else
                        {
                            cell.Rowspan = 2;
                        }
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        TableAddress.AddCell(cell);
                    }
                    else
                    {
                        cell               = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan       = 3;
                        cell.MinimumHeight = wid;
                        TableAddress.AddCell(cell);
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable TableItemDetails = new PdfPTable(6);
                TableItemDetails.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                TableItemDetails.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 4.5f, 2f, 2f, 2f, 3f };
                TableItemDetails.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(hcell);
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 6;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                TableItemDetails.AddCell(foot);

                TableItemDetails.HeaderRows = 2;
                TableItemDetails.FooterRows = 1;

                TableItemDetails.SkipFirstHeader = false;
                TableItemDetails.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    hg = TableItemDetails.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 3 || j == 4 || j == 5)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                            if (j == 5)
                            {
                                if (str[0].Length == 0)
                                {
                                    pcell.BorderWidthBottom = 0.01f;
                                    track = 1;
                                    dc2   = Convert.ToDecimal(str[j]);
                                }
                                else
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                        }
                        else
                        {
                            pcell        = new PdfPCell(new Phrase(str[j], font1));
                            pcell.Border = 0;
                        }
                        pcell.MinimumHeight       = 10;
                        pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        pcell.BorderWidthLeft     = 0.01f;
                        pcell.BorderWidthRight    = 0.01f;
                        TableItemDetails.AddCell(pcell);
                    }
                }
                double roundedAmt = Math.Round(totAmnt, 0);
                double diffAmount = roundedAmt - totAmnt;
                if (diffAmount != 0)
                {
                    TableItemDetails.AddCell("");
                    TableItemDetails.AddCell("");
                    PdfPCell cellTot = new PdfPCell(new Phrase("", font1));
                    cellTot.Colspan             = 3;
                    cellTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(cellTot);
                    TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", totAmnt), font2));

                    TableItemDetails.AddCell("");
                    TableItemDetails.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Rounding off", font1));
                    cellRound.Colspan             = 3;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    TableItemDetails.AddCell(cellRound);
                    TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                }
                TableItemDetails.AddCell("");
                TableItemDetails.AddCell("");
                PdfPCell cellTotal = new PdfPCell(new Phrase("Total", font1));
                cellTotal.Colspan             = 3;
                cellTotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                TableItemDetails.AddCell(cellTotal);
                TableItemDetails.AddCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font2));

                //-----
                string   total  = footer1 + NumberToString.convert(roundedAmt.ToString());
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font3));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                //fcell1.BorderWidthBottom = 0;
                TableItemDetails.AddCell(fcell1);

                PdfPTable tableSub = new PdfPTable(1);
                tableSub.DefaultCell.Border = 0;
                tableSub.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableSub.AddCell(new Phrase("Subject To Bangalore Jurisdiction", font2));
                PdfPCell celSub = new PdfPCell(tableSub);
                celSub.Border  = 0;
                celSub.Colspan = 6;
                TableItemDetails.AddCell(celSub);
                TableItemDetails.KeepRowsTogether(TableItemDetails.Rows.Count - 5, TableItemDetails.Rows.Count);
                Paragraph footer = new Paragraph(new Phrase("Note : " + footer2, font3));
                footer.Alignment = Element.ALIGN_LEFT;
                //--------------------
                PdfPTable TCTab = new PdfPTable(2);
                if (woh.TermsAndCond.Trim().Length != 0)
                {
                    Chunk TCchunk = new Chunk("General Terms & Conditions\n", font2);
                    TCchunk.SetUnderline(0.2f, -2f);
                    TCTab = new PdfPTable(2);
                    TCTab.WidthPercentage = 100;
                    PdfPCell TCCell = new PdfPCell();
                    TCCell.Colspan = 2;
                    TCCell.Border  = 0;
                    TCCell.AddElement(TCchunk);
                    TCTab.AddCell(TCCell);
                    try
                    {
                        string[] ParaTC = termsAndCond.Split(Main.delimiter2);
                        for (int i = 0; i < ParaTC.Length + 1; i++)
                        {
                            TCCell         = new PdfPCell();
                            TCCell.Colspan = 2;
                            TCCell.Border  = 0;
                            Paragraph header  = new Paragraph();
                            Paragraph details = new Paragraph();
                            details.IndentationLeft  = 12f;
                            details.IndentationRight = 12f;
                            details.Alignment        = Element.ALIGN_JUSTIFIED;
                            string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf(Main.delimiter1)) + ":";
                            string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf(Main.delimiter1) + 1);
                            header.Add(new Phrase(paraHeaderStr, font2));
                            details.Add(new Phrase(paraFooterStr, font1));
                            TCCell.AddElement(header);
                            TCCell.AddElement(details);
                            TCTab.AddCell(TCCell);
                        }
                    }
                    catch (Exception ex)
                    {
                        ////MessageBox.Show("Failed to Save 2 : "+ex.ToString());
                    }
                    try
                    {
                        TCTab.KeepRowsTogether(0, 3);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Failed to Save 3 : " + ex.ToString());
                    }
                }
                doc.Add(tableHeader);
                doc.Add(paragraphDocumentName);
                doc.Add(paragraphOpenCluse);
                doc.Add(TableAddress);
                doc.Add(TableItemDetails);
                doc.Add(footer);
                if (woh.TermsAndCond.Length != 0)
                {
                    doc.Add(TCTab);
                }
                doc.Close();

                if (woh.Status == 0 && woh.DocumentStatus < 99)
                {
                    String wmurl = "";
                    wmurl = "004.png";
                    PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
                }
                MessageBox.Show("Document Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to Save 4 : " + ex.ToString());
            }
        }
Esempio n. 16
0
        public override void OnOpenDocument(PdfWriter writer, Document document)
        {
            // create the fonts that are to be used
            // first the hightlight or Bold font
            fontTxtBold = FontFactory.GetFont(_boldFont.fontFamily, _boldFont.fontSize, _boldFont.foreColor);
            if (_boldFont.isBold)
            {
                fontTxtBold.SetStyle(Font.BOLD);
            }
            if (_boldFont.isItalic)
            {
                fontTxtBold.SetStyle(Font.ITALIC);
            }
            if (_boldFont.isUnderlined)
            {
                fontTxtBold.SetStyle(Font.UNDERLINE);
            }

            // next the normal font
            fontTxtRegular = FontFactory.GetFont(_normalFont.fontFamily, _normalFont.fontSize, _normalFont.foreColor);
            if (_normalFont.isBold)
            {
                fontTxtRegular.SetStyle(Font.BOLD);
            }
            if (_normalFont.isItalic)
            {
                fontTxtRegular.SetStyle(Font.ITALIC);
            }
            if (_normalFont.isUnderlined)
            {
                fontTxtRegular.SetStyle(Font.UNDERLINE);
            }

            // now build the header and footer templates
            try
            {
                float pageHeight = document.PageSize.Height;
                float pageWidth  = document.PageSize.Width;

                _headerWidth = (int)pageWidth - ((int)_rightMargin + (int)_leftMargin);
                _footerWidth = _headerWidth;

                if (hasHeader)
                {
                    // i basically dummy build the headers so i can trial fit them and see how much space they take.
                    float[] widths = new float[1] {
                        90f
                    };

                    PdfPTable hdrTable = new PdfPTable(1);
                    hdrTable.TotalWidth      = document.PageSize.Width - (_leftMargin + _rightMargin);
                    hdrTable.WidthPercentage = 95;
                    hdrTable.SetWidths(widths);
                    hdrTable.LockedWidth = true;

                    _headerHeight = 0;

                    for (int hdrIdx = 0; hdrIdx < (_headerLines.Length < 2 ? 2 : _headerLines.Length); hdrIdx++)
                    {
                        Paragraph hdrPara = new Paragraph(5, hdrIdx > _headerLines.Length - 1 ? string.Empty : _headerLines[hdrIdx], (hdrIdx > 0 ? fontTxtRegular : fontTxtBold));
                        PdfPCell  hdrCell = new PdfPCell(hdrPara);
                        hdrCell.HorizontalAlignment = Element.ALIGN_LEFT;
                        hdrCell.Border = 0;
                        hdrTable.AddCell(hdrCell);
                        _headerHeight = _headerHeight + (int)hdrTable.GetRowHeight(hdrIdx);
                    }

                    // iTextSharp underestimates the size of each line so fudge it a little
                    // this gives me 3 extra lines to play with on the spacing
                    _headerHeight = _headerHeight + (_fontPointSize * 3);
                }
                else
                {
                    _headerHeight = _fontPointSize * 3;
                }

                if (hasFooter)
                {
                    _footerHeight = (_fontPointSize * 2);
                }
                else
                {
                    _footerHeight = (_fontPointSize);
                }

                document.SetMargins(_leftMargin, _rightMargin, (_topMargin + _headerHeight), _footerHeight);

                cb = writer.DirectContent;

                if (hasHeader)
                {
                    headerTemplate = cb.CreateTemplate(_headerWidth, _headerHeight);
                }

                if (hasFooter)
                {
                    footerTemplate = cb.CreateTemplate(_footerWidth, _footerHeight);
                }
            }
            catch (DocumentException de)
            {
            }
            catch (System.IO.IOException ioe)
            {
            }
        }
Esempio n. 17
0
        public string PrintVoucher(ReceiptVoucherHeader pvh, List <ReceiptVoucherDetail> rvDetails)
        {
            string fileName = "";
            string payMode  = "";

            if (pvh.BookType.Equals("BANKBOOK"))
            {
                payMode = pvh.AccountNameDebit;
            }
            else
            {
                payMode = "CASH";
            }
            string HeaderString = "No; " + pvh.VoucherNo + ";Date; " + pvh.VoucherDate.ToString("dd-MM-yyyy") +
                                  ";Received Through;" + payMode + ";Payer;" + pvh.SLName + ";Amount;" + pvh.VoucherAmount + ";Amount In Words;" + NumberToString.convert(pvh.VoucherAmount.ToString()) +
                                  ";Narration;" + pvh.Narration;
            string ColHeader       = "SI No.;Bill No;Date;Amount;Account Name";
            string footer3         = "Receiver's Signature;Authorised Signatory";
            int    n               = 1;
            string ColDetailString = "";
            var    count           = rvDetails.Count();

            foreach (ReceiptVoucherDetail rvd in rvDetails)
            {
                if (n == count)
                {
                    ColDetailString = ColDetailString + n + "+" + rvd.BillNo + "+" + rvd.BillDate.ToString("dd-MM-yyyy") + "+" + rvd.AmountCredit + "+"
                                      + rvd.AccountNameCredit;
                }
                else
                {
                    ColDetailString = ColDetailString + n + "+" + rvd.BillNo + "+" + rvd.BillDate.ToString("dd-MM-yyyy") + "+" + rvd.AmountCredit + "+"
                                      + rvd.AccountNameCredit + ";";
                }
                //totQuant = totQuant + pod.Quantity;
                //totAmnt = totAmnt + (pod.Quantity * pod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = pvh.DocumentID + "-" + pvh.VoucherNo;
                sfd.ShowDialog();

                FileStream fs = new FileStream(sfd.FileName + ".pdf", FileMode.Create, FileAccess.Write);
                fileName = sfd.FileName + ".pdf";
                Rectangle rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                //String imageURL = @"D:\Smrutiranjan\PurchaseOrder\index.jpg";
                //iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
                String URL = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;
                Paragraph paragraph1 = new Paragraph(new Phrase("CELLCOMM SOLUTIONS Ltd.", font2));
                paragraph1.Alignment = Element.ALIGN_CENTER;
                Paragraph paragraph2 = new Paragraph(new Phrase("Receipt Voucher", font2));
                paragraph2.Alignment = Element.ALIGN_CENTER;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(';');

                PdfPTable table = new PdfPTable(4);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 2f, 1f, 1f, 2f };
                table.SetWidths(HWidths);
                PdfPCell cell = null;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i > 4 && (i % 2) != 0)
                    {
                        if (i % 2 == 0)
                        {
                            cell = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font2));
                        }
                        else
                        {
                            cell = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        }
                        cell.Colspan             = 3;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);
                    }
                    else
                    {
                        if (i % 2 == 0)
                        {
                            table.AddCell(new PdfPCell(new Phrase(HeaderStr[i].Trim(), font2)));
                        }
                        else
                        {
                            table.AddCell(new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1)));
                        }
                    }
                }
                Paragraph paragraph3 = new Paragraph(new Phrase("Bill Details", font2));
                paragraph3.Alignment     = Element.ALIGN_CENTER;
                paragraph3.SpacingBefore = 10;
                paragraph3.SpacingAfter  = 10;
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(5);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 3f, 3f, 3f, 5f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 5;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                string[] DetailStr = ColDetailString.Split(';');
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    hg = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split('+');
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 1 || j == 3 || j == 4)
                        {
                            pcell = new PdfPCell(new Phrase(str[j], font2));
                        }
                        else
                        {
                            pcell = new PdfPCell(new Phrase(str[j], font1));
                        }
                        pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(pcell);
                    }
                }
                string[] ft = footer3.Split(';');

                PdfPTable tableFooter = new PdfPTable(3);
                tableFooter.SpacingBefore = 30;
                tableFooter.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableFooter.WidthPercentage = 100;
                PdfPCell fcell1 = new PdfPCell(new Phrase(ft[0], font2));
                fcell1.Border = 0;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;

                PdfPCell fcell2 = new PdfPCell(new Phrase(ft[1], font2));
                fcell2.Border = 0;
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_CENTER;

                PdfPCell fcell3 = new PdfPCell();
                fcell3.Border = 0;

                tableFooter.AddCell(fcell1);
                tableFooter.AddCell(fcell3);
                tableFooter.AddCell(fcell2);
                if (table1.Rows.Count > 10)
                {
                    table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);
                }
                doc.Add(img);
                doc.Add(paragraph1);
                doc.Add(paragraph2);
                doc.Add(table);
                doc.Add(paragraph3);
                doc.Add(table1);
                doc.Add(tableFooter);
                doc.Close();
            }
            catch (Exception ie)
            {
            }
            return(fileName);
        }
Esempio n. 18
0
        public void PrintGatePassDetail(gatepassheader gph, List <gatepassdetail> GPDetails)
        {
            Dictionary <string, string> companyInfo = getCompanyInformation();
            string ColHeader       = "SI No.;Description;Quantity;Value(Approx.)";
            int    n               = 1;
            string ColDetailString = "";
            var    count           = GPDetails.Count();

            foreach (gatepassdetail gpd in GPDetails)
            {
                if (n == count)
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + gpd.StockItemName + Main.delimiter1 + gpd.Quantity +
                                      Main.delimiter1 + gpd.Value;
                }
                else
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + gpd.StockItemName + Main.delimiter1 + gpd.Quantity +
                                      Main.delimiter1 + gpd.Value + Main.delimiter2;
                }
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = gph.DocumentID + "-" + gph.GatePassNo;

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font            font1  = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font            font2  = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font            font3  = FontFactory.GetFont("Arial", 8, Font.BOLD | Font.UNDERLINE);
                Font            font4  = FontFactory.GetFont("Arial", 7, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                string          toData = "";
                CompanyDetailDB comDb  = new CompanyDetailDB();
                cmpnydetails    com    = comDb.getdetails().FirstOrDefault(c => c.companyID == Login.companyID);
                if (gph.CustomerID == null || gph.CustomerID.Trim().Length == 0)
                {
                    if (com != null)
                    {
                        toData = com.companyname + "\n" + gph.ToOfficeName;
                    }
                }
                else
                {
                    customer custDetail = CustomerDB.getCustomerDetailForPO(gph.CustomerID);
                    toData = custDetail.name + "\n" + custDetail.BillingAddress;
                }
                string HeaderString = "To : \n" + toData + Main.delimiter2 + "Gate Pass No : " + gph.GatePassNo + Main.delimiter2 +
                                      "Gate Pass Date : " + String.Format("{0:dd MMMM, yyyy}", gph.GatePassDate) + Main.delimiter2 +
                                      gph.SpecialNotes;

                String URL = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;

                PdfPTable tableHeader = new PdfPTable(2);

                tableHeader.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableHeader.AddCell(cellImg);

                PdfPCell  cellAdd = new PdfPCell();
                Paragraph ourAddr = new Paragraph("");

                if (com != null)
                {
                    ourAddr.Add(new Chunk(com.companyname + "\n", font2));
                    ourAddr.Add(new Chunk(com.companyAddress.Replace("\r\n", "\n"), font4));
                    StringBuilder sb = new StringBuilder();
                    sb.Append("\nGST : " + companyInfo["GST"] + "\nState Code for GST : " + companyInfo["StateCode"] + "\nCIN : " + companyInfo["CIN"] + "\nPAN : " + companyInfo["PAN"]);
                    ourAddr.Add(new Chunk(sb.ToString(), font4));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                    ourAddr.SetLeading(0.0f, 1.5f);
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableHeader.AddCell(cellAdd);

                Paragraph paragraph = new Paragraph(new Phrase("OUT GATE PASS", font3));
                paragraph.Alignment    = Element.ALIGN_CENTER;
                paragraph.SpacingAfter = 15;

                PdfPTable tableMain = new PdfPTable(4);
                tableMain.WidthPercentage = 100;
                float[] widthMain = new float[] { 1f, 5f, 2f, 2f };
                tableMain.SetWidths(widthMain);

                string[] header = HeaderString.Split(Main.delimiter2);
                foreach (string str in header)
                {
                    int index = Array.IndexOf(header, str);
                    if (index == 0)
                    {
                        PdfPCell cell = new PdfPCell(new Phrase(str, font1));
                        cell.Rowspan             = 3;
                        cell.Colspan             = 2;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        //cell.Border = 0;
                        tableMain.AddCell(cell);
                    }
                    else
                    {
                        PdfPCell cell = new PdfPCell(new Phrase(str, font1));
                        cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        cell.Colspan             = 2;
                        ///cell.Border = 0;
                        tableMain.AddCell(cell);
                    }
                }

                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(4);
                //table1.SpacingBefore = 10f;
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 1f, 5f, 2f, 2f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }

                int      track     = 0;
                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 2)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                        }
                        else
                        {
                            pcell        = new PdfPCell(new Phrase(str[j], font1));
                            pcell.Border = 0;
                        }
                        pcell.MinimumHeight       = 10;
                        pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        pcell.BorderWidthLeft     = 0.01f;
                        pcell.BorderWidthRight    = 0.01f;
                        pcell.BorderWidthBottom   = 0.5f;
                        table1.AddCell(pcell);
                    }
                }


                ///
                PdfPCell pcelBlank = new PdfPCell(new Phrase("", font1));
                pcelBlank.Border        = 0;
                pcelBlank.Colspan       = 4;
                pcelBlank.MinimumHeight = 40;
                table1.AddCell(pcelBlank);

                PdfPCell pcelNo = new PdfPCell(new Phrase("", font1));
                pcelNo.Border = 0;
                table1.AddCell(pcelNo);

                PdfPCell pcellAuth = new PdfPCell();
                pcellAuth = new PdfPCell(new Phrase("Approved By : ", font1));
                pcellAuth.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                pcellAuth.Colspan             = 3;
                pcellAuth.Border = 0;
                table1.AddCell(pcellAuth);

                table1.HeaderRows = 1; //For continuing column header in next page
                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);

                doc.Add(tableHeader);
                doc.Add(paragraph);
                doc.Add(tableMain);
                doc.Add(table1);
                doc.Close();
                MessageBox.Show("Document Saved");

                //String wmurl = "";
                //wmurl = "004.png";
                //PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                MessageBox.Show("Failed TO Save");
            }
        }
Esempio n. 19
0
        public void PrintWO(workorderheader woh, List <workorderdetail> WODetail, string totalTaxDetail)
        {
            string HeaderString = "No.: S-" + woh.WONo + Main.delimiter1 + "Date: " + woh.WODate.ToString("dd-MM-yyyy") + Main.delimiter1 +
                                  "Address:\n" + woh.CustomerName + "\n" + woh.POAddress + Main.delimiter1 +
                                  "Payment Terms:\n" + PTDefinitionDB.getPaymentTermString(woh.PaymentTerms) + Main.delimiter1 +
                                  "Target Date:\n" + woh.TargetDate.ToString("dd-MM-yyyy");
            string footer1         = "Amount Chargeable(In Words)\n\n";
            string ColHeader       = "SI No.;Description of Work;Location;Quantity;Rate;Amount";
            string footer2         = "";
            string footer3         = "for CELLCOMM SOLUTION LIMITED;Authorised Signatory";
            string termsAndCond    = getTCString(woh.TermsAndCond);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = WODetail.Count();

            //+ : main.delimeter1
            //; : main.delimiter2

            foreach (workorderdetail wod in WODetail)
            {
                if (n == count)
                {
                    //ColDetailString = ColDetailString + n + "+" + wod.Description + "+" + wod.WorkLocation + "+" + wod.Quantity + "+"
                    //                   + wod.Price + "+" + (wod.Quantity * wod.Price);
                    ColDetailString = ColDetailString + n + Main.delimiter1 + wod.Description + Main.delimiter1 + wod.WorkLocation + Main.delimiter1 + wod.Quantity + Main.delimiter1
                                      + wod.Price + Main.delimiter1 + (wod.Quantity * wod.Price);
                    if (wod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString + ";" +
                        //    "" + "+" +
                        //    wod.TaxCode + "+" +
                        //    "" + "+" +
                        //    "" + "+" +
                        //    "" + "+"  +
                        //    wod.Tax;
                        ColDetailString = ColDetailString + Main.delimiter2 +
                                          "" + Main.delimiter1 +
                                          wod.TaxCode + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          wod.Tax;
                    }
                }
                else
                {
                    //ColDetailString = ColDetailString + n + "+" + wod.Description + "+" + wod.WorkLocation + "+" + wod.Quantity + "+"
                    //                    + wod.Price + "+" + (wod.Quantity * wod.Price) + ";";
                    ColDetailString = ColDetailString + n + Main.delimiter1 + wod.Description + Main.delimiter1 + wod.WorkLocation + Main.delimiter1 + wod.Quantity + Main.delimiter1
                                      + wod.Price + Main.delimiter1 + (wod.Quantity * wod.Price) + Main.delimiter2;
                    if (wod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString +
                        //    "" + "+" +
                        //    wod.TaxCode + "+" +
                        //    "" + "+" +
                        //    "" + "+" +
                        //    "" + "+" +
                        //    wod.Tax + ";";

                        ColDetailString = ColDetailString +
                                          "" + Main.delimiter1 +
                                          wod.TaxCode + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          "" + Main.delimiter1 +
                                          wod.Tax + Main.delimiter2;
                    }
                }
                totQuant = totQuant + wod.Quantity;
                totAmnt  = totAmnt + (wod.Quantity * wod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = woh.DocumentID + "-" + woh.WONo;
                //sfd.ShowDialog();
                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }

                FileStream fs  = new FileStream(sfd.FileName + ".pdf", FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                //String imageURL = @"D:\Smrutiranjan\PurchaseOrder\index.jpg";
                //iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
                String URL = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;
                //--

                PdfPTable tableMain = new PdfPTable(2);

                tableMain.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableMain.AddCell(cellImg);

                PdfPCell        cellAdd = new PdfPCell();
                Paragraph       ourAddr = new Paragraph("");
                CompanyDetailDB compDB  = new CompanyDetailDB();
                cmpnydetails    det     = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                if (det != null)
                {
                    string addr = det.companyname + "\n" + det.companyAddress;
                    ourAddr           = new Paragraph(new Phrase(addr, font2));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableMain.AddCell(cellAdd);
                //----
                Paragraph paragraph = new Paragraph(new Phrase("PURCHASE ORDER", font2));
                paragraph.Alignment = Element.ALIGN_CENTER;

                //PrintPurchaseOrder prog = new PrintPurchaseOrder();
                string[] HeaderStr = HeaderString.Split(Main.delimiter1);

                PdfPTable table = new PdfPTable(2);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 4f, 3f };
                table.SetWidths(HWidths);
                PdfPCell cell;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    cell = new PdfPCell();
                    string[] subHdr = HeaderStr[i].Split(Main.delimiter1);
                    if (i == 2)
                    {
                        cell                     = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Rowspan             = 2;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);
                    }
                    else
                    {
                        table.AddCell(new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1)));
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(6);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 4.5f, 2f, 2f, 2f, 3f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 6;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 3 || j == 4 || j == 5)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                            if (j == 5)
                            {
                                if (str[0].Length == 0)
                                {
                                    pcell.BorderWidthBottom = 0.01f;
                                    track = 1;
                                    dc2   = Convert.ToDecimal(str[j]);
                                }
                                else
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                        }
                        else
                        {
                            pcell        = new PdfPCell(new Phrase(str[j], font1));
                            pcell.Border = 0;
                        }
                        //pcell.Border = 0;
                        //if (i == (DetailStr.Length - 1))
                        //{
                        //    pcell.MinimumHeight = 100;
                        //}
                        //else
                        pcell.MinimumHeight       = 10;
                        pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        pcell.BorderWidthLeft     = 0.01f;
                        pcell.BorderWidthRight    = 0.01f;
                        table1.AddCell(pcell);
                    }

                    if (track == 1)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            PdfPCell pcell1;

                            if (j == 5)
                            {
                                pcell1                   = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(dc1 + dc2)), font1));
                                pcell1.Border            = 0;
                                pcell1.BorderWidthBottom = 0.01f;
                            }
                            else
                            {
                                pcell1        = new PdfPCell(new Phrase(""));
                                pcell1.Border = 0;
                            }
                            pcell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            pcell1.BorderWidthLeft     = 0.01f;
                            pcell1.BorderWidthRight    = 0.01f;
                            table1.AddCell(pcell1);
                        }
                    }
                }
                double roundedAmt = Math.Round(woh.TotalAmount, 0);
                double diffAmount = roundedAmt - woh.TotalAmount;
                if (diffAmount != 0)
                {
                    table1.AddCell("");
                    table1.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Round off Adj.", font1));
                    cellRound.Colspan             = 3;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(cellRound);
                    table1.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                }
                table1.AddCell("");
                table1.AddCell("");
                PdfPCell cellTotal = new PdfPCell(new Phrase("Total", font1));
                cellTotal.Colspan             = 3;
                cellTotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.AddCell(cellTotal);
                table1.AddCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font1));

                //-----
                string   total  = footer1 + NumberToString.convert(roundedAmt.ToString());
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font3));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthBottom   = 0;
                table1.AddCell(fcell1);

                if (woh.SpecialNote.Trim().Length != 0)
                {
                    footer2 = "Note:\n" + woh.SpecialNote.Trim();
                }
                PdfPCell fcell2 = new PdfPCell(new Phrase(footer2, font1));
                fcell2.Colspan             = 4;
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell2.BorderWidthTop      = 0;
                fcell2.BorderWidthRight    = 0;
                table1.AddCell(fcell2);
                string[] ft = footer3.Split(';');

                PdfPCell fcell3 = new PdfPCell();
                Chunk    ch1    = new Chunk(ft[0], font1);
                Chunk    ch2    = new Chunk(ft[1], font1);
                Phrase   phrase = new Phrase();
                phrase.Add(ch1);
                for (int i = 0; i < 3; i++)
                {
                    phrase.Add(Chunk.NEWLINE);
                }
                phrase.Add(ch2);

                Paragraph para = new Paragraph();
                para.Add(phrase);
                para.Alignment = Element.ALIGN_RIGHT;
                fcell3.AddElement(para);
                fcell3.Border  = 0;
                fcell3.Colspan = 2;
                //fcell3.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                //fcell3.BorderWidthTop = 0.5f;
                fcell3.BorderWidthRight  = 0.5f;
                fcell3.BorderWidthBottom = 0.5f;
                fcell3.MinimumHeight     = 50;
                table1.AddCell(fcell3);
                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);
                //--------------------

                double    dd     = 0;
                PdfPTable taxTab = new PdfPTable(3);
                taxTab.WidthPercentage = 100;

                float[] twidth = new float[] { 3f, 3f, 10f };
                taxTab.SetWidths(twidth);
                if (woh.TaxAmount != 0)
                {
                    PdfPCell pcell;
                    pcell = new PdfPCell(new Phrase("Tax Details", font2));
                    taxTab.AddCell(pcell);
                    PdfPCell pcellc = new PdfPCell(new Phrase("Amount(" + woh.CurrencyID + ")", font2));
                    taxTab.AddCell(pcellc);
                    PdfPCell pcelllst = new PdfPCell(new Phrase("", font1));
                    pcelllst.Border = 0;
                    taxTab.AddCell(pcelllst);

                    string[] tax = totalTaxDetail.Split('\n');
                    for (int i = 0; i < tax.Length - 1; i++)
                    {
                        string[] subtax = tax[i].Split('-');
                        PdfPCell pcell1;
                        pcell1 = new PdfPCell(new Phrase(subtax[0], font1));
                        PdfPCell pcell2;
                        pcell2 = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(subtax[1])), font1));
                        PdfPCell pcell3 = new PdfPCell(new Phrase("", font1));
                        pcell3.Border = 0;
                        taxTab.AddCell(pcell1);
                        taxTab.AddCell(pcell2);
                        taxTab.AddCell(pcell3);
                    }
                    taxTab.AddCell(new Phrase("Total Tax Amount", font2));
                    taxTab.AddCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(woh.TaxAmount)), font2));
                    PdfPCell pcellt = new PdfPCell(new Phrase("", font1));
                    pcellt.Border = 0;
                    taxTab.AddCell(pcellt);
                    taxTab.KeepTogether  = true;
                    taxTab.SpacingAfter  = 2f;
                    taxTab.SpacingBefore = 3f;
                }

                //--------------------
                PdfPTable TCTab = new PdfPTable(2);
                if (woh.TermsAndCond.Trim().Length != 0)
                {
                    Chunk TCchunk = new Chunk("Terms And Conditoins:\n", font2);
                    TCchunk.SetUnderline(0.2f, -2f);
                    TCTab = new PdfPTable(2);
                    TCTab.WidthPercentage = 100;
                    PdfPCell TCCell = new PdfPCell();
                    TCCell.Colspan = 2;
                    TCCell.Border  = 0;
                    TCCell.AddElement(TCchunk);
                    TCTab.AddCell(TCCell);
                    try
                    {
                        string[] ParaTC = termsAndCond.Split(Main.delimiter2);
                        for (int i = 0; i < ParaTC.Length + 1; i++)
                        {
                            TCCell         = new PdfPCell();
                            TCCell.Colspan = 2;
                            TCCell.Border  = 0;
                            Paragraph header  = new Paragraph();
                            Paragraph details = new Paragraph();
                            details.IndentationLeft  = 12f;
                            details.IndentationRight = 12f;
                            string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf(Main.delimiter1)) + ":";
                            string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf(Main.delimiter1) + 1);
                            header.Add(new Phrase(paraHeaderStr, font2));
                            details.Add(new Phrase(paraFooterStr, font1));
                            TCCell.AddElement(header);
                            TCCell.AddElement(details);
                            TCTab.AddCell(TCCell);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        TCTab.KeepRowsTogether(0, 3);
                    }
                    catch (Exception ex)
                    {
                    }
                }
                doc.Add(tableMain);
                //doc.Add(img);
                //doc.Add(ourAddr);
                doc.Add(paragraph);
                doc.Add(table);
                doc.Add(table1);
                if (woh.TaxAmount != 0)
                {
                    doc.Add(taxTab);
                }
                if (woh.TermsAndCond.Length != 0)
                {
                    doc.Add(TCTab);
                }
                doc.Close();
                MessageBox.Show("Saved Sucessfully.");
            }
            catch (Exception ie)
            {
                MessageBox.Show("Failed TO Save");
            }
        }
Esempio n. 20
0
        /**
         * Splits a row to newHeight.
         * The returned row is the remainder. It will return null if the newHeight
         * was so small that only an empty row would result.
         *
         * @param new_height the new height
         * @return the remainder row or null if the newHeight was so small that only
         * an empty row would result
         */
        public PdfPRow SplitRow(PdfPTable table, int rowIndex, float new_height)
        {
            PdfPCell[] newCells = new PdfPCell[cells.Length];
            float[]    fixHs    = new float[cells.Length];
            float[]    minHs    = new float[cells.Length];
            bool       allEmpty = true;

            for (int k = 0; k < cells.Length; ++k)
            {
                float    newHeight = new_height;
                PdfPCell cell      = cells[k];
                if (cell == null)
                {
                    int index = rowIndex;
                    if (table.RowSpanAbove(index, k))
                    {
                        newHeight += table.GetRowHeight(index);
                        while (table.RowSpanAbove(--index, k))
                        {
                            newHeight += table.GetRowHeight(index);
                        }
                        PdfPRow row = table.GetRow(index);
                        if (row != null && row.GetCells()[k] != null)
                        {
                            newCells[k] = new PdfPCell(row.GetCells()[k]);
                            newCells[k].ConsumeHeight(newHeight);
                            newCells[k].Rowspan = row.GetCells()[k].Rowspan - rowIndex + index;
                            allEmpty            = false;
                        }
                    }
                    continue;
                }
                fixHs[k] = cell.FixedHeight;
                minHs[k] = cell.MinimumHeight;
                Image    img     = cell.Image;
                PdfPCell newCell = new PdfPCell(cell);
                if (img != null)
                {
                    if (newHeight > cell.EffectivePaddingBottom + cell.EffectivePaddingTop + 2)
                    {
                        newCell.Phrase = null;
                        allEmpty       = false;
                    }
                }
                else
                {
                    float      y;
                    ColumnText ct     = ColumnText.Duplicate(cell.Column);
                    float      left   = cell.Left + cell.EffectivePaddingLeft;
                    float      bottom = cell.Top + cell.EffectivePaddingBottom - newHeight;
                    float      right  = cell.Right - cell.EffectivePaddingRight;
                    float      top    = cell.Top - cell.EffectivePaddingTop;
                    switch (cell.Rotation)
                    {
                    case 90:
                    case 270:
                        y = SetColumn(ct, bottom, left, top, right);
                        break;

                    default:
                        y = SetColumn(ct, left, bottom, cell.NoWrap ? RIGHT_LIMIT : right, top);
                        break;
                    }
                    int status;
                    status = ct.Go(true);
                    bool thisEmpty = (ct.YLine == y);
                    if (thisEmpty)
                    {
                        newCell.Column = ColumnText.Duplicate(cell.Column);
                        ct.FilledWidth = 0;
                    }
                    else if ((status & ColumnText.NO_MORE_TEXT) == 0)
                    {
                        newCell.Column = ct;
                        ct.FilledWidth = 0;
                    }
                    else
                    {
                        newCell.Phrase = null;
                    }
                    allEmpty = (allEmpty && thisEmpty);
                }
                newCells[k]      = newCell;
                cell.FixedHeight = newHeight;
            }
            if (allEmpty)
            {
                for (int k = 0; k < cells.Length; ++k)
                {
                    PdfPCell cell = cells[k];
                    if (cell == null)
                    {
                        continue;
                    }
                    if (fixHs[k] > 0)
                    {
                        cell.FixedHeight = fixHs[k];
                    }
                    else
                    {
                        cell.MinimumHeight = minHs[k];
                    }
                }
                return(null);
            }
            CalculateHeights();
            PdfPRow split = new PdfPRow(newCells);

            split.widths = (float[])widths.Clone();
            split.CalculateHeights();
            return(split);
        }
Esempio n. 21
0
        public void PrintExportIO(invoiceoutheader ioh, List <invoiceoutdetail> IODetails, string taxStr, string podocID)
        {
            try
            {
                Dictionary <string, string> companyInfo = getCompanyInformation();
                string[] pos        = ioh.TrackingNos.Split(';');
                int      b          = 0;
                int[]    a          = (from s in pos where int.TryParse(s, out b) select b).ToArray();
                int      min        = a.Min();
                string[] dates      = ioh.TrackingDates.Split(';');
                string   poStr      = "";
                string   billingAdd = "";
                //StringBuilder sb = new StringBuilder();
                for (int i = 0; i < pos.Length - 1; i++)
                {
                    string   custPOStr = POPIHeaderDB.getCustomerPOAndDateForInvoiceOut(Convert.ToInt32(pos[i]), Convert.ToDateTime(dates[i]), podocID);
                    string[] custPO    = custPOStr.Split(Main.delimiter1);
                    if (Convert.ToInt32(pos[i]) == min)
                    {
                        billingAdd = custPO[2];
                    }
                    poStr = poStr + custPO[0] + ", Date : " + String.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(custPO[1])) + "\n";
                }
                companybank   cb      = CompanyBankDB.getCompBankDetailForIOPrint(ioh.BankAcReference);
                CompanyDataDB datadb  = new CompanyDataDB();
                string        ieccode = "";
                cmpnydata     cdata   = datadb.getData("1").FirstOrDefault(c => c.DataID == "ImportExportCode");
                if (cdata != null)
                {
                    ieccode = cdata.DataValue;
                }

                customer custDetail        = CustomerDB.getCustomerDetailForPO(ioh.ConsigneeID);
                string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
                string   ConsgAdd          = "Consignee:\n" + custDetail.name + Main.delimiter2 + "\n" + ioh.DeliveryAddress + "\n";
                string   buyer             = "Buyer:\n" + custDetail.name + Main.delimiter2 + "\n" + billingAdd + "\n";
                if (custDetail.StateName.ToString().Length != 0)
                {
                    ConsgAdd = ConsgAdd + "Sate Name:" + custDetail.StateName;
                    buyer    = buyer + "Sate Name:" + custDetail.StateName;
                    if (custDetail.StateCode.ToString().Length != 0)
                    {
                        ConsgAdd = ConsgAdd + " ,\nState Code:" + custDetail.StateCode;
                        buyer    = buyer + " ,\nState Code:" + custDetail.StateCode;
                    }
                }
                else
                {
                    if (custDetail.StateCode.ToString().Length != 0)
                    {
                        ConsgAdd = ConsgAdd + "\nState Code:" + custDetail.StateCode;
                        buyer    = buyer + "\nState Code:" + custDetail.StateCode;
                    }
                }
                //string buyer =
                if (custDetail.OfficeName.ToString().Length != 0)
                {
                    ConsgAdd = ConsgAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
                    buyer    = buyer + "\nGST:" + custDetail.OfficeName;    // For GST Code
                }
                if (CustomerDB.getCustomerPANForInvoicePrint(ioh.ConsigneeID).Length != 0)
                {
                    ConsgAdd = ConsgAdd + "\nPAN:" + custDetail.OfficeName; // For PAN Code
                    buyer    = buyer + "\nPAN:" + custDetail.OfficeName;    // For PAN Code
                }

                string HeaderString = buyer +

                                      Main.delimiter1 + "Invoice No : " + ioh.InvoiceNo + ", Date : " + String.Format("{0:dd MMMM, yyyy}", ioh.InvoiceDate) +
                                      Main.delimiter1 + "Buyer Reference : " + poStr +
                                      Main.delimiter1 + "IE Code : " + ieccode +
                                      Main.delimiter1 + "AD Code : " + ioh.ADCode +
                                      Main.delimiter1 + "Mode of Dispatch : " + ioh.TransportationModeName +
                                      Main.delimiter1 + "Terms of Payment : " + ioh.TermsOfPayment +
                                      Main.delimiter1 + "Country of origin of goods : " + ioh.OriginCountryName +
                                      Main.delimiter1 + "Country of final destination : " + ioh.FinalDestinatoinCountryName + Main.delimiter1 +

                                      ConsgAdd +

                                      //////Main.delimiter1 + "Pre-Carriage by : " + ioh.PreCarriageTransportationName +
                                      //////Main.delimiter1 + "Place of Receipt by pre-carrier : " + ioh.PreCarrierReceiptPlace +
                                      Main.delimiter1 + "Port of Loading : " + ioh.ExitPort +
                                      Main.delimiter1 + "Port of Discharge : " + ioh.EntryPort +
                                      Main.delimiter1 + "Final Destination : " + ioh.FinalDestinationPlace +
                                      Main.delimiter1 + "Terms of Delivery : " + ioh.TermsOfDelivery +
                                      Main.delimiter1 + ioh.SpecialNote;


                string          footer1   = "Amount In Words\n\n";
                string          ColHeader = "SI No.;Description of Goods;HSN;Quantity;Unit;Unit Rate;Amount";
                CompanyDetailDB compDB    = new CompanyDetailDB();
                cmpnydetails    det       = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                string          compName  = "";
                if (det != null)
                {
                    compName = det.companyname;
                }
                string footer2 = "\n\nAccount Name : " + compName + "\nAccount No : " + cb.AccountCode + "\nAccount Type : " + cb.AccountType + "\nBank : " +
                                 cb.BankName + "\nBranch : " + cb.BranchName + "\nSWIFT Code : " + cb.CompanyID;
                string footer3 = "For Cellcomm Solutions Limited;Authorised Signatory";
                //string termsAndCond = getTCString(poh.TermsAndCondition);
                double totQuant        = 0.00;
                double totAmnt         = 0.00;
                int    n               = 1;
                string ColDetailString = "";
                var    count           = IODetails.Count();
                foreach (invoiceoutdetail iod in IODetails)
                {
                    if (n == count)
                    {
                        ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + iod.HSNCode + Main.delimiter1 + iod.Quantity + Main.delimiter1
                                          + iod.Unit + Main.delimiter1 + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price);
                    }
                    else
                    {
                        ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + iod.HSNCode + Main.delimiter1 + iod.Quantity + Main.delimiter1
                                          + iod.Unit + Main.delimiter1 + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price) + Main.delimiter2;
                    }
                    totQuant = totQuant + iod.Quantity;
                    totAmnt  = totAmnt + (iod.Quantity * iod.Price);
                    n++;
                }

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                if (ioh.status == 0 && ioh.DocumentStatus < 99)
                {
                    sfd.FileName = ioh.DocumentID + "-Temp-" + ioh.TemporaryNo;
                }
                else
                {
                    sfd.FileName = ioh.DocumentID + "-" + ioh.InvoiceNo;
                }

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                rec.Bottom = 10;
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font   font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font   font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font   font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                Font   font4 = FontFactory.GetFont("Arial", 5, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                String URL   = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;

                PdfPTable tableMain = new PdfPTable(2);

                tableMain.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableMain.AddCell(cellImg);

                PdfPCell  cellAdd = new PdfPCell();
                Paragraph ourAddr = new Paragraph();
                if (det != null)
                {
                    //string addr = det.companyname + "\n" + det.companyAddress;
                    ourAddr.Add(new Chunk(det.companyname + "\n", font2));
                    ourAddr.Add(new Chunk(det.companyAddress, font4));
                    StringBuilder sb = new StringBuilder();
                    sb.Append("\nGST : " + companyInfo["GST"] + "\nState Code for GST : " + companyInfo["StateCode"] + "\nCIN : " + companyInfo["CIN"] + "\nPAN : " + companyInfo["PAN"]);
                    ourAddr.Add(new Chunk(sb.ToString(), font4));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                    ourAddr.SetLeading(0.0f, 1.5f);
                    //ourAddr = new Paragraph(new Phrase(addr, font2));
                    //ourAddr.Alignment = Element.ALIGN_RIGHT;
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableMain.AddCell(cellAdd);

                Paragraph paragraph = new Paragraph(new Phrase("Commercial Invoice", font2));
                paragraph.Alignment = Element.ALIGN_CENTER;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(Main.delimiter1);

                PdfPTable table = new PdfPTable(7);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 1f, 8f, 1.5f, 2f, 1.5f, 2f, 3f };
                table.SetWidths(HWidths);
                PdfPCell cell;
                int[]    arr = { 3, 7, 9, 10 };
                float    wid = 0;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 16)
                    {
                    }
                    if (i == 0 || i == 9)
                    {
                        string[] format = HeaderStr[i].Split(Main.delimiter2);
                        Phrase   phr    = new Phrase();
                        phr.Add(new Chunk(format[0], font2));
                        phr.Add(new Chunk(format[1], font1));
                        cell = new PdfPCell(phr);
                        if (i == 9)
                        {
                            cell.Rowspan = 7 - 2;
                        }
                        else
                        {
                            cell.Rowspan = 8;
                        }
                        cell.Colspan             = 2;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);
                    }
                    else
                    {
                        cell         = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan = 5;
                        table.AddCell(cell);
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(7);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 1f, 8f, 1.5f, 2f, 1.5f, 2f, 3f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    if (i == 5 || i == 6)
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim() + "\n(" + ioh.CurrencyID + ")", font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                    else
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 7;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 3 || j == 5 || j == 6)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                        }
                        else
                        {
                            if (j == 2)
                            {
                                if (str[j].Trim().Length == 0)
                                {
                                    pcell = new PdfPCell(new Phrase("", font1));
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else if (j == 4)
                            {
                                int m = 1;
                                if (Int32.TryParse(str[j], out m) == true)
                                {
                                    if (Convert.ToInt32(str[j]) == 0)
                                    {
                                        pcell = new PdfPCell(new Phrase("", font1));
                                    }
                                    else
                                    {
                                        pcell = new PdfPCell(new Phrase(str[j], font1));
                                    }
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(str[j], font1));
                            }
                            pcell.Border = 0;
                        }
                        pcell.MinimumHeight = 10;
                        if (j == 1)
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        }
                        else
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        }
                        pcell.BorderWidthLeft  = 0.01f;
                        pcell.BorderWidthRight = 0.01f;
                        table1.AddCell(pcell);
                    }
                }
                //-----------
                PdfPCell Temp = new PdfPCell(new Phrase(""));
                Temp.Border           = 0;
                Temp.BorderWidthLeft  = 0.01f;
                Temp.BorderWidthRight = 0.01f;

                double dd = 0;
                if (ioh.TaxAmount != 0)
                {
                    PdfPCell Temp1 = new PdfPCell(new Phrase(""));
                    Temp1.Border           = 0;
                    Temp1.BorderWidthTop   = 0.01f;
                    Temp1.BorderWidthLeft  = 0.01f;
                    Temp1.BorderWidthRight = 0.01f;
                    table1.AddCell(Temp1); //blank cell
                    table1.AddCell(Temp1);
                    PdfPCell cellCom = new PdfPCell(new Phrase("", font1));
                    cellCom.Colspan             = 4;
                    cellCom.Border              = 0;
                    cellCom.BorderWidthLeft     = 0.01f;
                    cellCom.BorderWidthRight    = 0.01f;
                    cellCom.BorderWidthTop      = 0.01f;
                    cellCom.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(cellCom);

                    PdfPCell cellTot = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(totAmnt)), font2));
                    cellTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(cellTot);


                    string[] tax = taxStr.Split(Main.delimiter2);
                    for (int i = 0; i < tax.Length - 1; i++)
                    {
                        table1.AddCell(Temp); //blank cell
                        table1.AddCell(Temp);

                        string[] subtax     = tax[i].Split(Main.delimiter1);
                        PdfPCell cellinrtax = new PdfPCell(new Phrase(subtax[0], font1));
                        cellinrtax.Colspan             = 4;
                        cellinrtax.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        table1.AddCell(cellinrtax);

                        PdfPCell pcell2;
                        pcell2 = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(subtax[1])), font1));
                        pcell2.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(pcell2);
                    }
                    double taxAmRnd = Math.Round(ioh.TaxAmount, 0);
                    if (taxAmRnd != ioh.TaxAmount)
                    {
                        table1.AddCell(Temp); //blank cell
                        table1.AddCell(Temp);
                        PdfPCell cellTotTax = new PdfPCell(new Phrase("", font1));
                        cellTotTax.Colspan          = 4;
                        cellTotTax.Border           = 0;
                        cellTotTax.BorderWidthLeft  = 0.01f;
                        cellTotTax.BorderWidthRight = 0.01f;
                        //cellCom.BorderWidthTop = 0.01f;
                        cellTotTax.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(cellTotTax);

                        PdfPCell cellTotTaxValue = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(totAmnt + ioh.TaxAmount)), font2));
                        cellTotTaxValue.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(cellTotTaxValue);
                    }
                }
                //-------------------



                double roundedAmt = Math.Round(ioh.InvoiceAmount, 0);
                double diffAmount = roundedAmt - ioh.InvoiceAmount;

                if (diffAmount != 0)
                {
                    table1.AddCell("");
                    table1.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Rounding off", font1));
                    cellRound.Colspan             = 4;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    table1.AddCell(cellRound);
                    table1.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                    //table1.AddCell("");
                }


                table1.AddCell("");
                table1.AddCell("");
                PdfPCell cellRoundTot = new PdfPCell(new Phrase("Total", font1));
                cellRoundTot.Colspan             = 4;
                cellRoundTot.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                table1.AddCell(cellRoundTot);

                PdfPCell roundTot = new PdfPCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font2));
                roundTot.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.AddCell(roundTot);

                string   total  = footer1 + NumberToString.convertFC(roundedAmt.ToString(), ioh.CurrencyID).Replace("INR", ioh.CurrencyID) + "\n\n";
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font1));
                fcell1.Colspan             = 6;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthBottom   = 0;
                fcell1.BorderWidthRight    = 0;
                fcell1.BorderWidthTop      = 0;
                table1.AddCell(fcell1);

                PdfPCell fcell4 = new PdfPCell(new Phrase("E. & O.E", font1));
                fcell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                fcell4.BorderWidthBottom   = 0;
                fcell4.BorderWidthLeft     = 0;
                fcell4.BorderWidthTop      = 0;
                table1.AddCell(fcell4);

                PdfPCell pcelNo = new PdfPCell(new Phrase("", font1));
                pcelNo.BorderWidthTop   = 0;
                pcelNo.BorderWidthRight = 0;
                table1.AddCell(pcelNo);

                Phrase phrs = new Phrase();
                phrs.Add(new Chunk("Bank Details for Payment", font2));

                phrs.Add(new Chunk(footer2, font1));
                //PdfPCell fcell2 = new PdfPCell(new Phrase(footer2, font1));

                PdfPCell fcell2 = new PdfPCell(phrs);
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_MIDDLE;
                fcell2.BorderWidthTop      = 0;
                fcell2.BorderWidthLeft     = 0;
                fcell2.BorderWidthRight    = 0;
                table1.AddCell(fcell2);

                PdfPCell pcelMid = new PdfPCell(new Phrase("", font1));
                pcelMid.Colspan = 3;
                //pcelMid.Border = 0;
                pcelMid.BorderWidthTop   = 0;
                pcelMid.BorderWidthLeft  = 0;
                pcelMid.BorderWidthRight = 0;
                table1.AddCell(pcelMid);

                string[] ft = footer3.Split(';');

                PdfPCell fcell3 = new PdfPCell();
                Chunk    ch1    = new Chunk(ft[0], font1);
                Chunk    ch2    = new Chunk(ft[1], font1);
                Phrase   phrase = new Phrase();
                phrase.Add(ch1);
                for (int i = 0; i < 3; i++)
                {
                    phrase.Add(Chunk.NEWLINE);
                }
                phrase.Add(ch2);

                Paragraph para = new Paragraph();
                para.Add(phrase);
                para.Alignment = Element.ALIGN_RIGHT;
                fcell3.AddElement(para);
                fcell3.Border            = 0;
                fcell3.Colspan           = 3;
                fcell3.BorderWidthTop    = 0f;
                fcell3.BorderWidthLeft   = 0f;
                fcell3.BorderWidthRight  = 0.5f;
                fcell3.BorderWidthBottom = 0.5f;
                fcell3.MinimumHeight     = 50;
                table1.AddCell(fcell3);

                PdfPTable tableSub = new PdfPTable(1);
                tableSub.DefaultCell.Border = 0;
                tableSub.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                tableSub.AddCell(new Phrase("Subject To Bangalore Jurisdiction", font2));

                PdfPCell celSub = new PdfPCell(tableSub);
                celSub.Border  = 0;
                celSub.Colspan = 7;
                table1.AddCell(celSub);

                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);

                doc.Add(tableMain);
                doc.Add(paragraph);
                doc.Add(table);
                doc.Add(table1);
                doc.Close();

                if (ioh.status == 0 && ioh.DocumentStatus < 99)
                {
                    String wmurl = "";
                    wmurl = "004.png";
                    PrintWaterMark.PdfStampWithNewFile(wmurl, sfd.FileName);
                }
                MessageBox.Show("Document Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                MessageBox.Show("Failed TO Save");
            }
        }
Esempio n. 22
0
        public void PrintIO(invoiceoutheader ioh, List <invoiceoutdetail> IODetails, string taxStr, string podocID)
        {
            Dictionary <string, string> companyInfo = getCompanyInformation();

            string[] pos = ioh.TrackingNos.Split(';');
            int      b   = 0;

            int[] a   = (from s in pos where int.TryParse(s, out b) select b).ToArray();
            int   min = a.Min();

            string[] dates      = ioh.TrackingDates.Split(';');
            string   poStr      = "";
            string   billingAdd = "";

            //StringBuilder sb = new StringBuilder();
            for (int i = 0; i < pos.Length - 1; i++)
            {
                string   custPOStr = POPIHeaderDB.getCustomerPOAndDateForInvoiceOut(Convert.ToInt32(pos[i]), Convert.ToDateTime(dates[i]), podocID);
                string[] custPO    = custPOStr.Split(Main.delimiter1);
                if (Convert.ToInt32(pos[i]) == min)
                {
                    billingAdd = custPO[2];
                }
                poStr = poStr + "\n" + custPO[0] + " : " + custPO[1];
            }
            companybank cb         = CompanyBankDB.getCompBankDetailForIOPrint(ioh.BankAcReference);
            customer    custDetail = CustomerDB.getCustomerDetailForPO(ioh.ConsigneeID);

            string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
            string   ConsgAdd          = "Consignee:\n" + custDetail.name + Main.delimiter2 + "\n" + custDetail.BillingAddress + "\n";
            string   buyer             = "Buyer:\n" + custDetail.name + Main.delimiter2 + "\n" + billingAdd + "\n";

            if (custDetail.StateName.ToString().Length != 0)
            {
                ConsgAdd = ConsgAdd + "Sate Name:" + custDetail.StateName;
                buyer    = buyer + "Sate Name:" + custDetail.StateName;
                if (custDetail.StateCode.ToString().Length != 0)
                {
                    ConsgAdd = ConsgAdd + " ,\nState Code:" + custDetail.StateCode;
                    buyer    = buyer + " ,\nState Code:" + custDetail.StateCode;
                }
            }
            else
            {
                if (custDetail.StateCode.ToString().Length != 0)
                {
                    ConsgAdd = ConsgAdd + "\nState Code:" + custDetail.StateCode;
                    buyer    = buyer + "\nState Code:" + custDetail.StateCode;
                }
            }
            //string buyer =
            if (custDetail.OfficeName.ToString().Length != 0)
            {
                ConsgAdd = ConsgAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
                buyer    = buyer + "\nGST:" + custDetail.OfficeName;    // For GST Code
            }
            if (CustomerDB.getCustomerPANForInvoicePrint(ioh.ConsigneeID).Length != 0)
            {
                ConsgAdd = ConsgAdd + "\nPAN:" + custDetail.OfficeName; // For PAN Code
                buyer    = buyer + "\nPAN:" + custDetail.OfficeName;    // For PAN Code
            }

            string HeaderString = companyBillingAdd[0] + Main.delimiter2 + "\n" + companyBillingAdd[1] + "\nGST:" + companyInfo["GST"] + "\nCIN:" + companyInfo["CIN"] + "\nPAN:" + companyInfo["PAN"] +
                                  Main.delimiter1 + "Invoice No : " + ioh.InvoiceNo + Main.delimiter1 + "Invoice Date: \n" + ioh.InvoiceDate.ToString("dd-MM-yyyy") +
                                  Main.delimiter1 + "Buyer PO No/Date:" + poStr + Main.delimiter1 +
                                  ConsgAdd +
                                  Main.delimiter1 + "Delivery Note No:\n" + "  " + Main.delimiter1 + "Delivery Note Date:\n" + "  " +
                                  Main.delimiter1 + "Mode/Terms Of Payment:\n" + ioh.TermsOfPayment + Main.delimiter1 +
                                  buyer +
                                  Main.delimiter1 + "Dispatch Through:\n" + ioh.TransportationType + Main.delimiter1 +
                                  "Terms of Delivery:\n" + "  ";
            string footer1   = "Amount In Words\n\n";
            string ColHeader = "SI No.;Description of Goods;HSN;Quantity;Unit;Unit Rate;Amount";
            string footer2   = "\n\nBank : " + cb.BankName + "\nBranch : " + cb.BranchName + "\nAC Type : " + cb.AccountType + "\nAC No : " +
                               cb.AccountCode + "\nSWIFT Code : " + cb.CompanyID + "\nIFSC Code : " + cb.CreateUser;
            string footer3 = "For Cellcomm Solution Limited;Authorised Signatory";
            //string termsAndCond = getTCString(poh.TermsAndCondition);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = IODetails.Count();
            string HSNCode         = "";

            foreach (invoiceoutdetail iod in IODetails)
            {
                if ((ioh.DocumentID == "SERVICEINVOICEOUT") || (ioh.DocumentID == "SERVICEEXPORTINVOICEOUT"))
                {
                    HSNCode = ServiceHSNMappingDB.getHSNCode(iod.StockItemID);
                }
                else
                {
                    HSNCode = ProductHSNMappingDB.getHSNCode(iod.StockItemID, iod.ModelNo);
                }
                //+ : main.delimiter1
                if (n == count)
                {
                    //ColDetailString = ColDetailString + n + "+" + iod.CustomerItemDescription + "+" + HSNCode + "+" + iod.Quantity + "+"
                    //                  + iod.Unit + "+" + iod.Price + "+" + (iod.Quantity * iod.Price);
                    ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + HSNCode + Main.delimiter1 + iod.Quantity + Main.delimiter1
                                      + iod.Unit + Main.delimiter1 + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price);
                    if (iod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString + Main.delimiter2 + "" + "+" + iod.TaxCode + "+" + "" + "+"
                        //              + "" + "+" + "" + "+" + "" + "+" + iod.Tax;
                        ColDetailString = ColDetailString + Main.delimiter2 + "" + Main.delimiter1 + iod.TaxCode + Main.delimiter1 + "" + Main.delimiter1
                                          + "" + Main.delimiter1 + "" + Main.delimiter1 + "" + Main.delimiter1 + iod.Tax;
                    }
                }
                else
                {
                    ColDetailString = ColDetailString + n + Main.delimiter1 + iod.CustomerItemDescription + Main.delimiter1 + HSNCode + Main.delimiter1 + iod.Quantity + Main.delimiter1
                                      + iod.Unit + Main.delimiter1 + iod.Price + Main.delimiter1 + (iod.Quantity * iod.Price) + Main.delimiter2;
                    if (iod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString + "" + "+" + iod.TaxCode + "+" + "" + "+"
                        //              + "" + "+" + "" + "+" + "" + "+" + iod.Tax + Main.delimiter2;
                        ColDetailString = ColDetailString + "" + Main.delimiter1 + iod.TaxCode + Main.delimiter1 + "" + Main.delimiter1
                                          + "" + Main.delimiter1 + "" + Main.delimiter1 + "" + Main.delimiter1 + iod.Tax + Main.delimiter2;
                    }
                }
                totQuant = totQuant + iod.Quantity;
                totAmnt  = totAmnt + (iod.Quantity * iod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = ioh.DocumentID + "-" + ioh.InvoiceNo;

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName + ".pdf", FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font   font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font   font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font   font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                String URL   = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;
                Paragraph paragraph = new Paragraph(new Phrase("Tax Invoice", font2));
                paragraph.Alignment = Element.ALIGN_CENTER;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(Main.delimiter1);

                PdfPTable table = new PdfPTable(7);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 0.5f, 8f, 1.5f, 2f, 1.5f, 2f, 3f };
                table.SetWidths(HWidths);
                PdfPCell cell;
                int[]    arr = { 3, 7, 9, 10 };
                float    wid = 0;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 0 || i == 4 || i == 8)
                    {
                        string[] format = HeaderStr[i].Split(Main.delimiter2);
                        Phrase   phr    = new Phrase();
                        phr.Add(new Chunk(format[0], font2));
                        phr.Add(new Chunk(format[1], font1));
                        //cell = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell                     = new PdfPCell(phr);
                        cell.Rowspan             = 2;
                        cell.Colspan             = 2;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        //wid = cell.MinimumHeight / 2;
                        table.AddCell(cell);
                    }
                    else if (arr.Contains(i))
                    {
                        cell               = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan       = 5;
                        cell.MinimumHeight = wid;
                        table.AddCell(cell);
                    }
                    else
                    {
                        cell = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        if (i % 2 != 0)
                        {
                            cell.Colspan = 3;
                        }
                        else
                        {
                            cell.Colspan = 2;
                        }
                        table.AddCell(cell);
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(7);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 8f, 1.5f, 2f, 1.5f, 2f, 3f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    if (i == 5 || i == 6)
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim() + "\n(" + ioh.CurrencyID + ")", font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                    else
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 7;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 3 || j == 5 || j == 6)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                            if (j == 6)
                            {
                                if (str[0].Length == 0)
                                {
                                    pcell.BorderWidthBottom = 0.01f;
                                    track = 1;
                                    dc2   = Convert.ToDecimal(str[j]);
                                }
                                else
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                        }
                        else
                        {
                            if (j == 2)
                            {
                                if (str[j].Trim().Length == 0)
                                {
                                    pcell = new PdfPCell(new Phrase("", font1));
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else if (j == 4)
                            {
                                int m = 1;
                                if (Int32.TryParse(str[j], out m) == true)
                                {
                                    if (Convert.ToInt32(str[j]) == 0)
                                    {
                                        pcell = new PdfPCell(new Phrase("", font1));
                                    }
                                    else
                                    {
                                        pcell = new PdfPCell(new Phrase(str[j], font1));
                                    }
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(str[j], font1));
                            }
                            pcell.Border = 0;
                        }
                        //pcell.Border = 0;
                        //if (i == DetailStr.Length - 1)
                        //{
                        //    pcell.MinimumHeight = 50;
                        //}
                        //else
                        pcell.MinimumHeight = 10;
                        //pcell.MinimumHeight = 20;
                        if (j == 1)
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        }
                        else
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        }
                        pcell.BorderWidthLeft  = 0.01f;
                        pcell.BorderWidthRight = 0.01f;
                        table1.AddCell(pcell);
                    }
                    if (track == 1)
                    {
                        for (int j = 0; j < 7; j++)
                        {
                            PdfPCell pcell1;

                            if (j == 6)
                            {
                                pcell1                   = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(dc1 + dc2)), font1));
                                pcell1.Border            = 0;
                                pcell1.BorderWidthBottom = 0.01f;
                            }
                            else
                            {
                                pcell1        = new PdfPCell(new Phrase(""));
                                pcell1.Border = 0;
                            }
                            pcell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            pcell1.BorderWidthLeft     = 0.01f;
                            pcell1.BorderWidthRight    = 0.01f;
                            table1.AddCell(pcell1);
                        }
                    }
                }
                table1.AddCell("");
                table1.AddCell(new Phrase("Total", font1));
                //table1.AddCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(totQuant)), font1));
                table1.AddCell("");
                table1.AddCell("");
                table1.AddCell("");
                //totAmnt = totAmnt + dd;
                table1.AddCell("");
                table1.AddCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(ioh.InvoiceAmount)), font1));

                string   total  = footer1 + NumberToString.convert(ioh.InvoiceAmount.ToString()).Replace("Indian Rupees", ioh.CurrencyID) + "\n\n";
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font1));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthBottom   = 0;
                fcell1.BorderWidthRight    = 0;
                fcell1.BorderWidthTop      = 0;
                table1.AddCell(fcell1);

                PdfPCell fcell4 = new PdfPCell(new Phrase("E. & O.E", font1));
                //fcell4.MinimumHeight = 50;
                fcell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                fcell4.BorderWidthBottom   = 0;
                //fcell4.BorderWidthRight = 0;
                fcell4.BorderWidthLeft = 0;
                fcell4.BorderWidthTop  = 0;
                table1.AddCell(fcell4);

                PdfPCell pcelNo = new PdfPCell(new Phrase("", font1));
                pcelNo.BorderWidthTop   = 0;
                pcelNo.BorderWidthRight = 0;
                table1.AddCell(pcelNo);

                Phrase phrs = new Phrase();
                phrs.Add(new Chunk("Bank Details", font2));
                phrs.Add(new Chunk(footer2, font1));
                //PdfPCell fcell2 = new PdfPCell(new Phrase(footer2, font1));
                PdfPCell fcell2 = new PdfPCell(phrs);
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_MIDDLE;
                //fcell2.BorderWidthTop = 0;
                //fcell2.BorderWidthRight = 0;
                table1.AddCell(fcell2);

                PdfPCell pcelMid = new PdfPCell(new Phrase("", font1));
                pcelMid.Colspan = 3;
                //pcelMid.Border = 0;
                pcelMid.BorderWidthTop   = 0;
                pcelMid.BorderWidthLeft  = 0;
                pcelMid.BorderWidthRight = 0;
                table1.AddCell(pcelMid);

                string[] ft = footer3.Split(';');

                PdfPCell fcell3 = new PdfPCell();
                Chunk    ch1    = new Chunk(ft[0], font1);
                Chunk    ch2    = new Chunk(ft[1], font1);
                Phrase   phrase = new Phrase();
                phrase.Add(ch1);
                for (int i = 0; i < 3; i++)
                {
                    phrase.Add(Chunk.NEWLINE);
                }
                phrase.Add(ch2);

                Paragraph para = new Paragraph();
                para.Add(phrase);
                para.Alignment = Element.ALIGN_RIGHT;
                fcell3.AddElement(para);
                fcell3.Border            = 0;
                fcell3.Colspan           = 3;
                fcell3.BorderWidthTop    = 0f;
                fcell3.BorderWidthLeft   = 0f;
                fcell3.BorderWidthRight  = 0.5f;
                fcell3.BorderWidthBottom = 0.5f;
                fcell3.MinimumHeight     = 50;
                table1.AddCell(fcell3);
                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);
                //-------------------------
                double    dd     = 0;
                PdfPTable taxTab = new PdfPTable(3);
                taxTab.WidthPercentage = 100;

                float[] twidth = new float[] { 3f, 3f, 10f };
                taxTab.SetWidths(twidth);
                if (ioh.TaxAmount != 0)
                {
                    PdfPCell pcell;
                    pcell = new PdfPCell(new Phrase("Tax Details", font2));
                    taxTab.AddCell(pcell);
                    PdfPCell pcellc = new PdfPCell(new Phrase("Amount(" + ioh.CurrencyID + ")", font2));
                    taxTab.AddCell(pcellc);
                    PdfPCell pcelllst = new PdfPCell(new Phrase("", font1));
                    pcelllst.Border = 0;
                    taxTab.AddCell(pcelllst);

                    string[] tax = taxStr.Split(Main.delimiter2);
                    for (int i = 0; i < tax.Length - 1; i++)
                    {
                        string[] subtax = tax[i].Split(Main.delimiter1);
                        PdfPCell pcell1;
                        pcell1 = new PdfPCell(new Phrase(subtax[0], font1));
                        PdfPCell pcell2;
                        pcell2 = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(subtax[1])), font1));
                        PdfPCell pcell3 = new PdfPCell(new Phrase("", font1));
                        pcell3.Border = 0;
                        taxTab.AddCell(pcell1);
                        taxTab.AddCell(pcell2);
                        taxTab.AddCell(pcell3);
                    }
                    taxTab.AddCell(new Phrase("Total Tax Amount", font2));
                    taxTab.AddCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(ioh.TaxAmount)), font2));
                    PdfPCell pcellt = new PdfPCell(new Phrase("", font1));
                    pcellt.Border = 0;
                    taxTab.AddCell(pcellt);
                    taxTab.KeepTogether  = true;
                    taxTab.SpacingAfter  = 2f;
                    taxTab.SpacingBefore = 3f;
                }
                //PdfPTable TCTab = new PdfPTable(2); ;
                //if (poh.TermsAndCondition.Trim().Length != 0)
                //{
                //    Chunk TCchunk = new Chunk("Terms And Conditoins:\n", font2);
                //    TCchunk.SetUnderline(0.2f, -2f);
                //    TCTab = new PdfPTable(2);
                //    TCTab.WidthPercentage = 100;
                //    PdfPCell TCCell = new PdfPCell();
                //    TCCell.Colspan = 2;
                //    TCCell.Border = 0;
                //    TCCell.AddElement(TCchunk);
                //    TCTab.AddCell(TCCell);
                //    try
                //    {
                //        string[] ParaTC = termsAndCond.Split(Main.delimiter2);
                //        for (int i = 0; i < ParaTC.Length - 1; i++)
                //        {
                //            TCCell = new PdfPCell();
                //            TCCell.Colspan = 2;
                //            TCCell.Border = 0;
                //            Paragraph header = new Paragraph();
                //            Paragraph details = new Paragraph();
                //            details.IndentationLeft = 12f;
                //            details.IndentationRight = 12f;
                //            string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf(Main.delimiter1)) + ":";
                //            string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf(Main.delimiter1) + 1);
                //            header.Add(new Phrase(paraHeaderStr, font2));
                //            details.Add(new Phrase(paraFooterStr, font1));
                //            TCCell.AddElement(header);
                //            TCCell.AddElement(details);
                //            TCTab.AddCell(TCCell);
                //        }
                //    }
                //    catch (Exception ex)
                //    {
                //        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                //    }
                //    try
                //    {
                //        if (TCTab.Rows.Count >= 3)
                //        {
                //            TCTab.KeepRowsTogether(0, 3);
                //        }
                //    }
                //    catch (Exception ex)
                //    {
                //        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                //    }
                //}
                //doc.Add(jpg);
                doc.Add(img);
                doc.Add(paragraph);
                doc.Add(table);
                doc.Add(table1);
                if (ioh.TaxAmount != 0)
                {
                    doc.Add(taxTab);
                }
                //if(poh.TermsAndCondition.Trim().Length != 0)
                //    doc.Add(TCTab);
                doc.Close();
                MessageBox.Show("Saved Sucessfully.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                MessageBox.Show("Failed TO Save");
            }
        }
        private void PrintDetailRow(DataRow dataRow, PdfPTable table)
        {
            PdfPCell cell;

            numberOfRows++;
            if (dataRow.Table.Columns.Contains("colRefurb"))
            {
                cell        = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colRefurb"], ""), _reportFont));
                cell.Border = Rectangle.NO_BORDER;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment   = Element.ALIGN_TOP;
                table.AddCell(cell);
            }

            string pAssignmentType;

            try
            {
                pAssignmentType = dataRow["colAssignmentType"] != null?Utilities.GetStringValue(dataRow["colAssignmentType"], "") : "";
            }
            catch (Exception)
            {
                pAssignmentType = "";
            }
            cell        = new PdfPCell(new Paragraph(Commons.GetPfiAssignmentAbbreviation(pAssignmentType), _reportFont));
            cell.Border = Rectangle.NO_BORDER;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.VerticalAlignment   = Element.ALIGN_TOP;
            table.AddCell(cell);

            cell        = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colNumber"], ""), _reportFont));
            cell.Border = Rectangle.NO_BORDER;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.VerticalAlignment   = Element.ALIGN_TOP;
            table.AddCell(cell);

            cell        = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colDescription"], ""), _reportFont));
            cell.Border = Rectangle.NO_BORDER;
            cell.HorizontalAlignment = Element.ALIGN_LEFT;
            cell.Colspan             = 2;//10.7 NAM: Added this line of code was added to cater for BZ 1313
            cell.VerticalAlignment   = Element.ALIGN_TOP;
            table.AddCell(cell);

            //10.7 NAM: chunk of code below was commented out to cater for BZ 1313

            /*
             * cell = new PdfPCell(new Paragraph(PawnUtilities.Utilities.GetStringValue(dataRow["colTags"], ""), _reportFont));
             * cell.Border = Rectangle.NO_BORDER;
             * cell.HorizontalAlignment = Element.ALIGN_CENTER;
             * cell.VerticalAlignment = Element.ALIGN_TOP;
             * table.AddCell(cell);*/

            cell        = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colCost"], ""), _reportFont));
            cell.Border = Rectangle.NO_BORDER;
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell.VerticalAlignment   = Element.ALIGN_TOP;
            table.AddCell(cell);

            cell        = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colRetail"], ""), _reportFont));
            cell.Border = Rectangle.NO_BORDER;
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell.VerticalAlignment   = Element.ALIGN_TOP;
            table.AddCell(cell);

            cell        = new PdfPCell(new Paragraph(Utilities.GetStringValue(dataRow["colReason"], ""), _reportFont));
            cell.Border = Rectangle.NO_BORDER;
            cell.HorizontalAlignment = Element.ALIGN_LEFT;
            cell.VerticalAlignment   = Element.ALIGN_TOP;
            table.AddCell(cell);
            float tableHeight = 0.0f;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                tableHeight += table.GetRowHeight(i);
            }

            if (tableHeight > PageSize.LETTER.Height - 72)
            {
                rowNumbers.Add(numberOfRows);
                document.Add(table);
                numberOfRows = 0;
                table.DeleteBodyRows();
                document.NewPage();
            }
        }
        private void PrintDetailRecord(DataRow dr, PdfPTable table)
        {
            numberOfRows++;
            var cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["userID"]), ReportFont))
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_TOP
            };

            table.AddCell(cell);

            cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["icn_doc"]), ReportFont))
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_TOP
            };
            table.AddCell(cell);

            cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["md_desc"]), ReportFont))
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_TOP
            };
            table.AddCell(cell);

            cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["loc_aisle"]), ReportFont))
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_CENTER,
                VerticalAlignment   = Element.ALIGN_TOP
            };
            table.AddCell(cell);

            cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["loc_shelf"]), ReportFont))
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_CENTER,
                VerticalAlignment   = Element.ALIGN_TOP
            };
            table.AddCell(cell);

            cell = new PdfPCell(new Paragraph(Utilities.GetStringValue(dr["location"]), ReportFont))
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_CENTER,
                VerticalAlignment   = Element.ALIGN_TOP
            };
            table.AddCell(cell);

            var sGunNumber = Utilities.GetStringValue(dr["gun_number"], string.Empty);

            sGunNumber = sGunNumber == "0" ? string.Empty : sGunNumber;
            cell       = new PdfPCell(new Paragraph(sGunNumber, ReportFont))
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_TOP,
                PaddingLeft         = -10
            };
            table.AddCell(cell);

            var tableHeight = table.Rows.Cast <object>().Select((t, i) => table.GetRowHeight(i)).Sum();

            if (tableHeight <= PageSize.LETTER.Height - 72)
            {
                return;
            }
            rowNumbers.Add(numberOfRows);
            document.Add(table);
            numberOfRows = 0;
            table.DeleteBodyRows();
            document.NewPage();
        }
Esempio n. 25
0
        static void PrintPO()
        {
            try
            {
                FileStream fs     = new FileStream("Purchase_Order.pdf", FileMode.Create, FileAccess.Write);
                Rectangle  rec    = new Rectangle(PageSize.A4);
                Document   doc    = new Document(rec);
                PdfWriter  writer = PdfWriter.GetInstance(doc, fs);
                MyEvent    evnt   = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font   font1              = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font   font2              = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                String imageURL           = @"D:\Smrutiranjan\PurchaseOrder\index.jpg";
                iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
                jpg.Alignment = Element.ALIGN_LEFT;
                Paragraph paragraph = new Paragraph(new Phrase("PURCHASE ORDER", font2));
                paragraph.Alignment = Element.ALIGN_CENTER;

                Program  prog      = new Program();
                string[] HeaderStr = prog.HeaderStr.Split(';');

                PdfPTable table = new PdfPTable(3);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 3f, 2f, 2f };
                table.SetWidths(HWidths);
                PdfPCell cell;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 0)
                    {
                        cell                     = new PdfPCell(new Phrase(HeaderStr[0].Trim(), font1));
                        cell.Rowspan             = 4;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);
                    }
                    else if ((i == 7) || ((i > 8) && (i <= 11)))
                    {
                        cell         = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan = 2;
                        table.AddCell(cell);
                    }
                    else if (i == 8)
                    {
                        cell         = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Rowspan = 3;
                        table.AddCell(cell);
                    }
                    else
                    {
                        table.AddCell(new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1)));
                    }
                }
                string[]  ColHeaderStr = prog.ColHeaderStr.Split(';');
                string[]  DetailStr    = prog.ColDetailStr.Split(';');
                PdfPTable table1       = new PdfPTable(6);
                table1.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 2.5f, 5f, 2f, 2f, 2f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                    hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(hcell);
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 6;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                float hg = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    hg = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split('+');
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;
                        if (j == 1 || j == 3 || j == 5)
                        {
                            pcell = new PdfPCell(new Phrase(str[j], font2));
                        }
                        else
                        {
                            pcell = new PdfPCell(new Phrase(str[j], font1));
                        }
                        pcell.Border = 0;
                        if (i == (DetailStr.Length - 1))
                        {
                            pcell.MinimumHeight = 100;
                        }
                        else
                        {
                            pcell.MinimumHeight = 20;
                        }
                        pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        pcell.BorderWidthLeft     = 0.01f;
                        pcell.BorderWidthRight    = 0.01f;
                        table1.AddCell(pcell);
                    }
                }
                table1.AddCell("");
                table1.AddCell("");
                table1.AddCell(new Phrase("Total", font1));
                table1.AddCell("****");
                table1.AddCell("");
                table1.AddCell("****");
                PdfPCell fcell1 = new PdfPCell(new Phrase(prog.footer1, font1));
                fcell1.Colspan             = 6;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthBottom   = 0;
                table1.AddCell(fcell1);

                PdfPCell fcell2 = new PdfPCell(new Phrase(prog.footer2, font1));
                fcell2.Colspan             = 3;
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell2.BorderWidthTop      = 0;
                table1.AddCell(fcell2);
                string[] ft = prog.footer3.Split(';');

                PdfPCell fcell3 = new PdfPCell();
                Chunk    ch1    = new Chunk(ft[0], font1);
                Chunk    ch2    = new Chunk(ft[1], font1);
                Phrase   phrase = new Phrase();
                phrase.Add(ch1);
                for (int i = 0; i < 3; i++)
                {
                    phrase.Add(Chunk.NEWLINE);
                }
                phrase.Add(ch2);

                Paragraph para = new Paragraph();
                para.Add(phrase);
                para.Alignment = Element.ALIGN_RIGHT;
                fcell3.AddElement(para);
                fcell3.Border  = 0;
                fcell3.Colspan = 3;
                //fcell3.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                fcell3.BorderWidthTop    = 0.5f;
                fcell3.BorderWidthRight  = 0.5f;
                fcell3.BorderWidthBottom = 0.5f;
                fcell3.MinimumHeight     = 50;
                table1.AddCell(fcell3);
                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);

                doc.Add(jpg);
                doc.Add(paragraph);
                doc.Add(table);
                doc.Add(table1);

                doc.Close();
            }
            catch (Exception ie)
            {
                Console.WriteLine("{0}" + ie);
            }
            Console.ReadKey();
        }
Esempio n. 26
0
        private void InitiateDocument()
        {
            PdfStream   = new MemoryStream();
            PdfDocument = new Document(ReportConfiguration.PageOrientation);
            PdfDocument.SetMargins(ReportConfiguration.MarginLeft,
                                   ReportConfiguration.MarginRight,
                                   ReportConfiguration.MarginTop, ReportConfiguration.MarginBottom);
            PdfWriter = PdfWriter.GetInstance(PdfDocument, PdfStream);

            // create logo, header and page number objects
            PdfPCell cell;

            HeaderSectionHeight = 0;
            LogoImage           = null;
            if (ReportConfiguration.LogoPath != null)
            {
                LogoImage = Image.GetInstance(ReportConfiguration.LogoPath);
                LogoImage.ScalePercent(ReportConfiguration.LogImageScalePercent);
                LogoImage.SetAbsolutePosition(PdfDocument.LeftMargin,
                                              PdfDocument.PageSize.Height - PdfDocument.TopMargin
                                              - LogoImage.ScaledHeight);

                HeaderSectionHeight = LogoImage.ScaledHeight;
            }

            Title = null;
            float titleHeight = 0;

            if ((ReportConfiguration.ReportTitle != null) ||
                (ReportConfiguration.ReportSubTitle != null))
            {
                Title            = new PdfPTable(1);
                Title.TotalWidth = PdfDocument.PageSize.Width
                                   - (PdfDocument.LeftMargin + PdfDocument.RightMargin);

                if (ReportConfiguration.ReportTitle != null)
                {
                    cell = new PdfPCell(new Phrase(ReportConfiguration.ReportTitle,
                                                   new Font(ReportFonts.HelveticaBold, 12)));
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.Border = 0;
                    Title.AddCell(cell);
                }

                if (ReportConfiguration.ReportSubTitle != null)
                {
                    cell = new PdfPCell(new Phrase(ReportConfiguration.ReportSubTitle,
                                                   new Font(ReportFonts.Helvetica, 10)));
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.PaddingTop          = 5;
                    cell.Border = 0;
                    Title.AddCell(cell);
                }

                // Get the height of the title section
                for (int i = 0; i < Title.Rows.Count; i++)
                {
                    titleHeight = titleHeight + Title.GetRowHeight(i);
                }
            }
            HeaderSectionHeight = (HeaderSectionHeight > titleHeight)
                ? HeaderSectionHeight : titleHeight;


            PageNumberLabel            = new PdfPTable(1);
            PageNumberLabel.TotalWidth = PdfDocument.PageSize.Width
                                         - (PdfDocument.LeftMargin + PdfDocument.RightMargin);
            cell = new PdfPCell(new Phrase
                                    ("Page Label", new Font(ReportFonts.Helvetica, 8)));
            cell.Border = 0;
            float pagenumberHeight = PageNumberLabel.GetRowHeight(0);

            HeaderSectionHeight = (HeaderSectionHeight > pagenumberHeight)
                ? HeaderSectionHeight : pagenumberHeight;
        }
Esempio n. 27
0
        public void PrintPO(poheader poh, List <podetail> PODetail, string taxStr)
        {
            Dictionary <string, string> companyInfo = getCompanyInformation();
            //string stateDetail =
            customer custDetail = CustomerDB.getCustomerDetailForPO(poh.CustomerID);

            string[] companyBillingAdd = CompanyAddressDB.getCompTopBillingAdd(Login.companyID);
            string   poNoSuffix        = "";

            if (poh.DocumentID == "POGENERAL")
            {
                poNoSuffix = "G-";
            }
            else if (poh.DocumentID == "PURCHASEORDER")
            {
                poNoSuffix = "P-";
            }
            string supplAdd = "Supplier:\n" + custDetail.name + Main.delimiter1 + "\n" + custDetail.BillingAddress + "\n";

            if (custDetail.StateName.ToString().Length != 0)
            {
                supplAdd = supplAdd + "Sate Name:" + custDetail.StateName;
            }
            if (custDetail.StateCode.ToString().Length != 0)
            {
                supplAdd = supplAdd + "\nState Code:" + custDetail.StateCode;
            }
            if (custDetail.OfficeName.ToString().Length != 0)
            {
                supplAdd = supplAdd + "\nGST:" + custDetail.OfficeName; // For GST Code
            }
            //; : main.delimiter2
            //$ : main.delimiter1
            string InvoiceTo    = "Invoice To: \n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + companyBillingAdd[1] + "\nGST:" + companyInfo["GST"] + "\nCIN:" + companyInfo["CIN"] + "\nPAN:" + companyInfo["PAN"];
            string DespatchTo   = "Dispatch To:\n" + companyBillingAdd[0] + Main.delimiter1 + "\n" + poh.DeliveryAddress + "\nGST:" + companyInfo["GST"];
            string HeaderString = supplAdd +
                                  Main.delimiter2 + "PO No : " + poNoSuffix + poh.PONo + Main.delimiter2 + "Date: " + poh.PODate.ToString("dd-MM-yyyy") +
                                  Main.delimiter2 + "Supplier Ref./Order No.\n" + poh.ReferenceQuotation.Replace(";", ",\n") +
                                  Main.delimiter2 + "Despatch Through:\n" + CatalogueValueDB.getParamValue("TransportationMode", poh.TransportationMode) +
                                  Main.delimiter2 + InvoiceTo +
                                  Main.delimiter2 + "Freight:\n" + CatalogueValueDB.getParamValue("Freight", poh.FreightTerms) +
                                  Main.delimiter2 + "Delivery Period:\n" + poh.DeliveryPeriod + " Days" + Main.delimiter2 +
                                  DespatchTo +
                                  Main.delimiter2 + "Tax And Duties:\n" + CatalogueValueDB.getParamValue("TaxStatus", poh.TaxTerms) +
                                  Main.delimiter2 + "Mode/Terms of Payment:\n" + CatalogueValueDB.getParamValue("PaymentMode", poh.ModeOfPayment) + "\n" + PTDefinitionDB.getPaymentTermString(poh.PaymentTerms);
            string footer1         = "Amount In Words\n\n";
            string ColHeader       = "SI No.;Description of Goods;Quantity;Unit;Unit Rate;Amount;Warranty\nIn Days";
            string footer2         = "";
            string footer3         = "for CELLCOMM SOLUTION LIMITED;Authorised Signatory";
            string termsAndCond    = getTCString(poh.TermsAndCondition);
            double totQuant        = 0.00;
            double totAmnt         = 0.00;
            int    n               = 1;
            string ColDetailString = "";
            var    count           = PODetail.Count();

            foreach (podetail pod in PODetail)
            {
                if (n == count)
                {
                    //ColDetailString = ColDetailString + n + "+" + pod.Description + "+" + pod.Quantity + "+"
                    //                  + pod.Unit + "+" + pod.Price + "+" + (pod.Quantity * pod.Price) + "+" + pod.WarrantyDays;
                    ColDetailString = ColDetailString + n + Main.delimiter1 + pod.Description + Main.delimiter1 + pod.Quantity + Main.delimiter1
                                      + pod.Unit + Main.delimiter1 + pod.Price + Main.delimiter1 + (pod.Quantity * pod.Price) + Main.delimiter1 + pod.WarrantyDays;
                    if (pod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString + ";" +"" + "+" + pod.TaxCode + "+" + "" + "+"
                        //              + "" + "+" + "" + "+" + pod.Tax + "+" + "";
                        ColDetailString = ColDetailString + Main.delimiter2 + "" + Main.delimiter1 + pod.TaxCode + Main.delimiter1 + "" + Main.delimiter1
                                          + "" + Main.delimiter1 + "" + Main.delimiter1 + pod.Tax + Main.delimiter1 + "";
                    }
                    // ColDetailString = ColDetailString
                }
                else
                {
                    //ColDetailString = ColDetailString + n + "+" + pod.Description + "+" + pod.Quantity + "+"
                    //                  + pod.Unit + "+" + pod.Price + "+" + (pod.Quantity * pod.Price) + "+" + pod.WarrantyDays + ";";
                    ColDetailString = ColDetailString + n + Main.delimiter1 + pod.Description + Main.delimiter1 + pod.Quantity + Main.delimiter1
                                      + pod.Unit + Main.delimiter1 + pod.Price + Main.delimiter1 + (pod.Quantity * pod.Price) + Main.delimiter1 + pod.WarrantyDays + Main.delimiter2;
                    if (pod.Tax != 0)
                    {
                        //ColDetailString = ColDetailString + "" + "+" + pod.TaxCode + "+" + "" + "+"
                        //             + "" + "+" + "" + "+" + pod.Tax + "+" + "" + Main.delimiter2;
                        ColDetailString = ColDetailString + "" + Main.delimiter1 + pod.TaxCode + Main.delimiter1 + "" + Main.delimiter1
                                          + "" + Main.delimiter1 + "" + Main.delimiter1 + pod.Tax + Main.delimiter1 + "" + Main.delimiter2;
                    }
                }
                totQuant = totQuant + pod.Quantity;
                totAmnt  = totAmnt + (pod.Quantity * pod.Price);
                n++;
            }
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title            = "Save As PDF";
                sfd.Filter           = "Pdf files (*.Pdf)|*.pdf";
                sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

                sfd.FileName = poh.DocumentID + "-" + poh.PONo;

                if (sfd.ShowDialog() == DialogResult.Cancel || sfd.FileName == "")
                {
                    return;
                }
                FileStream fs  = new FileStream(sfd.FileName + ".pdf", FileMode.Create, FileAccess.Write);
                Rectangle  rec = new Rectangle(PageSize.A4);
                iTextSharp.text.Document doc = new iTextSharp.text.Document(rec);
                PdfWriter writer             = PdfWriter.GetInstance(doc, fs);
                MyEvent   evnt = new MyEvent();
                writer.PageEvent = evnt;

                doc.Open();
                Font   font1 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                Font   font2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                Font   font3 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.ITALIC, BaseColor.BLACK);
                String URL   = "Cellcomm2.JPG";
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(URL);
                img.Alignment = Element.ALIGN_LEFT;


                PdfPTable tableMain = new PdfPTable(2);

                tableMain.WidthPercentage = 100;
                PdfPCell  cellImg = new PdfPCell();
                Paragraph pp      = new Paragraph();
                pp.Add(new Chunk(img, 0, 0));
                cellImg.AddElement(pp);
                cellImg.Border = 0;
                tableMain.AddCell(cellImg);

                PdfPCell        cellAdd = new PdfPCell();
                Paragraph       ourAddr = new Paragraph("");
                CompanyDetailDB compDB  = new CompanyDetailDB();
                cmpnydetails    det     = compDB.getdetails().FirstOrDefault(comp => comp.companyID == 1);
                if (det != null)
                {
                    string addr = det.companyname + "\n" + det.companyAddress;
                    ourAddr           = new Paragraph(new Phrase(addr, font2));
                    ourAddr.Alignment = Element.ALIGN_RIGHT;
                }
                cellAdd.AddElement(ourAddr);
                cellAdd.Border = 0;
                tableMain.AddCell(cellAdd);


                Paragraph paragraph = new Paragraph(new Phrase("PURCHASE ORDER", font2));
                paragraph.Alignment = Element.ALIGN_CENTER;

                PrintPurchaseOrder prog      = new PrintPurchaseOrder();
                string[]           HeaderStr = HeaderString.Split(Main.delimiter2);

                PdfPTable table = new PdfPTable(7);

                table.SpacingBefore   = 20f;
                table.WidthPercentage = 100;
                float[] HWidths = new float[] { 0.5f, 8f, 2f, 1.5f, 1.5f, 3f, 1.5f };
                table.SetWidths(HWidths);
                PdfPCell cell;
                int[]    arr = { 6, 7, 9, 10 };
                float    wid = 0;
                for (int i = 0; i < HeaderStr.Length; i++)
                {
                    if (i == 0 || i == 5 || i == 8)
                    {
                        string[] format = HeaderStr[i].Split(Main.delimiter1);
                        Phrase   phr    = new Phrase();
                        phr.Add(new Chunk(format[0], font2));
                        phr.Add(new Chunk(format[1], font1));
                        //cell = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell                     = new PdfPCell(phr);
                        cell.Rowspan             = 2;
                        cell.Colspan             = 2;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        //wid = cell.MinimumHeight / 2;
                        table.AddCell(cell);
                    }
                    else if (arr.Contains(i))
                    {
                        cell               = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        cell.Colspan       = 5;
                        cell.MinimumHeight = wid;
                        table.AddCell(cell);
                    }
                    else
                    {
                        cell = new PdfPCell(new Phrase(HeaderStr[i].Trim(), font1));
                        if (i % 2 != 0)
                        {
                            cell.Colspan = 3;
                        }
                        else
                        {
                            cell.Colspan = 2;
                        }
                        table.AddCell(cell);
                    }
                }
                string[] ColHeaderStr = ColHeader.Split(';');

                PdfPTable table1 = new PdfPTable(7);
                table1.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.WidthPercentage = 100;
                float[] width = new float[] { 0.5f, 8f, 2f, 1.5f, 2f, 2.5f, 1.5f };
                table1.SetWidths(width);

                for (int i = 0; i < ColHeaderStr.Length; i++)
                {
                    if (i == 4 || i == 5)
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim() + "\n(" + poh.CurrencyID + ")", font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                    else
                    {
                        PdfPCell hcell = new PdfPCell(new Phrase(ColHeaderStr[i].Trim(), font2));
                        hcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        table1.AddCell(hcell);
                    }
                }
                //---
                PdfPCell foot = new PdfPCell(new Phrase(""));
                foot.Colspan        = 7;
                foot.BorderWidthTop = 0;
                foot.MinimumHeight  = 0.5f;
                table1.AddCell(foot);

                table1.HeaderRows = 2;
                table1.FooterRows = 1;

                table1.SkipFirstHeader = false;
                table1.SkipLastFooter  = true;
                //---
                int     track = 0;
                decimal dc1   = 0;
                decimal dc2   = 0;

                string[] DetailStr = ColDetailString.Split(Main.delimiter2);
                float    hg        = 0f;
                for (int i = 0; i < DetailStr.Length; i++)
                {
                    track = 0;
                    hg    = table1.GetRowHeight(i + 1);
                    string[] str = DetailStr[i].Split(Main.delimiter1);
                    for (int j = 0; j < str.Length; j++)
                    {
                        PdfPCell pcell;

                        if (j == 2 || j == 4 || j == 5)
                        {
                            decimal p = 1;
                            if (Decimal.TryParse(str[j], out p))
                            {
                                pcell = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(str[j])), font1));
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(""));
                            }
                            pcell.Border = 0;
                            if (j == 5)
                            {
                                if (str[0].Length == 0)
                                {
                                    pcell.BorderWidthBottom = 0.01f;
                                    track = 1;
                                    dc2   = Convert.ToDecimal(str[j]);
                                }
                                else
                                {
                                    dc1 = Convert.ToDecimal(str[j]);
                                }
                            }
                        }
                        else
                        {
                            if (j == 6)
                            {
                                if ((str[j].Trim().Length == 0 || Convert.ToInt32(str[j]) == 0) && (track != 1))
                                {
                                    pcell = new PdfPCell(new Phrase("NA", font1));
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else if (j == 3)
                            {
                                int m = 1;
                                if (Int32.TryParse(str[j], out m) == true)
                                {
                                    if (Convert.ToInt32(str[j]) == 0)
                                    {
                                        pcell = new PdfPCell(new Phrase("", font1));
                                    }
                                    else
                                    {
                                        pcell = new PdfPCell(new Phrase(str[j], font1));
                                    }
                                }
                                else
                                {
                                    pcell = new PdfPCell(new Phrase(str[j], font1));
                                }
                            }
                            else
                            {
                                pcell = new PdfPCell(new Phrase(str[j], font1));
                            }

                            pcell.Border = 0;
                        }

                        //if (i == DetailStr.Length - 1)
                        //{
                        //    pcell.MinimumHeight = 50;
                        //}
                        //else
                        pcell.MinimumHeight = 10;
                        //pcell.MinimumHeight = 20;
                        if (j == 1)
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        }
                        else
                        {
                            pcell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        }
                        pcell.BorderWidthLeft  = 0.01f;
                        pcell.BorderWidthRight = 0.01f;

                        table1.AddCell(pcell);
                    }
                    //foreach()
                    if (track == 1)
                    {
                        for (int j = 0; j < 7; j++)
                        {
                            PdfPCell pcell1;

                            if (j == 5)
                            {
                                pcell1                   = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(dc1 + dc2)), font1));
                                pcell1.Border            = 0;
                                pcell1.BorderWidthBottom = 0.01f;
                            }
                            else
                            {
                                pcell1        = new PdfPCell(new Phrase(""));
                                pcell1.Border = 0;
                            }
                            pcell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            pcell1.BorderWidthLeft     = 0.01f;
                            pcell1.BorderWidthRight    = 0.01f;
                            table1.AddCell(pcell1);
                        }
                    }
                }

                double roundedAmt = Math.Round(poh.POValue, 0);
                double diffAmount = roundedAmt - poh.POValue;

                if (diffAmount != 0)
                {
                    table1.AddCell("");
                    table1.AddCell("");
                    PdfPCell cellRound = new PdfPCell(new Phrase("Round off Adj.", font1));
                    cellRound.Colspan             = 3;
                    cellRound.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    table1.AddCell(cellRound);
                    table1.AddCell(new Phrase(String.Format("{0:0.00}", diffAmount), font1));
                    table1.AddCell("");
                }

                table1.AddCell("");
                table1.AddCell("");
                PdfPCell cellTotal = new PdfPCell(new Phrase("Total", font1));
                cellTotal.Colspan             = 3;
                cellTotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table1.AddCell(cellTotal);
                table1.AddCell(new Phrase(String.Format("{0:0.00}", roundedAmt), font1));
                table1.AddCell("");

                string   total  = footer1 + NumberToString.convert(roundedAmt.ToString()).Replace("INR", poh.CurrencyID) + "\n\n";
                PdfPCell fcell1 = new PdfPCell(new Phrase((total), font1));
                fcell1.Colspan             = 6;
                fcell1.MinimumHeight       = 50;
                fcell1.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell1.BorderWidthBottom   = 0;
                fcell1.BorderWidthRight    = 0;
                fcell1.BorderWidthTop      = 0;
                table1.AddCell(fcell1);

                PdfPCell fcell4 = new PdfPCell(new Phrase("E. & O.E", font1));
                //fcell4.MinimumHeight = 50;
                fcell4.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                fcell4.BorderWidthBottom   = 0;
                //fcell4.BorderWidthRight = 0;
                fcell4.BorderWidthLeft = 0;
                fcell4.BorderWidthTop  = 0;
                table1.AddCell(fcell4);

                if (poh.SpecialNote.Trim().Length != 0)
                {
                    footer2 = "Note:\n" + poh.SpecialNote.Trim();
                }
                PdfPCell fcell2 = new PdfPCell(new Phrase(footer2, font1));
                fcell2.Colspan             = 4;
                fcell2.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                fcell2.BorderWidthTop      = 0;
                fcell2.BorderWidthRight    = 0;
                table1.AddCell(fcell2);
                string[] ft = footer3.Split(';');

                PdfPCell fcell3 = new PdfPCell();
                Chunk    ch1    = new Chunk(ft[0], font1);
                Chunk    ch2    = new Chunk(ft[1], font1);
                Phrase   phrase = new Phrase();
                phrase.Add(ch1);
                for (int i = 0; i < 3; i++)
                {
                    phrase.Add(Chunk.NEWLINE);
                }
                phrase.Add(ch2);

                Paragraph para = new Paragraph();
                para.Add(phrase);
                para.Alignment = Element.ALIGN_RIGHT;
                fcell3.AddElement(para);
                fcell3.Border            = 0;
                fcell3.Colspan           = 4;
                fcell3.BorderWidthTop    = 0f;
                fcell3.BorderWidthLeft   = 0f;
                fcell3.BorderWidthRight  = 0.5f;
                fcell3.BorderWidthBottom = 0.5f;
                fcell3.MinimumHeight     = 50;
                table1.AddCell(fcell3);
                table1.KeepRowsTogether(table1.Rows.Count - 4, table1.Rows.Count);
                PdfPTable taxTab = new PdfPTable(3);
                //taxTab.
                taxTab.WidthPercentage = 100;

                float[] twidth = new float[] { 3f, 3f, 10f };
                taxTab.SetWidths(twidth);
                double dd = 0;
                if (poh.TaxAmount != 0)
                {
                    PdfPCell pcell;
                    pcell = new PdfPCell(new Phrase("Tax Details", font2));
                    taxTab.AddCell(pcell);
                    PdfPCell pcellc = new PdfPCell(new Phrase("Amount(" + poh.CurrencyID + ")", font2));
                    taxTab.AddCell(pcellc);
                    PdfPCell pcelllst = new PdfPCell(new Phrase("", font1));
                    pcelllst.Border = 0;
                    taxTab.AddCell(pcelllst);
                    //for (int i = 0; i < 2; i++)
                    //{

                    //    if (i == 1)
                    //        pcell = new PdfPCell(new Phrase("Tax Details", font2));
                    //    else

                    //    //pcell.Border = 0;
                    //    //pcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                    //    //pcell.MinimumHeight = 20;
                    //    //pcell.BorderWidthLeft = 0.01f;
                    //    //pcell.BorderWidthRight = 0.01f;
                    //    table1.AddCell(pcell);
                    //}
                    string[] tax = taxStr.Split(Main.delimiter2);
                    for (int i = 0; i < tax.Length - 1; i++)
                    {
                        string[] subtax = tax[i].Split(Main.delimiter1);
                        PdfPCell pcell1;
                        pcell1 = new PdfPCell(new Phrase(subtax[0], font1));
                        PdfPCell pcell2;
                        pcell2 = new PdfPCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(subtax[1])), font1));
                        PdfPCell pcell3 = new PdfPCell(new Phrase("", font1));
                        pcell3.Border = 0;
                        //taxTab.AddCell(pcell3);
                        //pcell1.Border = 0;
                        //pcell1.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        //pcell1.BorderWidthLeft = 0.01f;
                        //pcell1.BorderWidthRight = 0.01f;
                        //if (i == (tax.Length - 2))
                        //{
                        //    pcell1.MinimumHeight = 100;
                        //}
                        //else
                        //pcell1.MinimumHeight = 20;
                        taxTab.AddCell(pcell1);
                        //pcell2.MinimumHeight = 20;
                        taxTab.AddCell(pcell2);
                        taxTab.AddCell(pcell3);
                    }
                    taxTab.AddCell(new Phrase("Total Tax Amount", font2));
                    taxTab.AddCell(new Phrase(String.Format("{0:0.00}", Convert.ToDecimal(poh.TaxAmount)), font2));
                    PdfPCell pcellt = new PdfPCell(new Phrase("", font1));
                    pcellt.Border = 0;
                    taxTab.AddCell(pcellt);
                    taxTab.KeepTogether  = true;
                    taxTab.SpacingAfter  = 2f;
                    taxTab.SpacingBefore = 3f;
                }
                PdfPTable TCTab = new PdfPTable(2);
                if (poh.TermsAndCondition.Trim().Length != 0)
                {
                    Chunk TCchunk = new Chunk("Terms And Conditoins:\n", font2);
                    TCchunk.SetUnderline(0.2f, -2f);
                    TCTab = new PdfPTable(2);
                    TCTab.WidthPercentage = 100;
                    PdfPCell TCCell = new PdfPCell();
                    TCCell.Colspan = 2;
                    TCCell.Border  = 0;
                    TCCell.AddElement(TCchunk);
                    TCTab.AddCell(TCCell);
                    try
                    {
                        string[] ParaTC = termsAndCond.Split(Main.delimiter2);
                        for (int i = 0; i < ParaTC.Length - 1; i++)
                        {
                            TCCell         = new PdfPCell();
                            TCCell.Colspan = 2;
                            TCCell.Border  = 0;
                            Paragraph header  = new Paragraph();
                            Paragraph details = new Paragraph();
                            details.IndentationLeft  = 12f;
                            details.IndentationRight = 12f;
                            string paraHeaderStr = (i + 1) + ". " + ParaTC[i].Substring(0, ParaTC[i].IndexOf(Main.delimiter1)) + ":";
                            string paraFooterStr = ParaTC[i].Substring(ParaTC[i].IndexOf(Main.delimiter1) + 1);
                            header.Add(new Phrase(paraHeaderStr, font2));
                            details.Add(new Phrase(paraFooterStr, font1));
                            TCCell.AddElement(header);
                            TCCell.AddElement(details);
                            TCTab.AddCell(TCCell);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                    }
                    try
                    {
                        if (TCTab.Rows.Count >= 3)
                        {
                            TCTab.KeepRowsTogether(0, 3);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error-" + ex.ToString());
                    }
                }
                doc.Add(tableMain);
                //doc.Add(jpg);
                //doc.Add(img);
                doc.Add(paragraph);
                doc.Add(table);
                doc.Add(table1);
                if (poh.TaxAmount != 0)
                {
                    doc.Add(taxTab);
                }
                if (poh.TermsAndCondition.Trim().Length != 0)
                {
                    doc.Add(TCTab);
                }
                doc.Close();
                MessageBox.Show("Document Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to Save Document");
            }
        }