123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using FastReport.Utils;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- namespace FastReport.FastQueryBuilder
- {
- internal class FieldsView : DataGridView
- {
- private List<Field> fields;
- public List<Field> Fields
- {
- get => fields;
- set
- {
- fields = value;
- // build a copy of fields list. Do not use DataSource = null; DataSource = value; because of bug in SWF
- var newList = new List<Field>();
- newList.AddRange(fields);
- DataSource = newList;
- UpdateGroupedFields();
- }
- }
- public List<Field> Groups { get; set; }
- public FieldsView()
- {
- AllowUserToAddRows = false;
- AllowUserToDeleteRows = false;
- AllowUserToResizeRows = false;
- AutoGenerateColumns = false;
- BackgroundColor = SystemColors.Control;
- ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- GridColor = SystemColors.Control;
- RowHeadersVisible = false;
- CellEndEdit += DoCellEndEdit;
- MyRes res = new MyRes("Forms,QueryBuilder");
- var nameColumn = new DataGridViewTextBoxColumn();
- nameColumn.HeaderText = res.Get("Name");
- nameColumn.DataPropertyName = "FullName";
- nameColumn.ReadOnly = true;
- var aliasColumn = new DataGridViewTextBoxColumn();
- aliasColumn.HeaderText = res.Get("Alias");
- aliasColumn.DataPropertyName = "Alias";
- var filterColumn = new DataGridViewTextBoxColumn();
- filterColumn.HeaderText = res.Get("Filter");
- filterColumn.DataPropertyName = "Filter";
- var groupColumn = new DataGridViewCheckBoxColumn();
- groupColumn.HeaderText = res.Get("Group");
- groupColumn.DataPropertyName = "Group";
- var orderColumn = new DataGridViewComboBoxColumn();
- orderColumn.HeaderText = res.Get("Order");
- orderColumn.DataPropertyName = "Order";
- orderColumn.FlatStyle = FlatStyle.Flat;
- orderColumn.Items.AddRange(new string[] { "", "Asc", "Desc" });
- var funcColumn = new DataGridViewComboBoxColumn();
- funcColumn.HeaderText = res.Get("Func");
- funcColumn.DataPropertyName = "Func";
- funcColumn.FlatStyle = FlatStyle.Flat;
- funcColumn.Items.AddRange(new string[] { "", "Avg", "Count", "Max", "Min", "Sum" });
- Columns.AddRange(new DataGridViewColumn[] { nameColumn, aliasColumn, filterColumn, groupColumn, orderColumn, funcColumn });
- }
- protected override void OnSizeChanged(EventArgs e)
- {
- base.OnSizeChanged(e);
- if (Columns.Count > 0)
- {
- int fixedWidth = 80;
- Columns[3].Width = Columns[4].Width = Columns[5].Width = this.LogicalToDevice(fixedWidth);
- Columns[0].Width = Columns[1].Width = Columns[2].Width = (Width - this.LogicalToDevice(fixedWidth * 3 + SystemInformation.VerticalScrollBarWidth)) / 3 - 1;
- }
- }
- private void DoCellEndEdit(object sender, DataGridViewCellEventArgs e)
- {
- UpdateGroupedFields();
- }
- private void UpdateGroupedFields()
- {
- if (Groups == null)
- return;
- // remove
- for (int i = 0; i < Groups.Count; i++)
- {
- if (!Fields.Contains(Groups[i]) || !Groups[i].Group)
- {
- Groups.RemoveAt(i);
- i--;
- }
- }
- // add
- foreach (Field f in Fields)
- {
- if (!Groups.Contains(f) && f.Group)
- Groups.Add(f);
- }
- }
- }
- }
|