private void Button_Click(object sender, RoutedEventArgs e) { try { foreach (char c in phoneNumberTextBox.Text) { if (c < '0' || c > '9' || phoneNumberTextBox.Text.Length != 7) { throw new Exception("Fill the Phone number field correctly"); } } branch.PhoneNumber = AreaCode.SelectedItem.ToString().Remove(0, 38) + branch.PhoneNumber; branch.BS = BranchSituation.EXIST; bl.AddBranch(branch); (Window.GetWindow(this) as StaffMenu).branchMessage.Visibility = Visibility.Visible; branch = new Branch(); this.DataContext = branch; this.kashrutLevelComboBox.ItemsSource = Enum.GetValues(typeof(Kashrut)); nameTextBox.Text = branch.Name; workersAmountTextBox.Text = branch.WorkersAmount.ToString(); addressTextBox.Text = branch.Address; phoneNumberTextBox.Text = branch.PhoneNumber; } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Add a branch button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Add_Click(object sender, RoutedEventArgs e) { // avoid stoping the program for an exception try { // getting the choice of the combobox box (with casting) branch.CashroutLevel = (CasheRoutLevel)(cashroutLevelComboBox.SelectedValue); // calling function off the bl bl.AddBranch(branch); // reinitialize data branch = new Branch(); this.DataContext = branch; } // in case we have an exception we catch it catch (Exception ex) { MessageBox.Show(ex.Message); } }