Example #1
0
 public void Partner_Added(object sender, PartnerAddedEventArgs e)
 {
     PartnerAdded?.Invoke(sender, e);
 }
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.PartnerName.Text == string.Empty)
            {
                MessageBox.Show(Application.Current.Resources["AddPartnerWindowEmptyPartnerErrorMessage"].ToString(),
                                Application.Current.Resources["AddPartnerWindowEmptyPartnerErroMessageBoxTitle"].ToString());
            }
            else
            {
                Node <Person> child = null;
                if (Regex.Split(this.ChildCombobox.SelectedValue.ToString(), " & ").Length == 1)
                {
                    child = PersonTree.GetNodeByName(PersonTree.Tree, this.ChildCombobox.SelectedValue.ToString(), string.Empty);
                }
                else if (Regex.Split(this.ChildCombobox.SelectedValue.ToString(), " & ").Length == 2)
                {
                    child = PersonTree.GetNodeByName(PersonTree.Tree, Regex.Split(this.ChildCombobox.SelectedValue.ToString(), " & ")[0],
                                                     Regex.Split(this.ChildCombobox.SelectedValue.ToString(), " & ")[1]);
                }

                string errorMessage = string.Empty;

                DateTime            birthDate;
                DateTime            deathDate;
                Nullable <DateTime> partnerBirthDate = null;
                Nullable <DateTime> partnerDeathDate = null;

                try
                {
                    birthDate        = DateTime.ParseExact(this.PartnerBirthDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None);
                    partnerBirthDate = (Nullable <DateTime>)birthDate;
                }
                catch (FormatException)
                {
                    if (this.PartnerBirthDate.Text.ToString() == string.Empty)
                    {
                        partnerBirthDate = null;
                    }
                    else
                    {
                        errorMessage += (string)FindResource("AddPartnerWindowPartnerBirthDateFormatError");
                    }
                }

                try
                {
                    deathDate        = DateTime.ParseExact(this.PartnerDeathDate.Text.ToString(), "dd/MM/yyyy", null, DateTimeStyles.None);
                    partnerDeathDate = (Nullable <DateTime>)deathDate;
                }
                catch (FormatException)
                {
                    if (this.PartnerDeathDate.Text.ToString() == string.Empty)
                    {
                        partnerDeathDate = null;
                    }
                    else
                    {
                        errorMessage += "\n" + (string)FindResource("AddPartnerWindowPartnerDeathDateFormatError");
                    }
                }

                if (errorMessage == string.Empty)
                {
                    if (PersonTree.GetNodeByName(PersonTree.Tree, this.PartnerName.Text, string.Empty) != null)
                    {
                        child.Value.IsPartnerInFamily = true;
                    }

                    child.Value.Partner           = this.PartnerName.Text;
                    child.Value.PartnerBirthDate  = partnerBirthDate;
                    child.Value.PartnerDeathDate  = partnerDeathDate;
                    child.Value.PartnerBirthPlace = this.PartnerBirthPlace.Text;

                    PartnerAddedEventArgs eventArgs = new PartnerAddedEventArgs();
                    eventArgs.childName   = child.Value.Name;
                    eventArgs.partnerName = child.Value.Partner;
                    eventArgs.birthDate   = child.Value.PartnerBirthDate;
                    eventArgs.deathDate   = child.Value.PartnerDeathDate;
                    eventArgs.birthPlace  = child.Value.PartnerBirthPlace;

                    PartnerAdded?.Invoke(this, eventArgs);
                    this.Close();
                }
                else
                {
                    MessageBox.Show(errorMessage, (string)FindResource("DateFormatErrorMessageBoxTitle"));
                }
            }
        }
 private void PartnerAdded(object sender, PartnerAddedEventArgs e)
 {
     generationManager.AddPartner(e.childName, e.partnerName, e.birthDate, e.deathDate, e.birthPlace);
 }