private void btnAddZebra_Click(object sender, EventArgs e) { //todo foreach (var zebra in this.myStudbook.GetAllZebras()) { if (zebra.Id == Convert.ToInt32(tbId.Text)) { MessageBox.Show("There is already a zebra like that in the list!"); return; } } Gender gender = Gender.MARE; if (rbStallion.Text == Gender.STALLION.ToString()) { gender = Gender.STALLION; } else if (rbUnknownGender.Text == Gender.UNKNOWN.ToString()) { gender = Gender.UNKNOWN; } int id = Convert.ToInt32(tbId.Text); int dz = Convert.ToInt32(tbDz.Text); int mother = Convert.ToInt32(tbMotherId.Text); int father = Convert.ToInt32(tbFatherId.Text); Zebra z = new Zebra(id, tbName.Text, dz, mother, father, gender); this.myStudbook.AddZebra(z); MessageBox.Show("You have added a new zebra!"); }
/// <summary> /// if this studbook already has a zebra with the same id as the id of zebra z /// then nothing is added and the returnvalue is false; /// otherwise z is added to the list of zebras and the returnvalue is true /// </summary> /// <param name="z"></param> /// <returns></returns> public bool AddZebra(Zebra z) {//todo if (GetZebra(z.Id) == null) { zebras.Add(z); return(true); } return(false); }
private void btnShowInfoOf1Zebra_Click(object sender, EventArgs e) { lbInfo.Items.Clear(); Zebra zebra = myStudbook.GetZebra(Convert.ToInt32(tbOthers.Text)); //todo if (zebra != null) { lbInfo.Items.Add(zebra.getInfo()); } else { MessageBox.Show("There is no zebra with that ID!"); } }
public void addSomeTestingStuff() { Zebra z; z = new Zebra(11, "Emma", -1); this.myStudbook.AddZebra(z); z = new Zebra(22, "Wilhelmina", 11); this.myStudbook.AddZebra(z); z = new Zebra(33, "Juliana", 32, 22, -1, Gender.MARE); this.myStudbook.AddZebra(z); z = new Zebra(35, "Bernhard", 15, -1, -1, Gender.STALLION); this.myStudbook.AddZebra(z); z = new Zebra(44, "Beatrix", 35, 33, 35, Gender.MARE); this.myStudbook.AddZebra(z); z = new Zebra(55, "Willem Alexander", 30, 44, -1, Gender.STALLION); this.myStudbook.AddZebra(z); z = new Zebra(60, "Maxima"); this.myStudbook.AddZebra(z); z = new Zebra(75, "Clara", 22, -1, 35, Gender.MARE); this.myStudbook.AddZebra(z); z = new Zebra(66, "Amalia", 44, 60, 55, Gender.MARE); this.myStudbook.AddZebra(z); z = new Zebra(32, "Sam"); this.myStudbook.AddZebra(z); z = new Zebra(36, "Samantha", 45, -1, 32, Gender.MARE); this.myStudbook.AddZebra(z); z = new Zebra(41, "Clara", 32, 36, 35, Gender.MARE); this.myStudbook.AddZebra(z); z = new Zebra(72, "Carlo", 52); this.myStudbook.AddZebra(z); z = new Zebra(61, "Dora", 47, 41, 72, Gender.MARE); this.myStudbook.AddZebra(z); z = new Zebra(62, "Emma", 26, 61, 35, Gender.MARE); this.myStudbook.AddZebra(z); }
/// <summary> /// if this studbook already has a zebra with the same id as the id of zebra z /// then nothing is added and the returnvalue is false; /// otherwise z is added to the list of zebras and the returnvalue is true /// </summary> /// <param name="z"></param> /// <returns></returns> public bool AddZebra(Zebra z) {//todo foreach (var zebra in this.zebras) { if (z.Id == zebra.Id) { return(false); } } //Father if (z.FatherId == -1) { z.FatherId = -1; } else if (z.FatherId > 0 && z.Gender == Gender.STALLION) { z.FatherId = z.FatherId; } else { z.FatherId = -1; } //Mother if (z.MotherId == -1) { z.MotherId = -1; } else if (z.MotherId > 0 && z.Gender == Gender.MARE) { z.MotherId = z.MotherId; } else { z.MotherId = -1; } this.zebras.Add(z); return(true); }