private void Delete_Click(object sender, RoutedEventArgs e) { int numOfItems = DataGrid.SelectedItems.Count; for (int i = 0; i < numOfItems; i++) { Book book = DataGrid.SelectedItems[i] as Book; DGItemsSource.Remove(book); } if (filterOn == true) { var Tempyear = year.SelectedValue; CSVSave(PathToFile); DGItemsSource.Clear(); YearCombo.Clear(); CSVLoad(PathToFile); year.SelectedValue = Tempyear; FilterTheBooks(); DataGrid.Items.SortDescriptions.Add(new SortDescription("Year", ListSortDirection.Descending)); } else { CSVSave(PathToFile); DGItemsSource.Clear(); YearCombo.Clear(); CSVLoad(PathToFile); FilterTheBooks(); DataGrid.Items.SortDescriptions.Add(new SortDescription("Year", ListSortDirection.Descending)); } }
private void Add_Click(object sender, RoutedEventArgs e) { DialogWindow AddWindow = new DialogWindow(); bool?result = AddWindow.ShowDialog(); if (result.HasValue && result.Value == true) { Book NewBook = AddWindow.ObjectBook; AddBook(NewBook.Author, NewBook.Title, NewBook.Year); YearCombo.Add(NewBook.Year); if (filterOn == true) { var Tempyear = year.SelectedValue; CSVSave(PathToFile); DGItemsSource.Clear(); YearCombo.Clear(); CSVLoad(PathToFile); year.SelectedValue = Tempyear; FilterTheBooks(); DataGrid.Items.SortDescriptions.Add(new SortDescription("Year", ListSortDirection.Descending)); } else { CSVSave(PathToFile); DGItemsSource.Clear(); YearCombo.Clear(); CSVLoad(PathToFile); FilterTheBooks(); DataGrid.Items.SortDescriptions.Add(new SortDescription("Year", ListSortDirection.Descending)); } } }
private void Edit_Click(object sender, RoutedEventArgs e) { if (DataGrid.SelectedItem != null) { DialogWindow EditWindow = new DialogWindow(); Book EditedBook = (Book)DataGrid.SelectedItem; EditWindow.Accept.Content = "Save"; EditWindow.Title = "Edit selected book"; EditWindow.AuthorData.Text = EditedBook.Author; EditWindow.TitleData.Text = EditedBook.Title; EditWindow.ComboYear.Text = EditedBook.Year.ToString(); bool?result = EditWindow.ShowDialog(); if (result.HasValue && result.Value == true) { for (int i = 0; i < DGItemsSource.Count; i++) { if (DGItemsSource[i].ID == EditedBook.ID) { DGItemsSource[i] = EditWindow.ObjectBook; } } if (filterOn == true) { var Tempyear = year.SelectedValue; CSVSave(PathToFile); DGItemsSource.Clear(); YearCombo.Clear(); CSVLoad(PathToFile); year.SelectedValue = Tempyear; FilterTheBooks(); DataGrid.Items.SortDescriptions.Add(new SortDescription("Year", ListSortDirection.Descending)); } else { CSVSave(PathToFile); DGItemsSource.Clear(); YearCombo.Clear(); CSVLoad(PathToFile); FilterTheBooks(); DataGrid.Items.SortDescriptions.Add(new SortDescription("Year", ListSortDirection.Descending)); } } } }