private void NewEmployeeButton_Click(object sender, RoutedEventArgs e) { // Check for valid input if (NewEmployeeNameTextBox.Text == "") { MessageBox.Show("Please enter a name for the new employee.", "Alert", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (NewEmployeeJobTitleTextBox.Text == "") { MessageBox.Show("Please enter a job title for the new employee.", "Alert", MessageBoxButton.OK, MessageBoxImage.Information); return; } // Add the employee EmployeeDirectory.AddEmployee(NewEmployeeNameTextBox.Text, NewEmployeeJobTitleTextBox.Text); EmployeeListView.Items.Refresh(); var Id = EmployeeDirectory.Employees[EmployeeDirectory.Employees.Count - 1].Id.ToString(); // Report command CommandsList.Add(string.Format("-Inserted Employee: {0} with the Id: {1}", NewEmployeeNameTextBox.Text, Id)); CommandsListView.Items.Refresh(); // Clear out input NewEmployeeNameTextBox.Text = ""; NewEmployeeJobTitleTextBox.Text = ""; }
private void EmployeeJobTitleTextBox_LostFocus(object sender, RoutedEventArgs e) { var TextBox = sender as TextBox; var Row = EmployeeListView.SelectedIndex; EmployeeDirectory.UpdateEmployee(Row, "JobTitle", TextBox.Text); if (Row >= 0) { var Id = EmployeeDirectory.Employees[Row].StringId; // Report command CommandsList.Add(string.Format("- Employee with Id: {0} has had JobTitle column updated to {1}", Id, TextBox.Text)); CommandsListView.Items.Refresh(); } }
private void DeleteButton_Click(object sender, RoutedEventArgs e) { var Index = EmployeeListView.SelectedIndex; var Id = EmployeeDirectory.Employees[Index].StringId; // Check for valid input if (Index >= 0) { EmployeeDirectory.DeleteEmployee(Index); EmployeeListView.Items.Refresh(); EmployeeListView.UnselectAll(); // Report command CommandsList.Add(string.Format("- Employee with Id: {0} has been removed", Id)); CommandsListView.Items.Refresh(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { EmployeeDirectory.LoadEmployees(); EmployeeListView.ItemsSource = EmployeeDirectory.Employees; CommandsListView.ItemsSource = CommandsList; }