// GET: Report public ActionResult Index() { using (var db = new Hungtri2019Entities()) { var date = DateTime.Today.AddDays(-1); var items = db.TblHistoryErrors.Where(x => x.CreateDate.Value >= date && x.Val != "").Take(10).OrderByDescending(x => x.CreateDate).ToList(); return(View(items)); } }
public ActionResult TmpReport() { Document pdfDoc = new Document(PageSize.A4, 25, 25, 140f, 15); PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfWriter.PageEvent = new ITextEvents(Server.MapPath("~/Content/Upload/logo.png")); pdfDoc.Open(); //for (int i = 0; i < 10; i++) //{ // Paragraph para = new Paragraph("Hello world. Checking Header Footer", new Font(Font.FontFamily.HELVETICA, 22)); // para.Alignment = Element.ALIGN_CENTER; // pdfDoc.Add(para); // pdfDoc.NewPage(); //} //Chunk chunk = new Chunk("Your Credit Card Statement Report has been Generated", FontFactory.GetFont("Arial", 20, Font.BOLDITALIC, BaseColor.MAGENTA)); //pdfDoc.Add(chunk); PdfPTable table = new PdfPTable(2); table.HeaderRows = 1; table.WidthPercentage = 100; table.HorizontalAlignment = 0; table.SpacingBefore = 20f; table.SpacingAfter = 30f; PdfPCell cell; Chunk chunk; cell = new PdfPCell(); chunk = new Chunk("Bao Cao Tang soi"); cell.AddElement(chunk); cell.Colspan = 2; cell.BackgroundColor = BaseColor.PINK; table.AddCell(cell); table.AddCell(new PdfPCell(new Phrase("Thoi gian Chay")) { BackgroundColor = BaseColor.GREEN }); table.AddCell(new PdfPCell(new Phrase("Danh sach loi")) { BackgroundColor = BaseColor.GREEN }); using (var db = new Hungtri2019Entities()) { var date = DateTime.Today.AddDays(-2); var items = db.TblHistoryErrors.Where(x => x.CreateDate.Value >= date && x.Val != "").OrderByDescending(x => x.CreateDate).Take(20).ToList(); var n = 0; foreach (var item in items) { table.AddCell(item.CreateDate.Value.ToString("MM/dd/yyyy H:mm:ss")); PdfPTable pdfPTable = new PdfPTable(2); foreach (var val in item.Val.Vals()) { n += 1; pdfPTable.AddCell(new PdfPCell(new Phrase(string.Format("{0}.... {1}", n, val.Key))) { Border = 0 }); pdfPTable.AddCell(new PdfPCell(new Phrase(val.Value)) { Border = 0 }); //if (n > 36) //{ // pdfDoc.NewPage(); // break; //} } //table.AddCell(item.Val); table.AddCell(pdfPTable); if (n % 36 == 0) { pdfDoc.Add(new Paragraph("Hello")); pdfDoc.NewPage(); //break; } } } //table.WriteSelectedRows(0, -1, 300, 300, pcb); //table.WriteSelectedRows(1, -1, 40, pdfDoc.PageSize.Height - 30, pdfWriter.DirectContent); pdfDoc.Add(table); pdfWriter.CloseStream = false; pdfDoc.Close(); Response.Buffer = false; Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Credit-Card-Report.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfDoc); Response.End(); return(View()); }