private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new LetranIntegratedSystemEntities())
                {
                    HRISEmployeeSchedule hRISEmployeeSchedule = new HRISEmployeeSchedule();
                    var empSched = db.HRISEmployeeSchedules.Where(m => m.EmployeeNumber == empnumber).FirstOrDefault();

                    if (empSched != null)
                    {
                        empSched.ShiftCode = cbShiftCode.Text;
                        db.SaveChanges();
                        MessageBox.Show("Successfully Updated.", "System Success", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Employee Schedule not found.", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong.", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #2
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new LetranIntegratedSystemEntities())
                {
                    if (String.IsNullOrEmpty(cbEmployee.Text))
                    {
                        MessageBox.Show("Employee cannot be empty.", "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }

                    if (String.IsNullOrEmpty(cbShiftCode.Text))
                    {
                        MessageBox.Show("Shift cannot be empty.", "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }

                    var empId       = Convert.ToInt32(cbEmployee.SelectedValue);
                    var emp         = db.Employees.Where(m => m.EmployeeID == empId).FirstOrDefault();
                    var empSchedule = db.HRISEmployeeSchedules.Where(m => m.EmployeeNumber == emp.EmployeeNo).FirstOrDefault();
                    var shiftCode   = Convert.ToString(cbShiftCode.SelectedValue);
                    if (emp != null)
                    {
                        HRISEmployeeSchedule hrisEmployeeSchedule = new HRISEmployeeSchedule();
                        hrisEmployeeSchedule.EmployeeNumber = emp.EmployeeNo;
                        hrisEmployeeSchedule.ShiftCode      = shiftCode;
                        db.HRISEmployeeSchedules.Add(hrisEmployeeSchedule);
                        db.SaveChanges();
                        emp.EmployeeScheduleId = hrisEmployeeSchedule.EmployeeScheduleId;
                        db.SaveChanges();
                        clear();
                        MessageBox.Show("Add Success.", "System Sucess!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Employee not found.", "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong.", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }