2012-12-10 10 views
0

我想从telerik radschedular的代码创建定期约会。从RadSchedular中的c#创建定期约会

Appointment recurringAppointment = new Appointment("1", 
      Convert.ToDateTime("12/12/2012 3:30 PM").ToUniversalTime(), 
      Convert.ToDateTime("12/12/2012 4:00 PM").ToUniversalTime(), 
      "Sample appointment"); 

RecurrenceRange range = new RecurrenceRange(); 
range.Start = recurringAppointment.Start; 
range.EventDuration = recurringAppointment.End - recurringAppointment.Start; 
range.MaxOccurrences = 10; 
HourlyRecurrenceRule rrule = new HourlyRecurrenceRule(2, range); 

创建约会和重复规则后,我无法合并它们。 telerik Appointment的'RecurrenceRule'属性接受一个字符串。所以我无法将我的HourlyRecurrenceRule添加到我创建的约会中。

任何类型的C#代码的帮助将不胜感激。

回答

1

布赖恩电源指出了this article

重复可为指定每小时,每天,每周,每月或每年 ,并能在一定的结束日期或间隔。你会发现这个 规则作为一个字符串传递给Appointment;最终结果 类似于以下内容:

DTSTART:20081122T143000Z \ r \ nDTEND:20081122T170000Z \ r \ nRRULE:FREQ = WEEKLY;

UNTIL = 20091021T040000Z; INTERVAL = 1个\ r \ n

Telerik's examples你可以看到,RecurrenceEditor接受RecurrenceRule对象,但约会的RecurrenceRule属性仅接受RecurrenceRule对象的字符串表示。

权代码的最后一行后,只需添加这一点,它应该做的伎俩:

recurringAppointment.RecurrenceRule = rrule.ToString() 
0

看起来,你从他们的文档代码:

http://www.telerik.com/help/aspnet-ajax/scheduler-working-with-recurring-appointments.html

继承人的代码的其余部分(从上面的网址)

// Prints the string representation of the recurrence rule: 
string rruleAsString = rrule.ToString(); 
Console.WriteLine("Recurrence rule:\n\n{0}\n", rruleAsString); 
// The string representation can be stored in a database, etc. 
// ... 
// Then it can be reconstructed using TryParse method: 
RecurrenceRule parsedRule; 
RecurrenceRule.TryParse(rruleAsString, out parsedRule); 
Console.WriteLine("After parsing (should be the same):\n\n{0}", parsedRule); 

的2种类型不能“相结合“,您可以使用重复规则字符串将约会保存到数据库中,并且在加载时使用TryParse方法重新创建具有相同属性的新重复规则。

希望它能帮助:)