private void AddMotherClick(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++; } } bool check2 = first_NameTextBox.Text.Any(who => char.IsLetter(who)); if (!check2) { if (typeof(string) != (last_NameTextBox.Text.GetType())) { last_NameTextBox.BorderBrush = Brushes.Red; tmp += "Invalid Last name! \n"; last_NameTextBox.Text = ""; count_ec++; } } if ((iDTextBox.Text != null) && (iDTextBox.Text != "0")) { if (typeof(int) != (Convert.ToInt32(iDTextBox.Text).GetType()) || (Convert.ToInt32(iDTextBox.Text.Length) < 8)) { iDTextBox.BorderBrush = Brushes.Red; tmp += "Invalid ID Number! \n"; iDTextBox.Text = ""; count_ec++; } } if (addressTextBox.Text != null) { if (typeof(string) != (addressTextBox.Text.GetType())) { addressTextBox.BorderBrush = Brushes.Red; tmp += "Invalid Address! \n"; addressTextBox.Text = ""; count_ec++; } } if (search_AreaTextBox.Text != null) { if (typeof(string) != (search_AreaTextBox.Text.GetType())) { search_AreaTextBox.BorderBrush = Brushes.Red; tmp += "Invalid Address! \n"; search_AreaTextBox.Text = ""; count_ec++; } } bool check = first_NameTextBox.Text.Any(who => char.IsLetter(who)); if (phone_NumberTextBox.Text != null) { if (!check || phone_NumberTextBox.ToString().Length < 9) { phone_NumberTextBox.BorderBrush = Brushes.Red; tmp += "Invalid Phone Number! \n"; phone_NumberTextBox.Text = ""; count_ec++; } } //check if selected hours bool flag = false; foreach (var item in mother.Needed_Hours) { if (item[0] != 0 && item[1] != 0) { flag = true; } } if (!flag) { tmp += "No hours selected \n"; count_ec++; } //check if hours(begin <end) ok flag = true; foreach (var item in mother.Needed_Hours) { if (item[0] > item[1]) { flag = false; } } if (!flag) { tmp += "Start time is less than end time\n"; count_ec++; } if (count_ec != 0) { throw new Exception(tmp); } else { bl.Add_Mom(mother); MessageBox.Show("Add Mother successful"); mother = new BE.Mother(); this.DataContext = mother; Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }