private void LevelComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (LevelComboBox.SelectedItem == null) { return; } string LevelName = LevelComboBox.SelectedItem.ToString(); string EmployeeId = EmployeeIdTextBox.Text.Trim(); LevelList.ForEach(e => { if (e.LevelName.Equals(LevelName)) { RankTextBox.Clear(); RankTextBox.Text = e.LevelId.ToString() + "." + EmployeeId; } }); }
private void EmployeeIdTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e) { Regex regex = new Regex("[^0-9]+"); e.Handled = regex.IsMatch(e.Text); // Change the rank when editing Employee ID only if a rank selected if (LevelComboBox.SelectedItem != null) { string LevelName = LevelComboBox.SelectedItem.ToString(); string EmployeeId = EmployeeIdTextBox.Text.Trim(); LevelList.ForEach(e => { if (e.LevelName.Equals(LevelName)) { RankTextBox.Clear(); RankTextBox.Text = e.LevelId.ToString() + "." + EmployeeId; } }); } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { if (EmployeeIdTextBox.Text.Trim() == "" || EmployeeNameTextBox.Text.Trim() == "" || RankTextBox.Text.Trim() == "" || FacutlyComboBox.SelectedItem == null || DepartmentComboBox.SelectedItem == null || CenterComboBox.SelectedItem == null || BuildingComboBox.SelectedItem == null || LevelComboBox.SelectedItem == null) { MessageBox.Show("Sorry! Fields cannot be empty!", "Error"); return; } Lecturer lecturer = new Lecturer { EmployeeId = Int32.Parse(EmployeeIdTextBox.Text.Trim()), EmployeeName = EmployeeNameTextBox.Text.Trim(), Rank = float.Parse(RankTextBox.Text.Trim()) }; string facultyName = FacutlyComboBox.SelectedItem.ToString(); string departmentName = DepartmentComboBox.SelectedItem.ToString(); string centerName = CenterComboBox.SelectedItem.ToString(); string buildingName = BuildingComboBox.SelectedItem.ToString(); string levelName = LevelComboBox.SelectedItem.ToString(); LecturerDataService lecturerDataService = new LecturerDataService(new EntityFramework.TimetableManagerDbContext()); if (!EmployeeIdTextBox.IsEnabled) { EmployeeIdTextBox.IsEnabled = true; lecturerDataService.UpdateLecturer(lecturer, facultyName, departmentName, centerName, buildingName, levelName).ContinueWith(result => { if (result != null) { MessageBox.Show("Lecture Updated!", "Success"); } else { MessageBox.Show("Sorry! Error occured!", "Error"); } }); } else { lecturerDataService.AddLecturer(lecturer, facultyName, departmentName, centerName, buildingName, levelName).ContinueWith(result => { if (result != null) { MessageBox.Show("Lecture Added!", "Success"); } else { MessageBox.Show("Sorry! Error occured!", "Error"); } }); } EmployeeIdTextBox.Clear(); EmployeeNameTextBox.Clear(); RankTextBox.Clear(); FacutlyComboBox.SelectedIndex = -1; DepartmentComboBox.SelectedIndex = -1; CenterComboBox.SelectedIndex = -1; BuildingComboBox.SelectedIndex = -1; LevelComboBox.SelectedIndex = -1; LecturerDataList.Clear(); _ = this.LoadLecturerData(); }