public byte[] GetActivityListsByProjectReport(ActivityListByProjectReportListViewModel request) { 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 }; PopulateForActivityListsByProjectReport(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()); } }
public byte[] GetActivityListsByProjectReport(ActivityListByProjectReportListViewModel request) { var result = new StringBuilder(); result.AppendFormat("Project:, {0}{1}", request.ProjectName, '\n'); result.Append('\n'); result.AppendFormat("{0}, {1}", '#', "Activity list name"); foreach (var activityTypes in request.ActivityTypes) { result.AppendFormat(", {0}%", activityTypes); } result.AppendFormat(", {0}, {1}, {2}, {3}{4}", "Avg.%", "Status", "Planned date", "Actual date", '\n'); var iteration = 0; foreach (var activityList in request.ActivityList) { result.AppendFormat("{0}, {1}", ++iteration, activityList.ActivityListName); foreach (var activityType in activityList.ActivityTypes) { if (activityType.Progress.HasValue) { result.AppendFormat(", {0}%", activityType.Progress); } else { result.Append(", -"); } } if (activityList.Average.HasValue) { result.AppendFormat(", {0}%", activityList?.Average.Value); } else { result.Append(", -"); } var status = "Completed"; if (!activityList.Average.HasValue || activityList.Average.Value == 0) { status = "New"; } else if (activityList.Average.Value < 100) { status = "Ongoing"; } result.AppendFormat(", {0}", status); if (activityList.PlannedDate.HasValue) { result.AppendFormat(", {0}", $"{activityList.PlannedDate.Value:dddd, dd MMMM yyyy}"); } else { result.Append(", -"); } if (activityList.ActualDate.HasValue) { result.AppendFormat(", {0}", $"{activityList.ActualDate.Value:dddd, dd MMMM yyyy}"); } else { result.Append(", -"); } result.Append('\n'); } return(Encoding.Unicode.GetBytes(result.ToString())); }
private void PopulateForActivityListsByProjectReport(CommonPdfParameter common, ActivityListByProjectReportListViewModel 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; foreach (var activity in request.ActivityList) { var columnOrder = 0; var row = table.AddRow(); row.Cells[columnOrder++].AddParagraph((++iteration).ToString()); row.Cells[columnOrder++].AddParagraph(activity.ActivityListName); foreach (var activityType in activity.ActivityTypes) { row.Cells[columnOrder++].AddParagraph(activityType?.Progress?.ToString() ?? "-"); } if (activity.Average.HasValue) { if (activity.Average == 100) { row.Cells[columnOrder++].AddParagraph("Completed"); } else { row.Cells[columnOrder++].AddParagraph(activity.Average == 0 ? "New" : "OnGoing"); } } else { row.Cells[columnOrder++].AddParagraph("New"); } row.Cells[columnOrder++].AddParagraph(activity.ActualDate.HasValue ? $"{activity.ActualDate:yyyy-M-d}" : "-"); row.Cells[columnOrder++].AddParagraph(activity.PlannedDate.HasValue ? $"{activity.PlannedDate:yyyy-M-d}" : "-"); 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.ActivityList.Count % common.PdfTableHelper.ItemsPerPage > 0) { section.AddPageBreak(); } table = CreateTableHeader(ref section, common.PdfTableHelper, tableCells); table.Rows.Alignment = RowAlignment.Center; #endregion }