public Solver.Filter ShowDialog(Solver.Filter filter) { if (filter == null) { Filter_ = null; Text = "Add Filter"; btnRevert.Enabled = false; } else { Filter_ = filter.DeepCopy(); Text = "Edit Filter"; btnRevert.Enabled = true; } LoadFromFilter(); DialogResult result = base.ShowDialog(); if (result == DialogResult.OK) { return(Filter_); } return(null); }
private void listBoxFilters_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); if (listBoxFilters.Items.Count == 0) { return; } Graphics g = e.Graphics; Solver.Filter filter = (Solver.Filter)listBoxFilters.Items[e.Index]; const int margin = 2; Rectangle r = new Rectangle(e.Bounds.X + margin, e.Bounds.Y + margin, e.Bounds.Width - 2 * margin, e.Bounds.Height - 2 * margin); Font font; Rectangle q; StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; // header: field name const int nameLeft = 5, nameTop = 5; font = new Font("Microsoft Sans Serif", 11f, FontStyle.Bold); q = new Rectangle(r.X + nameLeft, r.Y + nameTop, r.Width - nameLeft, r.Height - nameTop); g.DrawString(filter.Field.ToString(), font, Brushes.Black, q, format); // subheading: details of filter const int specLeft = 20, specTop = 25; font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular); q = new Rectangle(r.X + specLeft, r.Y + specTop, r.Width - specLeft, r.Height - specTop); string text = (filter.Exclude ? "Must not" : "Must") + " be " + Solver.Filter.FieldSpecificTest(filter) + " " + filter.ValueToString(); g.DrawString(text, font, Brushes.Black, q, format); g.DrawRectangle(Pens.Black, r); }
private void AddFilter() { FormFilterDetails formDetails = new FormFilterDetails(); Solver.Filter filter = formDetails.ShowDialog(null); if (filter == null) { return; } /*int index = listBoxFilters.SelectedIndex; * if (index == -1) * index = listBoxFilters.Items.Count; * listBoxFilters.Items.Insert(index, filter);*/ listBoxFilters.Items.Add(filter); listBoxFilters.SelectedIndex = listBoxFilters.Items.Count - 1; // not preset anymore ddPresets.SelectedIndex = -1; }
public Solver.Filter ShowDialog(Solver.Filter filter) { if (filter == null) { Filter_ = null; Text = "Add Filter"; btnRevert.Enabled = false; } else { Filter_ = filter.DeepCopy(); Text = "Edit Filter"; btnRevert.Enabled = true; } LoadFromFilter(); DialogResult result = base.ShowDialog(); if (result == DialogResult.OK) return Filter_; return null; }
private void btnOK_Click(object sender, EventArgs e) { if (ddField.SelectedIndex == -1) { MessageBox.Show("Please select which criteria the filter applies to.", "Filter Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ddField.Focus(); return; } if (ddExclude.SelectedIndex == -1) { MessageBox.Show("Please select the filter type.", "Filter Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ddExclude.Focus(); return; } if (ddTest.SelectedIndex == -1) { MessageBox.Show("Please select the filter test.", "Filter Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ddTest.Focus(); return; } int value = ParseValue(); if (value == -1) { return; } Filter_ = new Solver.Filter( ddExclude.SelectedIndex == 1, (Solver.FieldIndex)ddField.SelectedIndex, value, (Solver.FilterTest)ddTest.SelectedIndex); DialogResult = DialogResult.OK; Close(); }
private void EditFilter() { int index = listBoxFilters.SelectedIndex; if (index == -1) { return; } Solver.Filter filter = (Solver.Filter)listBoxFilters.SelectedItem; FormFilterDetails formDetails = new FormFilterDetails(); filter = formDetails.ShowDialog(filter); if (filter == null) { return; } listBoxFilters.Items.RemoveAt(index); listBoxFilters.Items.Insert(index, filter); listBoxFilters.SelectedIndex = index; // not preset anymore ddPresets.SelectedIndex = -1; }
private void btnOK_Click(object sender, EventArgs e) { if (ddField.SelectedIndex == -1) { MessageBox.Show("Please select which criteria the filter applies to.", "Filter Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ddField.Focus(); return; } if (ddExclude.SelectedIndex == -1) { MessageBox.Show("Please select the filter type.", "Filter Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ddExclude.Focus(); return; } if (ddTest.SelectedIndex == -1) { MessageBox.Show("Please select the filter test.", "Filter Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ddTest.Focus(); return; } int value = ParseValue(); if (value == -1) return; Filter_ = new Solver.Filter( ddExclude.SelectedIndex == 1, (Solver.FieldIndex)ddField.SelectedIndex, value, (Solver.FilterTest)ddTest.SelectedIndex); DialogResult = DialogResult.OK; Close(); }
private void btnOK_Click(object sender, EventArgs e) { // check if there were any changes bool changed = false; if (Solver_.Comparer.Criteria.Count == listBoxCriteria.Items.Count) { for (int i = 0; i < Solver_.Comparer.Criteria.Count; i++) { Solver.Criteria criteria = Solver_.Comparer.Criteria[i]; Solver.Criteria other = (Solver.Criteria)listBoxCriteria.Items[i]; if (criteria.FieldIndex != other.FieldIndex || criteria.Preference != other.Preference) { changed = false; break; } } } else { changed = true; } if (!changed && Solver_.Filters.Count == listBoxFilters.Items.Count) { for (int i = 0; i < Solver_.Filters.Count; i++) { Solver.Filter filter = Solver_.Filters[i]; Solver.Filter other = (Solver.Filter)listBoxFilters.Items[i]; if (filter.FieldIndex == other.FieldIndex && filter.Exclude == other.Exclude && filter.Test == other.Test && filter.ValueAsInt == other.ValueAsInt) { changed = false; break; } } } else { changed = true; } if (!changed) { DialogResult = DialogResult.Cancel; Close(); return; } // copy changes across Solver_.Comparer.Criteria.Clear(); foreach (Solver.Criteria criteria in listBoxCriteria.Items) { Solver_.Comparer.Criteria.Add(criteria); } Solver_.Filters.Clear(); foreach (Solver.Filter filter in listBoxFilters.Items) { Solver_.Filters.Add(filter); } DialogResult = DialogResult.OK; Close(); }