示例#1
0
        private void GetEmployees()
        {
            try
            {
                using (var db = new DMSIPayrollEntities())
                {
                    lEmployee = new List <DMSIClass._Employee>();
                    var employees = db.Employees.ToList();

                    foreach (var x in employees)
                    {
                        DMSIClass._Employee employee = new DMSIClass._Employee();
                        var company  = db.Companies.Where(m => m.CompanyID == x.CompanyID).FirstOrDefault();
                        var position = db.EmployeePositions.Where(m => m.EmployeePositionID == x.EmployeePositionID).FirstOrDefault();

                        employee.Name       = (x.LastName + ", " + x.FirstName + " " + x.MiddleName).ToUpper();
                        employee.Company    = company.CompanyName;
                        employee.Position   = position.PositionName;
                        employee.EmployeeID = x.EmployeeID;
                        employee.EmployeeNo = x.EmployeeNumber;
                        employee.PositionID = x.EmployeePositionID;

                        lEmployee.Add(employee);
                    }

                    datagridview.ItemsSource = lEmployee.OrderBy(m => m.Name);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new DMSIPayrollEntities())
                {
                    if (tbNoOfDays.Text == "" || dpStartDate.SelectedDate == null || dpStDate.SelectedDate == null || dpToDate.SelectedDate == null)
                    {
                        MessageBox.Show("Required fields cannot be empty.", "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }

                    List <CheckBox> checkBoxlist = new List <CheckBox>();
                    FindChildGroup <CheckBox>(datagridview, "checkboxinstance", ref checkBoxlist);
                    var checkeditems = checkBoxlist.Where(m => m.IsChecked == true).ToList();

                    foreach (var c in checkeditems)
                    {
                        Income income         = new Income();
                        DMSIClass._Employee x = c.DataContext as DMSIClass._Employee;
                        var position          = db.EmployeePositions.Where(m => m.EmployeePositionID == x.PositionID).FirstOrDefault();
                        income.EmployeeID  = x.EmployeeID;
                        income.NoOfDays    = Convert.ToInt32(tbNoOfDays.Text);
                        income.Amount      = income.NoOfDays * position.DailyRate;
                        income.StDate      = dpStDate.SelectedDate.Value;
                        income.ToDate      = dpToDate.SelectedDate.Value;
                        income.PayrollDate = dpStartDate.SelectedDate.Value;
                        db.Incomes.Add(income);
                        db.SaveChanges();
                    }

                    MessageBox.Show("Add Succesful", "System Succes!", MessageBoxButton.OK, MessageBoxImage.Information);
                    clear();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong.", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }