TotalEditorForm.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System;
  2. using System.Windows.Forms;
  3. using FastReport.Utils;
  4. using FastReport.Design;
  5. using FastReport.Data;
  6. namespace FastReport.Forms
  7. {
  8. internal partial class TotalEditorForm : BaseDialogForm
  9. {
  10. private ReportPage page;
  11. private Report report;
  12. private Total total;
  13. public Total Total
  14. {
  15. get { return total; }
  16. set
  17. {
  18. total = value;
  19. UpdateControls();
  20. }
  21. }
  22. private void UpdateControls()
  23. {
  24. tbTotalName.Text = total.Name;
  25. cbxFunction.SelectedIndex = (int)total.TotalType;
  26. if (total.TotalType != TotalType.Count)
  27. cbxDataColumn.Text = total.Expression;
  28. if (total.Evaluator != null && cbxDataBand.Items.IndexOf(total.Evaluator) != -1)
  29. cbxDataBand.SelectedItem = total.Evaluator;
  30. cbInvisibleRows.Checked = total.IncludeInvisibleRows;
  31. tbEvaluateCondition.Text = total.EvaluateCondition;
  32. if (total.PrintOn != null && cbxPrintOn.Items.IndexOf(total.PrintOn) != -1)
  33. cbxPrintOn.SelectedItem = total.PrintOn;
  34. cbResetAfterPrint.Checked = total.ResetAfterPrint;
  35. cbResetRepeated.Checked = total.ResetOnReprint;
  36. }
  37. private void tbEvaluateCondition_ButtonClick(object sender, EventArgs e)
  38. {
  39. using (ExpressionEditorForm form = new ExpressionEditorForm(report))
  40. {
  41. form.ExpressionText = tbEvaluateCondition.Text;
  42. if (form.ShowDialog() == DialogResult.OK)
  43. tbEvaluateCondition.Text = form.ExpressionText;
  44. }
  45. }
  46. private void cbxDataBand_SelectedIndexChanged(object sender, EventArgs e)
  47. {
  48. cbxPrintOn.Items.Clear();
  49. cbxPrintOn.Items.Add(0);
  50. if (cbxDataBand.SelectedIndex != -1)
  51. {
  52. DataBand dataBand = cbxDataBand.SelectedItem as DataBand;
  53. ObjectCollection list = new ObjectCollection();
  54. ReportPage page = dataBand.Page as ReportPage;
  55. while (page != null)
  56. {
  57. list.AddRange(page.AllObjects);
  58. if (page.Subreport != null)
  59. page = page.Subreport.Page as ReportPage;
  60. else
  61. break;
  62. }
  63. foreach (Base c in list)
  64. {
  65. Base band = c as BandBase;
  66. if (c is ChildBand)
  67. band = (c as ChildBand).GetTopParentBand;
  68. if (band is DataFooterBand || band is GroupFooterBand ||
  69. band is ColumnFooterBand || band is PageFooterBand || band is ReportSummaryBand)
  70. cbxPrintOn.Items.Add(c);
  71. }
  72. }
  73. cbxPrintOn.SelectedIndex = 0;
  74. }
  75. private void cbxFunction_SelectedIndexChanged(object sender, EventArgs e)
  76. {
  77. cbxDataColumn.Enabled = cbxFunction.SelectedIndex != 4;
  78. }
  79. private void TotalEditorForm_FormClosed(object sender, FormClosedEventArgs e)
  80. {
  81. if (DialogResult == DialogResult.OK)
  82. Done();
  83. }
  84. private void Init()
  85. {
  86. cbxDataColumn.Report = report;
  87. cbxFunction.SelectedIndex = 0;
  88. foreach (Base c in report.AllObjects)
  89. {
  90. if (c is DataBand)
  91. cbxDataBand.Items.Add(c);
  92. }
  93. if (cbxDataBand.Items.Count > 0)
  94. cbxDataBand.SelectedIndex = 0;
  95. Total total = new Total();
  96. total.Name = report.Dictionary.CreateUniqueName("Total");
  97. Total = total;
  98. }
  99. private void Done()
  100. {
  101. total.Name = tbTotalName.Text;
  102. total.TotalType = (TotalType)cbxFunction.SelectedIndex;
  103. total.Expression = cbxDataColumn.Text;
  104. if (cbxDataBand.SelectedIndex != -1)
  105. total.Evaluator = cbxDataBand.SelectedItem as DataBand;
  106. else
  107. total.Evaluator = null;
  108. total.IncludeInvisibleRows = cbInvisibleRows.Checked;
  109. total.EvaluateCondition = tbEvaluateCondition.Text;
  110. if (cbxPrintOn.SelectedIndex != 0)
  111. total.PrintOn = cbxPrintOn.SelectedItem as BandBase;
  112. else
  113. total.PrintOn = null;
  114. total.ResetAfterPrint = cbResetAfterPrint.Checked;
  115. total.ResetOnReprint = cbResetRepeated.Checked;
  116. }
  117. public override void Localize()
  118. {
  119. base.Localize();
  120. MyRes res = new MyRes("Forms,TotalEditor");
  121. Text = res.Get("");
  122. gbTotal.Text = res.Get("Total");
  123. lblTotalName.Text = res.Get("TotalName");
  124. lblFunction.Text = res.Get("Function");
  125. lblDataColumnOrExpression.Text = res.Get("DataColumnOrExpression");
  126. lblDataBand.Text = res.Get("DataBand");
  127. lblEvaluateCondition.Text = res.Get("EvaluateCondition");
  128. lblPrintOn.Text = res.Get("PrintOn");
  129. gbOptions.Text = res.Get("Options");
  130. cbResetAfterPrint.Text = res.Get("ResetAfterPrint");
  131. cbResetRepeated.Text = res.Get("ResetRepeated");
  132. cbInvisibleRows.Text = res.Get("InvisibleRows");
  133. cbxFunction.Items.AddRange(new object[] {
  134. res.Get("Sum"), res.Get("Min"), res.Get("Max"), res.Get("Avg"), res.Get("Count"), res.Get("CountDistinct") });
  135. }
  136. public override void UpdateDpiDependencies()
  137. {
  138. base.UpdateDpiDependencies();
  139. cbxDataBand.ItemHeight = this.LogicalToDevice(16);
  140. cbxPrintOn.ItemHeight = this.LogicalToDevice(16);
  141. tbEvaluateCondition.Image = GetImage(52);
  142. }
  143. public TotalEditorForm(Designer designer)
  144. {
  145. report = designer.ActiveReport;
  146. page = designer.ActiveReportTab.ActivePage as ReportPage;
  147. InitializeComponent();
  148. Localize();
  149. Init();
  150. UIUtils.CheckRTL(this);
  151. UpdateDpiDependencies();
  152. }
  153. }
  154. }