Exemplo n.º 1
0
 private void btnAddEmployeeFormSaveChanges_Click(object sender, EventArgs e)
 {
     employee.EmployeeFName      = employeeFNameTextBox.Text;
     employee.EmployeeLName      = employeeLNameTextBox.Text;
     employee.EmployeePhoneNum   = employeePhoneNumTextBox.Text;
     employee.EmployeeAddress    = employeeAddressTextBox.Text;
     employee.EmployeeCity       = employeeCityTextBox.Text;
     employee.EmployeeState      = employeeStateComboBox.SelectedValue.ToString();
     employee.EmployeeZipCode    = employeeZipCodeTextBox.Text;
     employee.EmployeeCurrentPay = Convert.ToDecimal(employeeCurrentPayTextBox.Text);
     AddEmpDb.Employees.Add(employee);
     AddEmpDb.SaveChanges();
     EmployeesListForm = new EmployeesListForm();
     EmployeesListForm.Show();
     this.Close();
 }
        //Deletes Employee
        private void btnEmployeeFormDeleteEmp_Click(object sender, EventArgs e)
        {
            if (employeeIDTextBox.Text == "")
            {
                MessageBox.Show("No employee selected. Please select an employee to delete", "Delete Error");
            }
            else
            {
                int currentEmp = Convert.ToInt32(employeeIDTextBox.Text);
                var editedEmp  = (from employee in EmpDb.Employees
                                  where employee.EmployeeID == currentEmp
                                  select employee).Single();

                DialogResult result = MessageBox.Show($"Delete {editedEmp.EmployeeFName} {editedEmp.EmployeeLName}?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        EmpDb.Employees.Remove(editedEmp);
                        EmpDb.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        this.Close();
                        if (EmpDb.Entry(editedEmp).State == EntityState.Detached)
                        {
                            MessageBox.Show("Another user has deleted that employee.", "Concurrency Error");
                        }
                        else
                        {
                            MessageBox.Show("Another user has updated that employee.", "Concurrency Error");
                        }
                    }
                    catch (DbUpdateException)
                    {
                        this.Close();
                        MessageBox.Show("Unable to delete employee. The employee is labeled as an employee that worked on an invoice.", "Employee Not Deleted");
                        EmployeesListForm newForm = new EmployeesListForm();
                        newForm.Show();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void btnAddEmployeeFormCancel_Click(object sender, EventArgs e)
 {
     EmployeesListForm = new EmployeesListForm();
     EmployeesListForm.Show();
     this.Close();
 }