DataSource.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using QuestPDF.Helpers;
  5. namespace QuestPDF.ReportSample
  6. {
  7. public static class DataSource
  8. {
  9. public static ReportModel GetReport()
  10. {
  11. return new ReportModel
  12. {
  13. Title = "Sample Report Document",
  14. HeaderFields = HeaderFields(),
  15. LogoData = Helpers.GetImage("Logo.png"),
  16. Sections = Enumerable.Range(0, 40).Select(x => GenerateSection()).ToList(),
  17. Photos = Enumerable.Range(0, 25).Select(x => GetReportPhotos()).ToList()
  18. };
  19. List<ReportHeaderField> HeaderFields()
  20. {
  21. return new List<ReportHeaderField>
  22. {
  23. new ReportHeaderField()
  24. {
  25. Label = "Scope",
  26. Value = "Internal activities"
  27. },
  28. new ReportHeaderField()
  29. {
  30. Label = "Author",
  31. Value = "Marcin Ziąbek"
  32. },
  33. new ReportHeaderField()
  34. {
  35. Label = "Date",
  36. Value = DateTime.Now.ToString("g")
  37. },
  38. new ReportHeaderField()
  39. {
  40. Label = "Status",
  41. Value = "Completed, found 2 issues"
  42. }
  43. };
  44. }
  45. ReportSection GenerateSection()
  46. {
  47. var sectionLength = Helpers.Random.NextDouble() > 0.75
  48. ? Helpers.Random.Next(20, 40)
  49. : Helpers.Random.Next(5, 10);
  50. return new ReportSection
  51. {
  52. Title = Placeholders.Label(),
  53. Parts = Enumerable.Range(0, sectionLength).Select(x => GetRandomElement()).ToList()
  54. };
  55. }
  56. ReportSectionElement GetRandomElement()
  57. {
  58. var random = Helpers.Random.NextDouble();
  59. if (random < 0.9f)
  60. return GetTextElement();
  61. if (random < 0.95f)
  62. return GetMapElement();
  63. return GetPhotosElement();
  64. }
  65. ReportSectionText GetTextElement()
  66. {
  67. return new ReportSectionText
  68. {
  69. Label = Placeholders.Label(),
  70. Text = Placeholders.Paragraph()
  71. };
  72. }
  73. ReportSectionMap GetMapElement()
  74. {
  75. return new ReportSectionMap
  76. {
  77. Label = "Location",
  78. Location = Helpers.RandomLocation()
  79. };
  80. }
  81. ReportSectionPhotos GetPhotosElement()
  82. {
  83. return new ReportSectionPhotos
  84. {
  85. Label = "Photos",
  86. PhotoCount = Helpers.Random.Next(1, 15)
  87. };
  88. }
  89. ReportPhoto GetReportPhotos()
  90. {
  91. return new ReportPhoto()
  92. {
  93. Comments = Placeholders.Sentence(),
  94. Date = DateTime.Now - TimeSpan.FromDays(Helpers.Random.NextDouble() * 100),
  95. Location = Helpers.RandomLocation()
  96. };
  97. }
  98. }
  99. }
  100. }