private void buttonAdd_Click_1(object sender, EventArgs e) { // Do some final checks and create a new individual and // add it to the list. Individual newIndividual = new Individual(); newIndividual.Name = textBoxName.Text; newIndividual.Sex = (Individual.SexEnum)comboBoxSex.SelectedItem; if (dateTimePickerActualDOB.Checked) { newIndividual.ActualDOB = dateTimePickerActualDOB.Value.Date; } if (dateTimePickerFieldDOB.Checked) { newIndividual.FieldEstimatedDOB = dateTimePickerFieldDOB.Value.Date; } newIndividual.Comment = textBoxComments.Text; newIndividual.IDNote = textBoxIDNotes.Text; if (!checkBoxMotherUnknown.Checked) { newIndividual.Mother = (Individual)comboBoxMother.SelectedItem; } // We need to check the IDs of both the current and new individuals // to generate and id so create a new list with all the indiviudals List <Individual> newAndCurrent = new List <Individual>(individualList); newAndCurrent.AddRange(this.newIndividuals); newIndividual.ID = Individual.GenerateNewId(newAndCurrent, DailyData.Current.TroopVisit, newIndividual.Sex); // We need to create initial individual sighting and ageclass entries IndividualSighting s = new IndividualSighting(); s.Individual = newIndividual; s.Comments = this.textBoxComments.Text; s.Sighting = (Sighting)this.comboBoxSighting.SelectedValue; s.TroopVisit = DailyData.Current.TroopVisit; newIndividual.SightingHistory.Add(s); IndividualAgeClass a = new IndividualAgeClass(); a.AgeClass = (AgeClass)this.comboBoxAgeClass.SelectedValue; a.TroopVisit = DailyData.Current.TroopVisit; a.Individual = newIndividual; a.Comments = textBoxComments.Text; newIndividual.AgeClassHistory.Add(a); // Add to binding list this.newIndividuals.Add(newIndividual); // Also add to list of Individuals for // id code updating this.individualList.Add(newIndividual); }
private void buttonAdd_Click(object sender, EventArgs e) { IndividualReproductiveState irs = new IndividualReproductiveState(); irs.Individual = (Individual)comboBoxFemales.SelectedItem; irs.TroopVisit = DailyData.Current.TroopVisit; irs.State = (ReproductiveState)comboBoxStateNew.SelectedItem; irs.Comments = textBoxCommentsNew.Text; foreach (IndividualReproductiveState x in boundReproductiveStates) { if (x.Individual.ID == irs.Individual.ID) { MessageBox.Show("This " + irs.Individual.Name + " already has an entry in the list. " + "Update the individuals detail with the 'Update' control."); return; } } // Is this female already listed as Adult? if (irs.Individual.CurrentAgeClass() == null || irs.Individual.CurrentAgeClass(DailyData.Current.TroopVisit.Date).AgeClass.ID != adult.ID) { MessageBox.Show("This " + irs.Individual.Name + " is not current listed as adult. " + "A an entry will be created to change her age class to 'A'"); IndividualAgeClass iac = new IndividualAgeClass(); iac.AgeClass = adult; iac.TroopVisit = DailyData.Current.TroopVisit; iac.Individual = irs.Individual; iac.Comments = "AUTOMATICALLY GENERATED ENTRY :- Age class changed to adult on observation of " + " start of first reproductive cycle."; DailyData.Current.NewAgeClass.Add(iac); } boundReproductiveStates.Add(irs); }
private void buttonOk_Click(object sender, EventArgs e) { // We need to do some final checks here, namely the free form // text fields. // Check that the ID is valid //if (!this.checkIDValidity(individuals, this.troopVisitFirstObserved, // (Individual.SexEnum)this.comboBoxSex.SelectedItem, //this.textBoxTrappingID.Text)) //{ // MessageBox.Show("The trapping ID that has been enter is not valid. It must a 4 digit code of the form:\r" + // "Troop ID of first observation + Sex + Digit + Digit" // , "Invalid Trapping ID" // , MessageBoxButtons.OK // , MessageBoxIcon.Error); //return; //} // Check that the name is valid if (this.textBoxName.Text.Length < 1 || this.textBoxName.Text.Length > 45) { MessageBox.Show("The Name that has been enter is too long. It must be less than 44 digits long" , "Invalid Name" , MessageBoxButtons.OK , MessageBoxIcon.Error); return; } // Check the IDNote is valid if (this.textBoxIDNotes.Text.Length > 200) { MessageBox.Show("The ID Note that has been enter is too long. It must be less than 200 digits long" , "Invalid ID Note" , MessageBoxButtons.OK , MessageBoxIcon.Error); return; } // Check the Comment is valid if (this.textBoxIDNotes.Text.Length > 200) { MessageBox.Show("The Comment that has been enter is too long. It must be less than 200 digits long" , "Invalid Comment" , MessageBoxButtons.OK , MessageBoxIcon.Error); return; } // Assign the values that were not bound individual.Sex = (Individual.SexEnum) this.comboBoxSex.SelectedItem; individual.TrappingID = this.textBoxTrappingID.Text; individual.Name = textBoxName.Text; //Session.SaveOrUpdate(); if (isNew) { // We need to create initial individual sighting and ageclass entries IndividualSighting s = new IndividualSighting(); s.Individual = this.individual; s.Comments = this.textBoxComments.Text; s.Sighting = (Sighting)this.comboBoxSighting.SelectedValue; s.TroopVisit = this.troopVisitFirstObserved; this.individual.SightingHistory.Add(s); IndividualAgeClass a = new IndividualAgeClass(); a.AgeClass = (AgeClass)this.comboBoxAgeClass.SelectedValue; a.TroopVisit = this.troopVisitFirstObserved; a.Individual = this.individual; a.Comments = textBoxComments.Text; this.individual.AgeClassHistory.Add(a); } Session.SaveOrUpdate(individual); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); }