Пример #1
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            object employeeID = dgvEmployee.Rows[_rowIndex].Cells[dgvEmployee.Columns["PayrollNumber"].Index].Value;

            if (Util.Confirm("Are you sure?"))
            {
                Employee employee = _dtCtrl.GetEmployee((int)employeeID);

                if (employee == null)
                {
                    throw new NullReferenceException("Employee not found or has been deleted");
                }

                _dtCtrl.BeginTransaction();
                try
                {
                    RemoveEmployeeFromTerminal(employee);

                    _dtCtrl.DeleteEmployee((int)employeeID);
                    _dtCtrl.DeleteEmployeeTerminalByEmployee(employee.EmployeeNumber);

                    _dtCtrl.CommitTransaction();

                    MessageBox.Show("Employee deleted.");
                    BindEmployee();
                }
                catch (Exception ex)
                {
                    _dtCtrl.RollbackTransaction();
                    Util.ShowErrorMessage(ex);
                }
            }
        }
Пример #2
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 });
            }
        }