Пример #1
0
        public static List <ERosterTable> GetRosterTableList(DatabaseConnection dbConn, int EmpID, DateTime RosterDate)
        {
            SortedList <TimeSpan, ERosterTable> ResultRosterTableList = new SortedList <TimeSpan, ERosterTable>();

            DBFilter rosterTableFilter = new DBFilter();

            rosterTableFilter.add(new Match("EmpID", EmpID));
            rosterTableFilter.add(new Match("RosterTableDate", "=", RosterDate));
            System.Collections.ArrayList rosterTableList = ERosterTable.db.select(dbConn, rosterTableFilter);
            if (rosterTableList.Count > 0)
            {
                int count = 0;
                foreach (ERosterTable rosterTable in rosterTableList)
                {
                    // sort the time if roster table is multiple roster code
                    // use millsecond for first in first out basis if the in time is same
                    ERosterCode rosterCode = new ERosterCode();
                    rosterCode.RosterCodeID = rosterTable.RosterCodeID;
                    if (ERosterCode.db.select(dbConn, rosterCode))
                    {
                        ResultRosterTableList.Add(rosterCode.RosterCodeInTime.TimeOfDay.Add(new TimeSpan(0, 0, 0, 0, count++)), rosterTable);
                    }
                }
            }
            else
            {
                ERosterTable rosterTable = new ERosterTable();
                rosterTable.EmpID           = EmpID;
                rosterTable.RosterTableDate = RosterDate;
                rosterTable.RosterCodeID    = 0;

                EEmpPositionInfo empPosInfo = AppUtils.GetLastPositionInfo(dbConn, RosterDate, EmpID);
                if (empPosInfo != null)
                {
                    if ((empPosInfo.EmpPosEffTo.Ticks.Equals(0) || RosterDate <= empPosInfo.EmpPosEffTo))
                    {
                        EWorkHourPattern workPattern = new EWorkHourPattern();
                        workPattern.WorkHourPatternID = empPosInfo.WorkHourPatternID;
                        if (EWorkHourPattern.db.select(dbConn, workPattern))
                        {
                            ERosterCode rosterCode = new ERosterCode();
                            rosterCode.RosterCodeID = workPattern.GetDefaultRosterCodeID(dbConn, RosterDate);
                            if (ERosterCode.db.select(dbConn, rosterCode))
                            {
                                rosterTable.RosterCodeID = rosterCode.RosterCodeID;
                            }
                        }
                    }
                }
                ResultRosterTableList.Add(new TimeSpan(), rosterTable);
            }
            return(new List <ERosterTable>(ResultRosterTableList.Values));
        }
Пример #2
0
        public static double GetEstimatedNumOfLeaveDays(DatabaseConnection dbConn, int EmpID, DateTime DateFrom, DateTime DateTo, int LeaveCodeID, out DateTime[] DateSkipArray)
        {
            System.Collections.ArrayList dateSkipArrayList = new System.Collections.ArrayList();

            EEmpPositionInfo empPos    = null;
            double           totalDays = 0;

            ELeaveType leaveType = new ELeaveType();

            leaveType.LeaveTypeIsUseWorkHourPattern = true;

            ELeaveCode leaveCode = new ELeaveCode();

            leaveCode.LeaveCodeID = LeaveCodeID;
            if (ELeaveCode.db.select(dbConn, leaveCode))
            {
                leaveType.LeaveTypeID = leaveCode.LeaveTypeID;
                ELeaveType.db.select(dbConn, leaveType);
            }
            for (DateTime currentDate = DateFrom; currentDate <= DateTo; currentDate = currentDate.AddDays(1))
            {
                //  default every date count = 1
                double dateCount = 1;
                if (EStatutoryHoliday.IsHoliday(dbConn, currentDate))
                {
                    if (!leaveType.LeaveTypeIsSkipStatutoryHolidayChecking)
                    {
                        dateCount = 0;
                    }
                }
                else if (EPublicHoliday.IsHoliday(dbConn, currentDate))
                {
                    if (!leaveType.LeaveTypeIsSkipPublicHolidayChecking)
                    {
                        dateCount = 0;
                    }
                }

                if (empPos == null)
                {
                    empPos = AppUtils.GetLastPositionInfo(dbConn, currentDate, EmpID);
                }
                else
                if (!empPos.EmpPosEffTo.Ticks.Equals(0) && empPos.EmpPosEffTo <= currentDate)
                {
                    empPos = AppUtils.GetLastPositionInfo(dbConn, currentDate, EmpID);
                }

                if (empPos != null)
                {
                    EWorkHourPattern workPattern = new EWorkHourPattern();
                    workPattern.WorkHourPatternID = empPos.WorkHourPatternID;
                    if (EWorkHourPattern.db.select(dbConn, workPattern))
                    {
                        if (leaveType.LeaveTypeIsUseWorkHourPattern)
                        {
                            dateCount = workPattern.GetDefaultDayUnit(dbConn, currentDate, leaveType.LeaveTypeIsSkipStatutoryHolidayChecking, leaveType.LeaveTypeIsSkipPublicHolidayChecking);
                        }
                    }
                }


                totalDays += dateCount;

                if (dateCount <= 0)
                {
                    dateSkipArrayList.Add(currentDate);
                }
            }

            DateSkipArray = (DateTime[])dateSkipArrayList.ToArray(typeof(DateTime));
            return(totalDays);
        }