public Employee GetEmployeeByEmployeeNumber(int employeeNumber)
        {
            OleDbCommand odCom = BuildSelectCmd("Employee", "TOP 1 *", "EmployeeNumber=@EmployeeNumber AND Active=TRUE", new object[] { "@ID", employeeNumber });
            OleDbDataReader odRdr = odCom.ExecuteReader();

            Employee employee = null;
            if (odRdr.Read())
            {
                employee = new Employee();

                employee.PayrollNumber = (int)odRdr["PayrollNumber"];
                employee.EmployeeNumber = (int)odRdr["EmployeeNumber"];
                employee.DepartmentID = (int)odRdr["DepartmentID"];
                employee.FirstName = odRdr["FirstName"].ToString();
                employee.LastName = odRdr["LastName"].ToString();
                employee.WorkingCalendarID = (int)odRdr["WorkingCalendarID"];
                employee.HiredDate = odRdr["HiredDate"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["HiredDate"]) : Config.MinDate;
                employee.LeftDate = odRdr["LeftDate"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["LeftDate"]) : Config.MinDate;
                employee.Birthday = odRdr["Birthday"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["Birthday"]) : Config.MinDate;
                employee.JobDescription = odRdr["JobDescription"].ToString();
                employee.PhoneNumber = odRdr["PhoneNumber"].ToString();
                employee.Address = odRdr["Address"].ToString();
                employee.Active = Convert.ToBoolean(odRdr["Active"]);
                employee.ActiveFrom = odRdr["ActiveFrom"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["ActiveFrom"]) : Config.MinDate;
                employee.ActiveTo = odRdr["ActiveTo"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["ActiveTo"]) : Config.MinDate;
                employee.FaceData1 = odRdr["FaceData1"].ToString();
                employee.FaceData2 = odRdr["FaceData2"].ToString();
                employee.FaceData3 = odRdr["FaceData3"].ToString();
                employee.FaceData4 = odRdr["FaceData4"].ToString();
                employee.FaceData5 = odRdr["FaceData5"].ToString();
                employee.FaceData6 = odRdr["FaceData6"].ToString();
                employee.FaceData7 = odRdr["FaceData7"].ToString();
                employee.FaceData8 = odRdr["FaceData8"].ToString();
                employee.FaceData9 = odRdr["FaceData9"].ToString();
                employee.FaceData10 = odRdr["FaceData10"].ToString();
                employee.FaceData11 = odRdr["FaceData11"].ToString();
                employee.FaceData12 = odRdr["FaceData12"].ToString();
                employee.FaceData13 = odRdr["FaceData13"].ToString();
                employee.FaceData14 = odRdr["FaceData14"].ToString();
                employee.FaceData15 = odRdr["FaceData15"].ToString();
                employee.FaceData16 = odRdr["FaceData16"].ToString();
                employee.FaceData17 = odRdr["FaceData17"].ToString();
                employee.FaceData18 = odRdr["FaceData18"].ToString();
            }
            odRdr.Close();
            return employee;
        }
        public List<AttendanceLogReport> GetAttendanceLogReportList(int iCompany, int iDepartment, DateTime beginDate, DateTime endDate)
        {
            List<AttendanceReport> attendanceReports = GetAttendanceReport(iCompany, iDepartment, beginDate, endDate, 0, true);
            if (attendanceReports.Count == 0)
                return null;

            List<string> lEmplNumbers = GetEmployeeNumberList(iCompany, iDepartment);
            if (lEmplNumbers == null || lEmplNumbers.Count == 0)
                return null;
            string sEmplNumbers = string.Join(",", lEmplNumbers.ToArray());

            OleDbCommand odCom = BuildSelectCmd("Department INNER JOIN Employee ON Department.ID = Employee.DepartmentID",
                "Employee.EmployeeNumber,Employee.FirstName,Employee.LastName,Employee.PayrollNumber,Employee.JobDescription,Department.Name as DepartmentName",
                "EmployeeNumber in(" + sEmplNumbers + ") AND Active=TRUE");

            OleDbDataReader odRdr = odCom.ExecuteReader();

            List<Employee> employeeList = new List<Employee>();
            Employee empl;
            while (odRdr.Read())
            {
                empl = new Employee();
                empl.EmployeeNumber = (int)odRdr["EmployeeNumber"];
                empl.PayrollNumber = (int)odRdr["PayrollNumber"];
                empl.LastName = odRdr["LastName"].ToString();
                empl.FirstName = odRdr["FirstName"].ToString();
                empl.JobDescription = odRdr["JobDescription"].ToString();
                //loan
                empl.FaceData1 = odRdr["DepartmentName"].ToString();
                employeeList.Add(empl);
            }
            odRdr.Close();

            //OleDbDataAdapter odApt = new OleDbDataAdapter(odCom);
            //DataTable dtEmpl = new DataTable();
            //odApt.Fill(dtEmpl);

            List<AttendanceLogReport> attLogs = new List<AttendanceLogReport>();
            AttendanceLogReport _attLog = null;

            Hashtable emplNumberOfRegularHours = new Hashtable();

            double numberOfRegularHours = 0;
            foreach (AttendanceReport attRp in attendanceReports)
            {
                _attLog = new AttendanceLogReport();

                if (emplNumberOfRegularHours.ContainsKey(attRp.EmployeeNumber))
                    numberOfRegularHours = (double)emplNumberOfRegularHours[attRp.EmployeeNumber];
                else
                {
                    PaymentRate pRate = GetPaymentRateByEmployeeAndWorkDay(attRp.EmployeeNumber, attRp.WorkFrom);
                    numberOfRegularHours = pRate.NumberOfRegularHours;
                    emplNumberOfRegularHours.Add(attRp.EmployeeNumber, numberOfRegularHours);
                }
                Employee employee = employeeList.Find(delegate(Employee e) { return e.EmployeeNumber == attRp.EmployeeNumber; });

                _attLog.FullName = employee.LastName + ", " + employee.FirstName;
                _attLog.PayrollNumber = employee.PayrollNumber;
                _attLog.JobDescription = employee.JobDescription;
                _attLog.Department = employee.FaceData1;

                _attLog.AttendanceRecordIDList = attRp.AttendanceRecordIDList;
                _attLog.DayTypeID = attRp.DayTypeID;
                _attLog.EmployeeNumber = attRp.EmployeeNumber;
                _attLog.OvertimeHour1 = attRp.OvertimeHour1;
                _attLog.OvertimeHour2 = attRp.OvertimeHour2;
                _attLog.OvertimeHour3 = attRp.OvertimeHour3;
                _attLog.OvertimeHour4 = attRp.OvertimeHour4;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.OvertimeRate1 = attRp.OvertimeRate1;
                _attLog.PayPeriodID = attRp.PayPeriodID;
                _attLog.RegularHour = numberOfRegularHours;
                _attLog.RegularRate = attRp.RegularRate;
                _attLog.TotalHour = attRp.RegularHour + attRp.OvertimeHour1 + attRp.OvertimeHour2 + attRp.OvertimeHour3 + attRp.OvertimeHour4;
                _attLog.WorkingHour = attRp.RegularHour;
                _attLog.WorkFrom = attRp.WorkFrom;
                _attLog.WorkTo = attRp.WorkTo;

                attLogs.Add(_attLog);
            }
            return attLogs;
        }
        public List<AttendanceLogRecord> GetAttendanceLogRecordList(int iCompany, int iDepartment, DateTime beginDate, DateTime endDate, int columnIndex, bool isOrderByAcs)
        {
            List<AttendanceReport> attendanceReports = GetAttendanceReport(iCompany, iDepartment, beginDate, endDate, columnIndex, isOrderByAcs);
            if (attendanceReports.Count == 0)
                return null;

            List<string> lEmplNumbers = GetEmployeeNumberList(iCompany, iDepartment);
            if (lEmplNumbers == null || lEmplNumbers.Count == 0)
                return null;
            string sEmplNumbers = string.Join(",", lEmplNumbers.ToArray());

            OleDbCommand odCom = BuildSelectCmd("Employee", "EmployeeNumber, FirstName, LastName", "EmployeeNumber IN(" + sEmplNumbers + ") AND Active=TRUE");

            OleDbDataReader odRdr = odCom.ExecuteReader();

            List<Employee> employeeList = new List<Employee>();
            Employee empl;
            while (odRdr.Read())
            {
                empl = new Employee();
                empl.EmployeeNumber = (int)odRdr["EmployeeNumber"];
                empl.LastName = odRdr["LastName"].ToString();
                empl.FirstName = odRdr["FirstName"].ToString();
                employeeList.Add(empl);
            }
            odRdr.Close();

            List<AttendanceLogRecord> attLogList = new List<AttendanceLogRecord>();
            AttendanceLogRecord attLog = null;

            List<AttendanceRecord> attRecordList = new List<AttendanceRecord>();
            AttendanceRecord attRecord = null;

            foreach (AttendanceReport attReport in attendanceReports)
            {
                string sAttendanceRecordIDs = attReport.AttendanceRecordIDList;
                sAttendanceRecordIDs = sAttendanceRecordIDs.Replace("{", "").Replace("}", ",").Trim(',');

                odCom = BuildSelectCmd("AttendanceRecord", "*", "ID IN(" + sAttendanceRecordIDs + ")");
                odRdr = odCom.ExecuteReader();

                attRecordList.Clear();
                while (odRdr.Read())
                {
                    attRecord = new AttendanceRecord();
                    attRecord.ID = (int)odRdr["ID"];
                    attRecord.EmployeeNumber = (int)odRdr["EmployeeNumber"];
                    attRecord.Note = odRdr["Note"].ToString();
                    attRecord.Time = (DateTime)odRdr["Time"];
                    attRecordList.Add(attRecord);
                }
                odRdr.Close();

                attRecordList.Sort(delegate(AttendanceRecord e1, AttendanceRecord e2) { return e1.Time.CompareTo(e2.Time); });
                int roundValue = GetConfig().RecordRoundingValue;
                foreach (AttendanceRecord att in attRecordList)
                {
                    att.Time = Util.RoundDateTime(att.Time, roundValue);
                }

                bool isCheckIn = true;
                bool isFirst = true;

                DateTime dDateLog = attRecordList[0].Time.Date;
                foreach (AttendanceRecord att in attRecordList)
                {
                    attLog = new AttendanceLogRecord();
                    if (isFirst)
                    {
                        attLog.EmployeeNumber = attReport.EmployeeNumber;
                        attLog.DateLog = attReport.WorkFrom.Date;

                        //TODO wrong number, total hours here is based on the in/out, not report
                        attLog.TotalHours = Math.Round(CalculateTotalHours(attRecordList), 2);

                        Employee employee = employeeList.Find(delegate(Employee e) { return e.EmployeeNumber == attReport.EmployeeNumber; });

                        attLog.EmployeeName = employee.LastName + ", " + employee.FirstName;
                        isFirst = false;
                    }

                    attLog.ID = att.ID;
                    attLog.TimeLog = (isCheckIn ? "In " : "Out ") + att.Time.ToString("HH:mm");
                    if (att.Time.Date.CompareTo(attReport.WorkFrom.Date) > 0)
                        attLog.TimeLog += " [" + att.Time.Date.ToShortDateString() + "]";
                    attLog.Note = att.Note;

                    attLogList.Add(attLog);

                    isCheckIn = !isCheckIn;
                }

                if (isCheckIn == false && dDateLog.Equals(DateTime.Now.Date) == false)
                {
                    attLog = new AttendanceLogRecord();
                    //attLog.DateLog = attReport.WorkFrom.Date;
                    //attLog.EmployeeNumber = attReport.EmployeeNumber;
                    attLog.TimeLog = "OutMistakes";
                    attLogList.Add(attLog);
                }
            }

            List<RoostedDayOff> roostedDayOffList = GetRoostedDayOffList();
            Hashtable hasEmplName = new Hashtable();
            if (roostedDayOffList.Count > 0)
            {
                AttendanceLogRecord attRc = null;
                foreach (RoostedDayOff roostedDayOff in roostedDayOffList)
                {
                    string employeeName = null;
                    if (hasEmplName.ContainsKey(roostedDayOff.EmployeeNumber))
                    {
                        employeeName = (string)hasEmplName[roostedDayOff.EmployeeNumber];
                    }
                    else
                    {
                        Employee employee = GetEmployeeByEmployeeNumber(roostedDayOff.EmployeeNumber);
                        if (employee == null)
                            continue;

                        employeeName = employee.LastName + ", " + employee.FirstName;

                        hasEmplName.Add(roostedDayOff.EmployeeNumber, employeeName );
                    }

                    attRc = new AttendanceLogRecord();
                    attRc.EmployeeNumber = roostedDayOff.EmployeeNumber;
                    attRc.EmployeeName = employeeName;
                    attRc.DateLog = roostedDayOff.Date;
                    attRc.TotalHours= roostedDayOff.TotalHours;
                    attRc.TimeLog = "Roosted day off";
                    attRc.Note = roostedDayOff.Note;

                    int indexRp = attLogList.FindIndex(0, delegate(AttendanceLogRecord e) { return e.EmployeeNumber == attRc.EmployeeNumber && e.DateLog.Date.CompareTo(attRc.DateLog.Date) == 1; });
                    if (indexRp < 0)
                    {
                        indexRp = attLogList.FindLastIndex(delegate(AttendanceLogRecord e) { return e.EmployeeNumber == attRc.EmployeeNumber; });

                        if (indexRp < 0)
                        {
                            indexRp = attLogList.FindIndex(delegate(AttendanceLogRecord e) { return e.EmployeeNumber > attRc.EmployeeNumber; });

                            if (indexRp < 0)
                            {
                                indexRp = attLogList.Count;
                            }
                        }
                        else
                            indexRp++;
                    }

                    int indexRp_1 = 0;
                    while (true)
                    {
                        if (indexRp > attLogList.Count - 1)
                            break;
                        indexRp_1 = attLogList.FindIndex(indexRp, 1, delegate(AttendanceLogRecord e) { return e.DateLog.Equals(DateTime.MinValue); });
                        if (indexRp_1 < 1)
                            break;
                        indexRp++;
                    }

                    attLogList.Insert(indexRp, attRc);
                }
                hasEmplName.Clear();
                roostedDayOffList.Clear();
            }
            return attLogList;
        }
Example #4
0
        private void btnImportFromFile_Click(object sender, EventArgs e)
        {
            StreamReader sReader = null;
            try
            {
                OpenFileDialog ofdImport = new OpenFileDialog();
                ofdImport.Filter = "Text files (*.txt)|*.txt";

                if (ofdImport.ShowDialog() == DialogResult.OK)
                {
                    sReader = new StreamReader(ofdImport.FileName);

                    string line = "";
                    List<Employee> employeeList = new List<Employee>();

                    while ((line = sReader.ReadLine()) != null)
                    {
                        if (line.StartsWith("Co./Last Name,First Name")) //is header
                            continue; //go to next line
                        else
                        {
                            Employee employee = new Employee();
                            GetEmployeeData(line, ref employee);

                            employeeList.Add(employee);
                        }
                    }

                    foreach (Employee employee in employeeList)
                    {
                        if (_dtCtrl.AddEmployee(employee, new List<Terminal>()) <= 0)
                            throw new Exception("Can not import employee " + employee.EmployeeNumber);
                    }

                    MessageBox.Show("Employee imported.");
                }
            }
            catch (Exception ex)
            {
                Util.ShowErrorMessage(ex);
            }
            finally
            {
                try
                {
                    sReader.Close();
                }
                catch { }
            }
        }
        private void SetUp()
        {
            ter.IPAddress = "10.0.0.101";
            ter.Name = "Ter1";

            Department dep = _dtCtrl.GetDepartmentList()[0];
            Company com = _dtCtrl.GetCompany(dep.CompanyID);

            emp = _dtCtrl.GetEmployeeList(com.ID, dep.ID)[0];
        }
        public bool IsNewEmployee(Employee employee)
        {
            bool result = false;
            OleDbCommand odCom = BuildSelectCmd("Employee", "PayrollNumber", "Active=TRUE AND EmployeeNumber=@EmployeeNumber", new object[] { "@EmployeeNumber", employee.EmployeeNumber });
            OleDbDataReader odRdr = odCom.ExecuteReader();

            result = (odRdr.Read() == false);
            odRdr.Close();
            return result;
        }
        public bool UpdateEmployee(Employee employee)
        {
            OleDbCommand odCom1 = BuildUpdateCmd("Employee",
                new string[] { "EmployeeNumber"
                ,"DepartmentID"
                ,"FirstName"
                ,"LastName"
                ,"WorkingCalendarID"
                ,"HiredDate"
                ,"LeftDate"
                ,"Birthday"
                ,"JobDescription"
                ,"PhoneNumber"
                ,"Address"
                ,"Active"
                ,"ActiveFrom"
                ,"ActiveTo"
                ,"FaceData1"
                ,"FaceData2"
                ,"FaceData3"
                ,"FaceData4"
                ,"FaceData5"
                ,"FaceData6"
                ,"FaceData7"
                ,"FaceData8"
                ,"FaceData9"
                ,"FaceData10"
                ,"FaceData11"
                ,"FaceData12"
                ,"FaceData13"
                ,"FaceData14"
                ,"FaceData15"
                ,"FaceData16"
                ,"FaceData17"
                ,"FaceData18"
                },
                new object[] { employee.EmployeeNumber
                ,employee.DepartmentID
                ,employee.FirstName
                ,employee.LastName
                ,employee.WorkingCalendarID
                ,employee.HiredDate
                ,employee.LeftDate
                ,employee.Birthday
                ,employee.JobDescription
                ,employee.PhoneNumber
                ,employee.Address
                ,employee.Active
                ,employee.ActiveFrom
                ,employee.ActiveTo
                ,employee.FaceData1
                ,employee.FaceData2
                ,employee.FaceData3
                ,employee.FaceData4
                ,employee.FaceData5
                ,employee.FaceData6
                ,employee.FaceData7
                ,employee.FaceData8
                ,employee.FaceData9
                ,employee.FaceData10
                ,employee.FaceData11
                ,employee.FaceData12
                ,employee.FaceData13
                ,employee.FaceData14
                ,employee.FaceData15
                ,employee.FaceData16
                ,employee.FaceData17
                ,employee.FaceData18
                },
                "PayrollNumber=@ID", new object[] { "@ID", employee.PayrollNumber }
            );

            return (odCom1.ExecuteNonQuery() == 1);
        }
        public Employee GetEmployee(Terminal terminal, int employeeNumber)
        {
            string devInfo = GetDeviceInfoStr(terminal);
            string command = "GetEmployee(id=" + employeeNumber + ")";
            IntPtr result = IntPtr.Zero;

            HwDev_Execute(devInfo, command, ref result);

            if (IsSuccess(result))
            {
                Employee employee = new Employee();

                employee.EmployeeNumber = Convert.ToInt32(GetValue(result, "id"));
                employee.FirstName = GetValue(result, "name");

                employee.FaceData1 = GetValue(result, "face_data", 1);
                employee.FaceData2 = GetValue(result, "face_data", 2);
                employee.FaceData3 = GetValue(result, "face_data", 3);
                employee.FaceData4 = GetValue(result, "face_data", 4);
                employee.FaceData5 = GetValue(result, "face_data", 5);
                employee.FaceData6 = GetValue(result, "face_data", 6);
                employee.FaceData7 = GetValue(result, "face_data", 7);
                employee.FaceData8 = GetValue(result, "face_data", 8);
                employee.FaceData9 = GetValue(result, "face_data", 9);
                employee.FaceData10 = GetValue(result, "face_data", 10);
                employee.FaceData11 = GetValue(result, "face_data", 11);
                employee.FaceData12 = GetValue(result, "face_data", 12);
                employee.FaceData13 = GetValue(result, "face_data", 13);
                employee.FaceData14 = GetValue(result, "face_data", 14);
                employee.FaceData15 = GetValue(result, "face_data", 15);
                employee.FaceData16 = GetValue(result, "face_data", 16);
                employee.FaceData17 = GetValue(result, "face_data", 17);
                employee.FaceData18 = GetValue(result, "face_data", 18);

                //string[] faceData = new string[]
                //{
                //    employee.FaceData1,
                //    employee.FaceData2,
                //    employee.FaceData3,
                //    employee.FaceData4,
                //    employee.FaceData5,
                //    employee.FaceData6,
                //    employee.FaceData7,
                //    employee.FaceData8,
                //    employee.FaceData9,
                //    employee.FaceData10,
                //    employee.FaceData11,
                //    employee.FaceData12,
                //    employee.FaceData13,
                //    employee.FaceData14,
                //    employee.FaceData15,
                //    employee.FaceData16,
                //    employee.FaceData17,
                //    employee.FaceData18
                //};

                //string resultString = Marshal.PtrToStringAnsi(result);

                //int iFrom, iTo, index = 0;
                //string keyName = "face_data=\"";
                //while ((iFrom = resultString.IndexOf(keyName)) >= 0 && index < faceData.Length)
                //{
                //    iFrom += keyName.Length;
                //    iTo = resultString.IndexOf("\"", iFrom);

                //    faceData[index] = resultString.Substring(iFrom, iTo - iFrom);

                //    resultString = resultString.Substring(iTo);
                //    index++;
                //}

                return employee;
            }
            else
            {
                throw new Exception(GetFailedReason(result));
            }
        }
        public bool UpdateEmployee(Terminal terminal, Employee employee)
        {
            string devInfo = GetDeviceInfoStr(terminal);
            string command = GetSetEmployeeCmdStr(employee);

            IntPtr result = IntPtr.Zero;
            HwDev_Execute(devInfo, command, ref result);

            //MessageBox.Show(Marshal.PtrToStringAnsi(result));

            return IsSuccess(result);
        }
Example #10
0
        private void AddTestMultiShiftNonFlexi(ref IDataController _dtCtrl)
        {
            #region add test company
            Company com = new Company();
            com.Name = DateTime.Now.Ticks.ToString();
            com.ID = _dtCtrl.AddCompany(com);
            #endregion

            #region 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);
            #endregion

            #region add test working calendar
            WorkingCalendar wCal = new WorkingCalendar();

            wCal.Name = DateTime.Now.Ticks.ToString();

            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 = 60;

            List<Shift> shiftList = new List<Shift>();
            Shift shift1 = new Shift();
            shift1.From = new DateTime(2000, 2, 2, 8, 0, 0);
            shift1.To = new DateTime(2000, 2, 2, 12, 0, 0);
            shiftList.Add(shift1);

            Shift shift2 = new Shift();
            shift2.From = new DateTime(2000, 2, 2, 14, 0, 0);
            shift2.To = new DateTime(2000, 2, 2, 18, 0, 0);
            shiftList.Add(shift2);

            Shift shift3 = new Shift();
            shift3.From = new DateTime(2000, 2, 2, 20, 0, 0);
            shift3.To = new DateTime(2000, 2, 3, 0, 0, 0);
            shiftList.Add(shift3);

            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 = 4;
            workingDayPaymentRate.RegularRate = 100;
            workingDayPaymentRate.NumberOfOvertime1 = 1;
            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, shiftList, breakList, holidayList, workingDayPaymentRate, nonWorkingDayPaymentRate, holidayPaymentRate, payPeriod);
            #endregion

            #region 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>());
            #endregion

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

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

            //att2 : expected totalHours: 4
            AttendanceRecord att13 = new AttendanceRecord();
            att13.EmployeeNumber = emp.EmployeeNumber;
            att13.Time = new DateTime(2010, 1, 1, 14, 0, 0);
            att13.ID = _dtCtrl.AddAttendanceRecord(att13);

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

            //att3 : expected totalHours: 4
            AttendanceRecord att21 = new AttendanceRecord();
            att21.EmployeeNumber = emp.EmployeeNumber;
            att21.Time = new DateTime(2010, 1, 1, 20, 0, 0);
            att21.ID = _dtCtrl.AddAttendanceRecord(att21);

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

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

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

            //att4 : expected totalHours: 4 + 1 over
            AttendanceRecord att41 = new AttendanceRecord();
            att41.EmployeeNumber = emp.EmployeeNumber;
            att41.Time = new DateTime(2010, 1, 2, 14, 00, 0);
            att41.ID = _dtCtrl.AddAttendanceRecord(att41);

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

            //att4 : expected totalHours:
            AttendanceRecord att51 = new AttendanceRecord();
            att51.EmployeeNumber = emp.EmployeeNumber;
            att51.Time = new DateTime(2010, 1, 2, 20, 06, 0);
            att51.ID = _dtCtrl.AddAttendanceRecord(att51);

            AttendanceRecord att52 = new AttendanceRecord();
            att52.EmployeeNumber = emp.EmployeeNumber;
            att52.Time = new DateTime(2010, 1, 2, 23, 2, 0);
            att52.ID = _dtCtrl.AddAttendanceRecord(att52);
            #endregion
        }
Example #11
0
        private void AddTestOneShiftFlexi(ref IDataController _dtCtrl)
        {
            #region add test company
            Company com = new Company();
            com.Name = DateTime.Now.Ticks.ToString();
            com.ID = _dtCtrl.AddCompany(com);
            #endregion

            #region 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);
            #endregion

            #region add test working calendar
            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 = 7;
            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);

            WorkingCalendar wCal = new WorkingCalendar();
            wCal.Name = DateTime.Now.Ticks.ToString();
            wCal.ApplyFlexiHours = true;
            wCal.FlexiHours = 40;
            wCal.WeekStartsOn = 3; //Thursday

            List<Shift> shiftList = new List<Shift>();
            Shift shift1 = new Shift();
            shift1.From = new DateTime(2000, 2, 2, 9, 0, 0);
            shift1.To = new DateTime(2000, 2, 2, 18, 0, 0);
            shiftList.Add(shift1);

            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;

            wCal.ID = _dtCtrl.AddWorkingCalendar(wCal, shiftList, new List<Break>(), holidayList, workingDayPaymentRate, nonWorkingDayPaymentRate, holidayPaymentRate, payPeriod);
            #endregion

            #region 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>());
            #endregion

            #region add test att records 2
            //att7 : expected regHour: 10
            AttendanceRecord att71 = new AttendanceRecord();
            att71.EmployeeNumber = emp.EmployeeNumber;
            att71.Time = new DateTime(2010, 1, 7, 9, 0, 0);
            att71.ID = _dtCtrl.AddAttendanceRecord(att71);

            AttendanceRecord att72 = new AttendanceRecord();
            att72.EmployeeNumber = emp.EmployeeNumber;
            att72.Time = new DateTime(2010, 1, 7, 19, 0, 0);
            att72.ID = _dtCtrl.AddAttendanceRecord(att72);

            //att8 : expected regHour: 8
            AttendanceRecord att81 = new AttendanceRecord();
            att81.EmployeeNumber = emp.EmployeeNumber;
            att81.Time = new DateTime(2010, 1, 8, 9, 0, 0);
            att81.ID = _dtCtrl.AddAttendanceRecord(att81);

            AttendanceRecord att82 = new AttendanceRecord();
            att82.EmployeeNumber = emp.EmployeeNumber;
            att82.Time = new DateTime(2010, 1, 8, 17, 0, 0);
            att82.ID = _dtCtrl.AddAttendanceRecord(att82);

            //att9 : expected regHour: 8
            AttendanceRecord att91 = new AttendanceRecord();
            att91.EmployeeNumber = emp.EmployeeNumber;
            att91.Time = new DateTime(2010, 1, 9, 9, 0, 0);
            att91.ID = _dtCtrl.AddAttendanceRecord(att91);

            AttendanceRecord att92 = new AttendanceRecord();
            att92.EmployeeNumber = emp.EmployeeNumber;
            att92.Time = new DateTime(2010, 1, 9, 17, 0, 0);
            att92.ID = _dtCtrl.AddAttendanceRecord(att92);

            //att10 : expected regHour: 8
            AttendanceRecord att101 = new AttendanceRecord();
            att101.EmployeeNumber = emp.EmployeeNumber;
            att101.Time = new DateTime(2010, 1, 10, 9, 00, 0);
            att101.ID = _dtCtrl.AddAttendanceRecord(att101);

            AttendanceRecord att102 = new AttendanceRecord();
            att102.EmployeeNumber = emp.EmployeeNumber;
            att102.Time = new DateTime(2010, 1, 10, 17, 0, 0);
            att102.ID = _dtCtrl.AddAttendanceRecord(att102);

            //att11 : expected regHour: 4
            AttendanceRecord att111 = new AttendanceRecord();
            att111.EmployeeNumber = emp.EmployeeNumber;
            att111.Time = new DateTime(2010, 1, 11, 9, 0, 0);
            att111.ID = _dtCtrl.AddAttendanceRecord(att111);

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

            //att12 : expected regHour: 2 overHour: 2
            AttendanceRecord att121 = new AttendanceRecord();
            att121.EmployeeNumber = emp.EmployeeNumber;
            att121.Time = new DateTime(2010, 1, 12, 9, 0, 0);
            att121.ID = _dtCtrl.AddAttendanceRecord(att121);

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

            //att13 : expected overHour: 2
            AttendanceRecord att131 = new AttendanceRecord();
            att131.EmployeeNumber = emp.EmployeeNumber;
            att131.Time = new DateTime(2010, 1, 13, 9, 0, 0);
            att131.ID = _dtCtrl.AddAttendanceRecord(att131);

            AttendanceRecord att132 = new AttendanceRecord();
            att132.EmployeeNumber = emp.EmployeeNumber;
            att132.Time = new DateTime(2010, 1, 13, 11, 0, 0);
            att132.ID = _dtCtrl.AddAttendanceRecord(att132);
            #endregion
        }
        private void AddAttRecord()
        {
            emp = _dtCtrl.GetEmployeeList()[0];

            attRecord.EmployeeNumber = emp.EmployeeNumber;
            attRecord.Note = "";
            //attRecord.PhotoData = "";
            attRecord.Time = DateTime.Now;

            attRecord.ID = _dtCtrl.AddAttendanceRecord(attRecord);
        }
Example #13
0
        private void RemoveEmployeeFromTerminal(Employee employee)
        {
            List<Terminal> terminalList = _dtCtrl.GetTerminalListByEmployee(employee.EmployeeNumber);

            foreach (Terminal terminal in terminalList)
            {
                if (_terCtrl.IsTerminalConnected(terminal))
                {
                    //throw new Exception("Do not do this yet. It is painful to add an employee from the terminal you know.");

                    if (_terCtrl.RemoveEmployee(terminal, employee.EmployeeNumber) == false)
                        throw new Exception("Cannot remove employee " + employee.EmployeeNumber + " from terminal " + terminal.Name + ".");
                }
                else
                {
                    UndeletedEmployeeNumber undeletedEmployeeNumber = new UndeletedEmployeeNumber();
                    undeletedEmployeeNumber.EmployeeNumber = employee.EmployeeNumber;
                    undeletedEmployeeNumber.TerminalID = terminal.ID;

                    if (_dtCtrl.AddUndeletedEmployeeNumber(undeletedEmployeeNumber) == false)
                        throw new Exception("Employee " + employee.EmployeeNumber + " could not be deleted.");
                }
            }
        }
Example #14
0
        private void GetEmployeeData(string line, ref Employee employee)
        {
            try
            {
                string[] data = line.Split(',');

                employee.Active = true;
                employee.Address = data[4] + " " + data[5] + " " + data[6] + " " + data[7];
                employee.Birthday = data[108] != "" ? Convert.ToDateTime(data[108], new CultureInfo("en-US")) : Config.MinDate;
                employee.DepartmentID = 1; //default department
                employee.EmployeeNumber = Convert.ToInt32(data[2]);
                employee.FirstName = data[1];
                employee.HiredDate = data[110] != "" ? Convert.ToDateTime(data[110], new CultureInfo("en-US")) : Config.MinDate;
                employee.LastName = data[0];
                employee.PhoneNumber = data[12];
                employee.WorkingCalendarID = -1;
            }
            catch (FormatException)
            {
                throw new Exception("Employee's CardID must be in number only");
            }
            catch (IndexOutOfRangeException)
            {
                throw new Exception("File format not supported");
            }
        }
        public List<Employee> GetEmployeeList(int compantID, int departmentID)
        {
            OleDbCommand odCom;
            if (departmentID == 1 && compantID == 1) //default company and default department
                odCom = BuildSelectCmd("Employee", "*", "DepartmentID=1 AND Active=TRUE");
            else if (departmentID > 0)
                odCom = BuildSelectCmd("Employee", "*", "DepartmentID=@ID AND Active=TRUE", new object[] { "@ID", departmentID });
            else if (compantID > 0) //WRONG
                odCom = BuildSelectCmd("Employee", "*", "DepartmentID in (SELECT ID FROM Department WHERE CompanyID=@ID) AND Active=TRUE", new object[] { "@ID", compantID });
            else // all companies and all department
                odCom = BuildSelectCmd("Employee", "*", "Active=TRUE");

            OleDbDataReader odRdr = odCom.ExecuteReader();
            List<Employee> employeeList = new List<Employee>();
            Employee employee = null;
            while (odRdr.Read())
            {
                employee = new Employee();

                employee.PayrollNumber = (int)odRdr["PayrollNumber"];
                employee.EmployeeNumber = (int)odRdr["EmployeeNumber"];
                employee.DepartmentID = (int)odRdr["DepartmentID"];
                employee.FirstName = odRdr["FirstName"].ToString();
                employee.LastName = odRdr["LastName"].ToString();
                employee.WorkingCalendarID = (int)odRdr["WorkingCalendarID"];
                employee.HiredDate = odRdr["HiredDate"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["HiredDate"]) : Config.MinDate;
                employee.LeftDate = odRdr["LeftDate"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["LeftDate"]) : Config.MinDate;
                employee.Birthday = odRdr["Birthday"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["Birthday"]) : Config.MinDate;
                employee.JobDescription = odRdr["JobDescription"].ToString();
                employee.PhoneNumber = odRdr["PhoneNumber"].ToString();
                employee.Address = odRdr["Address"].ToString();
                employee.Active = Convert.ToBoolean(odRdr["Active"]);
                employee.ActiveFrom = odRdr["ActiveFrom"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["ActiveFrom"]) : Config.MinDate;
                employee.ActiveTo = odRdr["ActiveTo"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["ActiveTo"]) : Config.MinDate;
                employee.FaceData1 = odRdr["FaceData1"].ToString();
                employee.FaceData2 = odRdr["FaceData2"].ToString();
                employee.FaceData3 = odRdr["FaceData3"].ToString();
                employee.FaceData4 = odRdr["FaceData4"].ToString();
                employee.FaceData5 = odRdr["FaceData5"].ToString();
                employee.FaceData6 = odRdr["FaceData6"].ToString();
                employee.FaceData7 = odRdr["FaceData7"].ToString();
                employee.FaceData8 = odRdr["FaceData8"].ToString();
                employee.FaceData9 = odRdr["FaceData9"].ToString();
                employee.FaceData10 = odRdr["FaceData10"].ToString();
                employee.FaceData11 = odRdr["FaceData11"].ToString();
                employee.FaceData12 = odRdr["FaceData12"].ToString();
                employee.FaceData13 = odRdr["FaceData13"].ToString();
                employee.FaceData14 = odRdr["FaceData14"].ToString();
                employee.FaceData15 = odRdr["FaceData15"].ToString();
                employee.FaceData16 = odRdr["FaceData16"].ToString();
                employee.FaceData17 = odRdr["FaceData17"].ToString();
                employee.FaceData18 = odRdr["FaceData18"].ToString();

                employeeList.Add(employee);
            }
            odRdr.Close();
            return employeeList;
        }
        private string GetSetEmployeeCmdStr(Employee employee)
        {
            //string cmd = "SetEmployee(id=\"" + employee.EmployeeNumber + "\" name=\"" + employee.FirstName + "\" calid=\"\" card_num=\"0Xffffffff\" authority=\"0X0\" check_type=\"face\" opendoor_type=\"face\"";
            string cmd = "SetEmployee(id=\"" + employee.EmployeeNumber + "\" name=\"" + employee.FirstName + "\" calid=\"\" card_num=\"0xffffffff\" authority=\"0X0\" check_type=\"face\" opendoor_type=\"face\"";

            //load face_data
            cmd += " face_data=\"" + employee.FaceData1 + "\"";
            cmd += " face_data=\"" + employee.FaceData2 + "\"";
            cmd += " face_data=\"" + employee.FaceData3 + "\"";
            cmd += " face_data=\"" + employee.FaceData4 + "\"";
            cmd += " face_data=\"" + employee.FaceData5 + "\"";
            cmd += " face_data=\"" + employee.FaceData6 + "\"";
            cmd += " face_data=\"" + employee.FaceData7 + "\"";
            cmd += " face_data=\"" + employee.FaceData8 + "\"";
            cmd += " face_data=\"" + employee.FaceData9 + "\"";
            cmd += " face_data=\"" + employee.FaceData10 + "\"";
            cmd += " face_data=\"" + employee.FaceData11 + "\"";
            cmd += " face_data=\"" + employee.FaceData12 + "\"";
            cmd += " face_data=\"" + employee.FaceData13 + "\"";
            cmd += " face_data=\"" + employee.FaceData14 + "\"";
            cmd += " face_data=\"" + employee.FaceData15 + "\"";
            cmd += " face_data=\"" + employee.FaceData16 + "\"";
            cmd += " face_data=\"" + employee.FaceData17 + "\"";
            cmd += " face_data=\"" + employee.FaceData18 + "\"";

            cmd += ")";

            return cmd;
        }
        public List<Employee> GetEmployeeListByTerminal(int terminalID)
        {
            OleDbCommand odCom = BuildSelectCmd("Employee", "*", "Active=TRUE AND EmployeeNumber IN (SELECT EmployeeNumber FROM EmployeeTerminal WHERE TerminalID=@terminalID)", new object[] { "@terminalID", terminalID });
            OleDbDataReader odRdr = odCom.ExecuteReader();

            List<Employee> employeeList = new List<Employee>();
            Employee employee = null;
            while (odRdr.Read())
            {
                employee = new Employee();

                employee.PayrollNumber = Convert.ToInt16(odRdr["PayrollNumber"]);
                employee.EmployeeNumber = Convert.ToInt32(odRdr["EmployeeNumber"]);
                employee.DepartmentID = Convert.ToInt16(odRdr["DepartmentID"]);
                employee.FirstName = odRdr["FirstName"].ToString();
                employee.LastName = odRdr["LastName"].ToString();
                employee.WorkingCalendarID = Convert.ToInt16(odRdr["WorkingCalendarID"]);
                employee.HiredDate = Convert.ToDateTime(odRdr["HiredDate"]);
                employee.LeftDate = Convert.ToDateTime(odRdr["LeftDate"]);
                employee.Birthday = Convert.ToDateTime(odRdr["Birthday"]);
                employee.JobDescription = odRdr["JobDescription"].ToString();
                employee.PhoneNumber = odRdr["PhoneNumber"].ToString();
                employee.Address = odRdr["Address"].ToString();
                employee.Active = Convert.ToBoolean(odRdr["Active"]);
                employee.ActiveFrom = Convert.ToDateTime(odRdr["ActiveFrom"]);
                if (typeof(DBNull) != odRdr["ActiveTo"].GetType())
                    employee.ActiveTo = (DateTime)odRdr["ActiveTo"];
                employee.FaceData1 = odRdr["FaceData1"].ToString();
                employee.FaceData2 = odRdr["FaceData2"].ToString();
                employee.FaceData3 = odRdr["FaceData3"].ToString();
                employee.FaceData4 = odRdr["FaceData4"].ToString();
                employee.FaceData5 = odRdr["FaceData5"].ToString();
                employee.FaceData6 = odRdr["FaceData6"].ToString();
                employee.FaceData7 = odRdr["FaceData7"].ToString();
                employee.FaceData8 = odRdr["FaceData8"].ToString();
                employee.FaceData9 = odRdr["FaceData9"].ToString();
                employee.FaceData10 = odRdr["FaceData10"].ToString();
                employee.FaceData11 = odRdr["FaceData11"].ToString();
                employee.FaceData12 = odRdr["FaceData12"].ToString();
                employee.FaceData13 = odRdr["FaceData13"].ToString();
                employee.FaceData14 = odRdr["FaceData14"].ToString();
                employee.FaceData15 = odRdr["FaceData15"].ToString();
                employee.FaceData16 = odRdr["FaceData16"].ToString();
                employee.FaceData17 = odRdr["FaceData17"].ToString();
                employee.FaceData18 = odRdr["FaceData18"].ToString();

                employeeList.Add(employee);
            }

            odRdr.Close();
            return employeeList;
        }
Example #18
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 });
            }
        }
        public int AddEmployee(Employee employee, List<Terminal> terminalList)
        {
            BeginTransaction();

            try
            {
                //if Employee is added from terminal then Employee No has been assigned already
                if (employee.EmployeeNumber <= 0)
                    employee.EmployeeNumber = GetAvailEmployeeNumber();
                else
                    AddEmployeeNumber(employee.EmployeeNumber);

                if (employee.EmployeeNumber > 0)
                {
                    employee.PayrollNumber = AddEmployee(employee);

                    if (terminalList.Count > 0)
                    {
                        List<EmployeeTerminal> employeeTerminalList = new List<EmployeeTerminal>();
                        foreach (Terminal terminal in terminalList)
                        {
                            EmployeeTerminal emplTerminal = new EmployeeTerminal();
                            emplTerminal.TerminalID = terminal.ID;
                            emplTerminal.EmployeeNumber = employee.EmployeeNumber;

                            employeeTerminalList.Add(emplTerminal);
                        }

                        AddEmployeeTerminal(employeeTerminalList);
                    }

                    CommitTransaction();
                }
                else
                {
                    throw new Exception("There's no more employee number available. Please enter your CC detail to purchase more.");
                }
            }
            catch (Exception)
            {
                RollbackTransaction();
                throw;
            }

            return employee.PayrollNumber;
        }
        private void AddTerminal()
        {
            ter1.Name = DateTime.Now.Ticks.ToString();
            ter1.IPAddress = "10.0.0.199";

            ter1.ID = _dtCtrl.AddTerminal(ter1);

            emp1 = new Employee();
            emp1.Active = true;
            emp1.ActiveFrom = DateTime.Today;
            emp1.ActiveTo = DateTime.Today.AddDays(1);
            emp1.Address = DateTime.Now.Ticks.ToString();
            emp1.Birthday = DateTime.Today.AddYears(-20);
            emp1.DepartmentID = _dtCtrl.GetDepartmentList()[0].ID;
            emp1.EmployeeNumber = 0;
            emp1.FirstName = DateTime.Now.Ticks.ToString();
            emp1.JobDescription = DateTime.Now.Ticks.ToString();
            emp1.HiredDate = DateTime.Today;
            emp1.LeftDate = DateTime.Today.AddYears(1);
            emp1.LastName = DateTime.Now.Ticks.ToString();
            emp1.PhoneNumber = DateTime.Now.Ticks.ToString();
            emp1.WorkingCalendarID = _dtCtrl.GetWorkingCalendarList()[0].ID;
            emp1.FaceData1 = "";
            emp1.FaceData2 = "";
            emp1.FaceData3 = "";
            emp1.FaceData4 = "";
            emp1.FaceData5 = "";
            emp1.FaceData6 = "";
            emp1.FaceData7 = "";
            emp1.FaceData8 = "";
            emp1.FaceData9 = "";
            emp1.FaceData10 = "";
            emp1.FaceData11 = "";
            emp1.FaceData12 = "";
            emp1.FaceData13 = "";
            emp1.FaceData14 = "";
            emp1.FaceData15 = "";
            emp1.FaceData16 = "";
            emp1.FaceData17 = "";
            emp1.FaceData18 = "";

            emp1.PayrollNumber = _dtCtrl.AddEmployee(emp1, new List<Terminal>() { ter1 });
        }
        private int AddEmployee(Employee employee)
        {
            OleDbCommand odCom1 = BuildInsertCmd("Employee",
                new string[] { "EmployeeNumber"
                ,"DepartmentID"
                ,"FirstName"
                ,"LastName"
                ,"WorkingCalendarID"
                ,"HiredDate"
                ,"LeftDate"
                ,"Birthday"
                ,"JobDescription"
                ,"PhoneNumber"
                ,"Address"
                ,"Active"
                ,"ActiveFrom"
                ,"ActiveTo"
                ,"FaceData1"
                ,"FaceData2"
                ,"FaceData3"
                ,"FaceData4"
                ,"FaceData5"
                ,"FaceData6"
                ,"FaceData7"
                ,"FaceData8"
                ,"FaceData9"
                ,"FaceData10"
                ,"FaceData11"
                ,"FaceData12"
                ,"FaceData13"
                ,"FaceData14"
                ,"FaceData15"
                ,"FaceData16"
                ,"FaceData17"
                ,"FaceData18"
                },
                new object[] { employee.EmployeeNumber
                ,employee.DepartmentID
                ,employee.FirstName
                ,employee.LastName
                ,employee.WorkingCalendarID
                ,employee.HiredDate
                ,employee.LeftDate
                ,employee.Birthday
                ,employee.JobDescription
                ,employee.PhoneNumber
                ,employee.Address
                ,employee.Active
                ,employee.ActiveFrom
                ,employee.ActiveTo
                ,employee.FaceData1
                ,employee.FaceData2
                ,employee.FaceData3
                ,employee.FaceData4
                ,employee.FaceData5
                ,employee.FaceData6
                ,employee.FaceData7
                ,employee.FaceData8
                ,employee.FaceData9
                ,employee.FaceData10
                ,employee.FaceData11
                ,employee.FaceData12
                ,employee.FaceData13
                ,employee.FaceData14
                ,employee.FaceData15
                ,employee.FaceData16
                ,employee.FaceData17
                ,employee.FaceData18
                }
            );

            if (odCom1.ExecuteNonQuery() == 1)
            {
                odCom1.CommandText = "SELECT @@IDENTITY";
                return Convert.ToInt32(odCom1.ExecuteScalar().ToString());
            }
            return -1;
        }
        private void AddEmployee()
        {
            //com.Name = DateTime.Now.Ticks.ToString();
            //com.ID = _dtCtrl.AddCompany(com);

            //dep.Name = DateTime.Now.Ticks.ToString();
            //dep.CompanyID = com.ID;
            //dep.SupDepartmentID = 0;
            //dep.ID = _dtCtrl.AddDepartment(dep);

            //wCal.Name = DateTime.Now.Ticks.ToString();
            //wCal.RegularWorkingFrom = DateTime.Today;
            //wCal.RegularWorkingTo = DateTime.Today;

            //List<Break> breakList = new List<Break>();
            //List<Holiday> holidayList = new List<Holiday>();

            //PaymentRate workingDayPaymentRate = new PaymentRate();
            //PaymentRate nonWorkingDayPaymentRate = new PaymentRate();
            //PaymentRate holidayPaymentRate = new PaymentRate();

            //PayPeriod payPeriod = new PayPeriod();
            //payPeriod.CustomPeriod = 5;
            //payPeriod.PayPeriodTypeID = 5; //custom
            //payPeriod.StartFrom = DateTime.Today;

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

            dep = _dtCtrl.GetDepartmentList()[0];
            com = _dtCtrl.GetCompany(dep.CompanyID);
            wCal = _dtCtrl.GetWorkingCalendarList()[0];
            ter = _dtCtrl.GetTerminalList()[0];

            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.FaceData1 = "";
            emp.FaceData2 = "";
            emp.FaceData3 = "";
            emp.FaceData4 = "";
            emp.FaceData5 = "";
            emp.FaceData6 = "";
            emp.FaceData7 = "";
            emp.FaceData8 = "";
            emp.FaceData9 = "";
            emp.FaceData10 = "";
            emp.FaceData11 = "";
            emp.FaceData12 = "";
            emp.FaceData13 = "";
            emp.FaceData14 = "";
            emp.FaceData15 = "";
            emp.FaceData16 = "";
            emp.FaceData17 = "";
            emp.FaceData18 = "";

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