public byte[] GetProjectGeneralReport(ProjectGeneralReportListViewModel request, DateTime startDate, DateTime dueDate) { var result = new StringBuilder(); result.AppendFormat("{0}, {1}{2}", "Project", request.ProjectName, '\n'); result.AppendFormat("{0}, {1}{2}", "Start date", $"{startDate:dddd, dd MMMM yyyy}", '\n'); result.AppendFormat("{0}, {1}{2}", "Due date", $"{dueDate:dddd, dd MMMM yyyy}", '\n'); result.Append('\n'); result.AppendFormat("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}{11}", "#", "Activity List", "Sprint", "Employee", "Activity", "Priority", "Est.", "Log.", "Progress", "Status", "Modified", '\n'); int iteration = 0; foreach (var activity in request.Activities) { result.AppendFormat("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}{11}", ++iteration, activity.ActivityListName, activity.SprintName, activity.EmployeeName, activity.ActivityName, activity.ActivityPriority, activity.Estimated, activity.Logged, activity.Progress, activity.ActivityStatus, string.Format("{0:dddd, dd MMMM yyyy}", activity.LastModified), '\n'); } result.AppendFormat("{0}, {1}, {2}{3}", "Total time", request.TotalEstimatedTime, request.TotalLoggedTime, '\n'); return(Encoding.Unicode.GetBytes(result.ToString())); }
public byte[] GetProjectGeneralReport(ProjectGeneralReportListViewModel request, DateTime startDate, DateTime dueDate) { var pdf = new PdfDocument(); var page = pdf.AddPage(); page.Orientation = PageOrientation.Landscape; page.Size = PageSize.A3; var pages = new List <PdfPage> { page }; //Create pdf content var doc = CreateDocument(nameof(this.GetProjectGeneralReport), string.Format("{1}, {0}", "Default", "Default")); var commonParameter = new CommonPdfParameter { Document = doc, Pdf = pdf, PdfPages = pages, StartDate = startDate, DueDate = dueDate }; PopulateForGeneralProjectReport(commonParameter, request); //Create renderer for content var renderer = new DocumentRenderer(doc); renderer.PrepareDocument(); var pageSize = GetPageSizeInXRectUnits(page.Size); var pageNumber = 0; foreach (var item in pages) { var gfx = XGraphics.FromPdfPage(item); var container = gfx.BeginContainer(pageSize, pageSize, XGraphicsUnit.Point); gfx.DrawRectangle(XPens.LightGray, pageSize); renderer.RenderPage(gfx, ++pageNumber); gfx.EndContainer(container); } using (MemoryStream ms = new MemoryStream()) { pdf.Save(ms, true); return(ms.ToArray()); } }
private void PopulateForGeneralProjectReport(CommonPdfParameter common, ProjectGeneralReportListViewModel request) { #region Header var section = common.Document.AddSection(); var header = section.Headers.Primary.AddParagraph(); header.AddText($"Project: {request.ProjectName}"); header.Format.Font.Size = common.PdfTableHelper.HeaderSize; header.Format.Font.Color = Colors.DarkBlue; header.Format.Font.Bold = true; header.Format.Font.Italic = true; header.Format.Alignment = ParagraphAlignment.Center; #endregion #region Table var tableCells = common.HeaderNames; var table = CreateTableHeader(ref section, common.PdfTableHelper, tableCells); var iteration = 0; // Not all pdf formats may include the same number of table headers var addColumn = common.PdfTableHelper.GetType() != typeof(PdfTableHelperA4) ? 1 : 0; foreach (var activity in request.Activities) { var row = table.AddRow(); row.Cells[0 + addColumn].AddParagraph(activity.ActivityListName); // Keep the sequence row.Cells[0].AddParagraph((++iteration).ToString()); // As it is here row.Cells[1 + addColumn].AddParagraph(activity.SprintName); row.Cells[2 + addColumn].AddParagraph(activity.EmployeeName); row.Cells[3 + addColumn].AddParagraph(activity.ActivityName); row.Cells[4 + addColumn].AddParagraph(activity.ActivityPriority.ToString()); row.Cells[5 + addColumn].AddParagraph(activity.Estimated.ToString("0.00")); row.Cells[6 + addColumn].AddParagraph(activity.Logged.ToString("0.00")); row.Cells[7 + addColumn].AddParagraph("" + activity.Progress); row.Cells[8 + addColumn].AddParagraph(activity.ActivityStatus.ToString()); row.Cells[9 + addColumn].AddParagraph(string.Format("{0:yyyy-M-d}", activity.LastModified)); if (iteration % common.PdfTableHelper.ItemsPerPage != 0) { continue; } section = common.Document.AddSection(); header = section.Headers.Primary.AddParagraph(); header.AddText(string.Empty); var page = common.Pdf.AddPage(); page.Orientation = PageOrientation.Landscape; page.Size = common.PdfTableHelper.PageSize; common.PdfPages.Add(page); section.AddPageBreak(); table = CreateTableHeader(ref section, common.PdfTableHelper, tableCells); } if (request.Activities.Count % common.PdfTableHelper.ItemsPerPage > 0) { section.AddPageBreak(); } var column = table.AddRow(); column.Borders.Style = BorderStyle.None; column = table.AddRow(); column.Format.Font.Bold = true; column.Cells[2].AddParagraph("Project"); column.Cells[3].AddParagraph(request.ProjectName); column = table.AddRow(); column.Format.Font.Bold = true; column.Cells[2].AddParagraph("Total Estimated:"); column.Cells[3].AddParagraph(request.TotalEstimatedTime.ToString("0.00")); column = table.AddRow(); column.Format.Font.Bold = true; column.Cells[2].AddParagraph("Total Logged:"); column.Cells[3].AddParagraph(request.TotalLoggedTime.ToString("0.00")); table = CreateTableHeader(ref section, common.PdfTableHelper, tableCells); table.Rows.Alignment = RowAlignment.Center; #endregion }