示例#1
0
        public bool AddAppointment(string subject, string startStr, string endStr, string colorStr,
                                   string dateFormat)
        {
            if (m_calendar == null)
            {
                return(false);
            }
            SFAppointment appointment = new SFAppointment();

            appointment.Subject = (NSString)subject;
            DateTime dt = DateTime.ParseExact(startStr, dateFormat, null);

            appointment.StartTime = (NSDate)DateTime.SpecifyKind(dt, DateTimeKind.Local);
            dt = DateTime.ParseExact(endStr, dateFormat, null);
            appointment.EndTime = (NSDate)DateTime.SpecifyKind(dt, DateTimeKind.Local);
            appointment.AppointmentBackground = UtilsiOS.String2Color(colorStr);

            var appointments = m_calendar.Appointments;

            if (appointments == null)
            {
                appointments = new NSMutableArray();
            }
            appointments.Add(appointment);
            m_calendar.Appointments = appointments;

            return(true);
        }
示例#2
0
        private NSMutableArray GetEnglishAppointments()
        {
            NSDate today = new NSDate();

            SetColors();
            SetEnglishCollectionSubjects();
            NSMutableArray appCollection = new NSMutableArray();
            NSCalendar     calendar      = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components.Hour   = 10;
            components.Minute = 0;
            components.Second = 0;

            // Get the year, month, day from the date
            NSDateComponents endDateComponents = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents.Hour   = 12;
            endDateComponents.Minute = 0;
            endDateComponents.Second = 0;
            Random randomNumber = new Random();

            for (int i = 0; i < 10; i++)
            {
                components.Hour        = randomNumber.Next(10, 16);
                endDateComponents.Hour = components.Hour + randomNumber.Next(1, 3);
                NSDate        startDate   = calendar.DateFromComponents(components);
                NSDate        endDate     = calendar.DateFromComponents(endDateComponents);
                SFAppointment appointment = new SFAppointment();
                appointment.StartTime             = startDate;
                appointment.EndTime               = endDate;
                components.Day                    = components.Day + 1;
                endDateComponents.Day             = endDateComponents.Day + 1;
                appointment.Subject               = (NSString)englishCollection[i];
                appointment.AppointmentBackground = colorCollection[i];
                appCollection.Add(appointment);
            }

            return(appCollection);
        }