private void BTArtiodactylCreate_Click(object sender, EventArgs e) { string name = Inputs.InputName(TBArtiodactylName.Text); if (name != null) { int weight = Inputs.InputWeight(TBArtiodactylWeight.Text); if (weight > 0) { int incubationPeriod = Inputs.InputIncubationPeriod(TBArtiodactylIncubationPeriod.Text); if (incubationPeriod > 0) { int lifeExpectancy = Inputs.InputLifeExpectancy(TBArtiodactylMaxAge.Text); if (lifeExpectancy > 0) { bool horns = false; if (checkBox1.Checked) { horns = true; } if (SupportingMethods.IsStringEmpty(TBArtiodactylHabitat.Text)) { SupportingMethods.ShowMistake(); } else { string habitat = TBArtiodactylHabitat.Text; OrderArtiodactyl artiodactyl = new OrderArtiodactyl(horns, habitat, incubationPeriod, lifeExpectancy, weight, name); SupportingMethods.zoo.Add(artiodactyl); artiodactyls.Add(artiodactyl); } } else { SupportingMethods.ShowMistake("Продолжительность жизни введена неверно"); } } else { SupportingMethods.ShowMistake("Период вынашивания введен неверно"); } } else { SupportingMethods.ShowMistake(content: "Вес введен неверно"); } } TBArtiodactylHabitat.Clear(); TBArtiodactylIncubationPeriod.Clear(); TBArtiodactylMaxAge.Clear(); TBArtiodactylName.Clear(); TBArtiodactylWeight.Clear(); }
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; } } } }