private void grdList_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex < 0) { return; } grdList.Rows[e.RowIndex].Selected = true; ////grdList.CurrentRow.DefaultCellStyle.BackColor = Color.LightSeaGreen; string columnName = grdList.Columns[e.ColumnIndex].Name; if (columnName.Equals("QtyDetails") || columnName.Equals("ClosePO")) { poheader poph = new poheader(); int totalvalue = Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["TotalValueBilled"].Value); poph.TemporaryNo = Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["gTemporaryNo"].Value.ToString()); poph.TemporaryDate = DateTime.Parse(grdList.Rows[e.RowIndex].Cells["gTemporaryDate"].Value.ToString()); poph.PODate = DateTime.Parse(grdList.Rows[e.RowIndex].Cells["gTrackingDate"].Value.ToString()); poph.PONo = Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["gTrackingNo"].Value.ToString()); poph.CustomerName = grdList.Rows[e.RowIndex].Cells["gCustomerName"].Value.ToString(); if (columnName.Equals("QtyDetails")) { showStockPOQuantity(poph); } if (columnName.Equals("ClosePO")) { PurchaseOrderDB popihdb = new PurchaseOrderDB(); if (popihdb.ClosePOPICheck(poph)) { MessageBox.Show("PO Closed"); btnView.PerformClick(); } else { string dstr = "PO No:" + poph.PONo + "\n" + "PO Date:" + poph.PODate.ToString("dd-MM-yyyy") + "\n" + "Customer:" + poph.CustomerName + "\n" + "Are you sure to Close the document ?"; DialogResult dialog = MessageBox.Show(dstr, "Close PO", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { if (popihdb.ClosePOPI2(poph)) { MessageBox.Show("PO Closed"); btnView.PerformClick(); } } } } } } catch (Exception ex) { MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error"); } }
private void showStockPOQuantity(poheader poph) { try { frmPopup = new Form(); frmPopup.StartPosition = FormStartPosition.Manual; frmPopup.BackColor = Color.CadetBlue; frmPopup.BackColor = Color.White; frmPopup.MaximizeBox = false; frmPopup.MinimizeBox = false; frmPopup.ControlBox = false; frmPopup.FormBorderStyle = FormBorderStyle.FixedSingle; frmPopup.Size = new Size(900, 400); frmPopup.Location = new Point(300, 200); //lv = POPIHeaderDB.getPONoWiseStockListView(Convert.ToInt32(txtPOTrackNo.Text), dtPOTrackDate.Value); DataGridView grdDetail = new DataGridView(); grdDetail.AllowUserToAddRows = false; grdDetail = fillgrddetail(poph); //-------------- grdDetail.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; grdDetail.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; grdDetail.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; grdDetail.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; grdDetail.RowHeadersVisible = false; grdDetail.AllowUserToAddRows = false; grdDetail.Bounds = new Rectangle(new Point(20, 60), new Size(850, 300)); frmPopup.Controls.Add(grdDetail); Label lblItemCode = new Label(); lblItemCode.Width = 500; lblItemCode.Text = "Tracking No:" + poph.PONo + " Date:" + poph.PODate.ToString("dd-MM-yyyy"); lblItemCode.Location = new Point(40, 10); frmPopup.Controls.Add(lblItemCode); Label lblItemName = new Label(); lblItemName.Width = 500; lblItemName.Text = "Customer:" + poph.CustomerName; lblItemName.Location = new Point(40, 35); frmPopup.Controls.Add(lblItemName); Button lvClose = new Button(); lvClose.BackColor = Color.Tan; lvClose.Text = "CLOSE"; lvClose.Location = new Point(40, 365); lvClose.Click += new System.EventHandler(this.grddetailclickClose); frmPopup.Controls.Add(lvClose); frmPopup.ShowDialog(); } catch (Exception ex) { } }
private void ShowAllDetails() { try { PurchaseOrderDB pdb = new PurchaseOrderDB(); poheader poh = pdb.getFilteredPurchaseOrderHeaderlist(docID, tempno, tempdate).FirstOrDefault(); if (poh != null) { txtDocID.Text = poh.DocumentID; //txtTrackingNo.Text = poh.TrackingNo.ToString(); //dtTrackingDate.Value = poh.TrackingDate; txtDevileryPeriod.Text = poh.DeliveryPeriod.ToString(); cmbCustomer.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbCustomer, poh.CustomerID); txtPONo.Text = poh.PONo.ToString(); dtPODate.Value = poh.PODate; cmbCurrency.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbCurrency, poh.CurrencyID); cmbPaymentMode.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbPaymentMode, poh.ModeOfPayment); cmbFreightTerms.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbFreightTerms, poh.FreightTerms); cmbTaxterms.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbTaxterms, poh.TaxTerms); cmbTransportationMode.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbTransportationMode, poh.TransportationMode); txtValidityperiod.Text = poh.validityPeriod.ToString(); txtFreightCharge.Text = poh.FreightCharge.ToString(); txtpaymentTerms.Text = getPaymentTermsExplained(poh.PaymentTerms); txtproductValue.Text = poh.ProductValueINR.ToString(); txtTaxvalue.Text = poh.TaxAmountINR.ToString(); txtPOvalue.Text = poh.POValueINR.ToString(); } poheader popd = new poheader(); popd.DocumentID = docID; popd.TemporaryNo = tempno; popd.TemporaryDate = tempdate; List <podetail> pod = PurchaseOrderDB.getPurchaseOrderDetails(popd); grdPRDetail.Rows.Clear(); int i = 0; double count = 0; foreach (podetail po in pod) { grdPRDetail.Rows.Add(); grdPRDetail.Rows[i].Cells["LineNo"].Value = grdPRDetail.Rows.Count; grdPRDetail.Rows[i].Cells["Item"].Value = po.StockItemID; grdPRDetail.Rows[i].Cells["ItemDesc"].Value = po.StockItemName; grdPRDetail.Rows[i].Cells["TaxCode"].Value = po.TaxCode; grdPRDetail.Rows[i].Cells["Quantity"].Value = po.Quantity; grdPRDetail.Rows[i].Cells["Price"].Value = po.Price; grdPRDetail.Rows[i].Cells["Tax"].Value = po.Tax; double valu = po.Price * po.Quantity + po.Tax; grdPRDetail.Rows[i].Cells["Value"].Value = valu; count += valu; i++; } txtTotalValue.Text = count.ToString(); } catch (Exception ex) { MessageBox.Show("Error in POOut"); } }
private void ShowAllDetails() { if (docID == "POPRODUCTINWARD" || docID == "POPRODUCTINWARD") { try { POPIHeaderDB popihdb = new POPIHeaderDB(); popiheader vd = popihdb.getPOPIHeader(tempno, tempdate, docID).FirstOrDefault(); if (vd != null) { txtDocID.Text = vd.DocumentID; txtTrackingNo.Text = vd.TrackingNo.ToString(); dtTrackingDate.Value = vd.TrackingDate; txtrefno.Text = vd.ReferenceNo; cmbCustomer.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbCustomer, vd.CustomerID); txtPONo.Text = vd.CustomerPONO; dtPODate.Value = vd.CustomerPODate; dtDeliveryDate.Value = vd.DeliveryDate; cmbOfficeID.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbOfficeID, vd.OfficeID); cmbProjectID.SelectedIndex = cmbProjectID.FindString(vd.ProjectID); cmbPaymentMode.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbPaymentMode, vd.PaymentMode); cmbFreightTerms.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbFreightTerms, vd.FreightTerms); cmbCurrency.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbCurrency, vd.CurrencyID); txtFreightCharge.Text = vd.FreightCharge.ToString(); dtValidateDate.Value = vd.ValidityDate; txtpaymentTerms.Text = getPaymentTermsExplained(vd.PaymentTerms); txtproductValue.Text = vd.ProductValueINR.ToString(); txtTaxvalue.Text = vd.TaxAmountINR.ToString(); txtPOvalue.Text = vd.POValueINR.ToString(); } popiheader popih = new popiheader(); popih.DocumentID = docID; popih.TemporaryNo = tempno; popih.TemporaryDate = tempdate; List <popidetail> POPIDetail = POPIHeaderDB.getPOPIDetail(popih); grdPRDetail.Rows.Clear(); int i = 0; double count = 0; foreach (popidetail pop in POPIDetail) { grdPRDetail.Rows.Add(); grdPRDetail.Rows[i].Cells["LineNo"].Value = grdPRDetail.Rows.Count; grdPRDetail.Rows[i].Cells["Item"].Value = pop.StockItemID; grdPRDetail.Rows[i].Cells["ItemDesc"].Value = pop.StockItemName; grdPRDetail.Rows[i].Cells["TaxCode"].Value = pop.TaxCode; grdPRDetail.Rows[i].Cells["Quantity"].Value = pop.Quantity; grdPRDetail.Rows[i].Cells["Price"].Value = pop.Price; grdPRDetail.Rows[i].Cells["Tax"].Value = pop.Tax; double valu = pop.Price * pop.Quantity + pop.Tax; grdPRDetail.Rows[i].Cells["Value"].Value = valu; count += valu; i++; } txtTotalValue.Text = count.ToString(); } catch (Exception ex) { MessageBox.Show("Error in POInward"); } } else if (docID == "PURCHASEORDER") { try { PurchaseOrderDB pdb = new PurchaseOrderDB(); poheader poh = pdb.getFilteredPurchaseOrderHeaderlist(docID, tempno, tempdate).FirstOrDefault(); if (poh != null) { txtDocID.Text = poh.DocumentID; //txtTrackingNo.Text = poh.TrackingNo.ToString(); //dtTrackingDate.Value = poh.TrackingDate; //txtrefno.Text = poh.ReferenceNo; cmbCustomer.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbCustomer, poh.CustomerID); //txtPONo.Text = poh.CustomerPONO; //dtPODate.Value = poh.CustomerPODate; //dtDeliveryDate.Value = poh.DeliveryDate; //cmbOfficeID.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbOfficeID, poh.OfficeID); //cmbProjectID.SelectedIndex = cmbProjectID.FindString(poh.ProjectID); //dtValidateDate.Value = poh.ValidityDate; txtpaymentTerms.Text = getPaymentTermsExplained(poh.PaymentTerms); txtproductValue.Text = poh.ProductValueINR.ToString(); txtTaxvalue.Text = poh.TaxAmountINR.ToString(); txtPOvalue.Text = poh.POValueINR.ToString(); } poheader popd = new poheader(); popd.DocumentID = docID; popd.TemporaryNo = tempno; popd.TemporaryDate = tempdate; List <podetail> pod = PurchaseOrderDB.getPurchaseOrderDetails(popd); grdPRDetail.Rows.Clear(); int i = 0; double count = 0; foreach (podetail po in pod) { grdPRDetail.Rows.Add(); grdPRDetail.Rows[i].Cells["LineNo"].Value = grdPRDetail.Rows.Count; grdPRDetail.Rows[i].Cells["Item"].Value = po.StockItemID; grdPRDetail.Rows[i].Cells["ItemDesc"].Value = po.StockItemName; grdPRDetail.Rows[i].Cells["TaxCode"].Value = po.TaxCode; grdPRDetail.Rows[i].Cells["Quantity"].Value = po.Quantity; grdPRDetail.Rows[i].Cells["Price"].Value = po.Price; grdPRDetail.Rows[i].Cells["Tax"].Value = po.Tax; double valu = po.Price * po.Quantity + po.Tax; grdPRDetail.Rows[i].Cells["Value"].Value = valu; count += valu; i++; } txtTotalValue.Text = count.ToString(); } catch (Exception ex) { MessageBox.Show("Error in POOut"); } } else if (docID == "WORKORDER") { try { } catch (Exception ex) { MessageBox.Show("Error in WorkOrder"); } } else if (docID == "POGENERAL") { try { } catch (Exception ex) { MessageBox.Show("Error in POgeneral"); } } else if (docID == "POINVOICEIN" || docID == "WOINVOICEIN" || docID == "POGENERALINVOICEIN") { try { } catch (Exception ex) { MessageBox.Show("Error in InvoiceIn"); } } else if (docID == "PRODUCTINVOICEOUT" || docID == "SERVICEINVOICEOUT") { try { } catch (Exception ex) { MessageBox.Show("Error in InvoiceOut"); } } }
////new public static List <poheader> getPurchaseOrderHeader(indentgeneralheader poh) { poheader pod; List <poheader> PODetail = new List <poheader>(); try { string query = ""; string refindent = poh.DocumentID + "(" + poh.DocumentNo + "" + Main.delimiter1 + "" + poh.DocumentDate.ToString("yyyy-MM-dd") + ");"; SqlConnection conn = new SqlConnection(Login.connString); query = "select DocumentID,DocumentName,TemporaryNo,TemporaryDate,PONo,PODate, " + "ReferenceIndent,ReferenceQuotation,CustomerID, " + "CustomerName,CurrencyID,DeliveryPeriod,ValidityPeriod, " + "TaxTerms,ModeOfPayment,PaymentTerms,TransportationMode, " + " FreightTerms,FreightCharge,DeliveryAddress,ProductValue,TaxAmount,POValue," + "ExchangeRate,ProductValueINR,TaxAmountINR " + ",POValueINR,Remarks,TermsAndCondition,Status,DocumentStatus,CreateTime," + "CreateUser,ForwardUser,ApproveUser,CreatorName " + ",ForwarderName,ApproverName,Comments,ForwarderList,CommentStatus " + "from ViewPOHeader where Status=1 and DocumentStatus=99 and ReferenceIndent like '%" + refindent + "%'"; SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { pod = new poheader(); pod.DocumentID = reader.GetString(0); pod.DocumentName = reader.GetString(1); pod.TemporaryNo = reader.GetInt32(2); pod.TemporaryDate = reader.GetDateTime(3).Date; pod.PONo = reader.GetInt32(4); pod.PODate = reader.GetDateTime(5).Date; pod.ReferenceIndent = reader.GetString(6); pod.ReferenceQuotation = reader.GetString(7); pod.CustomerID = reader.GetString(8); pod.CustomerName = reader.GetString(9); pod.CurrencyID = reader.GetString(10); pod.DeliveryPeriod = reader.GetInt32(11); pod.validityPeriod = reader.GetInt32(12); pod.TaxTerms = reader.GetString(13); pod.ModeOfPayment = reader.GetString(14); pod.PaymentTerms = reader.GetString(15); pod.TransportationMode = reader.GetString(16); pod.FreightTerms = reader.GetString(17); pod.FreightCharge = reader.GetDouble(18); pod.DeliveryAddress = reader.GetString(19); pod.ProductValue = reader.GetDouble(20); pod.TaxAmount = reader.GetDouble(21); pod.POValue = reader.GetDouble(22); pod.ExchangeRate = reader.GetDecimal(23); pod.ProductValueINR = reader.GetDouble(24); pod.TaxAmountINR = reader.GetDouble(25); pod.POValueINR = reader.GetDouble(26); pod.Remarks = reader.GetString(27); pod.TermsAndCondition = reader.GetString(28); pod.Status = reader.GetInt32(29); pod.DocumentStatus = reader.GetInt32(30); pod.CreateTime = reader.GetDateTime(31); pod.CreateUser = reader.GetString(32); pod.ForwardUser = reader.GetString(33); pod.ApproveUser = reader.GetString(34); pod.CreatorName = reader.GetString(35); pod.ForwarderName = reader.GetString(36); pod.ApproverName = reader.GetString(37); pod.Comments = reader.GetString(38); pod.ForwarderList = reader.GetString(39); pod.CommentStatus = reader.GetString(40); PODetail.Add(pod); } conn.Close(); } catch (Exception ex) { MessageBox.Show("Error querying Work Order Details"); } return(PODetail); }
private DataGridView fillgrddetail(poheader poph) { DataGridView grdDetail = new DataGridView(); try { grdDetail.RowHeadersVisible = false; DataGridViewTextBoxColumn dgvtx0 = new DataGridViewTextBoxColumn(); dgvtx0.Width = 50; dgvtx0.Name = "SlNo"; dgvtx0.Visible = true; grdDetail.Columns.Add(dgvtx0); DataGridViewTextBoxColumn dgvtx1 = new DataGridViewTextBoxColumn(); dgvtx1.Name = "LineNo"; dgvtx1.Visible = false; grdDetail.Columns.Add(dgvtx1); DataGridViewTextBoxColumn dgvtx2 = new DataGridViewTextBoxColumn(); dgvtx2.Width = 200; dgvtx2.Name = "Product"; grdDetail.Columns.Add(dgvtx2); DataGridViewTextBoxColumn dgvtx3 = new DataGridViewTextBoxColumn(); dgvtx3.Width = 200; dgvtx3.Name = "Description"; grdDetail.Columns.Add(dgvtx3); DataGridViewTextBoxColumn dgvtx4 = new DataGridViewTextBoxColumn(); dgvtx4.Width = 80; dgvtx4.Name = "MRNNo"; grdDetail.Columns.Add(dgvtx4); DataGridViewTextBoxColumn dgvtx5 = new DataGridViewTextBoxColumn(); dgvtx5.Width = 100; dgvtx5.Name = "MRNDate"; grdDetail.Columns.Add(dgvtx5); DataGridViewTextBoxColumn dgvtx7 = new DataGridViewTextBoxColumn(); dgvtx7.Width = 70; dgvtx7.DefaultCellStyle.Format = "N0"; dgvtx7.Name = "Quantity"; grdDetail.Columns.Add(dgvtx7); DataGridViewTextBoxColumn dgvtx8 = new DataGridViewTextBoxColumn(); dgvtx8.Width = 70; dgvtx8.DefaultCellStyle.Format = "N2"; dgvtx8.Name = "Price"; grdDetail.Columns.Add(dgvtx8); DataGridViewTextBoxColumn dgvtx9 = new DataGridViewTextBoxColumn(); dgvtx9.DefaultCellStyle.Format = "N2"; dgvtx9.Name = "Value"; grdDetail.Columns.Add(dgvtx9); DataGridViewTextBoxColumn dgvtx10 = new DataGridViewTextBoxColumn(); dgvtx10.Width = 70; dgvtx10.DefaultCellStyle.Format = "N0"; dgvtx10.Name = "BilledQty"; dgvtx10.HeaderText = "Recived Qty"; grdDetail.Columns.Add(dgvtx10); DataGridViewTextBoxColumn dgvtx11 = new DataGridViewTextBoxColumn(); dgvtx11.Width = 70; dgvtx11.DefaultCellStyle.Format = "N0"; dgvtx11.Name = "BalanceQty"; dgvtx11.HeaderText = "Balance Qty"; grdDetail.Columns.Add(dgvtx11); { List <podetail> POPIDetail = PurchaseOrderDB.getPOPIDetailqty2(poph); grdDetail.Rows.Clear(); var results = from p in POPIDetail group p by p.RowID into g select new { RowId = g.Key, StockItemName = g.FirstOrDefault().StockItemName, Description = g.FirstOrDefault().Description, Quantity = g.FirstOrDefault().Quantity, Price = g.FirstOrDefault().Price, BilledQuantity = g.Sum(S => S.BilledQuantity), MRNNo = g.Select(S => S.MRNNo).ToArray(), MRNDate = g.Select(S => S.MRNDate).ToArray() }; int i = 0; foreach (var popid in results) { try { grdDetail.Rows.Add(); grdDetail.Rows[i].Cells["SLNo"].Value = grdDetail.RowCount - 1; grdDetail.Rows[i].Cells["LineNo"].Value = popid.RowId; grdDetail.Rows[i].Cells["Product"].Value = popid.StockItemName; grdDetail.Rows[i].Cells["Description"].Value = popid.Description; grdDetail.Rows[i].Cells["MRNNo"].Value = string.Join(",", popid.MRNNo); grdDetail.Rows[i].Cells["MRNDate"].Value = string.Join(",", popid.MRNDate); grdDetail.Rows[i].Cells["Quantity"].Value = popid.Quantity; grdDetail.Rows[i].Cells["Description"].Value = popid.Description; grdDetail.Rows[i].Cells["Price"].Value = popid.Price; grdDetail.Rows[i].Cells["Value"].Value = popid.Quantity * popid.Price; grdDetail.Rows[i].Cells["BilledQty"].Value = popid.BilledQuantity; grdDetail.Rows[i].Cells["BalanceQty"].Value = Convert.ToDouble(popid.Quantity) - Convert.ToDouble(popid.BilledQuantity); i++; // productvalue = productvalue + popid.Quantity * popid.Price; // taxvalue = taxvalue + popid.Tax; } catch (Exception ex) { } } } } catch (Exception ex) { MessageBox.Show("Error in PO Quantity filling"); } return(grdDetail); }
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) { } }
private void grdList_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex < 0) { return; } DocumentUnlockDB dudb = new DocumentUnlockDB(); string columnName = grdList.Columns[e.ColumnIndex].Name; if (columnName.Equals("Unlock")) { prevdc.TemporaryNo = Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["TempNo"].Value); prevdc.TemporaryDate = Convert.ToDateTime(grdList.Rows[e.RowIndex].Cells["TempDate"].Value); prevdc.TableName = grdList.Rows[e.RowIndex].Cells["TableName"].Value.ToString(); string frwdList = grdList.Rows[e.RowIndex].Cells["ForwarderList"].Value.ToString(); if (frwdList == null) { MessageBox.Show("Failed to retrive Forwardlist"); return; } DialogResult dialog = MessageBox.Show("Are you sure to Unlock the document ?\n\nDocument Type\t: " + selectedDocName + "\nTemporary No\t: " + prevdc.TemporaryNo + "\nTemprary Date\t: " + prevdc.TemporaryDate.ToString("yyyy-MM-dd") + "\n" , "Confirmation", MessageBoxButtons.YesNo); if (dialog == DialogResult.No) { return; } string[] strArr = frwdList.Split(Main.delimiter2); int DocStat = strArr.Count(); ////if document is MRN, do not reverse if any issue from the MRN. ////if Invoice out, reverse all quantity before reversing the document if (selectedDocID == "MRN") { if (MRNHeaderDB.checkForIssuesFromMRN(prevdc.TemporaryNo, prevdc.TemporaryDate)) { //no issues (purchase return and Invoice) from MRN MessageBox.Show("Stock has been issued from MRN. Reversal request denied"); return; } else { if (dudb.updateDocForUnlockingMRN(prevdc, DocStat)) { MessageBox.Show("Document Unlocked with Updating Stock sucessfully."); grdList.Rows.RemoveAt(e.RowIndex); return; } else { MessageBox.Show("Document Failed to Unlocked"); return; } } } else if (selectedDocID == "POPRODUCTINWARD" || selectedDocID == "POSERVICEINWARD") { string result = POPIHeaderDB.checkForInvoiceIssuesForPOPI(prevdc.TemporaryNo, prevdc.TemporaryDate, selectedDocID); if (result == "error" || result.Length != 0) { if (result == "error") { return; } //Inivoice Prepared For this PO string InvPrepared = ""; string[] invArr = result.Split(Main.delimiter1); foreach (string str in invArr) { if (str.Length != 0) { string[] invNoDate = str.Split(';'); InvPrepared = InvPrepared + "\nTemporary No: " + invNoDate[0] + " Temporary Date: " + Convert.ToDateTime(invNoDate[1]).ToString("yyyy-MM-dd"); } } MessageBox.Show("Inivoice Prepared For this PO. Reversal request denied.\n" + InvPrepared, "Invoice Prepared Details"); return; } else { if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID)) { MessageBox.Show("PO Document Unlocked"); grdList.Rows.RemoveAt(e.RowIndex); return; } else { MessageBox.Show("Failed to unlock Document"); return; } } } else if (selectedDocID == "PRODUCTINVOICEOUT" || selectedDocID == "PRODUCTEXPORTINVOICEOUT" || selectedDocID == "SERVICEINVOICEOUT" || selectedDocID == "SERVICEEXPORTINVOICEOUT") { invoiceoutheader iohTemp = new invoiceoutheader(); iohTemp.TemporaryNo = prevdc.TemporaryNo; iohTemp.TemporaryDate = prevdc.TemporaryDate; iohTemp.DocumentID = selectedDocID; if (InvoiceOutHeaderDB.isInvoiceOutReceiptPreparedForInvOut(iohTemp)) { MessageBox.Show("Receipt Adjusted against this Invoice . Not allowed to Unlock."); return; } //return; if (dudb.updateDocForUnlockingInvoiceOUT(prevdc, DocStat, selectedDocID)) { if (selectedDocID == "PRODUCTINVOICEOUT" || selectedDocID == "PRODUCTEXPORTINVOICEOUT") { MessageBox.Show("Document Unlocked with Updating Stock sucessfully."); } else { MessageBox.Show("Document Unlocked sucessfully."); } grdList.Rows.RemoveAt(e.RowIndex); return; } else { MessageBox.Show("Document Failed to Unlocked"); return; } } else if (selectedDocID == "GTN") { if (GTNDB.checkForIssuesOfGTNInStock(prevdc.TemporaryNo, prevdc.TemporaryDate)) { //no issues (purchase return and Invoice) from MRN MessageBox.Show("Stock has been issued from GTN. Reversal request denied"); return; } else { if (dudb.updateDocForUnlockingGTN(prevdc, DocStat)) { MessageBox.Show("Document Unlocked with Updating Stock sucessfully."); grdList.Rows.RemoveAt(e.RowIndex); return; } else { MessageBox.Show("Document Failed to Unlocked"); return; } } } else if (selectedDocID == "POINVOICEIN" || selectedDocID == "WOINVOICEIN" || selectedDocID == "POGENERALINVOICEIN") { invoiceinheader iihTemp = new invoiceinheader(); iihTemp.TemporaryNo = prevdc.TemporaryNo; iihTemp.TemporaryDate = prevdc.TemporaryDate; iihTemp.DocumentID = selectedDocID; if (InvoiceInHeaderDB.isInvoiceInPaymentPreparedForInvIN(iihTemp)) { MessageBox.Show("Payment Adjusted against this Invoice . Not allowed to Unlock."); return; } if (dudb.updateDocForUnlockingInvoiceIN(prevdc, DocStat, selectedDocID)) { MessageBox.Show("Document Unlocked"); grdList.Rows.RemoveAt(e.RowIndex); return; } else { MessageBox.Show("Document Failed to Unlocked"); return; } } else if (selectedDocID == "WORKORDER") { workorderheader wohtemp = new workorderheader(); wohtemp.TemporaryNo = prevdc.TemporaryNo; wohtemp.TemporaryDate = prevdc.TemporaryDate; wohtemp.DocumentID = selectedDocID; workorderheader woh = WorkOrderDB.getWONOAndDateOFWO(wohtemp); if (WorkOrderDB.isInvoicePreparedForWO(woh.WONo, woh.WODate)) { MessageBox.Show("invoice received against this work order . Not allowed to Unlock."); return; } if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID)) { MessageBox.Show("Document Unlocked"); grdList.Rows.RemoveAt(e.RowIndex); return; } else { MessageBox.Show("Document Failed to Unlocked"); return; } } else if (selectedDocID == "PURCHASEORDER") { poheader pohtemp = new poheader(); pohtemp.TemporaryNo = prevdc.TemporaryNo; pohtemp.TemporaryDate = prevdc.TemporaryDate; pohtemp.DocumentID = selectedDocID; poheader poh = PurchaseOrderDB.getPONOAndDateOFPOOut(pohtemp); if (PurchaseOrderDB.isMRNPreparedForPO(poh.PONo, poh.PODate)) { MessageBox.Show("MRN received against this Purchase order . Not allowed to Unlock."); return; } if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID)) { MessageBox.Show("Document Unlocked"); grdList.Rows.RemoveAt(e.RowIndex); return; } else { MessageBox.Show("Document Failed to Unlocked"); return; } } else if (selectedDocID == "POGENERAL") { pogeneralheader pohtemp = new pogeneralheader(); pohtemp.TemporaryNo = prevdc.TemporaryNo; pohtemp.TemporaryDate = prevdc.TemporaryDate; pohtemp.DocumentID = selectedDocID; pogeneralheader poh = PurchaseOrderGeneralDB.getPONOAndDateOFPOGen(pohtemp); if (PurchaseOrderGeneralDB.isInvoicePreparedForPOGeneral(poh.PONo, poh.PODate)) { MessageBox.Show("invoice received against this Purchase order . Not allowed to Unlock."); return; } if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID)) { MessageBox.Show("Document Unlocked"); grdList.Rows.RemoveAt(e.RowIndex); return; } else { MessageBox.Show("Document Failed to Unlocked"); return; } } else if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID)) { MessageBox.Show("Document Unlocked"); grdList.Rows.RemoveAt(e.RowIndex); } else { MessageBox.Show("Failed to unlock Document"); } } } catch (Exception ex) { MessageBox.Show("Exception : Failed to unlock Document"); } }
////new public static List <poheader> getPurchaseOrderHeader(indentgeneralheader iigh) { poheader poh; List <poheader> PODetail = new List <poheader>(); try { string query = ""; string refindent = iigh.DocumentID + "(" + iigh.DocumentNo + "" + Main.delimiter1 + "" + iigh.DocumentDate.ToString("yyyy-MM-dd") + ");"; SqlConnection conn = new SqlConnection(Login.connString); query = "select RowID, DocumentID, DocumentName,TemporaryNo,TemporaryDate," + " PONo,PODate,ReferenceIndent,ReferenceQuotation,CustomerID,CustomerName,CurrencyID,DeliveryPeriod,ValidityPeriod,TaxTerms,ModeOfPayment,PaymentTerms," + " FreightTerms,FreightCharge,DeliveryAddress,ProductValue,TaxAmount,POValue,Remarks, " + " TermsAndCondition,Status,DocumentStatus,CreateTime,CreateUser,ForwardUser,ApproveUser,CreatorName,ForwarderName,ApproverName ,CommentStatus,ForwarderList" + " ,ExchangeRate, ProductValueINR, POValueINR, TaxAmountINR,TransportationMode,SpecialNote,PartialShipment,Transhipment,PackingSpec,PriceBasis,DeliveryAt,CountryID " + "from ViewPOHeader where Status=1 and DocumentStatus=99 and ReferenceIndent like '%" + refindent + "%'"; SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { poh = new poheader(); poh.RowID = reader.GetInt32(0); poh.DocumentID = reader.GetString(1); poh.DocumentName = reader.GetString(2); poh.TemporaryNo = reader.GetInt32(3); poh.TemporaryDate = reader.GetDateTime(4); poh.PONo = reader.GetInt32(5); if (!reader.IsDBNull(6)) { poh.PODate = reader.GetDateTime(6); } poh.ReferenceIndent = reader.GetString(7); poh.ReferenceQuotation = reader.GetString(8); poh.CustomerID = reader.GetString(9); poh.CustomerName = reader.GetString(10); poh.CurrencyID = reader.GetString(11); poh.DeliveryPeriod = reader.GetInt32(12); poh.validityPeriod = reader.GetInt32(13); poh.TaxTerms = reader.GetString(14); poh.ModeOfPayment = reader.GetString(15); poh.PaymentTerms = reader.GetString(16); //poh.CreditPeriod = reader.GetInt32(17); poh.FreightTerms = reader.GetString(17); poh.FreightCharge = reader.GetDouble(18); poh.DeliveryAddress = reader.GetString(19); poh.ProductValue = reader.GetDouble(20); poh.TaxAmount = reader.GetDouble(21); poh.POValue = reader.GetDouble(22); poh.Remarks = reader.GetString(23); poh.TermsAndCondition = reader.GetString(24); poh.Status = reader.GetInt32(25); poh.DocumentStatus = reader.GetInt32(26); poh.CreateTime = reader.GetDateTime(27); poh.CreateUser = reader.GetString(28); poh.ForwardUser = reader.GetString(29); poh.ApproveUser = reader.GetString(30); poh.CreatorName = reader.GetString(31); poh.ForwarderName = reader.GetString(32); poh.ApproverName = reader.GetString(33); if (!reader.IsDBNull(34)) { poh.CommentStatus = reader.GetString(34); } else { poh.CommentStatus = ""; } if (!reader.IsDBNull(35)) { poh.ForwarderList = reader.GetString(35); } else { poh.ForwarderList = ""; } poh.ExchangeRate = reader.GetDecimal(36); poh.ProductValueINR = reader.GetDouble(37); poh.POValueINR = reader.GetDouble(38); poh.TaxAmountINR = reader.GetDouble(39); poh.TransportationMode = reader.IsDBNull(40) ? "" : reader.GetString(40); poh.SpecialNote = reader.IsDBNull(41) ? "" : reader.GetString(41); poh.PartialShipment = reader.IsDBNull(42) ? "" : reader.GetString(42); poh.Transhipment = reader.IsDBNull(43) ? "" : reader.GetString(43); poh.PackingSpec = reader.IsDBNull(44) ? "" : reader.GetString(44); poh.PriceBasis = reader.IsDBNull(45) ? "" : reader.GetString(45); poh.DeliveryAt = reader.IsDBNull(46) ? "" : reader.GetString(46); poh.CountryID = reader.IsDBNull(47) ? "" : reader.GetString(47); PODetail.Add(poh); } conn.Close(); } catch (Exception ex) { MessageBox.Show("Error querying Work Order Details"); } return(PODetail); }
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"); } }
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"); } }