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); }); }
/// <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); }
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); }
/// <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); }
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); }
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); }); }
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!!"); } }
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(); } }); }
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); }); }
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; } }
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); } }
/// <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."); }
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); }); }
public void SaveAndRetrieveEvent(string Title, string Desc, string Date, string Time, string location, int reservation_id) { try{ EKEvent newEvent = EKEvent.FromStore(Apps.Current.EventStore); // set the alarm for 5 minutes from now newEvent.AddAlarm(EKAlarm.FromDate(ConvertDateTimeToNSDate(Date, Time, -120))); // make the event start 10 minutes from now and last 30 minutes newEvent.StartDate = (ConvertDateTimeToNSDate(Date, Time, 0)); newEvent.EndDate = (ConvertDateTimeToNSDate(Date, Time, 120)); newEvent.Title = Title; newEvent.Notes = Desc; newEvent.Location = location; newEvent.Calendar = Apps.Current.EventStore.DefaultCalendarForNewEvents; // save the event NSError e; Apps.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); } App.Database.saveCalendar(reservation_id, newEvent.EventIdentifier.ToString(), Date); var calendar = App.Database.getCalendar("-1"); } catch (Exception ex) { Services.Logs.Insights.Send("GetDateTimeMS", ex); } }
public async void AddEventToCalender(object sender, EventArgs e) { try { var store = new EKEventStore(); if (EKEventStore.GetAuthorizationStatus(EKEntityType.Reminder) == EKAuthorizationStatus.Authorized) { if (EKEventStore.GetAuthorizationStatus(EKEntityType.Event) == EKAuthorizationStatus.Authorized) { NSDate startDate = ConvertDateTimeToNSDate(BaseFunctions.GetDateTimeFull(App.reminderEvent.eventStartDate + " " + App.reminderEvent.eventStartTime)); NSDate endDate = ConvertDateTimeToNSDate(BaseFunctions.GetDateTimeFull(App.reminderEvent.eventEndDate + " " + App.reminderEvent.eventEndTime)); NSPredicate query = store.PredicateForEvents(startDate, endDate, null); EKCalendarItem[] events = store.EventsMatching(query); bool exists = false; for (int i = 0; i < events.Length; i++) { if (events[i].Title == App.reminderEvent.eventName) { exists = true; } } if (!exists) { EKEvent eEvent = EKEvent.FromStore(store); eEvent.AddAlarm(EKAlarm.FromDate(ConvertDateTimeToNSDate(BaseFunctions.GetDateTimeFull(App.reminderEvent.eventStartDate + " " + App.reminderEvent.eventStartTime)))); eEvent.StartDate = startDate; eEvent.EndDate = endDate; eEvent.Title = App.reminderEvent.eventName; eEvent.TimeZone = new NSTimeZone("UTC"); eEvent.Location = App.reminderEvent.eventAddress; eEvent.Notes = App.reminderEvent.eventDescription; eEvent.Calendar = store.DefaultCalendarForNewEvents; NSError eventError; store.SaveEvent(eEvent, EKSpan.ThisEvent, out eventError); EKReminder reminder = EKReminder.Create(store); reminder.Title = App.reminderEvent.eventName; reminder.AddAlarm(EKAlarm.FromDate(ConvertDateTimeToNSDate(BaseFunctions.GetDateTimeFull(App.reminderEvent.eventStartDate + " " + App.reminderEvent.eventStartTime)))); reminder.TimeZone = new NSTimeZone("UTC"); reminder.Calendar = store.DefaultCalendarForNewEvents; await App.Current.MainPage.DisplayAlert("Alert", "This event is added to your calender", "Ok"); } else { await App.Current.MainPage.DisplayAlert("Alert", "This event is already added to your calender", "Ok"); } } else { store.RequestAccess(EKEntityType.Event, StoreAcceptRequest); } } else { store.RequestAccess(EKEntityType.Reminder, StoreAcceptRequest); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }