Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        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));
                }
            }
        }
Exemplo n.º 3
0
        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));
                    }
                }
            }
        }
Exemplo n.º 4
0
 private void CSVLoad(string path)
 {
     using (var ReadStream = new StreamReader(path))
     {
         while (!ReadStream.EndOfStream)
         {
             var Split   = ReadStream.ReadLine().Split(';');
             var NewBook = new Book()
             {
                 ID     = DGItemsSource.Count,
                 Author = Split[0],
                 Title  = Split[1],
                 Year   = int.Parse(Split[2])
             };
             DGItemsSource.Add(NewBook);
             YearCombo.Add(int.Parse(Split[2]));
         }
         ReadStream.Close();
     }
     YearCombo = new ObservableCollection <int>(YearCombo.Distinct());
 }
Exemplo n.º 5
0
 public void AddBook(string Author, string Title, int Year)
 {
     DGItemsSource.Add(new Book {
         ID = 0, Author = Author, Title = Title, Year = Year
     });
 }