Ejemplo n.º 1
0
        private void BTBirdCreate_Click(object sender, EventArgs e)
        {
            string name = Inputs.InputName(TBBirdName.Text);

            if (name != null)
            {
                int weight = Inputs.InputWeight(TBBirdWeight.Text);
                if (weight > 0)
                {
                    bool flying = false;
                    if (CBFlying.Checked)
                    {
                        flying = true;
                    }
                    bool domestic = false;
                    if (CBDomestic.Checked)
                    {
                        domestic = true;
                    }

                    ClassBirds bird = new ClassBirds(flying, domestic, weight, name);
                    SupportingMethods.zoo.Add(bird);
                    birds.Add(bird);
                }
                else
                {
                    SupportingMethods.ShowMistake(content: "Вес введен неверно");
                }
            }

            TBBirdName.Clear();
            TBBirdWeight.Clear();
        }
Ejemplo n.º 2
0
        private void BTShowBirds_Click(object sender, EventArgs e)
        {
            int numberOfBirds = 0;

            foreach (object animal in SupportingMethods.zoo)
            {
                FindAndOutputBirds(animal);
            }
            if (numberOfBirds == 0)
            {
                string content = "Не было создано ни одной птицы";
                string header  = "info";
                MessageBox.Show(content, header, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            void FindAndOutputBirds(object animal)
            {
                if (animal is ClassBirds)
                {
                    numberOfBirds++;
                    ClassBirds bird = animal as ClassBirds;

                    string output = bird.Name + "\r\n";
                    TBOutputBirds.Text += output;
                }
            }
        }
Ejemplo n.º 3
0
        private void CountSumWeight()
        {
            foreach (object animal in SupportingMethods.zoo)
            {
                if (animal is KingdomAnimal)
                {
                    if (animal is ClassBirds)
                    {
                        if (selectedItem == 2)
                        {
                            ClassBirds bird = animal as ClassBirds;
                            numberOfObjectsWithThisType++;

                            sumWeight += bird.Weight;
                        }
                        continue;
                    }
                    if (animal is ClassMammals)
                    {
                        if (animal is OrderArtiodactyl)
                        {
                            if (selectedItem == 3)
                            {
                                OrderArtiodactyl artiodactyl = animal as OrderArtiodactyl;
                                numberOfObjectsWithThisType++;

                                sumWeight += artiodactyl.Weight;
                            }
                            continue;
                        }
                        if (selectedItem == 1)
                        {
                            ClassMammals mammal = animal as ClassMammals;
                            numberOfObjectsWithThisType++;

                            sumWeight += mammal.Weight;
                        }
                        continue;
                    }
                    if (selectedItem == 0)
                    {
                        KingdomAnimal being = animal as KingdomAnimal;
                        numberOfObjectsWithThisType++;

                        sumWeight += being.Weight;
                    }
                }
            }
        }