Example #1
0
        /// <summary>
        /// The button used to add an animal to the list box.
        /// </summary>
        /// <param name="sender"> Not available.</param>
        /// <param name="e"> The parameter is not used.</param>
        private void addAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get the selected animal type from the list box.
                AnimalType animalType = (AnimalType)this.animalTypeComboBox.SelectedItem;

                // Create an animal based on the type.
                Animal animal = AnimalFactory.CreateAnimal(animalType, "Yoooo", 17, 71, Gender.Female);

                // Make a new window with the new animal.
                AnimalWindow animalWindow = new AnimalWindow(animal);

                // If the dialog box is shown then add the animal to the list and repopulate the screen with the updated list.
                if (animalWindow.ShowDialog() == true)
                {
                    zoo.AddAnimal(animal);

                    PopulateAnimalListBox();
                }
                else
                {
                    // If the above code doesn't work, do nothing.
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("You must choose an animal type before you can add an animal.");
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new animal window to allow for editing a pre-existing animal.
        /// </summary>
        /// <param name="sender">System data.</param>
        /// <param name="e">Associated event data.</param>
        private void animalListBox_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            // Get the selected animal in the list box.
            Animal animal = this.animalListBox.SelectedItem as Animal;

            if (animal != null)
            {
                // Create new animal window.
                AnimalWindow animalWindow = new AnimalWindow(animal);

                // Show the animal window.
                animalWindow.ShowDialog();

                if (animalWindow.DialogResult == true)
                {
                    if (animal.IsPregnant == true)
                    {
                        this.comoZoo.RemoveAnimal(animal);
                        this.comoZoo.AddAnimal(animal);
                    }

                    PopulateAnimalListBox();
                }
            }
        }
Example #3
0
        /// <summary>
        /// When you double click on the animal box you can change its attributes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void animalListBox_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            // Get the selected item and cast it as an animal.
            Animal animal = (Animal)animalListBox.SelectedItem;

            // If the animal is not null then create a new animal window.
            if (animal != null)
            {
                AnimalWindow animalWindow = new AnimalWindow(animal);

                // If the dialog box is shown, re-populate the animal list box.
                if (animalWindow.ShowDialog() == true)
                {
                    if (animal.IsPregnant == true)
                    {
                        // Remove the animal from the zoo.
                        zoo.RemoveAnimal(animal);

                        // Add the animal back into the zoo.
                        zoo.AddAnimal(animal);
                    }
                }
                {
                    //PopulateAnimalListBox();
                }
            }
        }
        /// <summary>
        /// Edits the animal on the double-click event.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The arguments of the event.</param>
        private void animalListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Animal animal = this.animalListBox.SelectedItem as Animal;

            if (animal != null)
            {
                AnimalWindow window = new AnimalWindow(animal);

                window.ShowDialog();
            }
        }
        /// <summary>
        /// Adds an new animal to the zoo.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The event arguments of the event.</param>
        private void addAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            AnimalType animalType = (AnimalType)this.animalTypeComboBox.SelectedItem;

            Animal animal = AnimalFactory.CreateAnimal(animalType, "Animal", 0, 0.0, Gender.Female);

            AnimalWindow window = new AnimalWindow(animal);

            window.ShowDialog();

            if (window.DialogResult == true)
            {
                this.comoZoo.AddAnimal(animal);
            }
        }
Example #6
0
        /// <summary>
        /// Edits the selected animal.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The event arguments of the event.</param>
        private void animalListBox_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Animal animal = (Animal)this.animalListBox.SelectedItem;

            if (animal != null)
            {
                AnimalWindow window = new AnimalWindow(animal);

                if (window.ShowDialog() == true)
                {
                    if (animal.IsPregnant == true)
                    {
                        this.comoZoo.AddAnimal(animal);
                        this.comoZoo.RemoveAnimal(animal);
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// Adds an new animal to the zoo.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The event arguments of the event.</param>
        private void addAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AnimalType animalType = (AnimalType)this.animalTypeComboBox.SelectedItem;

                Animal animal = AnimalFactory.CreateAnimal(animalType, "Animal", 0, 0.0, Gender.Female);

                AnimalWindow window = new AnimalWindow(animal);

                window.ShowDialog();

                if (window.DialogResult == true)
                {
                    this.comoZoo.AddAnimal(animal);
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("An animal type must be selected before adding an animal to the zoo.");
            }
        }
Example #8
0
        /// <summary>
        /// Adds an animal to the animal list in the WPF.
        /// </summary>
        /// <param name="sender">System data.</param>
        /// <param name="e">Associated event data.</param>
        private void addAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get the selected animal from the combo box. Create a new animal using the animal factory's create animal method.
                AnimalType animalType = (AnimalType)this.animalTypeComboBox.SelectedItem;
                Animal     animal     = AnimalFactory.CreateAnimal(animalType, "Max", 2, 45, Gender.Female);

                AnimalWindow animalWindow = new AnimalWindow(animal);

                animalWindow.ShowDialog();

                if (animalWindow.DialogResult == true)
                {
                    comoZoo.AddAnimal(animal);

                    PopulateAnimalListBox();
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("An animal type must be selected before adding an animal to the zoo.");
            }
        }