Example #1
0
        private static void RefreshAndFilterEventList(
            ListView listView, TextBox eventIDTextBox, DatePicker datePickerStart,
            DatePicker datePickerEnd, ComboBox eventTypeComboBox, ComboBox stateComboBox,
            ComboBox severityComboBox, ListBox keywordsListBox)
        {
            // Make a new list with all the current objects in the DB to reference.
            List <Alert> AlertList = SQLite_Data_Access.SelectAll_DB();

            // Make a reversed StateDictionary to compare the values to the keys
            Dictionary <String, String> ReversedStateDictionary = new Dictionary <string, string>();

            foreach (var state in Alert.StateDictionary)
            {
                ReversedStateDictionary.Add(state.Value, state.Key);
            }

            // Build LINQ query based on current values
            if (!string.IsNullOrEmpty(eventIDTextBox.Text))
            {
                AlertList = AlertList.Where(alert => alert.Id.Contains(eventIDTextBox.Text)).ToList();
            }
            if (datePickerStart.SelectedDate != null && datePickerEnd.SelectedDate != null)
            {
                AlertList = AlertList.Where(alert => DateTime.Parse(alert.Date) >= datePickerStart.SelectedDate && DateTime.Parse(alert.Date) <= datePickerEnd.SelectedDate).ToList();
            }
            if (!string.IsNullOrEmpty(eventTypeComboBox.Text))
            {
                AlertList = AlertList.Where(alert => alert.EventType == eventTypeComboBox.Text).ToList();
            }
            if (!string.IsNullOrEmpty(stateComboBox.Text))
            {
                AlertList = AlertList.Where(alert => alert.State == ReversedStateDictionary[stateComboBox.Text]).ToList();
            }
            if (!string.IsNullOrEmpty(severityComboBox.Text))
            {
                AlertList = AlertList.Where(alert => alert.Severity == severityComboBox.Text).ToList();
            }
            if (KeywordsFromCheckBoxs(keywordsListBox).Count > 0)
            {
                foreach (var word in KeywordsFromCheckBoxs(keywordsListBox))
                {
                    AlertList = AlertList.Where(alert => alert.DescriptionKeywords.Contains(word)).ToList();
                }
            }

            // Finally add all the Alert objects that were filtered to the ListView
            // And clear old records
            listView.Items.Clear();
            foreach (var Alert in AlertList)
            {
                listView.Items.Add(Alert);
            }
        }
Example #2
0
        private static void UpdateUIStatusBar(StatusBar statusBar, ListView listView)
        {
            // Update all the items in the Status Bar

            // Grab all items in the statusbar
            List <StatusBarItem> ControlsInStatusBar = new List <StatusBarItem>();

            foreach (var item in statusBar.Items)
            {
                ControlsInStatusBar.Add((StatusBarItem)item);
            }

            // Handle the first StatusBar Item
            int NumberOfAllRecords   = SQLite_Data_Access.SelectAll_DB().Count;
            int NumberOfShownRecords = listView.Items.Count;

            ControlsInStatusBar[0].Content = $"Records Shown: {NumberOfShownRecords}/{NumberOfAllRecords}";

            // Handle the second StatusBar Item
            StartDispatcherTimer(ControlsInStatusBar[1]);
        }