|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.ComponentModel; |
| 4 | +using System.Data; |
| 5 | +using System.Drawing; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using System.Threading.Tasks; |
| 9 | +using System.Windows.Forms; |
| 10 | + |
| 11 | +namespace FindMissingRows |
| 12 | +{ |
| 13 | + public partial class FilterDialog : Form |
| 14 | + { |
| 15 | + public string FilterString { get; set; } |
| 16 | + public Form1 MainForm { private get; set; } |
| 17 | + |
| 18 | + public FilterDialog(object [] columnNames) |
| 19 | + { |
| 20 | + InitializeComponent(); |
| 21 | + |
| 22 | + filterColumn.Items.AddRange(columnNames); |
| 23 | + |
| 24 | + filterTypeCb.Items.AddRange(new string [] {"Equals", "Begins", "Ends" }); |
| 25 | + filterTypeCb.SelectedIndex = filterTypeCb.Items.IndexOf("Equals"); |
| 26 | + } |
| 27 | + |
| 28 | + private void apply_Click(object sender, EventArgs e) |
| 29 | + { |
| 30 | + MainForm.Filter(FilterString); |
| 31 | + } |
| 32 | + |
| 33 | + private void cancel_Click(object sender, EventArgs e) |
| 34 | + { |
| 35 | + Close(); |
| 36 | + } |
| 37 | + |
| 38 | + private void filterColumn_SelectedIndexChanged(object sender, EventArgs e) |
| 39 | + { |
| 40 | + if (filterColumn.SelectedItem != null) |
| 41 | + columnNameBox.Text = filterColumn.SelectedItem.ToString(); |
| 42 | + else |
| 43 | + columnNameBox.Text = string.Empty; |
| 44 | + UpdateFilter(); |
| 45 | + } |
| 46 | + |
| 47 | + private void UpdateFilter() |
| 48 | + { |
| 49 | + if (string.IsNullOrWhiteSpace(columnNameBox.Text) && string.IsNullOrWhiteSpace(filterTextBox.Text)) |
| 50 | + { |
| 51 | + FilterString = string.Empty; |
| 52 | + } |
| 53 | + else |
| 54 | + { |
| 55 | + switch (filterTypeCb.Text) |
| 56 | + { |
| 57 | + case "Equals": |
| 58 | + FilterString = string.Format("[{0}] = '{1}'", columnNameBox.Text, filterTextBox.Text); |
| 59 | + break; |
| 60 | + case "Begins": |
| 61 | + FilterString = string.Format("[{0}] LIKE '{1}*'", columnNameBox.Text, filterTextBox.Text); |
| 62 | + break; |
| 63 | + case "Ends": |
| 64 | + FilterString = string.Format("[{0}] LIKE '*{1}'", columnNameBox.Text, filterTextBox.Text); |
| 65 | + break; |
| 66 | + default: |
| 67 | + return; |
| 68 | + } // end switch |
| 69 | + } // end else |
| 70 | + |
| 71 | + // No column name in the filter creates an exception so clear the filter string |
| 72 | + if (string.IsNullOrEmpty(columnNameBox.Text)) |
| 73 | + FilterString = string.Empty; |
| 74 | + filterExpressionBox.Text = FilterString; |
| 75 | + } |
| 76 | + |
| 77 | + private void filterText_TextChanged(object sender, EventArgs e) |
| 78 | + { |
| 79 | + UpdateFilter(); |
| 80 | + } |
| 81 | + |
| 82 | + private void clearButton_Click(object sender, EventArgs e) |
| 83 | + { |
| 84 | + filterColumn.SelectedItem = null; |
| 85 | + filterTextBox.Text = string.Empty; |
| 86 | + UpdateFilter(); |
| 87 | + MainForm.Filter(FilterString); |
| 88 | + } |
| 89 | + |
| 90 | + private void filterTypeCb_SelectedIndexChanged(object sender, EventArgs e) |
| 91 | + { |
| 92 | + UpdateFilter(); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments