Пример #1
0
        private void AddTestData()
        {
            _dtCtrl.BeginTransaction();

            try
            {
                ClearDB();

                Invoke(new SetTextCallBack(SetText), new object[] { txtProgress, "Adding ..." });

                //AddTestOneShiftNonFlexi(ref _dtCtrl);

                //AddTestOneShiftFlexi(ref _dtCtrl);

                AddTestMultiShiftNonFlexi(ref _dtCtrl);

                _dtCtrl.CommitTransaction();

                Invoke(new SetTextCallBack(SetText), new object[] { txtProgress, "Adding Complete." });
            }
            catch (Exception ex)
            {
                _dtCtrl.RollbackTransaction();
                Invoke(new AddTextCallBack(SetText), new object[] { txtProgress, "Error: " + ex.Message });
            }
        }
Пример #2
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);
                }
            }
        }
Пример #3
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int terminalID = GetSelectedTerminalID();

            if (Util.Confirm("Are you sure you want to delete this Terminal? This cannot be undone."))
            {
                _dtCtrl.BeginTransaction();

                try
                {
                    bool brs1 = _dtCtrl.DeleteTerminal(terminalID);
                    bool brs2 = _dtCtrl.DeleteEmployeeTerminal(terminalID);

                    if (brs1 && brs2)
                    {
                        _dtCtrl.CommitTransaction();
                        LoadData();
                        MessageBox.Show("Terminal deleted.");
                    }
                    else
                    {
                        throw new Exception("Terminal could not be deleted.");
                    }
                }
                catch (Exception ex)
                {
                    _dtCtrl.RollbackTransaction();
                    Util.ShowErrorMessage(ex);
                }
            }
        }
Пример #4
0
        private void AddTestData()
        {
            _dtCtrl.BeginTransaction();

            try
            {
                Invoke(new SetTextCallBack(SetText), new object[] { txtProgress, "Adding ..." });

                //add test company
                Company com = new Company();
                com.Name = DateTime.Now.Ticks.ToString();
                com.ID   = _dtCtrl.AddCompany(com);

                //add test department
                Department dep = new Department();
                dep.CompanyID       = com.ID;
                dep.Name            = DateTime.Now.Ticks.ToString();
                dep.SupDepartmentID = 0; //root
                dep.ID = _dtCtrl.AddDepartment(dep);

                //add test working calendar
                WorkingCalendar wCal = new WorkingCalendar();

                wCal.Name = DateTime.Now.Ticks.ToString();
                wCal.RegularWorkingFrom = new DateTime(2000, 2, 2, 9, 0, 0);
                wCal.RegularWorkingTo   = new DateTime(2000, 2, 2, 18, 0, 0);

                wCal.WorkOnMonday    = true;
                wCal.WorkOnTuesday   = true;
                wCal.WorkOnWednesday = true;
                wCal.WorkOnThursday  = true;
                wCal.WorkOnFriday    = true;

                wCal.GraceForwardToEntry = 30;
                wCal.GraceBackwardToExit = 30;
                wCal.EarliestBeforeEntry = 60;
                wCal.LastestAfterExit    = 180;

                List <Break> breakList = new List <Break>();
                Break        break1    = new Break();
                break1.From = new DateTime(2000, 2, 2, 12, 0, 0);
                break1.To   = new DateTime(2000, 2, 2, 13, 0, 0);
                break1.Name = "break1";
                break1.Paid = true;

                breakList.Add(break1);

                List <Holiday> holidayList = new List <Holiday>();

                PaymentRate workingDayPaymentRate = new PaymentRate();
                workingDayPaymentRate.NumberOfRegularHours = 8;
                workingDayPaymentRate.RegularRate          = 100;
                workingDayPaymentRate.NumberOfOvertime1    = 8;
                workingDayPaymentRate.OvertimeRate1        = 200;

                PaymentRate nonWorkingDayPaymentRate = workingDayPaymentRate;
                PaymentRate holidayPaymentRate       = workingDayPaymentRate;

                PayPeriod payPeriod = new PayPeriod();
                payPeriod.CustomPeriod    = 5;
                payPeriod.PayPeriodTypeID = 5; //custom
                payPeriod.StartFrom       = new DateTime(2010, 1, 1);

                wCal.ID = _dtCtrl.AddWorkingCalendar(wCal, breakList, holidayList, workingDayPaymentRate, nonWorkingDayPaymentRate, holidayPaymentRate, payPeriod);

                //add test employee
                Employee emp = new Employee();
                emp.Active            = true;
                emp.ActiveFrom        = DateTime.Today;
                emp.ActiveTo          = DateTime.Today.AddDays(1);
                emp.Address           = DateTime.Now.Ticks.ToString();
                emp.Birthday          = DateTime.Today.AddYears(-20);
                emp.DepartmentID      = dep.ID;
                emp.EmployeeNumber    = 0;
                emp.FirstName         = DateTime.Now.Ticks.ToString();
                emp.JobDescription    = DateTime.Now.Ticks.ToString();
                emp.HiredDate         = DateTime.Today;
                emp.LeftDate          = DateTime.Today.AddYears(1);
                emp.LastName          = DateTime.Now.Ticks.ToString();
                emp.PhoneNumber       = DateTime.Now.Ticks.ToString();
                emp.WorkingCalendarID = wCal.ID;

                emp.PayrollNumber = _dtCtrl.AddEmployee(emp, new List <Terminal>());

                //add test att records
                //att1 : expected totalHours: 9
                AttendanceRecord att11 = new AttendanceRecord();
                att11.EmployeeNumber = emp.EmployeeNumber;
                att11.Time           = new DateTime(2010, 1, 1, 9, 0, 0);
                att11.ID             = _dtCtrl.AddAttendanceRecord(att11);

                AttendanceRecord att12 = new AttendanceRecord();
                att12.EmployeeNumber = emp.EmployeeNumber;
                att12.Time           = new DateTime(2010, 1, 1, 18, 0, 0);
                att12.ID             = _dtCtrl.AddAttendanceRecord(att12);

                AttendanceRecord att13 = new AttendanceRecord();
                att13.EmployeeNumber = emp.EmployeeNumber;
                att13.Time           = new DateTime(2010, 1, 1, 12, 0, 0);
                att13.ID             = _dtCtrl.AddAttendanceRecord(att13);

                AttendanceRecord att14 = new AttendanceRecord();
                att14.EmployeeNumber = emp.EmployeeNumber;
                att14.Time           = new DateTime(2010, 1, 1, 13, 0, 0);
                att14.ID             = _dtCtrl.AddAttendanceRecord(att14);

                //att2 : expected totalHours: 9
                AttendanceRecord att21 = new AttendanceRecord();
                att21.EmployeeNumber = emp.EmployeeNumber;
                att21.Time           = new DateTime(2010, 1, 2, 8, 45, 0);
                att21.ID             = _dtCtrl.AddAttendanceRecord(att21);

                AttendanceRecord att22 = new AttendanceRecord();
                att22.EmployeeNumber = emp.EmployeeNumber;
                att22.Time           = new DateTime(2010, 1, 2, 18, 15, 0);
                att22.ID             = _dtCtrl.AddAttendanceRecord(att22);

                //att3 : expected totalHours: 9.75
                AttendanceRecord att31 = new AttendanceRecord();
                att31.EmployeeNumber = emp.EmployeeNumber;
                att31.Time           = new DateTime(2010, 1, 3, 8, 15, 0);
                att31.ID             = _dtCtrl.AddAttendanceRecord(att31);

                AttendanceRecord att32 = new AttendanceRecord();
                att32.EmployeeNumber = emp.EmployeeNumber;
                att32.Time           = new DateTime(2010, 1, 3, 18, 0, 0);
                att32.ID             = _dtCtrl.AddAttendanceRecord(att32);

                //att4 : expected totalHours: 0 + out mistake alert
                AttendanceRecord att41 = new AttendanceRecord();
                att41.EmployeeNumber = emp.EmployeeNumber;
                att41.Time           = new DateTime(2010, 1, 4, 7, 00, 0);
                att41.ID             = _dtCtrl.AddAttendanceRecord(att41);

                AttendanceRecord att42 = new AttendanceRecord();
                att42.EmployeeNumber = emp.EmployeeNumber;
                att42.Time           = new DateTime(2010, 1, 4, 18, 0, 0);
                att42.ID             = _dtCtrl.AddAttendanceRecord(att42);

                //att5 : expected totalHours: 8.8x
                AttendanceRecord att51 = new AttendanceRecord();
                att51.EmployeeNumber = emp.EmployeeNumber;
                att51.Time           = new DateTime(2010, 1, 5, 9, 06, 0);
                att51.ID             = _dtCtrl.AddAttendanceRecord(att51);

                AttendanceRecord att52 = new AttendanceRecord();
                att52.EmployeeNumber = emp.EmployeeNumber;
                att52.Time           = new DateTime(2010, 1, 5, 18, 2, 0);
                att52.ID             = _dtCtrl.AddAttendanceRecord(att52);

                //att6 : expected totalHours: 8.5
                AttendanceRecord att61 = new AttendanceRecord();
                att61.EmployeeNumber = emp.EmployeeNumber;
                att61.Time           = new DateTime(2010, 1, 6, 9, 0, 0);
                att61.ID             = _dtCtrl.AddAttendanceRecord(att61);

                AttendanceRecord att62 = new AttendanceRecord();
                att62.EmployeeNumber = emp.EmployeeNumber;
                att62.Time           = new DateTime(2010, 1, 6, 18, 0, 0);
                att62.ID             = _dtCtrl.AddAttendanceRecord(att62);

                AttendanceRecord att63 = new AttendanceRecord();
                att63.EmployeeNumber = emp.EmployeeNumber;
                att63.Time           = new DateTime(2010, 1, 6, 12, 30, 0);
                att63.ID             = _dtCtrl.AddAttendanceRecord(att63);

                AttendanceRecord att64 = new AttendanceRecord();
                att64.EmployeeNumber = emp.EmployeeNumber;
                att64.Time           = new DateTime(2010, 1, 6, 13, 30, 0);
                att64.ID             = _dtCtrl.AddAttendanceRecord(att64);

                _dtCtrl.CommitTransaction();

                Invoke(new SetTextCallBack(SetText), new object[] { txtProgress, "Adding Complete." });
            }
            catch (Exception ex)
            {
                _dtCtrl.RollbackTransaction();
                Invoke(new AddTextCallBack(SetText), new object[] { txtProgress, "Error: " + ex.Message });
            }
        }
Пример #5
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                Employee employee = GetEmployeeUserInput();
                if (employee == null) //invalid input
                {
                    return;
                }

                if (_employeeID == -1) //add
                {
                    List <Terminal> terminals = GetTerminalsUserInput();

                    if (_dtCtrl.AddEmployee(employee, terminals) > 0)
                    {
                        if (Util.Confirm("Employee added. Do you want to add another employee?"))
                        {
                            SetState(-1);
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        throw new Exception("Employee could not be added.");
                    }
                }
                else //update
                {
                    _dtCtrl.BeginTransaction();

                    try
                    {
                        if (_dtCtrl.UpdateEmployee(employee) == false)
                        {
                            throw new Exception("Employee could not be updated.");
                        }

                        List <Terminal> terminals = GetTerminalsUserInput();

                        if (_dtCtrl.UpdateEmployeeTerminal(terminals, employee.EmployeeNumber) == false)
                        {
                            throw new Exception("Employee's Terminal Info could not be updated.");
                        }

                        _dtCtrl.CommitTransaction();
                        MessageBox.Show("Employee updated.");
                        this.Close();
                    }
                    catch
                    {
                        _dtCtrl.RollbackTransaction();
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Util.ShowErrorMessage(ex);
            }
        }