// ---------------------------------------------------------------------------------------------------- // Method filter button click private void filterButton_Click(object sender, EventArgs e) { try { Type columnType = manager.Data.Columns[filterColumnSelector.SelectedIndex].DataType; string columnName = (string)filterColumnSelector.SelectedItem; if (columnType.Equals(typeof(Int32))) { int from = Int32.Parse(fromTextBox.Text); int to = Int32.Parse(toTextBox.Text); if (to < from) { throw new FormatException("Upper limit is smaller than lower limit."); } manager.FilterIntegerData(columnName, from, to); } else if (columnType.Equals(typeof(Double))) { double from = Double.Parse(fromTextBox.Text); double to = Double.Parse(toTextBox.Text); if (to < from) { throw new FormatException("Upper limit is smaller than lower limit."); } manager.FilterDoubleData(columnName, from, to); } else if (columnType.Equals(typeof(DateTime))) { DateTime startDate = startDatePicker.Value; DateTime endDate = endDatePicker.Value; if (startDate == null || endDate == null) { throw new NullReferenceException("A date is null"); } if (startDate.CompareTo(endDate) > 0) { throw new FormatException("End date is after start date"); } manager.FilterDateData(columnName, startDate, endDate); } else if (columnType.Equals(typeof(String))) { manager.FilterStringData(columnName, stringFilterTextBox.Text); } else//boolean { manager.FilterBooleanData(columnName, Boolean.Parse((string)booleanComboBox.SelectedItem)); } UpdatePageInfoLabelsAndButtons(1); graphicsManager.UpdateCharts(); } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show("There was an error filtering the data, please check the following: \n 1. A filter criteria is selected\n 2. Numbers are written and written correctly.\n 3. If in range be sure the upper limit is larger than the lower limit\n 4. If criteria has a drop down list be sure at least a option is selected", "Something went wrong", MessageBoxButtons.OK, MessageBoxIcon.Error); } }