private void SComponentOnSelectedIndexChanged(object sender, EventArgs eventArgs) { var combobox = (ComboBox)sender; if (combobox == null) { return; } var filtro = ((SEnum <TypeFilter>)combobox.SelectedItem).Id; var name = combobox.Name.Substring(1); if (filtro != TypeFilter.Between) { panel1.Controls.RemoveByKey(combobox.Name + "And"); return; } Control componete = null; var typeComponent = (TypeFilterComponent)combobox.Tag; switch (typeComponent) { case TypeFilterComponent.ComboBox: var cb = new SComboBox(); cb.SetList(combobox.DataSource as IList); componete = cb; break; case TypeFilterComponent.Numeric: componete = new SNumeric(); break; case TypeFilterComponent.TextBox: componete = new STextBox(); break; case TypeFilterComponent.Date: componete = new SDateTimePicker() { SComponent = { Format = DateTimePickerFormat.Short, ShowCheckBox = true } }; break; case TypeFilterComponent.CheckBox: componete = new SCheckBox(); break; case TypeFilterComponent.DateTime: { componete = new SDateTimePicker() { SComponent = { Format = DateTimePickerFormat.Short, ShowCheckBox = true } }; } break; } if (componete == null) { return; } componete.Location = new Point((combobox.Parent.Parent.Location.X + combobox.Parent.Parent.Width + 10), combobox.Parent.Parent.Location.Y); componete.Name = combobox.Name + "And"; componete.Visible = true; componete.Width = 200; componete.Height = 52; panel1.Controls.Add(componete); }
/// <summary> /// Inicializa os filtros dentro do grid de forma dinamica conforme cadastro realizado. /// </summary> /// <param name="filters"></param> private void InitializeFilters(IList <Filter> filters) { // Utilizo objeto padrão para apenas usar o recurso de gerar lista apartir de um enum var sComboBox = new SComboBox(); sComboBox.SetEnumItems <TypeFilter>(TypeFilter.InitiatedBy); GridFilter.Clear(); foreach (var item in filters) { var row = new DataGridViewRow() { Tag = item }; var comboBox = new DataGridViewComboBoxCell { ValueMember = sComboBox.ValueMember, DisplayMember = sComboBox.DisplayMember, DataSource = sComboBox.SComponent.DataSource }; row.Cells.Add(new DataGridViewTextBoxCell()); row.Cells.Add(new DataGridViewTextBoxCell()); row.Cells.Add(new DataGridViewTextBoxCell()); row.Cells.Add(new DataGridViewTextBoxCell()); row.Cells[1] = comboBox; row.Cells[1].Value = item.DefaultTypeFilter; switch (item.TypeComponent) { case TypeFilterComponent.TextBox: row.Cells[0].Value = item.Display; row.Cells[0].ReadOnly = true; row.Cells[2] = new DataGridViewTextBoxCell(); row.Cells[3] = new DataGridViewTextBoxCell(); break; case TypeFilterComponent.ComboBox: break; case TypeFilterComponent.Date: row.Cells[0].Value = item.Display; row.Cells[0].ReadOnly = true; row.Cells[2] = new CalendarCell(); row.Cells[3] = new CalendarCell(); break; case TypeFilterComponent.Time: break; case TypeFilterComponent.DateTime: break; case TypeFilterComponent.CheckBox: break; case TypeFilterComponent.Numeric: break; default: break; } row.Cells[3].ReadOnly = item.DefaultTypeFilter != TypeFilter.Between; GridFilter.SComponent.Rows.Add(row); } GridFilter.SComponent.Refresh(); }
private void InicializarComponetesPesquisa(int queryId) { var query = new QueryApp().FindId(queryId); if (query == null) { return; } Query = query.Sql; var filters = query.Filters; panel1.Controls.Clear(); var localionY = 10; foreach (var item in filters) { var typeItem = item.TypeComponent; var display = GlobalUser.Translates.FirstOrDefault(c => c.PropertyName == item.Display)?.Portugues ?? item.Display; IComponent componete; switch (typeItem) { case TypeFilterComponent.ComboBox: var cb = new SComboBox(); cb.SetEnumItems(Type.GetType(item.NameColumn)); componete = cb; break; case TypeFilterComponent.Numeric: componete = new SNumeric(); break; case TypeFilterComponent.TextBox: componete = new STextBox(); break; case TypeFilterComponent.Date: componete = new SDateTimePicker { Format = DateTimePickerFormat.Custom, CustomFormat = "dd/MM/yyyy" }; break; case TypeFilterComponent.Time: componete = new SDateTimePicker { Format = DateTimePickerFormat.Custom, CustomFormat = "hh:mm:ss" }; break; case TypeFilterComponent.DateTime: componete = new SDateTimePicker { Format = DateTimePickerFormat.Custom, CustomFormat = "dd/MM/yyyy hh:mm:ss" }; break; case TypeFilterComponent.CheckBox: componete = new SCheckBox(); break; default: continue; } componete.Caption = display; componete.Location = new Point(10, localionY); //componete. = item.NameTable; componete.Name = item.NameColumn; componete.ToolTipContext = item.Code; componete.Others = item.NameTable; componete.Visible = true; componete.Width = 200; componete.Height = 52; var comboBox = new SComboBox() { Caption = "Selecione o Filtro", Location = new Point(200 + 20, localionY), Name = "F" + item.NameColumn, SComponent = { Name = "F" + item.NameColumn }, Visible = true, Width = 200, Height = 52 }; comboBox.SetEnumItems <TypeFilter>(item.DefaultTypeFilter); var removeFilters = comboBox.SComponent.DataSource as IList <SEnum <TypeFilter> >; var newFilters = new List <SEnum <TypeFilter> >(); foreach (var filter in removeFilters) { if (!item.InactiveFilters.Any(c => c.TypeFilter == filter.Id)) { newFilters.Add(filter); } } comboBox.SComponent.DataSource = newFilters; comboBox.SComponent.SelectedValue = item.DefaultTypeFilter; comboBox.SComponent.Tag = item.TypeComponent; comboBox.SComponent.SelectedIndexChanged += SComponentOnSelectedIndexChanged; Control[] controls = { (Control)componete, comboBox }; panel1.Controls.AddRange(controls); localionY = localionY + 55; if (typeItem != TypeFilterComponent.CheckBox) { continue; } ((SCheckBox)componete).SComponent.Parent.Dock = DockStyle.Bottom; ((SCheckBox)componete).SComponent.Parent.AutoSize = false; ((SCheckBox)componete).SComponent.Parent.Height = 30; } }