private bool Checking_emp_t(employee_type emp_t) { List <employee_type> l_ept = db1.employee_type.ToList(); foreach (employee_type ept in l_ept) { if (ept.salary_per_hour == emp_t.salary_per_hour && ept.type == emp_t.type) { return(true); } } return(false); }
private void sbmt_btn_Click(object sender, RoutedEventArgs e) { try { string gndr = ""; if (num_id_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your id"); } else if (f_name_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your first name"); } else if (l_name_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your last name"); } else if (phne_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your phone"); } else if (p_code_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your postal code"); } else if (city_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your city"); } else if (strt_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your street"); } else if (house_num_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your house number"); } else if (female_rdb.IsChecked == false && male_rdb.IsChecked == false) { msg_lsb.Items.Add("Failure Enter your gender"); } else if (emp_cmbbx.SelectedItem == null) { msg_lsb.Items.Add("Failure! Select your Type"); } else { if (male_rdb.IsChecked == true) { gndr = "male"; } else { gndr = "female"; } employee_type employee_Type = db1.employee_type.ToArray()[emp_cmbbx.SelectedIndex]; postal_code postal_Code = new postal_code { postal_c = Convert.ToInt32(p_code_txb.Text), city = city_txb.Text, street = strt_txb.Text, house_number = Convert.ToInt32(house_num_txb.Text) }; int number_id = 0; number_id = Convert.ToInt32(num_id_txb.Text); employee employ = new employee { is_working_now = "not at shift", deleted = "exist", id_number = num_id_txb.Text, first_name = f_name_txb.Text, last_name = l_name_txb.Text, phone = phne_txb.Text, gender = gndr, employee_type_id = emp_cmbbx.SelectedIndex + 1, employee_type = employee_Type }; db1.employee.Add(employ); employ.Id = Organize_employee_id(); if (Checking_postal_code(postal_Code)) { List <postal_code> pc = new List <postal_code>(); pc = db1.postal_code.ToList(); foreach (postal_code p in pc) { if (p.postal_c == postal_Code.postal_c) { employ.postal_code_postal_c = p.postal_c; employ.postal_code = p; } } } else { db1.postal_code.Add(postal_Code); employ.postal_code = postal_Code; employ.postal_code_postal_c = Convert.ToInt32(p_code_txb.Text); } this.db1.SaveChanges(); this.Close(); } } catch { MessageBox.Show("Failure! the number id of the worker is already existent in the system", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); this.Close(); } }
private void sbmt_btn_Click(object sender, RoutedEventArgs e) { int slryphour = 0; string gndr = ""; if (num_id_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your id"); } else if (name_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your name"); } else if (phne_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your phone"); } else if (city_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your city"); } else if (strt_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your street"); } else if (house_num_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your house number"); } else if (female_rdb.IsChecked == false && male_rdb.IsChecked == false) { msg_lsb.Items.Add("Failure Enter your gender"); } else if (emp_cmbbx.SelectedItem == null) { msg_lsb.Items.Add("Failure! Select your Type"); } else { if (male_rdb.IsChecked == true) { gndr = "male"; } else { gndr = "female"; } if (emp_cmbbx.Text == "Manager") { slryphour = 120; } else if (emp_cmbbx.Text == "Chef") { slryphour = 32; } else if (emp_cmbbx.Text == "Shift manager") { slryphour = 38; } else { slryphour = 29; } msg_lsb.Items.Add("The worker have been added"); employee_type employee_Type = db1.employee_type.Add(new employee_type { type = emp_cmbbx.Text, salaryperhour = slryphour }); postal_code postal_Code = db1.postal_code.Add(new postal_code { city = city_txb.Text, street = strt_txb.Text, house_number = house_num_txb.Text }); employee employ = new employee { deleted = 0, id_number = num_id_txb.Text, name = name_txb.Text, phone = phne_txb.Text, gender = gndr, employee_type = employee_Type, postal_code = postal_Code }; db1.employee.Add(employ); emp_dtgrid.ItemsSource = db1.employee.ToList(); this.db1.SaveChanges(); this.Close(); } }
private void sbmt_btn_Click(object sender, RoutedEventArgs e) { if (emp != null) { if (yes_lsb.IsSelected == true) { emp.deleted = "not exist"; emp.is_working_now = "not at shift"; db1.SaveChanges(); this.Close(); } else { emp.deleted = "exist"; int slryphour; string gndr; if (num_id_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter the id"); } else if (f_name_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your first name"); } else if (l_name_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your last name"); } else if (phne_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter the phone"); } else if (slph_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter the salary per hour"); } else if (city_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter the city"); } else if (p_code_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter your postal code"); } else if (strt_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter the street"); } else if (house_num_txb.Text == "") { msg_lsb.Items.Add("Failure! Enter the house number"); } else if (female_rdb.IsChecked == false && male_rdb.IsChecked == false) { msg_lsb.Items.Add("Failure Enter the gender"); } else if (emp_cmbbx.SelectedItem == null) { msg_lsb.Items.Add("Failure! Select the Type"); } else { if (male_rdb.IsChecked == true) { gndr = "male"; } else { gndr = "female"; } slryphour = Convert.ToInt32(slph_txb.Text); emp.id_number = num_id_txb.Text; emp.first_name = f_name_txb.Text; emp.last_name = l_name_txb.Text; emp.phone = phne_txb.Text; emp.gender = gndr; postal_code postal_Code = new postal_code { postal_c = Convert.ToInt32(p_code_txb.Text), city = city_txb.Text, street = strt_txb.Text, house_number = Convert.ToInt32(house_num_txb.Text) }; if (Checking_postal_code(postal_Code)) { List <postal_code> pc = db1.postal_code.ToList(); foreach (postal_code p in pc) { if (p.postal_c == postal_Code.postal_c) { emp.postal_code_postal_c = p.postal_c; emp.postal_code = p; } } } else { db1.postal_code.Add(postal_Code); emp.postal_code = postal_Code; emp.postal_code_postal_c = Convert.ToInt32(p_code_txb.Text); } if (slryphour != emp.employee_type.salary_per_hour) { employee_type emp_t = new employee_type { type = emp_cmbbx.Text, salary_per_hour = slryphour }; if (Checking_emp_t(emp_t)) { List <employee_type> l_ept = db1.employee_type.ToList(); foreach (employee_type ept in l_ept) { if (ept.salary_per_hour == emp_t.salary_per_hour && ept.type == emp_t.type) { emp.employee_type_id = ept.Id; emp.employee_type = ept; } } } else { db1.employee_type.Add(emp_t); db1.SaveChanges(); emp.employee_type_id = emp_t.Id; emp.employee_type = emp_t; db1.SaveChanges(); } } else { emp.employee_type = db1.employee_type.ToArray()[emp_cmbbx.SelectedIndex]; emp.employee_type_id = emp_cmbbx.SelectedIndex + 1; } if (emp.postal_code_postal_c != Convert.ToInt32(p_code_txb.Text)) { emp.postal_code_postal_c = Convert.ToInt32(p_code_txb.Text); } try { this.db1.SaveChanges(); this.Close(); } catch { MessageBox.Show("Failure! the number id of the worker is already existent in the system", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } } } } else { msg_lsb.Items.Add("Failure! Select the worker"); } }