Ejemplo n.º 1
0
        // Zet op stapel
        // Add the user input to each stapel and display all elements of each stapel.
        private void button1_Click(object sender, EventArgs e)
        {
            // Intstapel
            if (int_Field.Text != "")
            {
                try
                {
                    IntStapel.Toevoegen(int.Parse(int_Field.Text));
                    intStapel_Field.Text = IntStapel.ToString();
                    int_Field.Clear();
                }
                catch (FormatException err)
                {
                    Console.WriteLine(err.StackTrace);
                    MessageBox.Show("Number should be an integer.", err.GetType().ToString());
                }
                catch (OverflowException err)
                {
                    Console.WriteLine(err.StackTrace);
                    MessageBox.Show($"Number should be no bigger than {int.MaxValue}", err.GetType().ToString());
                }
            }

            // Stringstapel
            if (string_Field.Text != "")
            {
                StringStapel.Toevoegen(string_Field.Text);
                stringStapel_Field.Text = StringStapel.ToString();
                string_Field.Clear();
            }

            // Bookstapel
            if (title_Field.Text != "" || author_Field.Text != "" || date_Field.Text != "")
            {
                (string title, string author, string date)bookStrings = (title_Field.Text, author_Field.Text, date_Field.Text);
                var book = new Book(bookStrings.title, bookStrings.author, bookStrings.date);
                BookStapel.Toevoegen(book);
                bookStapel_Field.Text = BookStapel.ToString();
                title_Field.Clear();
                author_Field.Clear();
                date_Field.Clear();
            }
        }
Ejemplo n.º 2
0
        // Haal van stapel
        // Pop the first elements from each stapel. Display the popped element and display the remaining elements.
        private void button2_Click(object sender, EventArgs e)
        {
            {
                var result = IntStapel.Verwijderen();
                intStapel_ItemField.Text = result != 0 ? result.ToString() : "Stapel is leeg";
                intStapel_Field.Text     = IntStapel.ToString();
            }

            {
                var result = StringStapel.Verwijderen();
                stringStapel_ItemField.Text = result ?? "Stapel is leeg";
                stringStapel_Field.Text     = StringStapel.ToString();
            }

            {
                var result = BookStapel.Verwijderen();
                bookStapel_ItemField.Text = result != null?result.ToString() : "Stapel is leeg";

                bookStapel_Field.Text = BookStapel.ToString();
            }
        }