コード例 #1
0
ファイル: MainForm.cs プロジェクト: ann-marieb/cs2018
        /// <summary>
        /// Validate and add animal on Add animal button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddAnimal_Click(object sender, EventArgs e)
        {
            {
                //send animal info for validation and receive errorText.
                string errorText = AnimalMaker.ValidateInput(txtName.Text, txtAge.Text, lstGender.SelectedIndex,
                                                             lstSpecies.Text, txtAnimalCatInfo.Text, txtSpeciesInfo.Text);

                //if errorText is not empty, input is not valid.
                if (!string.IsNullOrEmpty(errorText))
                {
                    MessageBox.Show(errorText);
                }

                //if errorText is empty, input is valid.
                else
                {
                    bool notUsed = int.TryParse(txtAge.Text, out int ageInt);                                           //convert age from string to integer
                    var  animal  = AnimalMaker.MakeAnimal(txtName.Text, ageInt, lstGender.Text,
                                                          lstSpecies.Text, txtAnimalCatInfo.Text, txtSpeciesInfo.Text); //send info to AnimalMaker for creation of animal
                    bool addOK = animalManagerObj.AddAnimal(animal);                                                    //send animal to AnimalManager to be added
                    if (addOK)
                    {
                        UpdateAnimalList(); //display animal in Animal list
                        InitializeGui();    //clear form
                    }
                    else
                    {
                        MessageBox.Show("Animal not added");
                    }
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: ann-marieb/cs2018
        /// <summary>
        /// Create example animals to enable testing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPop_Click(object sender, EventArgs e)
        {
            var someAnimals = AnimalMaker.makeSomeAnimals(); //make example

            foreach (var animal in someAnimals)
            {
                animalManagerObj.AddAnimal(animal);
            }
            UpdateAnimalList(); //display animal in Animal list
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: ann-marieb/cs2018
        /// <summary>
        /// When Species is selected, display groupbox for species specific info.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstSpecies_SelectedIndexChanged(object sender, EventArgs e)
        {
            gbxSpecies.Text     = lstSpecies.Text;                        // name groupbox with selected species
            lblSpeciesInfo.Text = AnimalMaker.LabelText(lstSpecies.Text); //label for species specific info

            //if Animal Category "all" is selected, species selection generates groupbox name and
            //label for animal category specific info.
            if (lstAnimalCategory.Text == "all")
            {
                gbxAnimalCategory.Text = AnimalMaker.GroupBoxName(lstSpecies.Text);
                lblAnimalCatInfo.Text  = AnimalMaker.AnimalCategoryInfoWhenAnimalSelected(lstSpecies.Text);
            }
            gbxSpecies.Visible = true; //make groupbox visible
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: ann-marieb/cs2018
        /// <summary>
        /// When Animal Category is selected display groupbox for category specific info.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstAnimalCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            gbxAnimalCategory.Visible = true;                                               //make groupbox visible
            gbxAnimalCategory.Text    = lstAnimalCategory.Text;                             //name groupbox with selected animal category

            lstSpecies.DataSource    = AnimalMaker.GetSpeciesNames(lstAnimalCategory.Text); //populate Species listbox
            lstSpecies.SelectedIndex = -1;                                                  //unselect

            if (lstAnimalCategory.Text != "all")
            {
                lblAnimalCatInfo.Text = AnimalMaker.LabelText(lstAnimalCategory.Text); //label for animal category specific info
            }
            gbxSpecies.Visible = false;                                                //hide groupbox
        }