Ejemplo n.º 1
0
        /// <summary>
        /// Launchs the create new event controller.
        /// </summary>
        protected void LaunchModifyEvent()
        {
            // first we need to create an event it so we have one that we know exists
            // in a real world scenario, we'd likely either a) be modifying an event that
            // we found via a query, or 2) we'd do like this, in which we'd automatically
            // populate the event data, like for say a dr. appt. reminder, or something
            EKEvent newEvent = EKEvent.FromStore(App.Current.EventStore);

            // set the alarm for 10 minutes from now
            newEvent.AddAlarm(EKAlarm.FromDate(DateTime.Now.AddMinutes(10)));
            // make the event start 20 minutes from now and last 30 minutes
            newEvent.StartDate = DateTime.Now.AddMinutes(20);
            newEvent.EndDate   = DateTime.Now.AddMinutes(50);
            newEvent.Title     = "Get outside and do some exercise!";
            newEvent.Notes     = "This is your motivational event to go and do 30 minutes of exercise. Super important. Do this.";

            // create a new EKEventEditViewController. This controller is built in an allows
            // the user to create a new, or edit an existing event.
            MonoTouch.EventKitUI.EKEventEditViewController eventController =
                new MonoTouch.EventKitUI.EKEventEditViewController();

            // set the controller's event store - it needs to know where/how to save the event
            eventController.EventStore = App.Current.EventStore;
            eventController.Event      = newEvent;

            // wire up a delegate to handle events from the controller
            eventControllerDelegate          = new CreateEventEditViewDelegate(eventController);
            eventController.EditViewDelegate = eventControllerDelegate;

            // show the event controller
            PresentViewController(eventController, true, null);
        }
Ejemplo n.º 2
0
        public void SetEvent(DateTime date, string title, string note)
        {
            if (eventStore == null)
            {
                requestAccess();
            }

            // set the controller's event store - it needs to know where/how to save the event
            eventController.EventStore = eventStore;


            NSDate date2 = DateTimeToNSDate2(date);

            EKEvent newEvent = EKEvent.FromStore(eventController.EventStore);

            // set the alarm for 10 minutes from now

            newEvent.AddAlarm(EKAlarm.FromDate(date2));
            // make the event start 20 minutes from now and last 30 minutes
            newEvent.StartDate = date2;
            newEvent.EndDate   = date2.AddSeconds(1800);
            newEvent.Title     = title;
            newEvent.Notes     = note;
            newEvent.Calendar  = eventController.EventStore.DefaultCalendarForNewEvents;
            NSError a;

            eventController.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out a);
            Console.WriteLine("Event Saved, ID: " + newEvent.CalendarItemIdentifier);
        }
Ejemplo n.º 3
0
        public async Task <string> CreateAlarmAsync(string title, string description, DateTime timeInit, DateTime timeEnd, int alarmMinutes)
        {
            bool hasPermission = await ASkForPermissionsAsync();

            if (!hasPermission)
            {
                return(string.Empty);
            }
            if (appCalendar == null)
            {
                await CreateCalendarForAppAlarmsAsync();
            }

            if (appCalendar != null)
            {
                EKEvent reminder = EKEvent.FromStore(eventsStore);
                reminder.AddAlarm(EKAlarm.FromTimeInterval(-(alarmMinutes * 60)));
                reminder.StartDate = timeInit.ToNSDate();
                reminder.EndDate   = timeEnd.ToNSDate();
                reminder.Title     = title;
                reminder.Notes     = description;
                reminder.Calendar  = appCalendar;
                bool saved = eventsStore.SaveEvent(reminder, EKSpan.ThisEvent, out NSError e);
                if (e == null)
                {
                    return(reminder.CalendarItemIdentifier);
                }
            }

            return(string.Empty);
        }
Ejemplo n.º 4
0
        public Task <bool> AddReminderAsync(string id, CalendarEvent calEvent)
        {
            bool success = true;

            EventStore.RequestAccess(
                EKEntityType.Event,
                (granted, e) =>
            {
                if (granted)
                {
                    var newEvent = EKEvent.FromStore(EventStore);

                    newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(calEvent.Start.AddMinutes(-15))));
                    newEvent.StartDate = DateTimeToNSDate(calEvent.Start);
                    newEvent.EndDate   = DateTimeToNSDate(calEvent.End);
                    newEvent.Title     = calEvent.Name;
                    newEvent.Notes     = calEvent.Description;
                    newEvent.Location  = calEvent.Location;
                    newEvent.AllDay    = calEvent.AllDay;

                    newEvent.Calendar = EventStore.DefaultCalendarForNewEvents;
                }
                else
                {
                    this.contentDialogService.Alert("Access Denied", "User Denied Access to Calendar Data");
                    success = false;
                }
            });

            return(Task.FromResult(success));
        }
Ejemplo n.º 5
0
        public async Task <CalendarEvent> CreateNewEvent(OrgEvent orgEvent)
        {
            var result = await EventStore.RequestAccessAsync(EKEntityType.Event);

            if (result.Item1 && result.Item2 == null)
            {
                var newEvent = EKEvent.FromStore(EventStore);

                newEvent.AllDay    = true;
                newEvent.StartDate = orgEvent.StartTime.ToNSDate();
                newEvent.EndDate   = (orgEvent.EndTime ?? orgEvent.StartTime).ToNSDate();
                newEvent.Location  = string.Format("{0},{1}", orgEvent.Latitude, orgEvent.Longitude);
                newEvent.Title     = orgEvent.Title;
                newEvent.Notes     = orgEvent.Description;
                newEvent.Url       = _configuration.GetEventUrl(orgEvent.Id).ToNSUrl();

                newEvent.Calendar = EventStore.DefaultCalendarForNewEvents;

                var calendarEvent = new CalendarEvent(EventStore, newEvent);
                return(calendarEvent);
            }

            new UIAlertView(
                Localization.AccessDenied,
                Localization.UserDeniedAccessToCalendars,
                null,
                Localization.OK,
                null).Show();

            return(null);
        }
Ejemplo n.º 6
0
        partial void addTime(UIKit.UIBarButtonItem sender)
        {
            // Show the EKEventEditViewController
            var controller = new EKEventEditViewController();

            controller.EventStore = model.EventStore;
            controller.Completed += (object obj, EKEventEditEventArgs e) =>
            {
                DismissViewController(true, null);

                if (e.Action != EKEventEditViewAction.Canceled)
                {
                    // Update our events, since we added a new event.
                    model.FetchPokerEvents();
                }
            };
            controller.GetDefaultCalendarForNewEvents += delegate(EKEventEditViewController obj)
            {
                return(model.SelectedCalendar);
            };

            var ekevent = EKEvent.FromStore(model.EventStore);

            ekevent.Title     = PNVModel.DefaultEventTitle;
            ekevent.TimeZone  = NSTimeZone.LocalTimeZone;
            ekevent.StartDate = NSDate.Now;
            ekevent.EndDate   = NSDate.Now.AddSeconds(60 * 60);
            controller.Event  = ekevent;

            PresentViewController(controller, true, null);
        }
Ejemplo n.º 7
0
 public static void RegisterEvents(List <Calendar> events)
 {
     foreach (var item in events)
     {
         if (!item.RegisterEventForStoring)
         {
             continue;
         }
         EKEvent newEvent = EKEvent.FromStore(EventStore);
         newEvent.StartDate    = DateTimeToNSDate(item.Start).AddSeconds(-(3600 * 2));
         newEvent.EndDate      = DateTimeToNSDate(item.End).AddSeconds(-(3600 * 2));
         newEvent.Title        = item.ActiTitle;
         newEvent.Availability = EKEventAvailability.Busy;
         newEvent.Location     = item.Room.Code ?? String.Empty;
         newEvent.Notes        = "Type : " + item.TypeTitle + Environment.NewLine + "Module : " + item.Titlemodule;
         newEvent.Calendar     = Calendar;
         NSError e;
         bool    succes = EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
         if (succes)
         {
             item.EventKitID = newEvent.EventIdentifier;
         }
         else
         {
             throw new Exception("RegisterEvent failed");
         }
     }
 }
        /// <summary>
        /// Launchs the create new event controller.
        /// </summary>
        protected void LaunchModifyEvent()
        {
            // first we need to create an event it so we have one that we know exists
            // in a real world scenario, we'd likely either a) be modifying an event that
            // we found via a query, or 2) we'd do like this, in which we'd automatically
            // populate the event data, like for say a dr. appt. reminder, or something
            EKEvent newEvent = EKEvent.FromStore(CalendarParam.Current.EventStore);

            // set the alarm for 10 minutes from now
            newEvent.AddAlarm(EKAlarm.FromDate((NSDate)DateTime.FromFileTime(wkBooking.starting.ToFileTime())));
            // make the event start 20 minutes from now and last 30 minutes
            newEvent.StartDate = (NSDate)DateTime.Now.AddMinutes(20);
            newEvent.EndDate   = (NSDate)DateTime.Now.AddMinutes(50);
            newEvent.Title     = wkBooking.topic;
            newEvent.Location  = AppParam.campusName;
            newEvent.Notes     = wkBooking.description;


            // create a new EKEventEditViewController. This controller is built in an allows
            // the user to create a new, or edit an existing event.
            EventKitUI.EKEventEditViewController eventController =
                new EventKitUI.EKEventEditViewController();

            // set the controller's event store - it needs to know where/how to save the event
            eventController.EventStore = CalendarParam.Current.EventStore;
            eventController.Event      = newEvent;

            // wire up a delegate to handle events from the controller
            eventControllerDelegate          = new CreateEventEditViewDelegate(eventController);
            eventController.EditViewDelegate = eventControllerDelegate;

            // show the event controller
            PresentViewController(eventController, true, null);
        }
        void ICalendar.AddToCalendar(GenEvent genEvent)
        {
            var estZone      = TimeZoneInfo.FindSystemTimeZoneById("America/Indiana/Indianapolis");
            var newStartTime = TimeZoneInfo.ConvertTime(genEvent.StartDateTime, estZone, TimeZoneInfo.Local);
            var newEndTime   = TimeZoneInfo.ConvertTime(genEvent.EndDateTime, estZone, TimeZoneInfo.Local);

            eventStore = eventStore ?? new EKEventStore();

            eventStore.RequestAccess(EKEntityType.Event,
                                     (bool granted, NSError e) => {
                if (granted)
                {
                    EKEventStore eventStore = new EKEventStore();

                    //Insert the data into the agenda.
                    EKEvent newEvent   = EKEvent.FromStore(eventStore);
                    newEvent.StartDate = CalendarHelpers.DateTimeToNSDate(newStartTime);
                    newEvent.EndDate   = CalendarHelpers.DateTimeToNSDate(newEndTime);
                    newEvent.Title     = genEvent.Title;
                    newEvent.Notes     =
                        genEvent.Location + "\r\n\r\n"
                        + genEvent.Description + "\r\n\r\n"
                        + genEvent.LiveURL
                    ;

                    EKAlarm[] alarmsArray = new EKAlarm[1];
                    alarmsArray[0]        = EKAlarm.FromDate(newEvent.StartDate.AddSeconds(-600));
                    newEvent.Alarms       = alarmsArray;

                    newEvent.Calendar = eventStore.DefaultCalendarForNewEvents;
                    eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, true, out e);
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        //bool returned = await GlobalVars.notifier.Notify(ToastNotificationType.Success,
                        //    "Event added!", genEvent.Title + " has been added to your calendar!", TimeSpan.FromSeconds(3));
                        //var returned = await GlobalVars.notifier.Notify(new NotificationOptions()
                        //{
                        //    Title = "Event added!",
                        //    Description = genEvent.Title + " has been added to your calendar!",
                        //});
                        GlobalVars.DoToast(genEvent.Title + " has been added to your calendar!", GlobalVars.ToastType.Green);
                    });
                }
                //do something here
                else
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        //bool returned = await GlobalVars.notifier.Notify(ToastNotificationType.Error,
                        //    "Don't have permission!", "You need to allow this app to access the calendar first. Please change the setting in Settings -> Privacy -> Calendars.", TimeSpan.FromSeconds(4));
                        //var returned = await GlobalVars.notifier.Notify(new NotificationOptions()
                        //{
                        //    Title = "Don't have permission!",
                        //    Description = "You need to allow this app to access the calendar first. Please change the setting in Settings -> Privacy -> Calendars.",
                        //});
                        GlobalVars.DoToast("Need permission - you need to allow this app to access the calendar first. Please change the setting in Settings -> Privacy -> Calendars.", GlobalVars.ToastType.Red, 5000);
                    });
                }
            });
        }
Ejemplo n.º 10
0
        public async Task AddToCalendar(DateTime startTime, DateTime endTime, String subject, String details, Boolean isAllDay, UIViewController viewController)
        {
            var granted = await RequestAccessToCalendarAsync();

            if (granted)
            {
                EKEventEditViewController eventController = new EKEventEditViewController();

                // set the controller's event store - it needs to know where/how to save the event
                eventController.EventStore = AppCalendarSingleton.Current.EventStore;

                // wire up a delegate to handle events from the controller
                eventControllerDelegate          = new CreateEventEditViewDelegate(eventController);
                eventController.EditViewDelegate = eventControllerDelegate;

                EKEvent newEvent = EKEvent.FromStore(AppCalendarSingleton.Current.EventStore);
                newEvent.StartDate = (NSDate)DateTime.SpecifyKind(startTime, DateTimeKind.Utc);
                newEvent.EndDate   = (NSDate)DateTime.SpecifyKind(endTime, DateTimeKind.Utc);
                newEvent.Title     = subject;
                newEvent.Notes     = details;
                newEvent.AllDay    = isAllDay;
                //newEvent.AddAlarm(ConvertReminder(reminder, startTime));
                //newEvent.Availability = ConvertAppointmentStatus(status);

                eventController.Event = newEvent;

                // show the event controller
                viewController.PresentViewController(eventController, true, null);

                CLLocationManager locationManager = new CLLocationManager();

                // if (CLLocationManager.Status == CLAuthorizationStatus.NotDetermined)
                locationManager.RequestWhenInUseAuthorization();
            }
        }
Ejemplo n.º 11
0
        private void GenerarEvento(SalaJuntasReservacionModel Reservaciones)
        {
            RequestAccess(EKEntityType.Event, () =>
            {
                CLLocation location = new CLLocation();
                if (Reservaciones.Sucursal_Id == "1")
                {
                    location = new CLLocation(20.6766, -103.3812);
                }
                else
                {
                    location = new CLLocation(20.6766, -103.3812);
                }
                var structuredLocation         = new EKStructuredLocation();
                structuredLocation.Title       = Reservaciones.Sucursal_Domicilio;
                structuredLocation.GeoLocation = location;

                NSDateFormatter dateFormat = new NSDateFormatter();
                dateFormat.DateFormat      = "dd/MM/yyyy";
                NSDate newFormatDate       = dateFormat.Parse(Reservaciones.Sala_Fecha);

                EKEvent newEvent = EKEvent.FromStore(AppHelper.Current.EventStore);

                DateTime myDate = DateTime.ParseExact(Reservaciones.Sala_Fecha, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);

                var arrTime          = Reservaciones.Sala_Hora_Inicio.Split(':');
                var hora             = (double.Parse(arrTime[0]) - 1);
                var minutos          = double.Parse(arrTime[1]);
                var newDate          = myDate.AddHours(hora);
                var newDate2         = newDate.AddMinutes(minutos);
                var HoraAntesReunion = newDate2;
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(HoraAntesReunion.AddMinutes(30))));
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(HoraAntesReunion.AddMinutes(45))));
                if (newDate2 != null)
                {
                    hora         = hora + 1;
                    var newDate3 = myDate.AddHours(hora);
                    var newDate4 = newDate3.AddMinutes(minutos);

                    var HoraInicio     = this.DateTimeToNSDate(newDate4);
                    newEvent.StartDate = HoraInicio;
                    arrTime            = Reservaciones.Sala_Hora_Fin.Split(':');
                    hora             = double.Parse(arrTime[0]);
                    minutos          = double.Parse(arrTime[1]);
                    var newDate5     = myDate.AddHours(hora);
                    var newDate6     = newDate5.AddMinutes(minutos);
                    newEvent.EndDate = this.DateTimeToNSDate(newDate6);
                }
                newEvent.Title              = "Reservación de sala de juntas en " + Reservaciones.Sucursal_Descripcion + ", en el piso " + Reservaciones.Sala_Nivel + ", en la sala " + Reservaciones.Sala_Descripcion;
                newEvent.Notes              = "Se recomienda presentarse 5 minutos antes de su hora de reservación";
                newEvent.Calendar           = AppHelper.Current.EventStore.DefaultCalendarForNewEvents;
                newEvent.Location           = Reservaciones.Sucursal_Domicilio;
                newEvent.StructuredLocation = structuredLocation;
                NSError e;
                AppHelper.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
            });
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds an event for specified date.
        /// </summary>
        /// <returns>The event for date.</returns>
        /// <param name="Date">Date.</param>
        /// <param name="CalendarView">Calendar view.</param>
        /// <param name="sender">Sender.</param>
        public void AddEventForDate(DateTime Date, object CalendarView, object sender)
        {
            //create a new event
            var anNewEvent = EKEvent.FromStore(EventStore);

            anNewEvent.TimeZone  = NSTimeZone.LocalTimeZone;
            anNewEvent.StartDate = Date;
            anNewEvent.EndDate   = Date.AddDays(1).AddMinutes(-1);
            anNewEvent.AllDay    = true;
            anNewEvent.Calendar  = EventStore.DefaultCalendarForNewEvents;

            ShowEventEditor(anNewEvent, CalendarView as DSCalendarView, sender);
        }
Ejemplo n.º 13
0
        public void AddEvent(string Titulo, string Lugar, DateTime Inicio, DateTime Termina, string Descripcion)
        {
            try
            {
                EKEventStore evStore = new EKEventStore();
                evStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => {
                    if (!granted)
                    {
                        new UIAlertView("Acceso denegado", "El usuario no permite acceso al calendario", null, "ok", null).Show();
                    }
                });
                EKCalendar  calendar    = evStore.DefaultCalendarForNewEvents;
                NSPredicate evPredicate = evStore.PredicateForEvents(Inicio, Termina, evStore.GetCalendars(EKEntityType.Event));
                bool        encontrado  = false;

                evStore.EnumerateEvents(evPredicate, delegate(EKEvent calEvent, ref bool stop) {
                    if (calEvent.Title == Titulo)
                    {
                        encontrado = true;
                    }
                });
                if (encontrado)
                {
                    new UIAlertView("Evento", "El evento ya existe en el calendario", null, "ok", null).Show();
                }
                else
                {
                    EKEvent newEvent = EKEvent.FromStore(evStore);
                    newEvent.Title     = Titulo;
                    newEvent.Notes     = Descripcion;
                    newEvent.Calendar  = calendar;
                    newEvent.StartDate = Inicio;
                    newEvent.EndDate   = Termina;
                    newEvent.Location  = Lugar;
                    var error = new NSError(new NSString(""), 0);
                    evStore.SaveEvent(newEvent, EKSpan.ThisEvent, out error);
                    if (error.LocalizedDescription != "")
                    {
                        new UIAlertView("Evento", "Hubo un problema al agregar el evento " + error.LocalizedDescription, null, "ok", null).Show();
                    }
                    else
                    {
                        new UIAlertView("Evento", "El evento se agregó a su calendario", null, "ok", null).Show();
                    }
                }
            }
            catch (Exception) {
                new UIAlertView("Evento", "Hubo un problema al agregar el evento", null, "ok", null).Show();
            }
        }
Ejemplo n.º 14
0
        private void AddEventForReal(DateTime startDate, DateTime endDate, string title, string location, string description, Action <bool> callback, string id)
        {
            var store    = EventStore;
            var calendar = store.DefaultCalendarForNewEvents;

            if (calendar == null)
            {
                callback(false);
                Utils.EnsureInvokedOnMainThread(() =>
                                                new UIAlertView("No Calendars", "This is rather embarrassing for us to tell you, but you don't seem to have a calendar. Please configure a calendar to add session.", null, "OK", null).Show()
                                                );
                return;
            }



            if (EventExists(startDate, title, id))
            {
                callback(true);
                return;
            }

            var newEvent = EKEvent.FromStore(store);

            newEvent.Title        = title;
            newEvent.Notes        = description;
            newEvent.Calendar     = calendar;
            newEvent.TimeZone     = NSTimeZone.FromName("US/Eastern");
            newEvent.StartDate    = startDate.ToNSDate();
            newEvent.EndDate      = endDate.ToNSDate();
            newEvent.AllDay       = true;
            newEvent.Location     = location;
            newEvent.Availability = EKEventAvailability.Busy;
            NSError error;

            store.SaveEvent(newEvent, EKSpan.ThisEvent, true, out error);

            if (error == null)
            {
                callback(true);
            }
            else
            {
                callback(false);
                Utils.EnsureInvokedOnMainThread(() =>
                                                new UIAlertView("Sorry about the mess.", "Something went berserk and we couldn't add the session to your calendar, but it should be fixed now. Try again, please!", null, "OK", null).Show()
                                                );
            }
        }
Ejemplo n.º 15
0
        public async Task <bool> AddAppointment(MyAppointmentType appointment)
        {
            var eventStore = new EKEventStore();
            var granted    = await eventStore.RequestAccessAsync(EKEntityType.Event);

            if (granted.Item1)
            {
                EKEvent newEvent = EKEvent.FromStore(eventStore);
                newEvent.StartDate = DateTimeToNSDate(appointment.ExpireDate);
                newEvent.EndDate   = DateTimeToNSDate(appointment.ExpireDate.AddHours(1));
                newEvent.Title     = appointment.Title; newEvent.Notes = appointment.WhereWhen;
                newEvent.Calendar  = eventStore.DefaultCalendarForNewEvents;
                return(eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out NSError e));
            }
            return(false);
        }
Ejemplo n.º 16
0
        public void Add(int actionResult, DateTime inputDStart, DateTime inputDEnd, string inputTitle, string inputLocation)
        {
            App.Current.EventStore.RequestAccess(EKEntityType.Event,
                                                 (bool granted, NSError e) => {
                if (granted)
                {
                    EKEvent newEvent = EKEvent.FromStore(App.Current.EventStore);
                    // make the event start 20 minutes from now and last 30 minutes
                    newEvent.StartDate = DateTimeToNSDate(inputDStart);
                    newEvent.EndDate   = DateTimeToNSDate(inputDEnd);
                    newEvent.Title     = inputTitle;
                    newEvent.Location  = inputLocation;

                    EKReminder reminder = EKReminder.Create(App.Current.EventStore);
                    reminder.Title      = "Do something awesome!";
                    reminder.Calendar   = App.Current.EventStore.DefaultCalendarForNewReminders;

                    if (actionResult == 0)
                    {
                        newEvent.Calendar = App.Current.EventStore.DefaultCalendarForNewEvents;
                        App.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
                    }
                    else if (actionResult == 1)
                    {
                        NSError ee;
                        App.Current.EventStore.SaveReminder(reminder, true, out ee);
                    }
                    else if (actionResult == 2)
                    {
                        newEvent.Calendar = App.Current.EventStore.DefaultCalendarForNewEvents;
                        App.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
                    }
                    this.InvokeOnMainThread(() => {
                        var av = new UIAlertView("QR Code Scan Results:", "Successfully Added event!", null, "ok", null);
                        av.Show();
                    });
                }
                else
                {
                    this.InvokeOnMainThread(() => {
                        var av = new UIAlertView("Access Denied", "User Denied Access to Calendar Data", null, "ok", null);
                        av.Show();
                    });
                }
            });
        }
Ejemplo n.º 17
0
        private void agregaEventoaCalendario()
        {
            NSPredicate query = App.Current.EventStore.PredicateForEvents(funciones.ConvertDateTimeToNSDate(fechainicio), funciones.ConvertDateTimeToNSDate(fechafin), null);

            EKCalendarItem[] events = App.Current.EventStore.EventsMatching(query);

            if (events != null)
            {
                foreach (EKCalendarItem ev in events)
                {
                    if (ev.Title.Equals(titulo))
                    {
                        funciones.MessageBox("Error", "Ya tiene un evento con este titulo y a esa hora en su calendario");
                        return;
                    }
                }
            }


            EKEvent newEvent = EKEvent.FromStore(App.Current.EventStore);

            // set the alarm for 10 minutes from now
            DateTime fechaalarma = fechainicio.AddMinutes(-10);

            newEvent.AddAlarm(EKAlarm.FromDate(funciones.ConvertDateTimeToNSDate(fechaalarma)));
            // make the event start 20 minutes from now and last 30 minutes
            newEvent.StartDate = funciones.ConvertDateTimeToNSDate(fechainicio);
            newEvent.EndDate   = funciones.ConvertDateTimeToNSDate(fechafin);
            newEvent.Title     = titulo;
            newEvent.Notes     = notas;
            newEvent.Calendar  = App.Current.EventStore.DefaultCalendarForNewEvents;

            NSError e;

            App.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);

            if (e != null)
            {
                funciones.MessageBox("Error al guardar el evento", e.ToString());
                return;
            }
            else
            {
                funciones.MessageBox("Evento guardado", "Se ha guardado el evento en tu calendario!!");
            }
        }
Ejemplo n.º 18
0
        private void GenerarEvento()
        {
            RequestAccess(EKEntityType.Event, () =>
            {
                CLLocation location = new CLLocation();
                if (SucursalModel.Sucursal_Id == "1")
                {
                    location = new CLLocation(20.6766, -103.3812);
                }
                else
                {
                    location = new CLLocation(20.6766, -103.3812);
                }
                var structuredLocation         = new EKStructuredLocation();
                structuredLocation.Title       = SucursalModel.Sucursal_Domicilio;
                structuredLocation.GeoLocation = location;

                NSDateFormatter dateFormat = new NSDateFormatter();
                dateFormat.DateFormat      = "E, d MMM yyyy HH:mm";
                NSDate newFormatDate       = dateFormat.Parse(this.FechaReservacion);
                EKEvent newEvent           = EKEvent.FromStore(AppHelper.Current.EventStore);

                DateTime myDate      = ((DateTime)newFormatDate).ToLocalTime();
                var HoraAntesReunion = myDate.AddHours(1 * -1);
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(HoraAntesReunion.AddMinutes(30))));
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(HoraAntesReunion.AddMinutes(45))));
                if (myDate != null)
                {
                    newEvent.StartDate = DateTimeToNSDate(myDate);
                    newEvent.EndDate   = DateTimeToNSDate(myDate.AddHours(1));
                }
                newEvent.Title = "Visita de invitados en " + SucursalModel.Sucursal_Descripcion;
                newEvent.Notes = "Invitados: ";
                foreach (UsuarioModel Invitado in InvitadosCalendar)
                {
                    newEvent.Notes = newEvent.Notes + Invitado.Usuario_Nombre + " " + Invitado.Usuario_Apellidos + ". ";
                }
                newEvent.Notes              = newEvent.Notes + " Asunto: " + Asunto;
                newEvent.Calendar           = AppHelper.Current.EventStore.DefaultCalendarForNewEvents;
                newEvent.Location           = SucursalModel.Sucursal_Domicilio;
                newEvent.StructuredLocation = structuredLocation;
                NSError e;
                AppHelper.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
            });
        }
        public void CreateCalendarEntry(LocalCalendarEvent localCalendarEvent)
        {
            eventStore.RequestAccess(EKEntityType.Event,
                                     (bool granted, NSError e) => {
                if (granted)
                {
                    UIApplication.SharedApplication.InvokeOnMainThread(() => {
                        EventKitUI.EKEventEditViewController eventController = new EventKitUI.EKEventEditViewController();

                        eventController.EventStore = eventStore;

                        // wire up a delegate to handle events from the controller
                        var eventControllerDelegate      = new CreateEventEditViewDelegate(eventController, eventStore);
                        eventController.EditViewDelegate = eventControllerDelegate;

                        EKEvent newEvent = EKEvent.FromStore(eventStore);

                        newEvent.StartDate = (NSDate)(DateTime.SpecifyKind(localCalendarEvent.StartDate, DateTimeKind.Local));
                        if (localCalendarEvent.EndDate.HasValue)
                        {
                            newEvent.EndDate = (NSDate)(DateTime.SpecifyKind(localCalendarEvent.EndDate.Value, DateTimeKind.Local));
                        }

                        newEvent.Title    = localCalendarEvent.Subject;
                        newEvent.Notes    = localCalendarEvent.Description;
                        newEvent.Location = localCalendarEvent.Location;

                        if (localCalendarEvent.ReminderDate.HasValue)
                        {
                            newEvent.AddAlarm(EKAlarm.FromDate((NSDate)(DateTime.SpecifyKind(localCalendarEvent.ReminderDate.Value, DateTimeKind.Local))));
                        }

                        eventController.Event = newEvent;

                        // show the event controller
                        UIApplication.SharedApplication.Windows[0].RootViewController.PresentViewController(eventController, true, null);
                    });
                }
                else
                {
                    new UIAlertView("Access Denied", "User Denied Access to Calendar Data", null, "ok", null).Show();
                }
            });
        }
Ejemplo n.º 20
0
        public void AddEventWithStartTime(NSDate startDate)
        {
            // Create a new EKEvent and then set the properties on it.
            var e = EKEvent.FromStore(EventStore);

            e.Title     = DefaultEventTitle;
            e.TimeZone  = NSTimeZone.LocalTimeZone;
            e.StartDate = startDate;
            e.EndDate   = startDate.AddSeconds(60 * 60);            // 1 hour
            e.Calendar  = SelectedCalendar;

            // Save our new EKEvent
            NSError err;
            bool    success = EventStore.SaveEvent(e, EKSpan.FutureEvents, true, out err);

            if (!success)
            {
                Console.WriteLine("There was an error saving a new event: " + err);
            }
        }
Ejemplo n.º 21
0
        public string AddEvent(string Title, string Description, DateTime StartDate, DateTime EndDate, string StartTimeZone, string EndTimeZone)
        {
            try
            {
                EKEvent newEvent = EKEvent.FromStore(AppMain.Self.EventStore);
                // set the alarm for 10 minutes from now
                newEvent.AddAlarm(EKAlarm.FromDate(DateTimeToNSDate(StartDate.AddMinutes(10))));
                // make the event start 20 minutes from now and last 30 minutes
                newEvent.StartDate = DateTimeToNSDate(StartDate.AddMinutes(20));
                newEvent.EndDate   = DateTimeToNSDate(EndDate.AddMinutes(50));
                newEvent.Title     = Title;
                newEvent.Notes     = Description;

                EKCalendar[] calendars = AppMain.Self.EventStore.GetCalendars(EKEntityType.Event);
                if (calendars.Length > 0)
                {
                    newEvent.Calendar = calendars.FirstOrDefault();
                }
                else
                {
                    newEvent.Calendar = AppMain.Self.EventStore.DefaultCalendarForNewEvents;
                }

                //saving the event
                NSError errorEvent;
                AppMain.Self.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out errorEvent);

                if (errorEvent != null)
                {
                    throw new Exception(errorEvent.ToString());
                }


                return("event added: " + newEvent.CalendarItemIdentifier);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 22
0
        public void AddEventToCalendar(CultureInfo ci, DateTime from, DateTime until, string name, string location)
        {
            try
            {
                EventStore.RequestAccess(EKEntityType.Event,
                                         (granted, e) =>
                {
                    if (granted)
                    {
                        UIApplication.SharedApplication.InvokeOnMainThread(() =>
                        {
                            var eventController = new EKEventEditViewController
                            {
                                EventStore = EventStore
                            };

                            var eventControllerDelegate      = new CreateEventEditViewDelegate(eventController);
                            eventController.EditViewDelegate = eventControllerDelegate;

                            var newEvent       = EKEvent.FromStore(EventStore);
                            newEvent.StartDate = DateTimeToNsDate(from);
                            newEvent.EndDate   = DateTimeToNsDate(until);
                            newEvent.AllDay    = true;
                            newEvent.Location  = location;
                            newEvent.Title     = name;
                            newEvent.Calendar  = EventStore.DefaultCalendarForNewEvents;

                            eventController.Event = newEvent;

                            UIApplication.SharedApplication.Windows[0].RootViewController
                            .PresentViewController(eventController, true, null);
                        });
                    }
                });
            }
            catch (Exception)
            {
                // shht
            }
        }
Ejemplo n.º 23
0
        public void CreateCalendarEvent(CalendarEventModel calEvent)
        {
            if (CalendarEvent.eventStore == null)
            {
                CalendarEvent.eventStore = new EKEventStore();
            }

            RequestAccess(EKEntityType.Event, () =>
            {
                EKEvent newEvent = EKEvent.FromStore(CalendarEvent.eventStore);

                if (calEvent.HasReminder)
                {
                    newEvent.AddAlarm(EKAlarm.FromDate(ToNSDate(calEvent.StartTime.AddHours(-1))));
                }

                newEvent.StartDate = ToNSDate(calEvent.StartTime);
                newEvent.EndDate   = ToNSDate(calEvent.EndTime);
                newEvent.Title     = calEvent.Title;
                newEvent.Notes     = calEvent.Description;
                newEvent.Calendar  = CalendarEvent.eventStore.DefaultCalendarForNewEvents;

                NSError e;
                CalendarEvent.eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
                if (e != null)
                {
                    new UIAlertView("Error Saving Event", e.ToString(), null, "ok", null).Show();
                    return;
                }
                else
                {
                    new UIAlertView("Event Saved", "Event ID: " + newEvent.EventIdentifier, null, "ok", null).Show();
                    Console.WriteLine("Event Saved, ID: " + newEvent.EventIdentifier);
                }

                // to retrieve the event you can call
                EKEvent mySavedEvent = CalendarEvent.eventStore.EventFromIdentifier(newEvent.EventIdentifier);
                Console.WriteLine("Retrieved Saved Event: " + mySavedEvent.Title);
            });
        }
Ejemplo n.º 24
0
        public async Task <(bool result, CalendarEventModel model)> CreateCalendarEvent(CalendarEventModel calEvent)
        {
            (bool result, CalendarEventModel model)response = (false, calEvent);

            var result = await RequestAccess(EKEntityType.Event);

            if (result.granted)
            {
                var newEvent         = EKEvent.FromStore(CalendarEvent.EventStore);
                var selectedCalendar = CalendarEvent.EventStore.DefaultCalendarForNewEvents;
                if (calEvent.DeviceCalendar != null)
                {
                    selectedCalendar = CalendarEvent.EventStore.GetCalendar(calEvent.DeviceCalendar.Id);
                }

                newEvent.StartDate = calEvent.StartTime.ToNSDate();
                newEvent.EndDate   = calEvent.EndTime.ToNSDate();
                newEvent.Title     = calEvent.Title;
                newEvent.Notes     = calEvent.Description;
                newEvent.Calendar  = selectedCalendar;

                if (calEvent.HasReminder)
                {
                    var offset = calEvent.StartTime.AddMinutes(-calEvent.ReminderMinutes).ToNSDate();
                    newEvent.AddAlarm(EKAlarm.FromDate(offset));
                }

                NSError e;

                CalendarEvent.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, true, out e);

                if (e == null)
                {
                    response.result   = true;
                    response.model.Id = newEvent.EventIdentifier;
                }
            }

            return(response);
        }
Ejemplo n.º 25
0
 public bool AddToCalendar(CalendarModel calendarModel)
 {
     //var granted = EventStore.RequestAccessAsync(EKEntityType.Event);
     EventStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) =>
     {
         if (granted)
         {
             EKEvent newEvent   = EKEvent.FromStore(EventStore);
             newEvent.Title     = calendarModel.Title;
             newEvent.Notes     = calendarModel.Description;
             newEvent.StartDate = (NSDate)calendarModel.Start;
             newEvent.EndDate   = (NSDate)calendarModel.End;
             newEvent.Location  = calendarModel.Location;
             newEvent.Calendar  = EventStore.DefaultCalendarForNewEvents;
             EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
             return;
         }
         new UIAlertView("Access Denied,", "User Denied Access to Calendar Data", null, "ok", null).Show();
         Debug.WriteLine(e);
     });
     return(true);
 }
Ejemplo n.º 26
0
        private void AddEvent(string title, string addInfo, DateTime startDate, DateTime alertDate)
        {
            var newEvent = EKEvent.FromStore(EventStore);

            newEvent.AddAlarm(EKAlarm.FromDate(alertDate.LocalDateTimeToNSDate()));
            newEvent.StartDate = startDate.LocalDateTimeToNSDate();
            newEvent.EndDate   = startDate.AddHours(1).LocalDateTimeToNSDate();
            newEvent.Title     = title;
            newEvent.Notes     = addInfo;
            newEvent.Calendar  = EventStore.DefaultCalendarForNewEvents;
            NSError err;

            EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out err);
            if (err != null)
            {
                _logger.LogMessage("Err Saving Event : " + err);
            }
            else
            {
                _logger.LogMessage("Event Saved,  ID: " + newEvent.EventIdentifier);
            }
        }
Ejemplo n.º 27
0
        public async void AddAppointment(DateTime startTime, DateTime endTime, String subject, String location, String details, Boolean isAllDay, AppointmentReminder reminder, AppointmentStatus status)
        {
            var granted = await RequestAccessAsync();

            if (granted)
            {
                EKEvent newEvent = EKEvent.FromStore(this.EventStore);
                newEvent.StartDate = (NSDate)DateTime.SpecifyKind(startTime, DateTimeKind.Utc);
                newEvent.EndDate   = (NSDate)DateTime.SpecifyKind(endTime, DateTimeKind.Utc);
                newEvent.Title     = subject;
                newEvent.Location  = location;
                newEvent.Notes     = details;
                newEvent.AllDay    = isAllDay;
                newEvent.AddAlarm(ConvertReminder(reminder, startTime));
                newEvent.Availability = ConvertAppointmentStatus(status);

                NSError error;
                this.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out error);

                Console.WriteLine("Event Saved, ID: " + newEvent.CalendarItemIdentifier);
            }
        }
Ejemplo n.º 28
0
        private string CreateCalendarEvent(Task task)
        {
            EKEvent ekEvent = EKEvent.FromStore(App.CurrentApp.EventStore);

            ekEvent.StartDate = task.DateAndTime;
            ekEvent.EndDate   = Extensions.DateTimeToNSDate(Extensions.NSDateToDateTime(task.DateAndTime).AddHours(task.Duration));
            ekEvent.Title     = task.Name;
            ekEvent.Notes     = task.ShortLabel;
            ekEvent.Calendar  = App.CurrentApp.EventStore.DefaultCalendarForNewEvents;

            App.CurrentApp.EventStore.SaveEvent(ekEvent, EKSpan.ThisEvent, true, out NSError error);
            if (error != null)
            {
                Console.WriteLine(error);
                return(null);
            }
            else
            {
                Console.WriteLine("event was added into calendar");
                return(ekEvent.EventIdentifier);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// This method illustrates how to save and retrieve events programmatically.
        /// </summary>
        protected void SaveAndRetrieveEvent()
        {
            EKEvent newEvent = EKEvent.FromStore(App.Current.EventStore);

            // set the alarm for 5 minutes from now
            newEvent.AddAlarm(EKAlarm.FromDate(DateTime.Now.AddMinutes(5)));
            // make the event start 10 minutes from now and last 30 minutes
            newEvent.StartDate = DateTime.Now.AddMinutes(10);
            newEvent.EndDate   = DateTime.Now.AddMinutes(40);
            newEvent.Title     = "Appt. to do something Awesome!";
            newEvent.Notes     = "Find a boulder, climb it. Find a river, swim it. Find an ocean, dive it.";
            newEvent.Calendar  = App.Current.EventStore.DefaultCalendarForNewEvents;

            // save the event
            NSError e;

            App.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
            if (e != null)
            {
                new UIAlertView("Err Saving Event", e.ToString(), null, "ok", null).Show();
                return;
            }
            else
            {
                new UIAlertView("Event Saved", "Event ID: " + newEvent.EventIdentifier, null, "ok", null).Show();
                Console.WriteLine("Event Saved, ID: " + newEvent.EventIdentifier);
            }

            // to retrieve the event you can call
            EKEvent mySavedEvent = App.Current.EventStore.EventFromIdentifier(newEvent.EventIdentifier);

            Console.WriteLine("Retrieved Saved Event: " + mySavedEvent.Title);

            // to delete, note that once you remove the event, the reference will be null, so
            // if you try to access it you'll get a null reference error.
            App.Current.EventStore.RemoveEvent(mySavedEvent, EKSpan.ThisEvent, true, out e);
            Console.WriteLine("Event Deleted.");
        }
Ejemplo n.º 30
0
        public void CreateCalendarEvent(CalendarEventModel calEvent, Action <bool> callback)
        {
            if (CalendarEvent.eventStore == null)
            {
                CalendarEvent.eventStore = new EKEventStore();
            }

            RequestAccess(EKEntityType.Event, () =>
            {
                EKEvent newEvent = EKEvent.FromStore(CalendarEvent.eventStore);

                if (calEvent.HasReminder)
                {
                    newEvent.AddAlarm(EKAlarm.FromDate(ToNSDate(calEvent.StartTime.AddHours(-1))));
                }

                newEvent.StartDate = ToNSDate(calEvent.StartTime);
                newEvent.EndDate   = ToNSDate(calEvent.EndTime);
                newEvent.Title     = calEvent.Title;
                newEvent.Notes     = calEvent.Description;
                newEvent.Calendar  = CalendarEvent.eventStore.DefaultCalendarForNewEvents;

                NSError e;
                CalendarEvent.eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
                if (e != null)
                {
                    callback?.Invoke(false);
                }
                else
                {
                    callback?.Invoke(true);
                }

                // to retrieve the event you can call
                EKEvent mySavedEvent = CalendarEvent.eventStore.EventFromIdentifier(newEvent.EventIdentifier);
                Console.WriteLine("Retrieved Saved Event: " + mySavedEvent.Title);
            });
        }