示例#1
0
 void EditEmployee(int employeeId)
 {
     try
     {
         ERPEF    entity   = new ERPEF();
         Employee employee =
             entity.Employees.SingleOrDefault(
                 n => n.EmployeeId == employeeId
                 );
         if (employee != null)
         {
             labelId.Content              = employee.EmployeeId.ToString();
             textBoxFirstName.Text        = employee.FirstName;
             textBoxLastName.Text         = employee.LastName;
             textBoxAddress.Text          = employee.Address;
             DateOfBirth.SelectedDate     = employee.DateOfBirth;
             textBoxTelephone.Text        = employee.Telephone;
             textBoxCellphone.Text        = employee.Cellphone;
             textBoxEmail.Text            = employee.Email;
             comboBoxStates.SelectedValue = employee.StateCode;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#2
0
 private bool DeleteById(int employeeId)
 {
     try
     {
         using (ERPEF entity = new ERPEF())
         {
             Employee employee = entity.Employees.SingleOrDefault(
                 n => n.EmployeeId == employeeId
                 );
             entity.Employees.Remove(employee);
             return(entity.SaveChanges() > 0);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     return(false);
 }
示例#3
0
        private void DisplayData()
        {
            ERPEF entity = new ERPEF();

            listViewData.ItemsSource = entity.Employees.ToList();
        }
示例#4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ERPEF entity = new ERPEF();

            comboBoxStates.ItemsSource = entity.States.ToList();
        }
示例#5
0
 public void ExecuteSave(object sender, RoutedEventArgs e)
 {
     try
     {
         using (ERPEF entity = new ERPEF())
         {
             if (labelId.Content != null && labelId.Content.ToString() != "")
             {
                 int employeeId = Convert.ToInt32(labelId.Content);
                 var employee   =
                     entity.Employees.SingleOrDefault(
                         n => n.EmployeeId == employeeId
                         );
                 employee.FirstName   = textBoxFirstName.Text;
                 employee.LastName    = textBoxLastName.Text;
                 employee.Address     = textBoxAddress.Text;
                 employee.DateOfBirth = DateOfBirth.SelectedDate;
                 employee.Telephone   = textBoxTelephone.Text;
                 employee.Cellphone   = textBoxCellphone.Text;
                 employee.Email       = textBoxEmail.Text;
                 employee.StateCode   = Convert.ToString(comboBoxStates.SelectedValue);
                 if (entity.SaveChanges() > 0)
                 {
                     MessageBox.Show("Success to update employee!");
                 }
                 else
                 {
                     MessageBox.Show("Failed to update employee or nothing changes!");
                 }
             }
             else
             {
                 var employee = new Employee()
                 {
                     FirstName   = textBoxFirstName.Text,
                     LastName    = textBoxLastName.Text,
                     Address     = textBoxAddress.Text,
                     DateOfBirth = DateOfBirth.SelectedDate,
                     Telephone   = textBoxTelephone.Text,
                     Cellphone   = textBoxCellphone.Text,
                     Email       = textBoxEmail.Text,
                     StateCode   = Convert.ToString(comboBoxStates.SelectedValue),
                     IsActivated = true
                 };
                 entity.Employees.Add(employee);
                 if (entity.SaveChanges() > 0)
                 {
                     MessageBox.Show("Success to add new employee!");
                 }
                 else
                 {
                     MessageBox.Show("Failed to add new employee or duplicate data!");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }