コード例 #1
0
        public static void KiemTraDinhKy(DateTime dtStart, DateTime dtEnd, string rRule, List <DuyetLichHop> lstDuyetLich, LichHop item)
        {
            string parsed  = string.Empty; //set up the return string
            string calType = string.Empty; //need a scratchpad
            Dictionary <string, string> rruleElems = new Dictionary <string, string>();

            parsed = getElemValue(rRule);
            string[] elements = parsed.Split(';');

            for (int i = 0; i < elements.Length; i++)
            {
                string[] tmp = elements[i].Split('=');
                rruleElems.Add(tmp[0], tmp[1]);
            }

            string abc       = rruleElems["FREQ"];
            int    timeToAdd = 0;

            try
            {
                //timeToAdd = Convert.ToInt32(rruleElems["COUNT"]);
            }
            catch
            {
                timeToAdd = 0;
            }
            switch (rruleElems["FREQ"].ToLower())
            {
            case "daily":
                string[] days = rruleElems["BYDAY"].Split(',');
                dtEnd   = dtEnd.AddDays(timeToAdd);
                calType = "days";
                break;

            case "weekly":
                dtEnd = dtEnd.AddDays(timeToAdd * 7);
                try
                {
                    days = rruleElems["BYDAY"].Split(',');
                    parseDayNames(days, dtStart, dtEnd, lstDuyetLich, item);
                }
                catch
                {
                    //just in case we missed something on this one
                    throw new Exception("Error while processing Recurrence Rule");
                }
                break;

            case "monthly":
                calType = "months";
                dtEnd   = dtEnd.AddMonths(timeToAdd);
                //see if it's positional
                try
                {
                    string bsp = getDayEnding(rruleElems["BYSETPOS"]);
                }
                catch
                {
                    //Ok, no BYSETPOS, let's go for BYMONTHDAY
                    //  string bsp = getDayEnding(rruleElems["BYMONTHDAY"]);
                }
                break;

            case "yearly":
                calType = "years";
                dtEnd   = dtEnd.AddYears(timeToAdd);
                //looks a lot like monthly....
                string mName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt32(rruleElems["BYMONTH"]));
                //see if it's positional
                try
                {
                    string bsp = getDayEnding(rruleElems["BYSETPOS"]);
                }
                catch
                {
                    //Ok, no BYSETPOS, let's go for BYMONTHDAY
                    //string bsp = getDayEnding(rruleElems["BYMONTHDAY"]);
                }
                break;

            default:
                break;
            }
        }
コード例 #2
0
        private static void parseDayNames(string[] days, DateTime dtStart, DateTime dtEnd, List <DuyetLichHop> lstDuyetLich, LichHop item)
        {
            if (days.Length < 7)
            {
                for (int d = 0; d < days.Length; d++)
                {
                    switch (getDayName(days[d]))
                    {
                    case "Monday":
                    {
                        for (DateTime i = dtStart; i.Date <= dtEnd.Date; i = i.AddDays(1))
                        {
                            if (i.DayOfWeek.ToString() == "Monday")
                            {
                                DuyetLichHop lich = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, i, true);
                                lstDuyetLich.Add(lich);
                            }
                        }
                        break;
                    }

                    case "Tuesday":
                    {
                        for (DateTime i = dtStart; i.Date <= dtEnd.Date; i = i.AddDays(1))
                        {
                            if (i.DayOfWeek.ToString() == "Tuesday")
                            {
                                DuyetLichHop lich = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, i, true);
                                lstDuyetLich.Add(lich);
                            }
                        }
                        break;
                    }

                    case "Wednesday":
                    {
                        for (DateTime i = dtStart; i.Date <= dtEnd.Date; i = i.AddDays(1))
                        {
                            if (i.DayOfWeek.ToString() == "Wednesday")
                            {
                                DuyetLichHop lich = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, i, true);
                                lstDuyetLich.Add(lich);
                            }
                        }
                        break;
                    }

                    case "Thursday":
                    {
                        for (DateTime i = dtStart; i.Date <= dtEnd.Date; i = i.AddDays(1))
                        {
                            if (i.DayOfWeek.ToString() == "Thursday")
                            {
                                DuyetLichHop lich = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, i, true);
                                lstDuyetLich.Add(lich);
                            }
                        }
                        break;
                    }

                    case "Friday":
                    {
                        for (DateTime i = dtStart; i.Date <= dtEnd.Date; i = i.AddDays(1))
                        {
                            if (i.DayOfWeek.ToString() == "Friday")
                            {
                                DuyetLichHop lich = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, i, true);
                                lstDuyetLich.Add(lich);
                            }
                        }
                        break;
                    }

                    case "Saturday":
                    {
                        for (DateTime i = dtStart; i.Date <= dtEnd.Date; i = i.AddDays(1))
                        {
                            if (i.DayOfWeek.ToString() == "Saturday")
                            {
                                DuyetLichHop lich = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, i, true);
                                lstDuyetLich.Add(lich);
                            }
                        }
                        break;
                    }

                    case "Sunday":
                    {
                        for (DateTime i = dtStart; i.Date <= dtEnd.Date; i = i.AddDays(1))
                        {
                            if (i.DayOfWeek.ToString() == "Sunday")
                            {
                                DuyetLichHop lich = new DuyetLichHop(item.Subject, item.RoomId.Value, item.Start.Value, item.End.Value, i, true);
                                lstDuyetLich.Add(lich);
                            }
                        }
                        break;
                    }

                    default:
                        break;
                    }
                }
            }
        }