Exemple #1
0
 public WorkAreaVisitEvent(WorkDay _workDay, WorkArea _workArea, AreaVisitEvent _event)
 {
     workDay = _workDay;
     workArea = _workArea;
     device = _event.device;
     areaEvent = _event;
 }
Exemple #2
0
        public void init()
        {
            db = new pgworkDBEntities();
            try
            {
                currentWorkDay = (
                    from m in db.WorkDays
                    where m.workDayState == WorkDayState.wdstInProgress
                    select m
                ).First<WorkDay>();
            }
            catch (Exception)
            {
                currentWorkDay = null;
            }

            _initTimers();
        }
Exemple #3
0
        private void _finishAllWorkDays(WorkDay _excludeWorkDay)
        {
            try
            {
                List<WorkDay> startedWorkDays = (
                    from m in db.WorkDays
                    where m.workDayState == WorkDayState.wdstInProgress && m.startTime > Core.now() && m.endTime < Core.now()
                    select m
                ).ToList<WorkDay>();

                foreach (WorkDay _day in startedWorkDays)
                {
                    if (_excludeWorkDay != null && _day.workDayId == _excludeWorkDay.workDayId)
                        continue;
                    _stopWorkDay(_day);
                }
            }
            catch (Exception)
            {
                currentWorkDay = null;
            }
        }
Exemple #4
0
 public WorkDayEventArgs(WorkDay _day)
 {
     m_workDay = _day;
 }
Exemple #5
0
        private void _stopWorkDay()
        {
            Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
            WorkDay nextDay = _findNextWorkDay();
            if (nextDay != null) {
                m_startTimer.Interval = nextDay.startTime - unixTimestamp;
                m_startTimer.Enabled = true;
            }
            if (m_currentWorkDay == null)
                return;

            m_stopTimer.Enabled = false;

            m_currentWorkDay.workDayState = WorkDayState.wdstFinished;
            _riseWorkDayEnd(m_currentWorkDay);
            m_currentWorkDay = null;

            if (nextDay != null) {
                m_startTimer.Interval = nextDay.startTime - unixTimestamp;
                m_startTimer.Enabled = true;
            }
        }
Exemple #6
0
        private void _startWorkDay(WorkDay _day)
        {
            m_startTimer.Enabled = false;

            Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
            m_currentWorkDay = _day;
            m_currentWorkDay.workDayState = WorkDayState.wdstInProgress;
            _riseWorkDayStart(m_currentWorkDay);
            m_stopTimer.Interval = m_currentWorkDay.startTime - unixTimestamp;
            m_stopTimer.Enabled = true;
        }
Exemple #7
0
 private void _riseWorkDayStart(WorkDay _day)
 {
     EventHandler<WorkDayEventArgs> handler = WorkDayStartEvent;
     if (handler != null)
         handler(this, new WorkDayEventArgs(_day));
 }
Exemple #8
0
 public WorkDayStopEvent(WorkDay _workDay)
 {
     workDay = _workDay;
 }
Exemple #9
0
 public WorkDayStartEvent(WorkDay _workDay)
 {
     workDay = _workDay;
 }
Exemple #10
0
        private void _updateWorkdayTimer(object _sender, System.Timers.ElapsedEventArgs _args)
        {
            int nTimeNow = Core.now();
            try
            {
                WorkDay inProgressWorkDay = (
                    from m in db.WorkDays
                    where m.workDayState == WorkDayState.wdstInProgress
                    select m
                ).First<WorkDay>();
                if (inProgressWorkDay.endTime < nTimeNow)
                    _stopWorkDay(inProgressWorkDay);
                if (currentWorkDay != null && inProgressWorkDay.workDayId == currentWorkDay.workDayId)
                    currentWorkDay = null;
            }
            catch (Exception) {}

            try
            {
                List<WorkDay> shouldBeStartedWorkDays = (
                    from m in db.WorkDays
                    where m.workDayState == WorkDayState.wdstNotStarted && m.startTime > nTimeNow && m.endTime < nTimeNow
                    select m
                ).ToList<WorkDay>();
                Debug.Assert(shouldBeStartedWorkDays.Count <= 1); // System work only with one workday at the moment.
                if (shouldBeStartedWorkDays.Count == 1)
                {
                    // we should start this work day.
                    currentWorkDay = shouldBeStartedWorkDays[0];
                    _startWorkDay(shouldBeStartedWorkDays[0]);
                }
            }
            catch (Exception) { }
        }
Exemple #11
0
 private void _stopWorkDay(WorkDay _workDay)
 {
     _workDay.workDayState = WorkDayState.wdstFinished;
     db.SaveChanges();
     WorkDayStopEventHandler(this, new WorkDayStopEvent(_workDay));
 }
Exemple #12
0
 private void _startWorkDay(WorkDay _workDay)
 {
     _workDay.workDayState = WorkDayState.wdstInProgress;
     db.SaveChanges();
     WorkDayStartEventHandler(this, new WorkDayStartEvent(_workDay));
 }