DataBandEditorForm.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System;
  2. using System.Windows.Forms;
  3. using FastReport.Utils;
  4. using FastReport.Data;
  5. using FastReport.Controls;
  6. namespace FastReport.Forms
  7. {
  8. internal partial class DataBandEditorForm : BaseDialogForm
  9. {
  10. private DataBand band;
  11. private bool firstRun;
  12. private Report Report
  13. {
  14. get { return band.Report; }
  15. }
  16. private DataColumnComboBox[] ComboArray
  17. {
  18. get { return new DataColumnComboBox[] { cbxSort1, cbxSort2, cbxSort3 }; }
  19. }
  20. private RadioButton[] AscArray
  21. {
  22. get { return new RadioButton[] { rbSortAsc1, rbSortAsc2, rbSortAsc3 }; }
  23. }
  24. private RadioButton[] DescArray
  25. {
  26. get { return new RadioButton[] { rbSortDesc1, rbSortDesc2, rbSortDesc3 }; }
  27. }
  28. private void FillSort(DataSourceBase dataSource, bool reset)
  29. {
  30. SortCollection sort = band.Sort;
  31. for (int i = 0; i < ComboArray.Length; i++)
  32. {
  33. ComboArray[i].Report = Report;
  34. ComboArray[i].DataSource = dataSource;
  35. if (i >= sort.Count || reset)
  36. {
  37. ComboArray[i].Text = "";
  38. AscArray[i].Checked = true;
  39. DescArray[i].Checked = false;
  40. }
  41. else
  42. {
  43. ComboArray[i].Text = sort[i].Expression;
  44. AscArray[i].Checked = !sort[i].Descending;
  45. DescArray[i].Checked = sort[i].Descending;
  46. }
  47. }
  48. }
  49. private void GetSort()
  50. {
  51. band.Sort.Clear();
  52. for (int i = 0; i < ComboArray.Length; i++)
  53. {
  54. if (!String.IsNullOrEmpty(ComboArray[i].Text))
  55. band.Sort.Add(new Sort(ComboArray[i].Text, DescArray[i].Checked));
  56. }
  57. }
  58. private void tvDataSource_AfterSelect(object sender, TreeViewEventArgs e)
  59. {
  60. if (!firstRun)
  61. {
  62. DataSourceBase data = tvDataSource.SelectedNode.Tag as DataSourceBase;
  63. FillSort(data, true);
  64. }
  65. firstRun = false;
  66. }
  67. private void tvDataSource_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  68. {
  69. DialogResult = DialogResult.OK;
  70. }
  71. private void tbFilter_ButtonClick(object sender, EventArgs e)
  72. {
  73. tbFilter.Text = Editors.EditExpression(Report, tbFilter.Text);
  74. }
  75. private void DataBandEditorForm_Shown(object sender, EventArgs e)
  76. {
  77. tvDataSource.Focus();
  78. }
  79. private void DataBandEditorForm_FormClosed(object sender, FormClosedEventArgs e)
  80. {
  81. Done();
  82. }
  83. private void Init()
  84. {
  85. firstRun = true;
  86. tvDataSource.CreateNodes(band.Report.Dictionary);
  87. tvDataSource.SelectedItem = band.DataSource == null ? "" : band.DataSource.FullName;
  88. tvDataSource.Visible = tvDataSource.Nodes.Count > 1;
  89. lblNoData.Visible = !tvDataSource.Visible;
  90. FillSort(band.DataSource, false);
  91. tbFilter.Text = band.Filter;
  92. }
  93. private void Done()
  94. {
  95. if (DialogResult == DialogResult.OK)
  96. {
  97. band.DataSource = tvDataSource.SelectedNode == null ? null : tvDataSource.SelectedNode.Tag as DataSourceBase;
  98. GetSort();
  99. band.Filter = tbFilter.Text;
  100. }
  101. }
  102. public override void Localize()
  103. {
  104. base.Localize();
  105. MyRes res = new MyRes("Forms,DataBandEditor");
  106. Text = res.Get("");
  107. pnDataSource.Text = res.Get("DataSource");
  108. lblNoData.Text = res.Get("NoData");
  109. pnSort.Text = res.Get("Sort");
  110. lblSort1.Text = res.Get("SortBy");
  111. lblSort2.Text = res.Get("ThenBy");
  112. lblSort3.Text = res.Get("ThenBy");
  113. for (int i = 0; i < AscArray.Length; i++)
  114. {
  115. AscArray[i].Text = res.Get("Ascending");
  116. DescArray[i].Text = res.Get("Descending");
  117. }
  118. pnFilter.Text = res.Get("Filter");
  119. lblFilter.Text = res.Get("Expression");
  120. }
  121. public override void UpdateDpiDependencies()
  122. {
  123. base.UpdateDpiDependencies();
  124. tbFilter.Image = GetImage(52);
  125. tvDataSource.ImageList = GetImages();
  126. this.MinimumSize = this.LogicalToDevice(new System.Drawing.Size(540, 312));
  127. }
  128. public DataBandEditorForm(DataBand band)
  129. {
  130. this.band = band;
  131. CanSaveRestoreState = true;
  132. InitializeComponent();
  133. Localize();
  134. Init();
  135. UIUtils.CheckRTL(this);
  136. UpdateDpiDependencies();
  137. }
  138. }
  139. }