private void AddChildClick(object sender, RoutedEventArgs e) { string tmp = ""; int count_ec = 0; try { bool check1 = first_NameTextBox.Text.Any(who => char.IsLetter(who)); if (first_NameTextBox.Text != null) { if (!check1) { first_NameTextBox.BorderBrush = Brushes.Red; tmp += "Invalid First name! \n"; first_NameTextBox.Text = ""; count_ec++; } } if ((DateTime)dateDatePicker.SelectedDate >= (DateTime.Today)) { tmp += "Invalid Date!"; count_ec++; } bool check = iDTextBox.Text.Any(who => !char.IsLetter(who)); if ((iDTextBox.Text != null) && (iDTextBox.Text != "0")) { if (!check) { iDTextBox.BorderBrush = Brushes.Red; tmp += "Invalid ID Number! \n"; iDTextBox.Text = ""; count_ec++; } } if (count_ec != 0) { throw new Exception(tmp); } else { bl.Add_Chaild(child); MessageBox.Show("Add child successful"); child = new BE.Child(); this.DataContext = child; Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); first_NameTextBox.BorderBrush = Brushes.Black; iDTextBox.BorderBrush = Brushes.Black; } }