Пример #1
0
        //Create animal
        private Animal CreateAnimal()
        {
            int age_value      = int.Parse(ageTxtBox.Text);
            int textbox1_value = int.Parse(textBox1.Text);

            Category cat = (Category)categoryCmb.SelectedIndex;

            switch (cat)
            {
            case Category.Mammal:
                Mammal mammal = (Mammal)animalObjCmb.SelectedIndex;
                switch (mammal)
                {
                case Mammal.Cat:
                    Cat m_cat = new Cat(nameTxtBox.Text, age_value, (Gender)genderCmb.SelectedIndex, textbox1_value, textBox2.Text);
                    return(m_cat);

                case Mammal.Dog:
                    Dog m_dog = new Dog(nameTxtBox.Text, age_value, (Gender)genderCmb.SelectedIndex, textbox1_value, textBox2.Text);
                    return(m_dog);

                case Mammal.Deer:
                    Deer m_deer = new Deer(nameTxtBox.Text, age_value, (Gender)genderCmb.SelectedIndex, textbox1_value, textBox2.Text);
                    return(m_deer);

                default:
                    break;
                }
                break;

            case Category.Bird:
                Bird bird = (Bird)animalObjCmb.SelectedIndex;
                switch (bird)
                {
                case Bird.Eagle:
                    Eagle m_eagle = new Eagle(nameTxtBox.Text, age_value, (Gender)genderCmb.SelectedIndex, textbox1_value, textBox2.Text);
                    return(m_eagle);

                case Bird.Duck:
                    Duck m_duck = new Duck(nameTxtBox.Text, age_value, (Gender)genderCmb.SelectedIndex, textbox1_value, textBox2.Text);
                    return(m_duck);

                case Bird.Chicken:
                    Chicken m_chicken = new Chicken(nameTxtBox.Text, age_value, (Gender)genderCmb.SelectedIndex, textbox1_value, textBox2.Text);
                    return(m_chicken);

                default:
                    break;
                }
                break;
            }
            return(null);
        }
Пример #2
0
        // Show the selected animals informations its their textboxes or comboboxes
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox_Animals.SelectedIndex > -1)
            {
                Animal an = m_anim_mngr.GetAt(listBox_Animals.SelectedIndex);

                genderCmb.SelectedIndex = (int)an.GenderOfAnimal;
                nameTxtBox.Text         = an.Name;
                ageTxtBox.Text          = an.Age.ToString();

                if (an is Eagle)
                {
                    Eagle eg = (Eagle)an;
                    categoryCmb.SelectedIndex  = (int)Category.Bird;
                    animalObjCmb.SelectedIndex = (int)Bird.Eagle;
                    textBox1.Text = eg.WingsLength.ToString();
                    textBox2.Text = eg.BirdType;
                    UpdateLabel(Category.Bird);
                    comboBoxEaterType.SelectedIndex = (int)an.GetEaterType();
                    SpecieNameLbl.Text = an.GetSpecies();

                    string[] list = an.GetFoodSchedule().GetFoodSchedule();
                    listbox_Food_Schedule.Items.AddRange(list);
                }

                if (an is Duck)
                {
                    Duck duck = (Duck)an;
                    categoryCmb.SelectedIndex  = (int)Category.Bird;
                    animalObjCmb.SelectedIndex = (int)Bird.Duck;
                    textBox1.Text = duck.WingsLength.ToString();
                    textBox2.Text = duck.BirdType;
                    UpdateLabel(Category.Bird);
                    comboBoxEaterType.SelectedIndex = (int)an.GetEaterType();
                    SpecieNameLbl.Text = an.GetSpecies();

                    string[] list = an.GetFoodSchedule().GetFoodSchedule();
                    listbox_Food_Schedule.Items.AddRange(list);
                }

                if (an is Chicken)
                {
                    Chicken chick = (Chicken)an;
                    categoryCmb.SelectedIndex  = (int)Category.Bird;
                    animalObjCmb.SelectedIndex = (int)Bird.Chicken;
                    textBox1.Text = chick.WingsLength.ToString();
                    textBox2.Text = chick.BirdType;
                    UpdateLabel(Category.Bird);
                    comboBoxEaterType.SelectedIndex = (int)an.GetEaterType();
                    SpecieNameLbl.Text = an.GetSpecies();

                    string[] list = an.GetFoodSchedule().GetFoodSchedule();
                    listbox_Food_Schedule.Items.AddRange(list);
                }

                if (an is Deer)
                {
                    Deer deer = (Deer)an;
                    categoryCmb.SelectedIndex  = (int)Category.Mammal;
                    animalObjCmb.SelectedIndex = (int)Mammal.Deer;
                    textBox1.Text = deer.NumberOfTooth.ToString();
                    textBox2.Text = deer.LengthOfTail;
                    UpdateLabel(Category.Mammal);
                    comboBoxEaterType.SelectedIndex = (int)an.GetEaterType();
                    SpecieNameLbl.Text = an.GetSpecies();

                    string[] list = an.GetFoodSchedule().GetFoodSchedule();
                    listbox_Food_Schedule.Items.AddRange(list);
                }

                if (an is Cat)
                {
                    Cat cat = (Cat)an;
                    categoryCmb.SelectedIndex  = (int)Category.Mammal;
                    animalObjCmb.SelectedIndex = (int)Mammal.Cat;
                    textBox1.Text = cat.NumberOfTooth.ToString();
                    textBox2.Text = cat.LengthOfTail;
                    UpdateLabel(Category.Mammal);
                    comboBoxEaterType.SelectedIndex = (int)an.GetEaterType();
                    SpecieNameLbl.Text = an.GetSpecies();

                    string[] list = an.GetFoodSchedule().GetFoodSchedule();
                    listbox_Food_Schedule.Items.AddRange(list);
                }

                if (an is Dog)
                {
                    Dog cat = (Dog)an;
                    categoryCmb.SelectedIndex  = (int)Category.Mammal;
                    animalObjCmb.SelectedIndex = (int)Mammal.Dog;
                    textBox1.Text = cat.NumberOfTooth.ToString();
                    textBox2.Text = cat.LengthOfTail;
                    UpdateLabel(Category.Mammal);
                    comboBoxEaterType.SelectedIndex = (int)an.GetEaterType();
                    SpecieNameLbl.Text = an.GetSpecies();

                    string[] list = an.GetFoodSchedule().GetFoodSchedule();
                    listbox_Food_Schedule.Items.AddRange(list);
                }
            }
        }