private void searchButton_Click(object sender, RoutedEventArgs e) { var username = usernameInput.Text; var password = passwordInput.Password; var to = ToDate.Text; var from = FromDate.Text; var visitors = Visitors.Text; var mins = MinsViewed.Text; var views = Views.Text; if (string.IsNullOrWhiteSpace(to) || string.IsNullOrWhiteSpace(from) || string.IsNullOrWhiteSpace(visitors) || string.IsNullOrWhiteSpace(views) || string.IsNullOrWhiteSpace(mins)) { MessageBox.Show(Application.Current.MainWindow, "All fields must be populated."); return; } deleteView.Items.Clear(); deleteView.Items.Add(new ListBoxItem() { Content = new TextBlock() { Text = "Batch loading your sessions. This may take a few minutes, please be patient." } }); try { var backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += (s, e1) => { try { sessions = BulkDeleteRecordingSchedules.FetchSessions(username, password, new Services.SessionFilter() { StartDate = Convert.ToDateTime(from), EndDate = Convert.ToDateTime(to), MinutesViewed = Convert.ToDouble(mins), NumberOfViews = Convert.ToDouble(views), NumberOfVisitors = Convert.ToDouble(visitors) }); } catch (Exception ex) { log.Warn(ex); MessageBox.Show("An error occurred. Details: " + ex.Message); } }; backgroundWorker.RunWorkerCompleted += (s, e2) => { App.Current.Dispatcher.Invoke((Action) delegate { deleteView.Items.Clear(); if (sessions != null && sessions.Count > 0) { foreach (var session in sessions) { StackPanel panel = new StackPanel(); panel.Orientation = Orientation.Horizontal; panel.Margin = new Thickness(5, 3, 5, 3); panel.ToolTip = session.Key.Name; CheckBox check = new CheckBox(); check.Tag = session.Key.Id.ToString(); check.Width = 25; panel.Children.Add(check); TextBlock text = new TextBlock(); text.Width = 260; text.TextWrapping = TextWrapping.NoWrap; text.Text = session.Key.Name; panel.Children.Add(text); TextBlock textFolder = new TextBlock(); textFolder.Width = 200; textFolder.TextWrapping = TextWrapping.NoWrap; textFolder.Text = session.Key.FolderName; panel.Children.Add(textFolder); TextBlock textDate = new TextBlock(); textDate.Width = 140; textDate.TextWrapping = TextWrapping.NoWrap; textDate.Text = session.Key.StartTime.ToString(); panel.Children.Add(textDate); TextBlock noViewsText = new TextBlock(); noViewsText.Margin = new Thickness(20, 0, 0, 0); noViewsText.Width = 75; noViewsText.Text = session.Value.NumberOfViews.ToString(); panel.Children.Add(noViewsText); TextBlock minsText = new TextBlock(); minsText.Margin = new Thickness(5, 0, 0, 0); minsText.Width = 75; minsText.Text = String.Format("{0:0.00}", session.Value.MinutesViewed); panel.Children.Add(minsText); TextBlock visitorsText = new TextBlock(); visitorsText.Margin = new Thickness(5, 0, 0, 0); visitorsText.Width = 25; visitorsText.Text = session.Value.NumberOfVisitors.ToString(); panel.Children.Add(visitorsText); ListViewItem item = new ListViewItem(); item.Content = panel; deleteView.Items.Add(item); } } else { deleteView.Items.Add(new ListBoxItem() { Content = new TextBlock() { Text = "No Results" } }); } }); }; backgroundWorker.RunWorkerAsync(); } catch (Exception ex) { log.Warn(ex); MessageBox.Show(string.Format("An error has occurred. Details: {0}", ex.Message)); } }
private void deleteButton_Click(object sender, RoutedEventArgs e) { var username = usernameInput.Text; var password = passwordInput.Password; List <Guid> guids = new List <Guid>(); List <ListBoxItem> itemsToRemove = new List <ListBoxItem>(); try { var backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += (s, e1) => { App.Current.Dispatcher.Invoke((Action) delegate { if (deleteView.Items != null) { foreach (ListBoxItem item in deleteView.Items) { if (item != null && item.Content is StackPanel) { StackPanel sp = (StackPanel)item.Content; CheckBox check = (CheckBox)sp.Children[0]; if (check.IsChecked.HasValue && check.IsChecked.Value) { guids.Add(new Guid(check.Tag.ToString())); itemsToRemove.Add(item); } } } } if (guids.Count > 0) { BulkDeleteRecordingSchedules.DeleteSessions(username, password, guids.ToArray()); } if (itemsToRemove.Count > 0) { foreach (ListBoxItem item in itemsToRemove) { if (item != null) { deleteView.Items.Remove(item); } } } }); }; backgroundWorker.RunWorkerCompleted += (s, e2) => { App.Current.Dispatcher.Invoke((Action) delegate { Status.Content = guids.Count + " session(s) have been deleted"; }); }; backgroundWorker.RunWorkerAsync(); } catch (Exception ex) { log.Warn(ex); Status.Content = string.Format("An error has occurred. Details: {0}", ex.Message); } }