Extensions.Blazor.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using FastReport.Table;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Text;
  6. namespace FastReport.Web
  7. {
  8. public static partial class Extensions
  9. {
  10. public static void FindClickedObject(
  11. this Report Report,
  12. ReportComponentBase obj,
  13. int pageN,
  14. Action<ReportComponentBase, ReportPage, int> action)
  15. {
  16. if (Report.PreparedPages == null)
  17. return;
  18. ReportPage page = Report.PreparedPages.GetPage(pageN);
  19. if (page != null)
  20. {
  21. action(obj, page, pageN);
  22. page.Dispose();
  23. }
  24. }
  25. public static void FindEditableObject<T>(
  26. this Report Report,
  27. ReportComponentBase obj,
  28. int pageN,
  29. Action<T, ReportPage, int> action
  30. )
  31. where T : ReportComponentBase
  32. {
  33. if (Report.PreparedPages == null)
  34. return;
  35. bool found = false;
  36. string objectName = obj.Name;
  37. while (pageN < Report.PreparedPages.Count && !found)
  38. {
  39. ReportPage page = Report.PreparedPages.GetPage(pageN);
  40. if (page != null)
  41. {
  42. ObjectCollection allObjects = page.AllObjects;
  43. foreach (Base report_obj in allObjects)
  44. {
  45. if (report_obj is ReportComponentBase c)
  46. {
  47. if (c is TableBase table)
  48. {
  49. for (int i = 0; i < table.RowCount; i++)
  50. {
  51. for (int j = 0; j < table.ColumnCount; j++)
  52. {
  53. TableCell textcell = table[j, i];
  54. if (textcell.Name == objectName)
  55. {
  56. action(textcell as T, page, pageN);
  57. found = true;
  58. break;
  59. }
  60. }
  61. if (found)
  62. break;
  63. }
  64. }
  65. else if (c is T reportComponent)
  66. {
  67. if (c.Name == objectName)
  68. {
  69. action(reportComponent, page, pageN);
  70. found = true;
  71. break;
  72. }
  73. }
  74. if (found)
  75. break;
  76. }
  77. }
  78. page.Dispose();
  79. pageN++;
  80. }
  81. }
  82. }
  83. }
  84. }