WebReport.Tabs.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Linq;
  7. using FastReport.Web.Application;
  8. using System.Drawing;
  9. namespace FastReport.Web
  10. {
  11. public partial class WebReport
  12. {
  13. private int numberNextTab = 1;
  14. private int currentTabIndex;
  15. #region Public Properties
  16. /// <summary>
  17. /// Active report tab
  18. /// </summary>
  19. public ReportTab CurrentTab
  20. {
  21. get => Tabs[CurrentTabIndex];
  22. set => Tabs[CurrentTabIndex] = value;
  23. }
  24. /// <summary>
  25. /// Active tab index
  26. /// </summary>
  27. public int CurrentTabIndex
  28. {
  29. get
  30. {
  31. if (currentTabIndex >= Tabs.Count)
  32. currentTabIndex = Tabs.Count - 1;
  33. if (currentTabIndex < 0)
  34. currentTabIndex = 0;
  35. return currentTabIndex;
  36. }
  37. set => currentTabIndex = value;
  38. }
  39. /// <summary>
  40. /// Shows different ReportPage in tabs.
  41. /// Default value: false.
  42. /// </summary>
  43. public bool SplitReportPagesInTabs { get; set; } = false;
  44. /// <summary>
  45. /// List of report tabs
  46. /// </summary>
  47. public ReportTabCollection Tabs { get; } = new ReportTabCollection() { new ReportTab() { Report = new Report(), Closeable = false } };
  48. // for Tabs max-width
  49. internal int ReportMaxWidth { get; set; } = 800;
  50. #endregion
  51. /// <summary>
  52. /// Add report pages in tabs after load report
  53. /// </summary>
  54. internal void SplitReportPagesByTabs()
  55. {
  56. if (SplitReportPagesInTabs)
  57. {
  58. var report = Report;
  59. for (int pageN = 0; pageN < report.Pages.Count; pageN++)
  60. {
  61. var page = report.Pages[pageN];
  62. if (page is ReportPage reportPage)
  63. {
  64. if (pageN == 0)
  65. {
  66. Tabs[0].Name = reportPage.Name;
  67. Tabs[0].MinPageIndex = 0;
  68. continue;
  69. }
  70. if (!reportPage.Visible)
  71. continue;
  72. int numberPage = 0;
  73. for (int i = 0; i < report.PreparedPages.Count; i++)
  74. {
  75. var preparedPage = report.PreparedPages.GetPage(i);
  76. if (preparedPage.OriginalComponent.Name == reportPage.Name)
  77. {
  78. numberPage = i;
  79. break;
  80. }
  81. }
  82. Tabs.Add(new ReportTab()
  83. {
  84. Closeable = false,
  85. CurrentPageIndex = numberPage,
  86. MinPageIndex = numberPage,
  87. Name = reportPage.Name,
  88. NeedParent = false,
  89. Report = report//,
  90. });
  91. }
  92. }
  93. }
  94. }
  95. internal string GetCurrentTabName()
  96. {
  97. if (SplitReportPagesInTabs)
  98. return Report.GetReportName;
  99. return GetTabName(CurrentTabIndex);
  100. }
  101. internal string GetTabName(int i)
  102. {
  103. if (String.IsNullOrEmpty(Tabs[i].Name))
  104. {
  105. string s = Tabs[i].Report.ReportInfo.Name;
  106. if (String.IsNullOrEmpty(s))
  107. s = Path.GetFileNameWithoutExtension(Tabs[i].Report.FileName);
  108. if (String.IsNullOrEmpty(s))
  109. s = (i + 1).ToString();
  110. return s;
  111. }
  112. else
  113. return Tabs[i].Name;
  114. }
  115. #region Navigation
  116. internal void SetTab(int value)
  117. {
  118. CurrentTabIndex = value;
  119. if (CurrentTabIndex < Tabs.Count - 1)
  120. numberNextTab = value + 1;
  121. else
  122. numberNextTab = value;
  123. //CurrentPageIndex = CurrentTab.MinPageIndex;
  124. }
  125. #endregion
  126. }
  127. }