/// <summary> /// User adds a spouse to a person /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lbSpouseAdd_Click(object sender, EventArgs e) { if (lbSpouseAdd.ForeColor == SystemColors.InactiveCaption) { // Button inactivated return; } Person spouse = (Person)cmbMarriageSpouse.SelectedItem; if (spouse == null) { return; } Person man = (mCurrentPerson.gender == Gender.Male) ? mCurrentPerson : spouse; Person woman = (mCurrentPerson.gender == Gender.Male) ? spouse : mCurrentPerson; // Create a marriage instance, but store it in a temporary variable in case the user changes his mind. Marriage m = new Marriage(man.id, woman.id, tbMarriageDate.Text, tbMarriageLocation.Text, tbMarriageNotes.Text); mTempMarriages.Add(m); lbSpouses.Items.Add(spouse); lbSpouses.DisplayMember = "listBoxString"; lbSpouses.ValueMember = "id"; }
/// <summary> /// Adds a marriage /// </summary> /// <param name="m"></param> public void AddMarriage(Marriage m) { if (!mMarriages.Contains(m)) { mMarriages.Add(m); } // Make sure both husband and wife is updated mDictPersons[m.husband].AddMarriage(m.id); mDictPersons[m.wife].AddMarriage(m.id); }
/// <summary> /// Removes a marriage /// </summary> /// <param name="m">Marriage instance</param> public void RemoveMarriage(Marriage m) { mMarriages.Remove(m); }
/// <summary> /// Add a marriage /// </summary> /// <param name="man"></param> /// <param name="woman"></param> /// <param name="text"></param> /// <param name="place"></param> /// <param name="notes"></param> /// <returns></returns> public Marriage AddMarriage(Person man, Person woman, String text, String place, String notes) { // See if there already is a marriage containing these twe people for (int i = 0; i < mMarriages.Count; i++) { if (mMarriages[i].husband == man.id && mMarriages[i].wife == woman.id) { // Already there... return mMarriages[i]; } } // Not there ...add a new one Marriage m = new Marriage(man.id, woman.id, text, place, notes); man.AddMarriage(m.id); woman.AddMarriage(m.id); mMarriages.Add(m); return m; }