Beispiel #1
0
        simpleInd indMethods = new simpleInd();  //methods access

        //Add button is clicked, user wants to add a monkey to starting population
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //Step 1: retrieve data from form
            if (Validator.TextEntered(txtAge, "Age") &&
                Validator.IsInt(txtAge, "Age") &&
                Validator.WithinRange(txtAge, 0, 360, "Age"))
            {
                age      = Convert.ToInt32(txtAge.Text);                                         //get individual's age from form
                ageClass = indMethods.AssignAgeClass(age);                                       //get an age class designation based on age
                simpleInd newInd = new simpleInd(countID, ageClass, age, false, 0, false, 0, 0); //create a new individual w no dependencies
                countID++;

                //Does an adult female have a dependent infant? If yes, get age and sex of infant
                //REFACTOR THIS INTO OWN METHOD
                if (chkDepInf.Checked)
                {
                    if (Validator.TextEntered(txtInfAge, "Infant Age") &&
                        Validator.IsInt(txtInfAge, "Infant Age") &&
                        Validator.WithinRange(txtInfAge, 0, 11, "Infant Age"))
                    {
                        infAge                  = Convert.ToInt32(txtInfAge.Text);                                //how old is dependent infant?
                        newInd.DepInf           = true;                                                           //declare infant dependency
                        newInd.MonthsSinceBirth = infAge;                                                         //add 6 months of pregnancy time to age

                        if (rdoFemale.Checked)                                                                    //dependent infant is a female, need to add a baby to population
                        {
                            simpleInd baby = new simpleInd(countID, 0, infAge, false, 0, false, 0, newInd.IndID); //create baby, link to mom
                            countID++;
                            newInd.DepInfFem = true;
                            newInd.DepInfID  = baby.IndID; //link mom to baby
                            startingPop.Add(newInd);
                            startingPop.Add(baby);
                        }
                        else //male baby, need to track but not add to population
                        {
                            newInd.DepInf = true;
                            startingPop.Add(newInd); //mom is added with
                        }
                    }
                }

                else //no dependent infant info added, just add individual to population as is.
                {
                    newInd.MonthsSinceBirth = 12; //no dependent, so assume it has been at least a year since ind had an infant
                    startingPop.Add(newInd);
                }
                RefreshPopulation(startingPop, lstPop, txtStartPop);
                ResetForm();
            }
        }