// Function:        This button is first checking that items were selected
        //                  in the combo boxes.Then it is grabbing those inputs no matter what they are.If the search
        //                  box is looking at the local computer or local network than it is using the server instance name
        //                  as the server name else it will put together the computer name and instance name.
        //                  Grabs the sources from the DB, then checks the quality of the tags.
        // ====================================================================================================================
        public void Run(object sender, RoutedEventArgs e)
        {
            try
            {
                allReports.Clear();
                var ash      = new AreaSourceHandler();
                var allAreas = ash.GetAreas();
                AreaTreeView.ItemsSource = allAreas.FindAll(i => i.RecursiveParentId == 0);

                var sources = _sqlServer.QueryAwxSources();
                sources                = ash.AssignSourceToArea(sources, allAreas);
                allReports             = _qualityCheck.CheckAll(sources, allAreas);
                Report.ItemsSource     = allReports;
                RerunButton.Visibility = Visibility.Visible;
            }
            catch (Exception)
            {
                MessageBox.Show("Could not run quality check.");
            }
        }
        // Function:        Recollects all the sources from the db, rechecks the quality, and only puts on display
        //                  reports that were previously on the screen before pushing the button.
        // ====================================================================================================================
        private void RerunButton_Click(object sender, RoutedEventArgs e)
        {
            var listOnDisplay = ((List <ReportModel>)Report.ItemsSource).ToList();

            allReports.Clear();
            var ash      = new AreaSourceHandler();
            var allAreas = ash.GetAreas();

            AreaTreeView.ItemsSource = allAreas.FindAll(i => i.RecursiveParentId == 0);

            var sources = _sqlServer.QueryAwxSources();

            sources    = ash.AssignSourceToArea(sources, allAreas);
            allReports = _qualityCheck.CheckAll(sources, allAreas);

            List <ReportModel> newList = new List <ReportModel>();

            foreach (ReportModel oldReport in listOnDisplay)
            {
                newList.AddRange(allReports.FindAll(r => r.SourceID == oldReport.SourceID));
            }

            Report.ItemsSource = newList.OrderBy(report => report.PointStatus).ThenBy(report => report.TagName);
        }