Exemplo n.º 1
0
        private void ClearLibrary_Click(object sender, RoutedEventArgs e)
        {
            BookList.Clear();
            AudiobookList.Clear();
            MovieList.Clear();
            totalToRead   = 0;
            totalToListen = 0;
            totalToWatch  = 0;
            int selectedCategory = CategoryComboBox.SelectedIndex;

            SetNewsTextBlocks(selectedCategory);
        }
Exemplo n.º 2
0
        private void DelateButton_Click(object sender, RoutedEventArgs e)
        {
            int selectedCategory = CategoryComboBox.SelectedIndex;

            switch (selectedCategory)
            {
            case 0:
                try
                {
                    totalToRead = BookList[KsiazkaListView.SelectedIndex].News(totalToRead, "subtract");
                    BookList.RemoveAt(KsiazkaListView.SelectedIndex);
                }
                catch
                {
                    MessageBox.Show("Zaznacz którą książkę chcesz usunąć lub zmień kategorię.", "Usuń pozycję");
                }
                break;

            case 1:
                try
                {
                    totalToListen = AudiobookList[AudiobookListView.SelectedIndex].News(totalToListen, "subtract");
                    AudiobookList.RemoveAt(AudiobookListView.SelectedIndex);
                }
                catch
                {
                    MessageBox.Show("Zaznacz którego audiobooka chcesz usunąć lub zmień kategorię.", "Usuń pozycję");
                }
                break;

            case 2:
                try
                {
                    totalToWatch = MovieList[FilmListView.SelectedIndex].News(totalToWatch, "subtract");
                    MovieList.RemoveAt(FilmListView.SelectedIndex);
                }
                catch
                {
                    MessageBox.Show("Zaznacz który film chcesz usunąć lub zmień kategorię.", "Usuń pozycję");
                }
                break;
            }
            SetNewsTextBlocks(selectedCategory);
        }
Exemplo n.º 3
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            string author = AuthorTextBox.Text;
            string title = TitleTextBox.Text;
            string releaseDate, nISBN;

            Categories category = (Categories)Enum.Parse(typeof(Categories), CategoryComboBox.Text);
            Types      type     = (Types)Enum.Parse(typeof(Types), TypeComboBox.Text);

            int numberOfPages, length, numberOfActors;
            int selectedCategory = CategoryComboBox.SelectedIndex;

            switch (selectedCategory)
            {
            case 0:
                try
                {
                    nISBN         = FirstAdditionalInformationInfoTextBox.Text;
                    numberOfPages = int.Parse(SecondAdditionalInformationInfoTextBox.Text);

                    Book book = new Book(title, author, category, type, nISBN, numberOfPages);
                    BookList.Add(book);

                    totalToRead = book.News(totalToRead, "add");
                }
                catch
                {
                    MessageBox.Show("Ilość stron powinna być podana jako liczba", "Zła wartość");
                }
                break;

            case 1:
                try
                {
                    length         = int.Parse(SecondAdditionalInformationInfoTextBox.Text);
                    numberOfActors = int.Parse(FirstAdditionalInformationInfoTextBox.Text);

                    Audiobook audiobook = new Audiobook(title, author, category, type, length, numberOfActors);
                    AudiobookList.Add(audiobook);

                    totalToListen = audiobook.News(totalToListen, "add");
                }
                catch
                {
                    MessageBox.Show("Czas trwania oraz liczba aktorów powinny być podane jako liczby", "Zła wartość");
                }
                break;

            case 2:
                try
                {
                    releaseDate = FirstAdditionalInformationInfoTextBox.Text;
                    length      = int.Parse(SecondAdditionalInformationInfoTextBox.Text);

                    Movie movie = new Movie(title, author, category, type, length, releaseDate);
                    MovieList.Add(movie);

                    totalToWatch = movie.News(totalToWatch, "add");
                }
                catch
                {
                    MessageBox.Show("Czas trwania powinien być podany jako liczba", "Zła wartość");
                }
                break;
            }
            SetNewsTextBlocks(selectedCategory);
        }
Exemplo n.º 4
0
        private void ReadTXTFile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string fileName = TXTfilePath.Text + TXTfileName.Text + ".txt";

                FileStream fileStream = new FileStream(fileName,
                                                       FileMode.Open, FileAccess.Read);

                try
                {
                    StreamReader streamReader = new StreamReader(fileStream);

                    while (streamReader.EndOfStream == false)
                    {
                        string   line  = streamReader.ReadLine();
                        string[] table = line.Split('_');

                        if (table[0] == "Książka")
                        {
                            Categories category      = (Categories)Enum.Parse(typeof(Categories), "Książka");
                            string     title         = table[1];
                            string     author        = table[2];
                            string     nISBN         = table[3];
                            int        numberOfPages = int.Parse(table[4]);
                            Types      type          = (Types)Enum.Parse(typeof(Types), table[5]);
                            Book       book          = new Book(title, author, category, type, nISBN, numberOfPages);
                            BookList.Add(book);
                            totalToRead = book.News(totalToRead, "add");
                        }
                        else if (table[0] == "Audiobook")
                        {
                            Categories category       = (Categories)Enum.Parse(typeof(Categories), "Audiobook");
                            string     title          = table[1];
                            string     author         = table[2];
                            int        length         = int.Parse(table[3]);
                            int        numberOfActors = int.Parse(table[4]);
                            Types      type           = (Types)Enum.Parse(typeof(Types), table[5]);
                            Audiobook  audiobook      = new Audiobook(title, author, category, type, length, numberOfActors);
                            AudiobookList.Add(audiobook);
                            totalToListen = audiobook.News(totalToListen, "add");
                        }
                        else if (table[0] == "Film")
                        {
                            Categories category    = (Categories)Enum.Parse(typeof(Categories), "Film");
                            string     title       = table[1];
                            string     author      = table[2];
                            int        length      = int.Parse(table[3]);
                            string     releaseDate = table[4];
                            Types      type        = (Types)Enum.Parse(typeof(Types), table[5]);
                            Movie      movie       = new Movie(title, author, category, type, length, releaseDate);
                            MovieList.Add(movie);
                            totalToWatch = movie.News(totalToWatch, "add");
                        }
                        else
                        {
                            MessageBox.Show("Wystąpił błąd podczas odczytywana danych z pliku");
                        }
                    }

                    streamReader.Close();

                    MessageBox.Show("Wczytano pomyslnie");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Nie można wczytać pliku.");
                }
                int selectedCategory = CategoryComboBox.SelectedIndex;
                SetNewsTextBlocks(selectedCategory);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Nie można otworzyć pliku.");
            }
        }