Esempio n. 1
0
        public async Task<ActionResult> Index()
        {
            if (User.Identity.IsAuthenticated == false)
                return RedirectToAction("Login", "Account");
            var curUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());
            var userPlaceID = curUser.PlaceId;

            List<SegmentSurvey> surveys = await ApiHelper.GetSegmentSurveysByPlaceID(userPlaceID);
            DashBoardViewModel data = DataTools.Get_X_Year_Road_Information(userPlaceID);

            ReportViewModel result = new ReportViewModel(surveys, data, curUser.PlaceName, ApiHelper.GetPlaceById(curUser.PlaceId).Result.Type);

            return View(result);
        }
Esempio n. 2
0
        public void GenerateExcel()
        {
            if (User.Identity.IsAuthenticated == false)
                return;
            var user = UserManager.FindByIdAsync(User.Identity.GetUserId()).Result;
            List<SegmentSurvey> surveys = ApiHelper.GetSegmentSurveysByPlaceID(user.PlaceId).Result;
            surveys.OrderBy(suv=>suv.RoadId);
            DashBoardViewModel X_Year_data = DataTools.Get_X_Year_Road_Information(user.PlaceId);
            ReportViewModel result = new ReportViewModel(surveys, X_Year_data, user.PlaceName, ApiHelper.GetPlaceById(user.PlaceId).Result.Type);
            using (var excelPackage = new ExcelPackage())
            {
                // edit overall information for summary report
                excelPackage.Workbook.Properties.Author = "COPACES-CC Data Management System";
                excelPackage.Workbook.Properties.Company = "Georgia Institute of Technology";
                excelPackage.Workbook.Worksheets.Add("Summary Report");
                excelPackage.Workbook.Worksheets.Add("Detailed Report");
                var sheet1 = excelPackage.Workbook.Worksheets[1];
                sheet1.Name = "Summary Report";
                sheet1.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                sheet1.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
                sheet1.Cells.Style.Font.Size = 9;
                sheet1.Cells.Style.Font.Name = "Calibri";





                // header, 2 rows
                sheet1.Cells["A1:I1"].Merge = true;
                sheet1.Cells["A1"].Value = "Segment Condition Summary for " + result.Jurisdiction + " " + result.PlaceType.ToUpper();
                sheet1.Cells["A1"].Style.Font.Size = 13;
                sheet1.Cells["A1"].Style.Font.Bold = true;
                sheet1.Cells["A2:C2"].Merge = true;
                sheet1.Cells[2, 1].Value = "Total Road Mileage: " + result.ReportData.TotalLength/5280+"  miles";
                sheet1.Cells["G2:I2"].Merge = true;
                sheet1.Cells["G2"].Value = "Report generated on " + result.dateTime;


                // coloum names
                sheet1.Cells["A3"].Value = "District";
                sheet1.Cells["B3"].Value = "Road ID";
                sheet1.Cells["C3"].Value = "Road Name";
                sheet1.Cells["D3"].Value = "Inventory ID";
                sheet1.Cells["E3"].Value = "From";
                sheet1.Cells["F3"].Value = "To";
                sheet1.Cells["G3"].Value = "Survey Date";
                sheet1.Cells["H3"].Value = "COPACES Rating";
                sheet1.Cells["I3"].Value = "Windshield Score";

                int row = 4;
                foreach (var item in surveys)
                {
                    int col = 1;
                    var road = ApiHelper.GetRoadById(item.RoadId).Result;
                    var seg = ApiHelper.GetSegmentByRoadIdAndSequenceId(item.RoadId, item.SequenceId).Result;
                    if (seg == null) continue;
                    sheet1.Cells[row, col++].Value = road.District;
                    sheet1.Cells[row, col++].Value = item.RoadId;
                    sheet1.Cells[row, col++].Value = road.Name;
                    sheet1.Cells[row, col++].Value = item.InventId;
                    sheet1.Cells[row, col++].Value = seg.From;
                    sheet1.Cells[row, col++].Value = seg.To;
                    var datatime = (DateTime)item.RoadSurveyDate;
                    sheet1.Cells[row, col++].Value = datatime.ToString("d");
                    if (item.CopacesRating != null)
                    {
                        sheet1.Cells[row, col++].Value = item.CopacesRating;
                    }
                    else
                    {
                        sheet1.Cells[row, col++].Value = "";
                    }
                    if (item.IsWindshieldSurvey)
                    {
                        sheet1.Cells[row, col++].Value = item.WindshieldScore;
                    }
                    if (row % 4 == 0)
                    {
                        for (int i = 1; i < 10; i++)
                        {
                            sheet1.Cells[row, i].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                        }
                    }

                    for (int i = 1; i < 10; i++)
                    {
                        sheet1.Cells[row, i].Style.Border.Right.Style = ExcelBorderStyle.Thin;

                    }

                    row++;
                }
                for (int i = 1; i < 10; i++)
                {
                    sheet1.Cells[row, i].Style.Border.Top.Style = ExcelBorderStyle.Thin;

                }



                // set columns style
                sheet1.Column(1).Width = 12;
                sheet1.Column(2).Width = 13.5;
                sheet1.Column(3).Width = 12.6;
                sheet1.Column(4).Width = 9.4;
                sheet1.Column(5).Width = 14;
                sheet1.Column(6).Width = 14;
                sheet1.Column(7).Width = 12;
                sheet1.Column(8).Width = 12.5;
                sheet1.Column(9).Width = 14;
                for (int i = 1; i < 10; i++)
                {
                    sheet1.Cells[3, i].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    sheet1.Cells[3, i].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                }









                var sheet2 = excelPackage.Workbook.Worksheets[2];
                sheet2.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                sheet2.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
                sheet2.Cells.Style.Font.Size = 8;
                sheet2.Cells.Style.Font.Name = "Calibri";

                sheet2.Cells["A1:AB1"].Merge = true;
                sheet2.Cells["A1"].Value = "Detailed Pavement Condition Survey for " + result.Jurisdiction + " " + result.PlaceType.ToUpper();
                sheet2.Cells["A1"].Style.Font.Size = 13;
                sheet2.Cells["A1"].Style.Font.Bold = true;
                sheet2.Cells["K2:P2"].Merge = true;
                sheet2.Cells["K2"].Value = "Report Peroid: Lastest";
                sheet2.Cells["A4:F4"].Merge = true;
                sheet2.Cells[4, 1].Value = "Total Road Mileage: " + String.Format("{0:0.00}", (result.ReportData.TotalLength / 5280)).ToString() + "miles" + "   Total Survey Mileage: " + String.Format("{0:0.00}",(result.ReportData.Finished_X_yearLength[0] / 5280)).ToString() + "  miles";
                sheet2.Cells["W4:AB4"].Merge = true;
                sheet2.Cells["W4"].Value = "Report generated on " + result.dateTime;



                sheet2.Cells["A5:C5"].Merge = true;
                sheet2.Cells["A5"].Value = "Location";
                sheet2.Cells["D5:E5"].Merge = true;
                sheet2.Cells["D5"].Value = "Rut Depth";
                sheet2.Cells["F5:I5"].Merge = true;
                sheet2.Cells["F5"].Value = "Load Cracking";
                sheet2.Cells["J5:K5"].Merge = true;
                sheet2.Cells["J5"].Value = "Block Cracking";
                sheet2.Cells["L5:N5"].Merge = true;
                sheet2.Cells["L5"].Value = "Refection Cracking";
                sheet2.Cells["O5:P5"].Merge = true;
                sheet2.Cells["O5"].Value = "Raveling";
                sheet2.Cells["Q5:R5"].Merge = true;
                sheet2.Cells["Q5"].Value = "Edge Distress";
                sheet2.Cells["S5:T5"].Merge = true;
                sheet2.Cells["S5"].Value = "Bleeding/ Flushing";
                sheet2.Cells["U5:V5"].Merge = true;
                sheet2.Cells["U5"].Value = "Corrugation/ Pushing";
                sheet2.Cells["W5:X5"].Merge = true;
                sheet2.Cells["W5"].Value = "Loss Pavement Section";
                sheet2.Cells["Z5"].Value = "COPACES Rating";
                sheet2.Cells["AA5"].Value = "Windshield Survey";
                sheet2.Cells["AB5"].Value = "Windshield Score";

                var coloum = 1;
                for (int i = 1; i < 29; i++)
                {
                    sheet2.Cells[5, i].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                    sheet2.Cells[5, i].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    sheet2.Cells[5, i].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                    sheet2.Cells[5, i].Style.WrapText = true;
                    sheet2.Cells[6, i].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                    sheet2.Cells[6, i].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    sheet2.Cells[6, i].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                    sheet2.Cells[6, i].Style.TextRotation = 90;
                }

                sheet2.Cells[6, coloum++].Value = "Road Name";
                sheet2.Cells[6, coloum++].Value = "Survey Date";
                sheet2.Cells[6, coloum++].Value = "Inventory Id";
                sheet2.Cells[6, coloum++].Value = "Outside WP(1/8 in)";
                sheet2.Cells[6, coloum++].Value = "Inside WP(1/8)";
                sheet2.Cells[6, coloum++].Value = "Severity1";
                sheet2.Cells[6, coloum++].Value = "Severity2";
                sheet2.Cells[6, coloum++].Value = "Severity3";
                sheet2.Cells[6, coloum++].Value = "Severity4";
                sheet2.Cells[6, coloum++].Value = "% of Sample";
                sheet2.Cells[6, coloum++].Value = "Severity(1,2,3)";
                sheet2.Cells[6, coloum++].Value = "No. of Cracks";
                sheet2.Cells[6, coloum++].Value = "Total Length";
                sheet2.Cells[6, coloum++].Value = "Severity(1,2,3)";
                sheet2.Cells[6, coloum++].Value = "% of Sample";
                sheet2.Cells[6, coloum++].Value = "Severity(1,2,3)";
                sheet2.Cells[6, coloum++].Value = "% of Sample";
                sheet2.Cells[6, coloum++].Value = "Severity(1,2,3)";
                sheet2.Cells[6, coloum++].Value = "% of Sample";
                sheet2.Cells[6, coloum++].Value = "Severity(1,2,3)";
                sheet2.Cells[6, coloum++].Value = "% of Sample";
                sheet2.Cells[6, coloum++].Value = "Severity(1,2,3)";
                sheet2.Cells[6, coloum++].Value = "% of Sample";
                sheet2.Cells[6, coloum++].Value = "Severity(1,2,3)";
                sheet2.Cells[6, coloum++].Value = "Patches & Potholes";

                row = 7;
                foreach (var item in surveys)
                {
                    if ((row - 7) % 4 == 0)
                    {
                        for (int i = 1; i < 29; i++)
                        {
                            sheet2.Cells[row, i].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                        }
                    }
                    int col = 1;
                    var roadNmae = DataTools.GetRoadNameById(item.RoadId);
                    var seg = ApiHelper.GetSegmentByRoadIdAndSequenceId(item.RoadId, item.SequenceId).Result;
                    if (seg == null) continue;
                    sheet2.Cells[row, col].Style.Border.Left.Style = ExcelBorderStyle.Thin;
                    sheet2.Cells[row, col++].Value = roadNmae;
                    var date = (DateTime)item.SegSurveyDate;
                    sheet2.Cells[row, col++].Value = date.ToString("d");
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    sheet2.Cells[row, col++].Value = item.InventId;

                    if (item.RutOutWp == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.RutOutWp.ToString();
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.RutInWp == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.RutInWp.ToString();
                    }

                    if (item.LoadLevel1 == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.LoadLevel1;
                    }

                    if (item.LoadLevel2 == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.LoadLevel2;
                    }

                    if (item.LoadLevel3 == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.LoadLevel3;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.LoadLevel4 == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.LoadLevel4;
                    }

                    if (item.BlockPercentage == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.BlockPercentage;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.BlockLevel == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.BlockLevel;
                    }

                    if (item.ReflectNum == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.ReflectNum;
                    }

                    if (item.ReflectLength == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.ReflectLength;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.ReflectLevel == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.ReflectLevel;
                    }

                    if (item.RavelPercentage == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.RavelPercentage;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.RavelLevel == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.RavelLevel;
                    }

                    if (item.EdgePercentage == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.EdgePercentage;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.EdgeLevel == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.EdgeLevel;
                    }

                    if (item.BleedPercentage == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.BleedPercentage;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.BleedLevel == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.BleedLevel;
                    }

                    if (item.CorrugPercentage == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.CorrugPercentage;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.CorrugLevel == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.CorrugLevel;
                    }

                    if (item.LossPavPercentage == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.LossPavPercentage;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.LossPavLevel == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.LossPavLevel;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.PatchPotholeNum == null)
                    {
                        sheet2.Cells[row, col++].Value = 0;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = item.PatchPotholeNum;
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.CopacesRating != null)
                    {
                        sheet2.Cells[row, col++].Value = item.CopacesRating;
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = "";
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    if (item.IsWindshieldSurvey == true)
                    {
                        sheet2.Cells[row, col++].Value = "Yes";
                    }
                    else
                    {
                        sheet2.Cells[row, col++].Value = "No";
                    }
                    sheet2.Cells[row, col].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    sheet2.Cells[row++, col].Value = item.WindshieldScore;
                }
                for (int k = 1; k < 29; k++)
                {
                    sheet2.Cells[row, k].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                }
                sheet2.Cells[6, 1].Style.Border.Left.Style = ExcelBorderStyle.Thin;
                sheet2.Cells[5, 1].Style.Border.Left.Style = ExcelBorderStyle.Thin;

                sheet2.Column(1).Width = 11;
                sheet2.Column(2).Width = 10;
                sheet2.Column(3).Width = 8;
                for (int j = 4; j < 21; j++)
                {
                    sheet2.Column(j).Width = 3;
                }
                sheet2.Column(10).Width = 3.2;
                sheet2.Column(21).Width = 4;
                sheet2.Column(22).Width = 4;
                sheet2.Column(23).Width = 3.14;
                sheet2.Column(24).Width = 3.14;
                sheet2.Column(25).Width = 4;
                sheet2.Column(26).Width = 6.57;
                sheet2.Column(27).Width = 8.29;
                sheet2.Column(28).Width = 8.29;

                // save to memory stream;
                Response.ClearContent();
                Response.BinaryWrite(excelPackage.GetAsByteArray());
                Response.AddHeader("content-disposition",
                          "attachment;filename=results.xlsx");
                Response.ContentType = "application/excel";
                Response.Flush();
                Response.End();
            }
        }
Esempio n. 3
0
        public FileStreamResult  GeneratePDF()
        {
            if (User.Identity.IsAuthenticated == false)
                return null;
            // prepare data
            var user = UserManager.FindByIdAsync(User.Identity.GetUserId()).Result;
            List<SegmentSurvey> surveys = ApiHelper.GetSegmentSurveysByPlaceID(user.PlaceId).Result;
            surveys.OrderBy(suv => suv.RoadId);
            DashBoardViewModel X_Year_data = DataTools.Get_X_Year_Road_Information(user.PlaceId);
            ReportViewModel result = new ReportViewModel(surveys, X_Year_data, user.PlaceName, ApiHelper.GetPlaceById(user.PlaceId).Result.Type);

            // PDF initial setting
            Document document = new Document(PageSize.A4.Rotate(), 10, 10, 10, 10);
            MemoryStream stream = new MemoryStream();

            // set fonts
            BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
            Font title_font = new Font(bfTimes, 10, Font.NORMAL, Color.BLACK);
            Font basefont = new Font(bfTimes, 8, Font.NORMAL, Color.BLACK);

            try
            {
                PdfWriter pdfWriter = PdfWriter.GetInstance(document, stream);
                pdfWriter.CloseStream = false;
                document.Open();
                Paragraph title = new Paragraph("Segment Condition Summary for   " + result.Jurisdiction + " " + result.PlaceType.ToUpper(), title_font);
                title.Alignment = Element.ALIGN_CENTER;
                document.Add(title);
                document.Add(new Paragraph("                                           Total Road Mileage: " + result.ReportData.TotalLength / 5280 + "miles " + "                                                                                                                                                                                                                        Report generated on " + result.dateTime, basefont));
                document.Add(new Paragraph("          "));
                /*    SECTION 1
                 *    FOR SUMMARY REPORT
                 * 
                 * 
                 * 
                 * 
                 */
                // Add table content blow:
                PdfPTable table = new PdfPTable(9);
                PdfPCell[] cols = new PdfPCell[9];

                PdfPCell col1 = new PdfPCell(new Paragraph("District", basefont));
                col1.BorderWidthTop = 0.3f;
                table.AddCell(col1);
                PdfPCell col2 = new PdfPCell(new Paragraph("Road ID", basefont));
                col2.BorderWidthTop = 0.3f;
                table.AddCell(col2);
                PdfPCell col3 = new PdfPCell(new Paragraph("Road Name", basefont));
                col3.BorderWidthTop = 0.3f;
                table.AddCell(col3);
                PdfPCell col4 = new PdfPCell(new Paragraph("Inventory ID", basefont));
                col4.BorderWidthTop = 0.3f;
                table.AddCell(col4);
                PdfPCell col5 = new PdfPCell(new Paragraph("From", basefont));
                col5.BorderWidthTop = 0.3f;
                table.AddCell(col5);
                PdfPCell col6 = new PdfPCell(new Paragraph("To", basefont));
                col6.BorderWidthTop = 0.3f;
                table.AddCell(col6);
                PdfPCell col7 = new PdfPCell(new Paragraph("Survey Date", basefont));
                col7.BorderWidthTop = 0.3f;
                table.AddCell(col7);
                PdfPCell col8 = new PdfPCell(new Paragraph("COPACES Rating", basefont));
                col8.BorderWidthTop = 0.3f;
                table.AddCell(col8);
                PdfPCell col9 = new PdfPCell(new Paragraph("Windshield Score", basefont));
                col9.BorderWidthTop = 0.3f;
                table.AddCell(col9);




                int row = 1;
                foreach (var item in surveys)
                {
                    var road = ApiHelper.GetRoadById(item.RoadId).Result;
                    var seg = ApiHelper.GetSegmentByRoadIdAndSequenceId(item.RoadId, item.SequenceId).Result;
                    if (seg == null) continue;
                    cols[0] = new PdfPCell(new Paragraph(road.District, basefont));
                    cols[1] = new PdfPCell(new Paragraph(item.RoadId, basefont));
                    cols[2] = new PdfPCell(new Paragraph(road.Name, basefont));    
                    cols[3] = new PdfPCell(new Paragraph(item.InventId.ToString(), basefont));    
                    cols[4] = new PdfPCell(new Paragraph(seg.From, basefont));    
                    cols[5] = new PdfPCell(new Paragraph(seg.To, basefont));    
                    var datatime = (DateTime)item.RoadSurveyDate;
                    cols[6] = new PdfPCell(new Paragraph(datatime.ToString("d"), basefont));   
                    if (item.CopacesRating!=null){
                        cols[7] = new PdfPCell(new Paragraph(item.CopacesRating.ToString(), basefont));  
                    } else {
                        cols[7] = new PdfPCell(new Paragraph("", basefont));  

                    }
                    if(item.IsWindshieldSurvey){
                        cols[8] = new PdfPCell(new Paragraph(item.WindshieldScore.ToString(), basefont)); 
                    } else{
                        cols[8] = new PdfPCell(new Paragraph("", basefont)); 
                    }
                    for (int i = 0; i < cols.Length; i++)
                    {

                        cols[i].BorderWidthTop = 0;
                        cols[i].BorderWidthBottom = 0;
                        cols[i].BorderWidthLeft = 0.3f;
                        cols[i].BorderWidthRight = 0.3f;
                    }
                    if (row % 4 == 0)
                    {
                        for (int i = 0; i < cols.Length; i++)
                        {
                            cols[i].BorderWidthTop = 0.3f;
                        }
                    }

                    for (int i = 0; i < cols.Length; i++)
                    {
                        table.AddCell(cols[i]);
                    }

                    row++;
                }
                for (int i = 0; i < cols.Length; i++)
                {
                    cols[i] = new PdfPCell(new Paragraph("", basefont));
                    cols[i].BorderWidth = 0;
                    cols[i].BorderWidthTop = 0.3f;
                    table.AddCell(cols[i]);
                }
                document.Add(table);





                /*          SECTION 2
                 *          FOR DETAILED REPORT
                 * 
                 * 
                 */
                document.NewPage();
                Paragraph title2 = new Paragraph("Detailed Pavement Condition Survey for   " + result.Jurisdiction + " " + result.PlaceType.ToUpper(), title_font);
                title2.Alignment = Element.ALIGN_CENTER;
                document.Add(title2);
                document.Add(new Paragraph("                                           Total Road Mileage: " + String.Format("{0:0.00}",result.ReportData.TotalLength / 5280) + "miles "+"                                                                                                                                                                                                                        Report generated on " + result.dateTime, basefont));
                Paragraph reportTime = new Paragraph("Report Peroid: Last", basefont);
                reportTime.Alignment = Element.ALIGN_CENTER;
                document.Add(reportTime);
                document.Add(new Paragraph("          "));
                PdfPTable Detailed_table = new PdfPTable(28);
                float[] widths = new float[] { 11f, 14.5f, 11f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 13f, 13f, 13f };
                Detailed_table.SetWidths(widths);
                Detailed_table.HorizontalAlignment=Element.ALIGN_CENTER;

                row=1;
                PdfPCell Location =	new PdfPCell(new Phrase("Location"));
	            Location.Colspan=3;
                Detailed_table.AddCell(Location);
                PdfPCell RutDepth= new PdfPCell(new Phrase("Rut Depth"));
                RutDepth.Colspan=2;
                Detailed_table.AddCell(RutDepth);
                PdfPCell LoadCracking= new PdfPCell(new Phrase("Load Cracking"));
                LoadCracking.Colspan=4;
                Detailed_table.AddCell(LoadCracking);
                PdfPCell BlockCracking= new PdfPCell(new Phrase("Block Cracking "));
                BlockCracking.Colspan=2;
                Detailed_table.AddCell(BlockCracking);
                PdfPCell RefectionCracking= new PdfPCell(new Phrase(" Refection Cracking"));
                RefectionCracking.Colspan=3;
                Detailed_table.AddCell(RefectionCracking);
                PdfPCell Raveling= new PdfPCell(new Phrase("Raveling"));
                Raveling.Colspan=2;
                Detailed_table.AddCell(Raveling);
                PdfPCell EdgeDistress= new PdfPCell(new Phrase("Edge Distress"));
                EdgeDistress.Colspan=2;
                Detailed_table.AddCell(EdgeDistress);
                PdfPCell Bleeding= new PdfPCell(new Phrase(" Bleeding/ Flushing"));
                Bleeding.Colspan=2;
                Detailed_table.AddCell(Bleeding);
                PdfPCell Corrugation= new PdfPCell(new Phrase("Corrugation/Pushing"));
                Corrugation.Colspan=2;
                Detailed_table.AddCell(Corrugation);
                PdfPCell LossPavement= new PdfPCell(new Phrase("Loss Pavement"));
                LossPavement.Colspan=2;
                Detailed_table.AddCell(LossPavement);
                PdfPCell gap= new PdfPCell(new Phrase(" "));
                Detailed_table.AddCell(gap);
                PdfPCell COPACESRating= new PdfPCell(new Phrase("COPACES Rating"));
                Detailed_table.AddCell(COPACESRating);
                PdfPCell WindshieldSurvey= new PdfPCell(new Phrase("Windshield Survey"));
                Detailed_table.AddCell(WindshieldSurvey);
                PdfPCell WindshieldScore= new PdfPCell(new Phrase("Windshield Score"));
                Detailed_table.AddCell(WindshieldSurvey);

                // third line
                PdfPCell RoadName = new PdfPCell(new Paragraph("Road Name"));
                RoadName.Rotation = 90;
                Detailed_table.AddCell(RoadName);
                PdfPCell SurveyDate= new PdfPCell(new Paragraph("Survey Date"));
                SurveyDate.Rotation = 90;
                Detailed_table.AddCell(SurveyDate);
                PdfPCell InventoryID = new PdfPCell(new Paragraph("Inventory ID"));
                InventoryID.Rotation = 90;
                Detailed_table.AddCell(InventoryID);
                PdfPCell OutsideWP= new PdfPCell(new Paragraph("Outside WP(1/8 in)"));
                OutsideWP.Rotation = 90;
                Detailed_table.AddCell(OutsideWP);
                PdfPCell InsideWP=new PdfPCell(new Paragraph("Inside WP(1/8 in)"));
                InsideWP.Rotation = 90;
                Detailed_table.AddCell(InsideWP);
                PdfPCell Severity1=new PdfPCell(new Paragraph("Severity1"));
                Severity1.Rotation = 90;
                Detailed_table.AddCell(Severity1);
                PdfPCell Severity2 = new PdfPCell(new Paragraph("Severity2"));
                Severity2.Rotation = 90;
                Detailed_table.AddCell(Severity2);
                PdfPCell Severity3 = new PdfPCell(new Paragraph("Severity3"));
                Severity3.Rotation = 90;
                Detailed_table.AddCell(Severity3);
                PdfPCell Severity4 = new PdfPCell(new Paragraph("Severity4"));
                Severity4.Rotation = 90;
                Detailed_table.AddCell(Severity4);
                PdfPCell Sample = new PdfPCell(new Paragraph("% of Sample"));
                Sample.Rotation = 90;
                Detailed_table.AddCell(Sample);
                PdfPCell Severity123 = new PdfPCell(new Paragraph("Severity(1,2,3)"));
                Severity123.Rotation = 90;
                Detailed_table.AddCell(Severity123);
                PdfPCell NoCracks = new PdfPCell(new Paragraph("No. Of Cracks"));
                NoCracks.Rotation = 90;
                Detailed_table.AddCell(NoCracks);
                PdfPCell TotalLength = new PdfPCell(new Paragraph("Total Length"));
                TotalLength.Rotation = 90;
                Detailed_table.AddCell(TotalLength);
                Detailed_table.AddCell(Severity123);
                Detailed_table.AddCell(Sample);
                Detailed_table.AddCell(Severity123);
                Detailed_table.AddCell(Sample);
                Detailed_table.AddCell(Severity123);
                Detailed_table.AddCell(Sample);
                Detailed_table.AddCell(Severity123);
                Detailed_table.AddCell(Sample);
                Detailed_table.AddCell(Severity123);
                Detailed_table.AddCell(Sample);
                Detailed_table.AddCell(Severity123);
                PdfPCell Patches = new PdfPCell(new Paragraph("Patches & Potholes"));
                Patches.Rotation = 90;
                Detailed_table.AddCell(Patches);
                Detailed_table.AddCell(gap);
                Detailed_table.AddCell(gap);
                Detailed_table.AddCell(gap);


                row = 7;
                cols= new PdfPCell[28];
                foreach (var item in surveys)
                {
                    //var road = ApiHelper.GetRoadById(item.RoadId).Result;
                    var roadName = DataTools.GetRoadNameById(item.RoadId);
                    var seg = ApiHelper.GetSegmentByRoadIdAndSequenceId(item.RoadId, item.SequenceId).Result;
                    if (seg == null) continue;
                    cols[0] = new PdfPCell(new Paragraph(roadName));
                    var date = (DateTime)item.SegSurveyDate;
                    cols[1] = new PdfPCell(new Paragraph(date.ToString("d")));
                    cols[2] = new PdfPCell(new Paragraph(item.InventId.ToString()));
                    cols[3] = item.RutOutWp == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.RutOutWp.ToString()));
                    cols[4] = item.RutInWp == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.RutInWp.ToString()));
                    cols[5] = item.LoadLevel1 == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.LoadLevel1.ToString()));
                    cols[6] = item.LoadLevel2 == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.LoadLevel2.ToString()));
                    cols[7] = item.LoadLevel3 == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.LoadLevel3.ToString()));
                    cols[8] = item.LoadLevel4 == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.LoadLevel4.ToString()));
                    cols[9] = item.BlockPercentage == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.BlockPercentage.ToString()));
                    cols[10] = item.BlockLevel == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.BlockLevel.ToString()));
                    cols[11] = item.ReflectNum == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.ReflectNum.ToString()));
                    cols[12] = item.ReflectLength == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.ReflectLength.ToString()));
                    cols[13] = item.ReflectLevel == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.ReflectLevel.ToString()));
                    cols[14] = item.RavelPercentage == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.RavelPercentage.ToString()));
                    cols[15] = item.RavelLevel == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.RavelLevel.ToString()));
                    cols[16] = item.EdgePercentage == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.EdgePercentage.ToString()));
                    cols[17] = item.EdgeLevel == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.BleedPercentage.ToString()));
                    cols[18] = item.BleedPercentage == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.BleedPercentage.ToString()));
                    cols[19] = item.BleedLevel == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.BleedLevel.ToString()));
                    cols[20] = item.CorrugPercentage == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.CorrugPercentage.ToString()));
                    cols[21] = item.CorrugLevel == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.CorrugLevel.ToString()));
                    cols[22] = item.LossPavPercentage == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.LossPavPercentage.ToString()));
                    cols[23] = item.LossPavLevel == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.LossPavLevel.ToString()));
                    cols[24] = item.PatchPotholeNum == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.PatchPotholeNum.ToString()));
                    cols[25] = item.CopacesRating == null ? new PdfPCell(new Paragraph("0")) : new PdfPCell(new Paragraph(item.CopacesRating.ToString()));
                    cols[26] = item.IsWindshieldSurvey == true ? new PdfPCell(new Paragraph("Yes")) : new PdfPCell(new Paragraph("No"));
                    cols[27] = (item.WindshieldScore == null ) ? new PdfPCell(new Paragraph("")) : new PdfPCell(new Paragraph(item.WindshieldScore.ToString()));

                    for (int i = 0; i < cols.Length; i++)
                    {
                        cols[i].BorderWidth = 0;
                        cols[i].HorizontalAlignment = Element.ALIGN_CENTER;
                    }
                    cols[2].BorderWidthRight = 0.3f;
                    cols[4].BorderWidthRight = 0.3f;
                    cols[8].BorderWidthRight = 0.3f;
                    cols[10].BorderWidthRight = 0.3f;
                    cols[13].BorderWidthRight = 0.3f;
                    cols[15].BorderWidthRight = 0.3f;
                    cols[17].BorderWidthRight = 0.3f;
                    cols[19].BorderWidthRight = 0.3f;
                    cols[26].BorderWidthRight = 0.3f;
                    cols[25].BorderWidthRight = 0.3f;
                    cols[24].BorderWidthRight = 0.3f;
                    cols[23].BorderWidthRight = 0.3f;
                    cols[21].BorderWidthRight = 0.3f;
                    cols[0].BorderWidthLeft = 0.3f;
                    cols[cols.Length - 1].BorderWidthRight = 0.3f;
                    if ((row - 7) % 4 == 0)
                    {
                        for (int i = 0; i < cols.Length; i++)
                        {
                            cols[i].BorderWidthTop = 0.3f;
                        }
                    }
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Detailed_table.AddCell(cols[i]);
                    }
                    row++;
                }
                for (int i = 0; i < cols.Length; i++)
                {
                    cols[i] = new PdfPCell(new Paragraph("", basefont));
                    cols[i].BorderWidth = 0;
                    cols[i].BorderWidthTop = 0.3f;
                    Detailed_table.AddCell(cols[i]);
                }
                document.Add(Detailed_table);
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            document.Close();

            stream.Flush(); //Always catches me out
            stream.Position = 0; //Not sure if this is required

            return File(stream, "application/pdf", "Report.pdf");


        }