Example #1
0
        private void ClearDB()
        {
            _dtCtrl.BeginTransaction();
            try
            {
                Invoke(new SetTextCallBack(SetText), new object[] { txtProgress, "Clearing..." });

                //clear undel employee
                foreach (UndeletedEmployeeNumber undelEmp in _dtCtrl.GetUndeletedEmployeeNumberList())
                {
                    _dtCtrl.DeleteUndeletedEmployeeNumber(undelEmp);
                }

                //clear uncal att records
                _dtCtrl.DeleteAllUncalculatedAttendanceRecord();

                //clear att reports
                _dtCtrl.DeleteAllAttendanceReport();

                //clear att records
                _dtCtrl.DeleteAllAttendanceRecord();

                //clear employee
                foreach (Employee emp in _dtCtrl.GetEmployeeList())
                {
                    //clear employee terminal
                    _dtCtrl.DeleteEmployeeTerminalByEmployee(emp.EmployeeNumber);

                    _dtCtrl.DeleteEmployee(emp.PayrollNumber);
                }

                //clear employee number

                //clear department
                foreach (Department dep in _dtCtrl.GetDepartmentList())
                {
                    if (dep.ID != 1)
                    {
                        _dtCtrl.DeleteDepartment(dep.ID);
                    }
                }

                //clear company
                foreach (Company com in _dtCtrl.GetCompanyList())
                {
                    if (com.ID != 1)
                    {
                        _dtCtrl.DeleteCompany(com.ID);
                    }
                }

                //clear working calendar
                foreach (WorkingCalendar wCal in _dtCtrl.GetWorkingCalendarList())
                {
                    List <Shift> shiftList = _dtCtrl.GetShiftListByWorkingCalendar(wCal.ID);

                    foreach (Shift shift in shiftList)
                    {
                        _dtCtrl.DeleteShift(shift.ID);
                    }

                    _dtCtrl.DeleteWorkingCalendar(wCal.ID);
                }

                //clear pay period

                _dtCtrl.CommitTransaction();

                Invoke(new SetTextCallBack(SetText), new object[] { txtProgress, "Clearing Complete." });
            }
            catch (Exception ex)
            {
                _dtCtrl.RollbackTransaction();
                Invoke(new AddTextCallBack(SetText), new object[] { txtProgress, "Error: " + ex.Message });
            }
        }