Create Appointment - Frequency Weekly by Code?

1 posts, 0 answers
  1. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 24 Apr 2012 Link to this post

    Hi,

    I'm not able to create an appointment with a frequency like weekly by c# Code! No error but the appointment is not shown in
    the scheduleview! Why?

    I'm using WPF RadControls 2012 Q1 SP1 and c# .Net 4.0

    foreach (DataRow tasks_dr in passw_dt.Rows)
        {
            DateTime start = Convert.ToDateTime(tasks_dr.Field<String>("StartDatum"));
         
             switch (start.DayOfWeek)
              {
                  case DayOfWeek.Saturday:
                         start = start.AddDays(2);
                         break;
                   case DayOfWeek.Sunday:
                          start = start.AddDays(1);
                           break;
               }
     
               TimeSpan duration = TimeSpan.FromDays(5);
                DateTime end = Convert.ToDateTime(tasks_dr.Field<String>("Enddatum"));
                switch (end.DayOfWeek)
                {
                    case DayOfWeek.Sunday:
                         end = end.AddDays(-1);
                          break;
                     case DayOfWeek.Monday:
                          end = end.AddDays(-2);
                          break;
                  }
               
                  Appointment appointment = new Appointment
                   {
                       Start = start,
                       Url = Convert.ToString(tasks_dr.Field<Int64>("id") + "#" + tasks_dr.Field<String>("Betreuer")),
                       End = end,
                       Subject = tasks_dr.Field<String>("Subject"),
                       Body = tasks_dr.Field<String>("Body"),
                       Importance = GetImportance(tasks_dr.Field<String>("Importance"))
                    };
     
                    if (tasks_dr.Field<String>("Kategorie") == "Fertig")
                    {
                        appointment.Category = this.Categories[0];
                    }
                    else if (tasks_dr.Field<String>("Kategorie") == "in Arbeit")
                    {
                        appointment.Category = this.Categories[1];
                    }
                    else
                    {
                        appointment.Category = this.Categories[2];
                    }
     
                    if (tasks_dr.Field<Int64>("Ganztag") == 0)
                    {
                        appointment.IsAllDayEvent = false;
                    }
                    else
                    {
                        appointment.IsAllDayEvent = true;
                    }
     
                    var Pattern = new RecurrencePattern();
                    Pattern.Frequency = GetFreuqency(tasks_dr.Field<String>("Frequency"));
     
                    if (Pattern.Frequency != RecurrenceFrequency.None)
                    {
                        Pattern.DayOrdinal = Convert.ToInt32(tasks_dr.Field<Int64>("DayOridnal"));
                        Pattern.DaysOfWeekMask = GetDay(tasks_dr.Field<String>("DaysofWeekMask"));
                        Pattern.FirstDayOfWeek = GetFirstday(tasks_dr.Field<Int64>("FirstDayOfWeek"));                   
                        Pattern.Interval = Convert.ToInt32(tasks_dr.Field<Int64>("Interval"));
                        Pattern.MaxOccurrences = Convert.ToInt32(tasks_dr.Field<Int64>("MaxOccurrences"));
                        Pattern.MonthOfYear = Convert.ToInt32(tasks_dr.Field<Int64>("MonthofYear"));
                        Pattern.DayOfMonth = Convert.ToInt32(tasks_dr.Field<Int64>("DayofMonth"));
     
                        System.DateTime? RecursUntil_d;
                        if (tasks_dr.Field<String>("RecursUntil") != "")
                        {
                            RecursUntil_d = Convert.ToDateTime(tasks_dr.Field<String>("RecursUntil"));                       
                        }                   
                        Pattern.RecursUntil = RecursUntil_d;
     
                        appointment.RecurrenceRule = new RecurrenceRule(Pattern);
                    }
                    this.appointments.Add(appointment);

    Every appointment withput a freqeuncy is shown fine. Thanks
    Rgards
    Rene
Back to Top