private static PdfPTable GenerateBatteryAllCustDashboard(string ProcessDate) { BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); Font times = new Font(bfTimes, 12, Font.ITALIC, Color.RED); Font fontTinyItalic = FontFactory.GetFont("Arial", 7, iTextSharp.text.Font.ITALIC, Color.GRAY); PdfPTable table = new PdfPTable(6); //actual width of table in points //table.TotalWidth = 216f; //fix the absolute width of the table // table.LockedWidth = true; table.WidthPercentage = (90.0f); //relative col widths in proportions - 1/3 and 2/3 // float[] widths = new float[] { 1f, 2f }; float[] colWidths = { 70, 70, 70, 70, 70, 70 }; table.SetWidths(colWidths); table.HorizontalAlignment = 1; //leave a gap before and after the table table.SpacingBefore = 20f; table.SpacingAfter = 30f; table.DefaultCell.HorizontalAlignment = 2; //table.DefaultCell.Border = (PdfPCell.BOTTOM_BORDER); table.DefaultCell.GrayFill = 1; table.DefaultCell.Border = (PdfPCell.RECTANGLE); table.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255); table.DefaultCell.BorderColorBottom = new iTextSharp.text.Color(255, 255, 255); table.DefaultCell.Padding = 4; //PdfPCell cell = new PdfPCell(new Phrase("Products","Test")); //cell.Colspan = 2; //cell.Border = 0; //cell.HorizontalAlignment = 1; //table.AddCell(cell); //Creating First Row that will contain the Title // table.AddCell(""); Color headRowColor = new Color(0, 0, 0); Color headRowFontColor = new Color(255, 255, 255); iTextSharp.text.Font fontIstRow = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.WHITE); // iTextSharp.text.Cell c1 = new iTextSharp.text.Cell(""); string c1Text = "VEHICLE"; PdfPCell cell1 = new PdfPCell(new Phrase(c1Text, fontIstRow)); cell1.HorizontalAlignment = 1; cell1.Border = 0; cell1.GrayFill = 1; cell1.BackgroundColor = headRowColor; table.AddCell(cell1); //c1.UseBorderPadding = false; string c2Text = "I_MIN(A)"; PdfPCell cell2 = new PdfPCell(new Phrase(c2Text, fontIstRow)); cell2.HorizontalAlignment = 1; cell2.Border = 0; cell2.GrayFill = 1; cell2.BackgroundColor = headRowColor; table.AddCell(cell2); string c3Text = "I_MAX(A)"; PdfPCell cell3 = new PdfPCell(new Phrase(c3Text, fontIstRow)); cell3.HorizontalAlignment = 1; cell3.Border = 0; cell3.GrayFill = 1; cell3.BackgroundColor = headRowColor; table.AddCell(cell3); string c6Text = "TEMP(C)"; PdfPCell cell6 = new PdfPCell(new Phrase(c6Text, fontIstRow)); cell6.HorizontalAlignment = 1; cell6.Border = 0; cell6.GrayFill = 1; cell6.BackgroundColor = headRowColor; table.AddCell(cell6); string c7Text = "SOC(%)"; PdfPCell cell7 = new PdfPCell(new Phrase(c7Text, fontIstRow)); cell7.HorizontalAlignment = 1; cell7.Border = 0; cell7.GrayFill = 1; cell7.BackgroundColor = headRowColor; table.AddCell(cell7); string c8Text = "Drive(Hr)"; PdfPCell cell8 = new PdfPCell(new Phrase(c8Text, fontIstRow)); cell8.HorizontalAlignment = 1; cell8.Border = 0; cell8.GrayFill = 1; cell8.BackgroundColor = headRowColor; table.AddCell(cell8); //table.AddCell("Drive_h"); //table.AddCell("Temp"); //table.AddCell("Soc"); //table.AddCell("Drive_h"); DateTime dtProcessDate; bool IsProcessDate = DateTime.TryParse(ProcessDate, out dtProcessDate); iTextSharp.text.Font fontDynmaicRows = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8,iTextSharp.text.Font.BOLD,iTextSharp.text.Color.BLACK); iTextSharp.text.Font fontDynmaicRowsRed = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.RED); iTextSharp.text.Font fontDynmaicRowsNormal = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK); iTextSharp.text.Font fontDynmaicRowsRedNormal = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.RED); GetData gd = new GetData(); DataTable dataTable_TempData = new DataTable(); dataTable_TempData = gd.Dt_DailyGrab_GetBatteryDashAllCust(dtProcessDate, 0); table.HeaderRows = 1; table.DefaultCell.BorderWidth = 1; Color altRow = new Color(242, 242, 242); int i = 0; foreach (DataRow dRow in dataTable_TempData.Rows) { i++; if (i % 2 == 1) { table.DefaultCell.BackgroundColor = altRow; } else { table.DefaultCell.BackgroundColor = Color.WHITE; } if (dRow[9].ToString() == "1") { // table.AddCell(new Phrase(dRow[0].ToString(), fontDynmaicRowsRed)); PdfPCell Cell1Hdr = new PdfPCell(new Phrase(dRow[1].ToString().ToUpper(), fontDynmaicRows)); Cell1Hdr.HorizontalAlignment = Element.ALIGN_LEFT; if (i % 2 == 1) { Cell1Hdr.BackgroundColor = altRow; } else { Cell1Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell1Hdr); //PdfPCell Cell2Hdr = new PdfPCell(new Phrase(dRow[2].ToString(), fontDynmaicRowsNormal)); //Cell2Hdr.HorizontalAlignment = Element.ALIGN_LEFT; //table.AddCell(Cell2Hdr); //PdfPCell Cell3Hdr = new PdfPCell(new Phrase(dRow[3].ToString(), fontDynmaicRows)); //Cell3Hdr.HorizontalAlignment = Element.ALIGN_LEFT; //table.AddCell(Cell3Hdr); PdfPCell Cell4Hdr = new PdfPCell(new Phrase(dRow[4].ToString(), fontDynmaicRowsRed)); Cell4Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell4Hdr.BackgroundColor = altRow; } else { Cell4Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell4Hdr); PdfPCell Cell5Hdr = new PdfPCell(new Phrase(dRow[5].ToString(), fontDynmaicRowsRedNormal)); Cell5Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell5Hdr.BackgroundColor = altRow; } else { Cell5Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell5Hdr); PdfPCell Cell6Hdr = new PdfPCell(new Phrase(dRow[6].ToString(), fontDynmaicRowsRedNormal)); Cell6Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell6Hdr.BackgroundColor = altRow; } else { Cell6Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell6Hdr); PdfPCell Cell7Hdr = new PdfPCell(new Phrase(dRow[7].ToString(), fontDynmaicRowsRedNormal)); Cell7Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell7Hdr.BackgroundColor = altRow; } else { Cell7Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell7Hdr); PdfPCell Cell8Hdr = new PdfPCell(new Phrase(dRow[8].ToString(), fontDynmaicRowsRedNormal)); Cell8Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell8Hdr.BackgroundColor = altRow; } else { Cell8Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell8Hdr); //table.AddCell(new Phrase(dRow[1].ToString(), fontDynmaicRowsRed)); //table.AddCell(new Phrase(dRow[4].ToString(), fontDynmaicRowsRed)); //table.AddCell(new Phrase(dRow[5].ToString(), fontDynmaicRowsRed)); //table.AddCell(new Phrase(dRow[6].ToString(), fontDynmaicRowsRed)); //table.AddCell(new Phrase(dRow[7].ToString(), fontDynmaicRowsRed)); //table.AddCell(new Phrase(dRow[8].ToString(), fontDynmaicRowsRed)); } else { // table.AddCell(new Phrase(dRow[0].ToString(), fontDynmaicRows)); PdfPCell Cell1Hdr = new PdfPCell(new Phrase(dRow[1].ToString().ToUpper(), fontDynmaicRows)); Cell1Hdr.HorizontalAlignment = Element.ALIGN_LEFT; if (i % 2 == 1) { Cell1Hdr.BackgroundColor = altRow; } else { Cell1Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell1Hdr); //PdfPCell Cell2Hdr = new PdfPCell(new Phrase(dRow[2].ToString(), fontDynmaicRowsNormal)); //Cell2Hdr.HorizontalAlignment = Element.ALIGN_LEFT; //table.AddCell(Cell2Hdr); //PdfPCell Cell3Hdr = new PdfPCell(new Phrase(dRow[3].ToString(), fontDynmaicRows)); //Cell3Hdr.HorizontalAlignment = Element.ALIGN_LEFT; //table.AddCell(Cell3Hdr); PdfPCell Cell4Hdr = new PdfPCell(new Phrase(dRow[4].ToString(), fontDynmaicRowsNormal)); Cell4Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell4Hdr.BackgroundColor = altRow; } else { Cell4Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell4Hdr); PdfPCell Cell5Hdr = new PdfPCell(new Phrase(dRow[5].ToString(), fontDynmaicRowsNormal)); Cell5Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell5Hdr.BackgroundColor = altRow; } else { Cell5Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell5Hdr); PdfPCell Cell6Hdr = new PdfPCell(new Phrase(dRow[6].ToString(), fontDynmaicRowsNormal)); Cell6Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell6Hdr.BackgroundColor = altRow; } else { Cell6Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell6Hdr); PdfPCell Cell7Hdr = new PdfPCell(new Phrase(dRow[7].ToString(), fontDynmaicRowsNormal)); Cell7Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell7Hdr.BackgroundColor = altRow; } else { Cell7Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell7Hdr); PdfPCell Cell8Hdr = new PdfPCell(new Phrase(dRow[8].ToString(), fontDynmaicRowsNormal)); Cell8Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell8Hdr.BackgroundColor = altRow; } else { Cell8Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell8Hdr); // table.AddCell(new Phrase(dRow[1].ToString(), fontDynmaicRows)); //table.AddCell(new Phrase(dRow[4].ToString(), fontDynmaicRowsNormal)); //table.AddCell(new Phrase(dRow[5].ToString(), fontDynmaicRowsNormal)); //table.AddCell(new Phrase(dRow[6].ToString(), fontDynmaicRowsNormal)); //table.AddCell(new Phrase(dRow[7].ToString(), fontDynmaicRowsNormal)); //table.AddCell(new Phrase(dRow[8].ToString(), fontDynmaicRowsNormal)); } } return table; }