private void AddButton_Click(object sender, RoutedEventArgs e) { try { if (specialComboBox.SelectedValue == null) { throw new Exception("you must select specialization"); } if (idTextBox.BorderBrush == Brushes.Red || accountNoTextBox.BorderBrush == Brushes.Red || specialComboBox.SelectedItem == null) { throw new Exception("Invalid data"); } myBank.AccountNo = Convert.ToInt32(accountNoTextBox.Text); myBank.BankNo = Convert.ToInt32(bankNoTextBox.SelectedValue); myBank.BranchNo = Convert.ToInt32(branchNoTextBox.SelectedValue); myBank.BankName = bankNameTextBox.Text; myBank.BranchAdd = branchAddTextBox.Text; myBank.BranchCity = branchCityTextBox.Text; employee.MyAccount = myBank; bl.AddEmployee(employee); specialComboBox.ItemsSource = bl.GetAllSpecialization(); employee = new Employee(); myBank = new BankAccount(); specialComboBox.Items.Refresh(); this.grid1.DataContext = employee; bankNoTextBox.SelectedValue = null; branchNoTextBox.SelectedValue = null; bankNameTextBox.Text = ""; accountNoTextBox.Text = "0"; throw new Exception("Add employee successfully!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button_Click(object sender, RoutedEventArgs e) { if (idBox.Text.Equals("")) { MessageBox.Show("Please enter an ID number.", "Error"); } else if (nameBox.Text.Equals("")) { MessageBox.Show("Please enter a name.", "Error"); } else if (lastNameBox.Text.Equals("")) { MessageBox.Show("Please enter a last name.", "Error"); } else if (dobBox.Text.Equals("")) { MessageBox.Show("Please enter a date of birth.", "Error"); } else if (addressBox.Text.Equals("")) { MessageBox.Show("Please enter an address.", "Error"); } else if (specBox.Text.Equals("")) { MessageBox.Show("Please enter a specialization number.", "Error"); } else if (telBox.Text.Equals("")) { MessageBox.Show("Please enter a telephone number", "Error"); } else if (educationComboBox.SelectedValue == null) { MessageBox.Show("Please select an education", "Error"); } else if (bankAccountBox.Text.Equals("")) { MessageBox.Show("Please enter a bank account number.", "Error"); } else if (bankNameBox.Text.Equals("")) { MessageBox.Show("Please enter a bank name.", "Error"); } else if (bankCodeBox.Text.Equals("")) { MessageBox.Show("Please enter a bank code.", "Error"); } else if (branchCodeBox.Text.Equals("")) { MessageBox.Show("Please enter a branch code.", "Error"); } else if (branchCityBox.Text.Equals("")) { MessageBox.Show("Please enter a branch city.", "Error"); } else if (branchAddressBox.Text.Equals("")) { MessageBox.Show("Please enter a branch address.", "Error"); } else { bool army = false, record = false; if (armyYes.IsChecked == true) { army = true; } if (recordYes.IsChecked == true) { record = true; } string education = educationComboBox.SelectedItem.ToString(); switch (education) { case "Student": education = "student"; break; case "First degree": education = "firstDegree"; break; case "Second degree": education = "secondDegree"; break; case "Third degree": education = "thirdDegree"; break; case "Certification": education = "certification"; break; } try { bl.AddEmployee(nameBox.Text, lastNameBox.Text, Convert.ToInt32(idBox.Text), Convert.ToInt32(telBox.Text), addressBox.Text, (Education)Enum.Parse(typeof(Education), education), army, record, Convert.ToInt32(specBox.Text), dobBox.Text, Convert.ToInt32(bankCodeBox.Text), bankNameBox.Text, Convert.ToInt32(branchCodeBox.Text), branchAddressBox.Text, branchCityBox.Text, Convert.ToInt32(bankAccountBox.Text)); MessageBox.Show("Employee has been successfuly added."); idBox.Clear(); nameBox.Clear(); lastNameBox.Clear(); dobBox.Clear(); addressBox.Clear(); specBox.Clear(); telBox.Clear(); educationComboBox.Text = ""; educationComboBox.SelectedItem = null; bankAccountBox.Clear(); bankNameBox.Clear(); bankCodeBox.Clear(); branchCodeBox.Clear(); branchCityBox.Clear(); branchAddressBox.Clear(); } catch (FormatException ex) { MessageBox.Show(ex.Message, "Error"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } }