예제 #1
0
        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!");
        }
예제 #2
0
 /// <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);
 }
예제 #3
0
파일: Form1.cs 프로젝트: fabestine1/MyThing
        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!");
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        /// <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);
        }