private void ShowAllDetails() { try { if (docID == "CASHPAYMENTVOUCHER" || docID == "BANKPAYMENTVOUCHER") { grdPRDetail.Columns["PartyCode"].Visible = false; grdPRDetail.Columns["PartyName"].Visible = false; grdPRDetail.Columns["SLType"].Visible = false; grdPRDetail.Columns["ChequeNo"].Visible = true; grdPRDetail.Columns["ChequeDate"].Visible = true; paymentvoucher vh = new paymentvoucher(); vh.DocumentID = docID; vh.VoucherNo = voucherNo; vh.VoucherDate = voucherDate; paymentvoucher pvh = PaymentVoucherDB.getVoucherHeaderForTrialBalance(vh); txtTemporarryNo.Text = pvh.TemporaryNo.ToString(); dtTempDate.Value = pvh.TemporaryDate; txtVoucherNo.Text = pvh.VoucherNo.ToString(); dtVoucherDate.Value = pvh.VoucherDate; txtvoucherType.Text = pvh.VoucherType; cmbBookType.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbBookType, pvh.BookType); txtPayeeCode.Text = pvh.SLCode.ToString(); txtPayeeName.Text = pvh.SLName; txtBillDetails.Text = pvh.BillDetails; cmbBankTransMode.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbBankTransMode, pvh.BankTransactionMode); cmbOfficeID.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbOfficeID, pvh.OfficeID); cmbProjectID.SelectedIndex = cmbProjectID.FindString(pvh.ProjectID); cmbCurrencyID.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbCurrencyID, pvh.CurrencyID); txtExchangeRate.Text = pvh.ExchangeRate.ToString(); txtVoucherAmount.Text = pvh.VoucherAmount.ToString(); txtvoucherAmountINR.Text = pvh.VoucherAmountINR.ToString(); txtAmountInWords.Text = NumberToString.convert(pvh.VoucherAmount.ToString()).Trim().Replace("INR", pvh.CurrencyID); txtnarration.Text = pvh.Narration.ToString(); List <paymentvoucherdetail> VDetail = PaymentVoucherDB.getVoucherDetail(pvh); grdPRDetail.Rows.Clear(); int i = 0; decimal totCredit = 0; decimal totDebit = 0; foreach (paymentvoucherdetail vd in VDetail) { AddPRDetailRow(); grdPRDetail.Rows[i].Cells["AccountCode"].Value = vd.AccountCode; grdPRDetail.Rows[i].Cells["AccountName"].Value = vd.AccountName; grdPRDetail.Rows[i].Cells["AmountDebit"].Value = vd.AmountDebit; totDebit = totDebit + vd.AmountDebit; grdPRDetail.Rows[i].Cells["AmountCredit"].Value = vd.AmountCredit; totCredit = totCredit + vd.AmountCredit; grdPRDetail.Rows[i].Cells["ChequeNo"].Value = vd.ChequeNo; grdPRDetail.Rows[i].Cells["ChequeDate"].Value = vd.ChequeDate; i++; } txtTotalCreditAmnt.Text = totCredit.ToString(); txtTotalDebitAmnt.Text = totDebit.ToString(); } else if (docID == "BANKRECEIPTVOUCHER" || docID == "CASHRECEIPTVOUCHER") { grdPRDetail.Columns["PartyCode"].Visible = false; grdPRDetail.Columns["PartyName"].Visible = false; grdPRDetail.Columns["SLType"].Visible = false; grdPRDetail.Columns["ChequeNo"].Visible = true; grdPRDetail.Columns["ChequeDate"].Visible = true; ReceiptVoucherHeader vh = new ReceiptVoucherHeader(); vh.DocumentID = docID; vh.VoucherNo = voucherNo; vh.VoucherDate = voucherDate; ReceiptVoucherHeader rvh = ReceiptVoucherDB.getReceiptVoucherHeaderForTrailbalance(vh); txtTemporarryNo.Text = rvh.TemporaryNo.ToString(); dtTempDate.Value = rvh.TemporaryDate; txtVoucherNo.Text = rvh.VoucherNo.ToString(); dtVoucherDate.Value = rvh.VoucherDate; txtvoucherType.Text = rvh.VoucherType; cmbBookType.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbBookType, rvh.BookType); txtPayeeCode.Text = rvh.SLCode.ToString(); txtPayeeName.Text = rvh.SLName; txtBillDetails.Text = rvh.BillDetails; cmbBankTransMode.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbBankTransMode, rvh.BankTransactionMode); cmbOfficeID.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbOfficeID, rvh.OfficeID); cmbProjectID.SelectedIndex = cmbProjectID.FindString(rvh.ProjectID); cmbCurrencyID.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbCurrencyID, rvh.CurrencyID); txtExchangeRate.Text = rvh.ExchangeRate.ToString(); txtVoucherAmount.Text = rvh.VoucherAmount.ToString(); txtvoucherAmountINR.Text = rvh.VoucherAmountINR.ToString(); txtAmountInWords.Text = NumberToString.convert(rvh.VoucherAmount.ToString()).Trim().Replace("INR", rvh.CurrencyID); txtnarration.Text = rvh.Narration.ToString(); List <ReceiptVoucherDetail> VDetail = ReceiptVoucherDB.getVoucherDetail(rvh); grdPRDetail.Rows.Clear(); int i = 0; decimal totCredit = 0; decimal totDebit = 0; foreach (ReceiptVoucherDetail vd in VDetail) { AddPRDetailRow(); grdPRDetail.Rows[i].Cells["AccountCode"].Value = vd.AccountCode; grdPRDetail.Rows[i].Cells["AccountName"].Value = vd.AccountName; grdPRDetail.Rows[i].Cells["AmountDebit"].Value = vd.AmountDebit; totDebit = totDebit + vd.AmountDebit; grdPRDetail.Rows[i].Cells["AmountCredit"].Value = vd.AmountCredit; totCredit = totCredit + vd.AmountCredit; grdPRDetail.Rows[i].Cells["ChequeNo"].Value = vd.ChequeNo; grdPRDetail.Rows[i].Cells["ChequeDate"].Value = vd.ChequeDate; i++; } txtTotalCreditAmnt.Text = totCredit.ToString(); txtTotalDebitAmnt.Text = totDebit.ToString(); } else if (docID == "JOURNALVOUCHER" || docID == "PJV" || docID == "SJV") { grdPRDetail.Columns["PartyCode"].Visible = true; grdPRDetail.Columns["PartyName"].Visible = true; grdPRDetail.Columns["SLType"].Visible = true; grdPRDetail.Columns["ChequeNo"].Visible = false; grdPRDetail.Columns["ChequeDate"].Visible = false; JournalVoucherHeader jvhTemp = new JournalVoucherHeader(); jvhTemp.DocumentID = docID; jvhTemp.JournalNo = voucherNo; jvhTemp.JournalDate = voucherDate; JournalVoucherHeader jvh = JournalVoucherDB.getJournalHeaderForTrialBalance(jvhTemp); txtTemporarryNo.Text = jvh.TemporaryNo.ToString(); //txtvoucherType.Text = "Journal"; dtTempDate.Value = jvh.TemporaryDate; //txtAmountInWords.Text = NumberToString.convert(txtTotalDebitAmnt.Text); txtVoucherNo.Text = jvh.JournalNo.ToString(); dtVoucherDate.Value = jvh.JournalDate; txtnarration.Text = jvh.Narration.ToString(); decimal totDebit = 0; decimal totCredit = 0; List <JournalVoucherDetail> JVDetail = JournalVoucherDB.getJournalVoucherDetail(jvh); grdPRDetail.Rows.Clear(); int i = 0; foreach (JournalVoucherDetail jvd in JVDetail) { AddPRDetailRow(); grdPRDetail.Rows[i].Cells["AccountCode"].Value = jvd.AccountCode; grdPRDetail.Rows[i].Cells["AccountName"].Value = jvd.AccountName; grdPRDetail.Rows[i].Cells["PartyCode"].Value = jvd.SLCode; grdPRDetail.Rows[i].Cells["PartyName"].Value = jvd.SLName; grdPRDetail.Rows[i].Cells["SLType"].Value = jvd.SLType; grdPRDetail.Rows[i].Cells["AmountDebit"].Value = jvd.AmountDebit; grdPRDetail.Rows[i].Cells["AmountCredit"].Value = jvd.AmountCredit; totDebit = totDebit + jvd.AmountDebit; totCredit = totCredit + jvd.AmountCredit; i++; } txtTotalCreditAmnt.Text = totCredit.ToString(); txtTotalDebitAmnt.Text = totDebit.ToString(); txtAmountInWords.Text = NumberToString.convert(txtTotalDebitAmnt.Text); } } catch (Exception ex) { MessageBox.Show("Error in showing details"); } }
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); }