ReportDataForm.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using FastReport.Data;
  5. using FastReport.Utils;
  6. namespace FastReport.Forms
  7. {
  8. internal partial class ReportDataForm : BaseDialogForm
  9. {
  10. private Report report;
  11. private bool IsBusinessObjectNode(TreeNode node)
  12. {
  13. while (node != null)
  14. {
  15. if (node.Tag is BusinessObjectDataSource)
  16. return true;
  17. node = node.Parent;
  18. }
  19. return false;
  20. }
  21. private void UpdateNames(TreeNodeCollection root)
  22. {
  23. foreach (TreeNode node in root)
  24. {
  25. DataComponentBase data = node.Tag as DataComponentBase;
  26. if (data != null && !(data is DataConnectionBase))
  27. node.Text = cbAliases.Checked ? data.Alias : data.Name;
  28. UpdateNames(node.Nodes);
  29. }
  30. }
  31. private void UpdateNames()
  32. {
  33. tvData.BeginUpdate();
  34. UpdateNames(tvData.Nodes);
  35. tvData.EndUpdate();
  36. }
  37. private void CheckEnabled(TreeNodeCollection root)
  38. {
  39. foreach (TreeNode node in root)
  40. {
  41. DataComponentBase data = node.Tag as DataComponentBase;
  42. if (data != null && !(data is DataConnectionBase))
  43. data.Enabled = node.Checked;
  44. // do not check relation columns - they should be handled by its original datasources
  45. if (!(data is Relation))
  46. CheckEnabled(node.Nodes);
  47. }
  48. }
  49. private void EnableItem(TreeNodeCollection root, DataComponentBase item)
  50. {
  51. foreach (TreeNode node in root)
  52. {
  53. DataComponentBase data = node.Tag as DataComponentBase;
  54. if (data == item)
  55. {
  56. node.Checked = true;
  57. break;
  58. }
  59. CheckEnabled(node.Nodes);
  60. }
  61. }
  62. private void ReportDataForm_FormClosing(object sender, FormClosingEventArgs e)
  63. {
  64. if (DialogResult == DialogResult.OK)
  65. Done();
  66. }
  67. private void tvData_BeforeExpand(object sender, TreeViewCancelEventArgs e)
  68. {
  69. TreeNode node = e.Node;
  70. if (!node.Checked && IsBusinessObjectNode(node))
  71. {
  72. node.Checked = true;
  73. }
  74. }
  75. private void tvData_AfterCheck(object sender, TreeViewEventArgs e)
  76. {
  77. TreeNode node = e.Node;
  78. if (IsBusinessObjectNode(node))
  79. {
  80. BusinessObjectConverter conv = new BusinessObjectConverter(report.Dictionary);
  81. conv.CheckNode(node);
  82. }
  83. else
  84. {
  85. DataComponentBase data = node.Tag as DataComponentBase;
  86. if (node.Checked && data is Relation)
  87. EnableItem(tvData.Nodes, (data as Relation).ParentDataSource);
  88. }
  89. }
  90. private void cbAliases_CheckedChanged(object sender, EventArgs e)
  91. {
  92. UpdateNames();
  93. }
  94. private void Init()
  95. {
  96. tvData.CreateNodes(report.Dictionary);
  97. // remove existing business objects nodes
  98. for (int i = 0; i < tvData.Nodes.Count; i++)
  99. {
  100. if (tvData.Nodes[i].Tag is BusinessObjectDataSource)
  101. {
  102. tvData.Nodes.RemoveAt(i);
  103. i--;
  104. }
  105. }
  106. // create nodes using BOConverter
  107. BusinessObjectConverter conv = new BusinessObjectConverter(report.Dictionary);
  108. foreach (DataSourceBase data in report.Dictionary.DataSources)
  109. {
  110. if (data is BusinessObjectDataSource)
  111. conv.CreateTree(tvData.Nodes, data);
  112. }
  113. }
  114. private void Done()
  115. {
  116. CheckEnabled(tvData.Nodes);
  117. report.Dictionary.UpdateRelations();
  118. // create business objects based on tree
  119. BusinessObjectConverter conv = new BusinessObjectConverter(report.Dictionary);
  120. foreach (TreeNode node in tvData.Nodes)
  121. {
  122. if (node.Tag is BusinessObjectDataSource)
  123. {
  124. conv.CreateDataSource(node);
  125. }
  126. }
  127. }
  128. public override void Localize()
  129. {
  130. base.Localize();
  131. Text = Res.Get("Forms,ReportData");
  132. lblHint.Text = Res.Get("Forms,ReportData,Hint");
  133. cbAliases.Text = Res.Get("Forms,ReportData,Aliases");
  134. }
  135. public override void UpdateDpiDependencies()
  136. {
  137. base.UpdateDpiDependencies();
  138. tvData.ImageList = GetImages();
  139. MinimumSize = this.LogicalToDevice(new Size(280, 330));
  140. }
  141. public ReportDataForm(Report report)
  142. {
  143. this.report = report;
  144. CanSaveRestoreState = true;
  145. InitializeComponent();
  146. Localize();
  147. Init();
  148. UIUtils.CheckRTL(this);
  149. UpdateDpiDependencies();
  150. }
  151. }
  152. }