Example #1
0
        private DateTimeCollection GetSeletedRects()
        {
            DateTimeCollection coll = new DateTimeCollection();

            foreach (ActRect rc in m_rects)
            {
                if (rc.IsSelected == true && rc.Tag != null)
                {
                    int      index   = (int)rc.Tag;
                    DateTime newDate = new DateTime(m_iYear, m_iMonth, m_iDay, 0, 0, 0);

                    if (index < 0 && index > -10)
                    {
                        newDate = m_dtSelected.AddMonths(1);
                        index   = -index;
                    }
                    else if (index < 0 && index < -20)
                    {
                        newDate = m_dtSelected.AddMonths(-1);
                        index   = -index;
                    }

                    coll.Add(new DateTime(newDate.Year, newDate.Month, index, 0, 0, 0));
                }
            }

            return(coll);
        }
Example #2
0
        public async Task <ActionResult <IEnumerable <FullCalendarEvent> > > GetSchedules(int id, [FromQuery] DateRange dateRange)
        {
            var employee = await _context.Employees
                           .Include(e => e.Schedules)
                           .ThenInclude(m => m.Exceptions)
                           .FirstOrDefaultAsync(e => e.EmployeeId == id);

            if (employee == null)
            {
                return(NotFound());
            }

            var events = new List <FullCalendarEvent>();

            foreach (var schedule in employee.Schedules)
            {
                var vacations = new DateTimeCollection();
                foreach (var exception in schedule.Exceptions)
                {
                    vacations.AddRange(exception.GetInstancesBetween(dateRange.Start, dateRange.End));
                }

                var shifts = new DateTimeCollection();
                shifts.AddRange(schedule.GetInstancesBetween(dateRange.Start, dateRange.End)
                                .Where(s => !vacations.Any(v => v.Date == s.Date)));

                var timespan = schedule.EndDate == null ?
                               new System.TimeSpan(24, 0, 0) :
                               schedule.EndDate - schedule.StartDate;

                foreach (var shift in shifts.Select((date, index) => new { date, index }))
                {
                    events.Add(new FullCalendarEvent
                    {
                        Id      = $"event_{schedule.EmployeeId}_{schedule.ScheduleId}_{shift.index.ToString().PadLeft(5, '0')}",
                        GroupId = $"event_{schedule.EmployeeId}_{schedule.ScheduleId}",
                        Title   = schedule.Title,
                        Start   = shift.date,
                        End     = shift.date.AddHours(timespan.Value.Hours)
                    });
                }
            }

            return(events);
        }
Example #3
0
 void radCalendar1_SelectionChanged(object sender, EventArgs e)
 {
     AddEventRoot("SelectionChanged");
     AddTextToListBox("    The following dates have been added to\n    SelectedDates collection in RadCalendar:");
     for (int i = 0; i < this.radCalendar1.SelectedDates.Count; i++)
     {
         if (!oldSelections.Contains(this.radCalendar1.SelectedDates[i]))
         {
             AddTextToListBox("    " + this.radCalendar1.SelectedDates[i]);
         }
     }
     if (oldSelections != null)
     {
         // Remove if to reproduce exception. Click erratically on the Calendar and oldSelections becomes null.
         // SelectionChanged fires before SelectionChanging?
         oldSelections.BeginUpdate();
         oldSelections.Clear();
         oldSelections.EndUpdate();
     }
     oldSelections = null;
 }
Example #4
0
        /// <summary>
        /// Deletes the raw data for an item.
        /// </summary>
        private int[] DeleteAtTime(HdaItem item, DateTimeCollection timestamps)
        {
            string methodName = "IOPCHDA_SyncUpdate.DeleteAtTime";

            int count = timestamps.Count;
            int[] serverHandles = new int[count];
            System.Runtime.InteropServices.ComTypes.FILETIME[] pTimestamps = new System.Runtime.InteropServices.ComTypes.FILETIME[count];

            for (int ii = 0; ii < count; ii++)
            {
                serverHandles[ii] = item.ServerHandle;
                pTimestamps[ii] = ComUtils.GetFILETIME(timestamps[ii]);
            }

            IntPtr ppErrors;

            try
            {
                IOPCHDA_SyncUpdate server = BeginComCall<IOPCHDA_SyncUpdate>(methodName, true);

                server.DeleteAtTime(
                    count,
                    serverHandles,
                    pTimestamps,
                    out ppErrors);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);

                int[] errors = new int[count];

                for (int ii = 0; ii < count; ii++)
                {
                    errors[ii] = ResultIds.E_FAIL;
                }

                return errors;
            }
            finally
            {
                EndComCall(methodName);
            }

            return ComUtils.GetInt32s(ref ppErrors, count, true);
        }
Example #5
0
        /// <summary>
        /// Reads a UTC date/time array from the stream.
        /// </summary>
        public DateTimeCollection ReadDateTimeArray(string fieldName)
        {
            bool isNil = false;

            DateTimeCollection values = new DateTimeCollection();
                                    
            if (BeginField(fieldName, true, out isNil))
            {                                
                PushNamespace(Namespaces.OpcUaXsd);
                
                while (MoveToElement("DateTime"))
                {
                    values.Add(ReadDateTime("DateTime"));
                }

                // check the length.
                if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
                {
                    throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
                }

                PopNamespace();

                EndField(fieldName);
                return values;
            }

            if (isNil)
            {
                return null;
            }

            return values;
        }
        private DateTimeCollection GetSeletedRects()
        {
            DateTimeCollection coll = new DateTimeCollection();

              foreach( ActRect rc in m_rects )
              {
            if( rc.IsSelected == true && rc.Tag != null )
            {
              int index = (int)rc.Tag;
              DateTime newDate = new DateTime( m_iYear, m_iMonth, m_iDay, 0, 0, 0 );

              if( index < 0 && index > -10 )
              {
            newDate = m_dtSelected.AddMonths(1);
            index = -index;
              }
              else if( index < 0 && index < -20 )
              {
            newDate = m_dtSelected.AddMonths(-1);
            index = -index;
              }

              coll.Add( new DateTime( newDate.Year, newDate.Month, index, 0, 0, 0 ) );
            }
              }

              return coll;
        }
        /// <summary>
        /// Reads a UTC date/time array from the stream.
        /// </summary>
        public DateTimeCollection ReadDateTimeArray(string fieldName)
        {
            int length = ReadArrayLength();

            if (length == -1)
            {
                return null;
            }

            DateTimeCollection values = new DateTimeCollection(length);

            for (int ii = 0; ii < length; ii++)
            {
                values.Add(ReadDateTime(null));
            }

            return values;
        }
Example #8
0
        /// <summary>
        /// This method is used to return all recurring instances between the two specified date/times based on
        /// the current settings.
        /// </summary>
        /// <param name="fromDate">The minimum date/time on or after which instances should occur.</param>
        /// <param name="toDate">The maximum date/time on or before which instances should occur.</param>
        /// <returns>Returns a <see cref="DateTimeCollection"/> of <see cref="DateTime" /> objects that represent
        /// the instances found between the two specified date/times.</returns>
        private DateTimeCollection GenerateInstances(DateTime fromDate, DateTime toDate)
        {
            RecurDateTimeCollection rdtc;
            RecurDateTime rdt;
            int idx, count, lastYear = -1;

            DateTimeCollection dcDates = new DateTimeCollection();

            // If undefined or if the requested range is outside that of the recurrence, don't bother.  Just
            // return an empty collection.  Note that for defined recurrences that use a count, we'll always
            // have to expand it.
            if(frequency == RecurFrequency.Undefined || startDate > toDate || untilDate < fromDate)
                return dcDates;

            RecurDateTime start = new RecurDateTime(startDate), end = new RecurDateTime(untilDate),
                from = new RecurDateTime(fromDate), to = new RecurDateTime(toDate);

            RecurDateTime current = freqRules.FindStart(this, start, end, from, to);

            // If there's nothing to generate, stop now
            if(current == null)
                return dcDates;

            rdtc = new RecurDateTimeCollection();

            // Initialize the filtering arrays.  These help speed up the filtering process by letting us do one
            // look up as opposed to comparing all elements in the collection.
            Array.Clear(isSecondUsed, 0, isSecondUsed.Length);
            Array.Clear(isMinuteUsed, 0, isMinuteUsed.Length);
            Array.Clear(isHourUsed, 0, isHourUsed.Length);
            Array.Clear(isDayUsed, 0, isDayUsed.Length);
            Array.Clear(isMonthDayUsed, 0, isMonthDayUsed.Length);
            Array.Clear(isNegMonthDayUsed, 0, isNegMonthDayUsed.Length);
            Array.Clear(isYearDayUsed, 0, isYearDayUsed.Length);
            Array.Clear(isNegYearDayUsed, 0, isNegYearDayUsed.Length);
            Array.Clear(isMonthUsed, 0, isMonthUsed.Length);

            if(bySecond.Count != 0)
                foreach(int second in bySecond)
                    isSecondUsed[second] = true;

            if(byMinute.Count != 0)
                foreach(int minute in byMinute)
                    isMinuteUsed[minute] = true;

            if(byHour.Count != 0)
                foreach(int hour in byHour)
                    isHourUsed[hour] = true;

            if(byMonth.Count != 0)
                foreach(int month in byMonth)
                    isMonthUsed[month - 1] = true;

            // When filtering, the instance is ignored
            if(byDay.Count != 0)
                foreach(DayInstance di in byDay)
                    isDayUsed[(int)di.DayOfWeek] = true;

            // Negative days are from the end of the month
            if(byMonthDay.Count != 0)
                foreach(int monthDay in byMonthDay)
                    if(monthDay > 0)
                        isMonthDayUsed[monthDay] = true;
                    else
                        isNegMonthDayUsed[0 - monthDay] = true;

            // Negative days are from the end of the year
            if(byYearDay.Count != 0)
                foreach(int yearDay in byYearDay)
                    if(yearDay > 0)
                        isYearDayUsed[yearDay] = true;
                    else
                        isNegYearDayUsed[0 - yearDay] = true;

            do
            {
                rdtc.Clear();
                rdtc.Add(current);

                // The spec is rather vague about how some of the rules are used together.  For example, it says
                // that rule parts for a period of time less than the frequency generally expand it.  However,
                // an example for the MONTHLY frequency shows that when BYMONTHDAY and BYDAY are used together,
                // BYDAY acts as a filter for BYMONTHDAY not an expansion of the frequency.  When used by
                // themselves, the rules in question do act as expansions.  There are no examples for the yearly
                // frequency that show how all of the various combinations interact so I'm making some
                // assumptions based on an evaluation of what makes the most sense.
                switch(frequency)
                {
                    case RecurFrequency.Yearly:
                        // This one gets rather messy so it's separate
                        ExpandYearly(rdtc);
                        break;

                    case RecurFrequency.Monthly:
                        if(freqRules.ByMonth(this, rdtc) != 0)
                            if(freqRules.ByYearDay(this, rdtc) != 0)
                            {
                                // If BYMONTHDAY and BYDAY are specified, expand by month day and filter by day.
                                // If one but not the other or neither is specified, handle them in order as
                                // usual.
                                if(byMonthDay.Count != 0 && byDay.Count != 0)
                                {
                                    if(Expand.ByMonthDay(this, rdtc) != 0)
                                        if(Filter.ByDay(this, rdtc) != 0)
                                        {
                                            // These always expand if used
                                            Expand.ByHour(this, rdtc);
                                            Expand.ByMinute(this, rdtc);
                                            Expand.BySecond(this, rdtc);
                                        }
                                }
                                else
                                    if(Expand.ByMonthDay(this, rdtc) != 0)
                                        if(freqRules.ByDay(this, rdtc) != 0)
                                        {
                                            // These always expand if used
                                            Expand.ByHour(this, rdtc);
                                            Expand.ByMinute(this, rdtc);
                                            Expand.BySecond(this, rdtc);
                                        }
                            }
                        break;

                    default:
                        // Everything else is fairly straightforward.  We just expand or filter based on the
                        // frequency type and what rules are specified.
                        if(freqRules.ByMonth(this, rdtc) != 0)
                            if(freqRules.ByYearDay(this, rdtc) != 0)
                                if(freqRules.ByMonthDay(this, rdtc) != 0)
                                    if(freqRules.ByDay(this, rdtc) != 0)
                                        if(freqRules.ByHour(this, rdtc) != 0)
                                            if(freqRules.ByMinute(this, rdtc) != 0)
                                                freqRules.BySecond(this, rdtc);
                        break;
                }

                // Sort the dates and remove invalid and duplicate dates
                rdtc.Sort();

                for(idx = 0, count = rdtc.Count; idx < count; idx++)
                {
                    rdt = rdtc[idx];

                    // If not valid, discard it.
                    if(!rdt.IsValidDate())
                    {
                        rdtc.RemoveAt(idx);
                        idx--;
                        count--;
                        continue;
                    }

                    // Discard it if it falls on a holiday
                    if(!canOccurOnHoliday)
                    {
                        // If this is the first call or the year changes, get the holidays in the date's year
                        // and the next year.
                        if(holDates == null || lastYear != rdt.Year)
                        {
                            holDates = new HashSet<DateTime>(holidays.HolidaysBetween(rdt.Year, rdt.Year + 1));
                            lastYear = rdt.Year;
                        }

                        // Note that we only compare the date part as the holiday's time probably will not match
                        // the recurrence's time.
                        if(holDates.Contains(rdt.ToDateTime().Date))
                        {
                            rdtc.RemoveAt(idx);
                            idx--;
                            count--;
                            continue;
                        }
                    }

                    // Discard it if it's a duplicate
                    if(idx != 0 && rdt == rdtc[idx - 1])
                    {
                        rdtc.RemoveAt(idx);
                        idx--;
                        count--;
                        continue;
                    }
                }

                if(rdtc.Count != 0)
                {
                    // Apply the BYSETPOS rule and remove entries prior to the start or past the end of the
                    // ranges.
                    if(bySetPos.Count != 0)
                    {
                        foreach(int nPos in bySetPos)
                        {
                            // Invert negative values.  They'll select elements indexed from the end of the
                            // array.
                            if(nPos < 0)
                                idx = nPos + rdtc.Count;
                            else
                                idx = nPos - 1;

                            if(idx >= 0 && idx < rdtc.Count)
                                if(rdtc[idx] >= start && rdtc[idx] <= end && rdtc[idx] >= from && rdtc[idx] <= to)
                                    dcDates.Add(rdtc[idx].ToDateTime());
                        }
                    }
                    else
                        for(idx = 0; idx < rdtc.Count; idx++)
                            if(rdtc[idx] >= start && rdtc[idx] <= end && rdtc[idx] >= from && rdtc[idx] <= to)
                                dcDates.Add(rdtc[idx].ToDateTime());

                    // Handle MaxOccurrences property.  Note that if it's used, it is assumed that the limiting
                    // range starts at the recurrence start.  Otherwise, we have no way of knowing how many
                    // occurred between the recurrence start and the limiting range's start date.
                    if(maxOccur != 0 && dcDates.Count > maxOccur)
                        dcDates.RemoveRange(maxOccur, dcDates.Count - maxOccur);
                }

                // Loop until the end of the recurrence or the range
            } while(freqRules.FindNext(this, end, to, current) && (maxOccur == 0 || dcDates.Count < maxOccur));

            // Sort the collection one last time.  There's no guaranteed order of selection if BYSETPOS was used.
            dcDates.Sort(true);

            return dcDates;
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            dateComboBox.Items.Clear();
            dateComboBox.ResetText();
            timeComboBox.Items.Clear();
            timeComboBox.ResetText();
            timeComboBox.SelectedIndex = -1;
            dateComboBox.Enabled       = false;
            timeComboBox.Enabled       = false;

            var tutorComboboxItem = tutorComboBox.SelectedItem as ComboBoxHandler.ComboboxItem;

            if (tutorComboboxItem != null)
            {
                var dateDataTable = tutoR_AVAILABLE_TIMES_SEARCH_BY_TUTORTableAdapter1.GetData(Convert.ToInt32(tutorComboboxItem.Value));

                DateTimeCollection datesAndTimes = new DateTimeCollection();
                //add all unique dates
                foreach (var item in dateDataTable.OrderBy(i => i.date_free))
                {
                    var oneDate = new DateTimes {
                        Date = item.date_free
                    };
                    if (datesAndTimes.FindDateCollection(oneDate) != null)
                    {
                        var foundItem = datesAndTimes.FindDateCollection(oneDate);
                        var times     = new Times
                        {
                            Time         = item.date_free.TimeOfDay,
                            TutorTimesId = item.tutor_time_id
                        };
                        foundItem.Times.Add(times);
                    }
                    else
                    {
                        var times = new Times
                        {
                            Time         = item.date_free.TimeOfDay,
                            TutorTimesId = item.tutor_time_id
                        };
                        oneDate.Times.Add(times);
                        datesAndTimes.CollectionOfDateTimes.Add(oneDate);
                    }
                }

                foreach (var date in datesAndTimes.CollectionOfDateTimes)
                {
                    var cmbItem = new ComboBoxHandler.ComboboxItem
                    {
                        Text  = date.Date.ToLongDateString(),
                        Value = date
                    };
                    dateComboBox.Items.Add(cmbItem);
                }

                dateComboBox.Enabled = true;
            }
            else
            {
                ClearForm();
            }
        }
Example #10
0
        /// <summary>
        /// Creates a new instance of FAMonthView class. Initiated control could be uses in PopupMode or Normal mode, depending on the use.
        /// </summary>
        /// <param name="popupMode"></param>
        public FAMonthView(bool popupMode)
        {
            IsPopupMode = popupMode;
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);

            selectedDateRange = new DateTimeCollection();
            selectedDateRange.CollectionChanged += OnSelectionCollectionChanged;

            base.Size = new Size(166, 166);
            base.Font = new Font("Tahoma", 8.25F);
            base.Enabled = true;

            scrollOption = ScrollOptionTypes.Month;
            showEmptyButton = true;
            showTodayButton = true;

            FALocalizeManager.Instance.LocalizerChanged += OnLocalizerChanged;
        }
        /// <summary>
        /// Reads a UTC date/time array from the stream.
        /// </summary>
        public DateTimeCollection ReadDateTimeArray(string fieldName)
        {
            var values = new DateTimeCollection();

            List<object> token = null;

            if (!ReadArrayField(fieldName, out token))
            {
                return values;
            }

            for (int ii = 0; ii < token.Count; ii++)
            {
                try
                {
                    m_stack.Push(token[ii]);
                    values.Add(ReadDateTime(null));
                }
                finally
                {
                    m_stack.Pop();
                }
            }

            return values;
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            dateComboBox.Items.Clear();
            dateComboBox.ResetText();
            timeComboBox.Items.Clear();
            timeComboBox.ResetText();
            timeComboBox.SelectedIndex = -1;
            dateComboBox.Enabled = false;
            timeComboBox.Enabled = false;

            var tutorComboboxItem = tutorComboBox.SelectedItem as ComboBoxHandler.ComboboxItem;

            if (tutorComboboxItem != null)
            {
                var dateDataTable = tutoR_AVAILABLE_TIMES_SEARCH_BY_TUTORTableAdapter1.GetData(Convert.ToInt32(tutorComboboxItem.Value));

                DateTimeCollection datesAndTimes = new DateTimeCollection();
                //add all unique dates
                foreach (var item in dateDataTable.OrderBy(i => i.date_free))
                {
                    var oneDate = new DateTimes { Date = item.date_free };
                    if (datesAndTimes.FindDateCollection(oneDate) != null)
                    {
                        var foundItem = datesAndTimes.FindDateCollection(oneDate);
                        var times = new Times
                        {
                            Time = item.date_free.TimeOfDay,
                            TutorTimesId = item.tutor_time_id
                        };
                        foundItem.Times.Add(times);
                    }
                    else
                    {
                        var times = new Times
                        {
                            Time = item.date_free.TimeOfDay,
                            TutorTimesId = item.tutor_time_id
                        };
                        oneDate.Times.Add(times);
                        datesAndTimes.CollectionOfDateTimes.Add(oneDate);
                    }
                }

                foreach (var date in datesAndTimes.CollectionOfDateTimes)
                {
                    var cmbItem = new ComboBoxHandler.ComboboxItem
                    {
                        Text = date.Date.ToLongDateString(),
                        Value = date
                    };
                    dateComboBox.Items.Add(cmbItem);
                }

                dateComboBox.Enabled = true;
            }
            else
            {
                ClearForm();
            }
        }
Example #13
0
        /// <summary>
        /// Move to the next element
        /// </summary>
        /// <returns>Returns true if not at the end, false if it is</returns>
        public bool MoveNext()
        {
            bool hasMore = true;

            // First time through?
            if(dates == null)
            {
                // If it's got a count, generate them all as we can't do it by yearly ranges.  There shouldn't be
                // too many although it's possible.
                if(recurrence.MaximumOccurrences != 0)
                    dates = recurrence.InstancesBetween(start, DateTime.MaxValue);
                else
                {
                    // If it's got an end date, we'll generate instances in one year increments.  This should be
                    // more efficient for long running or never ending sequences.
                    end = start.AddYears(1).AddSeconds(-1);
                    dates = recurrence.InstancesBetween(start, end);
                }
            }
            else
                idx++;

            if(idx >= dates.Count)
            {
                // If it uses a count, we got them all on the first call so stop now
                if(recurrence.MaximumOccurrences != 0)
                    hasMore = false;
                else
                {
                    idx = 0;

                    // Advance one year at a time until we get something or the end date is reached
                    do
                    {
                        if(start.Year < DateTime.MaxValue.Year)
                        {
                            start = end.AddSeconds(1);

                            if(start > recurrence.RecurUntil)
                            {
                                hasMore = false;
                                break;
                            }
                        }
                        else
                        {
                            hasMore = false;
                            break;
                        }

                        if(start.Year < DateTime.MaxValue.Year)
                            end = start.AddYears(1).AddSeconds(-1);
                        else
                            end = new DateTime(DateTime.MaxValue.Year, 12, 31, 23, 59, 59);

                        dates = recurrence.InstancesBetween(start, end);

                    } while(dates.Count == 0);
                }
            }

            return hasMore;
        }
Example #14
0
 /// <summary>
 /// Reset the enumerator to the start
 /// </summary>
 public void Reset()
 {
     idx = 0;
     start = recurrence.StartDateTime;
     dates = null;
 }
Example #15
0
 void radCalendar1_SelectionChanging(object sender, SelectionEventArgs e)
 {
     AddEventRoot("SelectionChanging");
     AddTextToListBox("     new dates are added to SelectedDates\n     collection in RadCalendar.");
     oldSelections = this.radCalendar1.SelectedDates.Clone();
 }