BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
In my .NET Maui app, I can add an appointment, but only on the selection event it creates a new Appointment, Here is my code.
var oldtest = e.OldValue.ToString();
var newtest = e.NewValue.ToString();
// Navigation.PushAsync(new SetupPage());
ControlViewModel cvm = new ControlViewModel();
cvm.SchedulerEvents = new ObservableCollection<SchedulerAppointment>
{
new SchedulerAppointment
{
StartTime = Convert.ToDateTime(e.NewValue.ToString()),
EndTime = Convert.ToDateTime(e.NewValue.ToString()),
Subject=testString
}
};
//Adding the scheduler appointment collection to the AppointmentsSource of .NET MAUI Scheduler.
schedulerx.AppointmentsSource = cvm.SchedulerEvents;
How can I perform some basic CRUD processes with using the opened Appointment collection. I don't wan to create a new collection, because I lose the previous appointments.
Is there an example where the appointments are persisted between app sessions, e.g. appts saved in a SQLite db?
Something like this example would be helpful the the .NET MAUI scheduler control.
https://ej2.syncfusion.com/documentation/schedule/how-to/add-edit-and-remove-events/
Hi Fritz,
#Regarding Editing the appointment in the MAUI Scheduler
As of now, the scheduler does not have in-built appointment editor support. We have already logged the feature request for the same. We will implement this feature in any of our upcoming releases.
You can achieve your requirement of custom appointment editor with the help of Tapped event. Inside the event, you can add the custom appointment editor as per your requirement. Please refer to the code snippet for your reference.
Code snippet
private void Scheduler_Tapped(object sender, SchedulerTappedEventArgs e) { if (e.Appointments != null) { this.Navigation.PushAsync(new EditorPage((SchedulerAppointment)e.Appointments[0], (e.Appointments[0] as SchedulerAppointment).StartTime, this.Scheduler)); } } |
Please refer to the demo sample in the following locations.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SchedulerMAUI-1783832785
Output
Please let us know if you have any concerns.
Regards,
SaiGanesh Sakthivel
SaiGanesh ,
e.Appointments == null the first time app launched. Nothing happens.
Fritz
Fitz,
You can achieve your requirement of adding the new appointment inside the custom appointment editor with the help of Tapped event. Inside the event, you can add the new appointment by passing the datetime parameter to the custom editor page. Please refer to the code snippet for your reference.
Code snippet
private void Scheduler_Tapped(object sender, SchedulerTappedEventArgs e) { if (e.Appointments != null) { this.Navigation.PushAsync(new EditorPage((SchedulerAppointment)e.Appointments[0], (e.Appointments[0] as SchedulerAppointment).StartTime, this.Scheduler)); } else { this.Navigation.PushAsync(new EditorPage(null, (DateTime)e.Date, this.Scheduler)); } } |
Please refer to the demo sample in the following locations.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SchedulerMAUI-1823128303
Please let us know if you have any concerns.
Thanks, the last mod adds a new appointment. But as to the original post, "CRUD"? I still don't see how to persist the changes between different sessions, preferably I would like to use SQLite.
Thank
Fitz,
#Regarding Fetch the appointment from the SQlite database
We have prepared the sample with Sqlite database. Please refer to the following steps for your reference. Please refer to the following steps for your reference.
Step 1: Create the Database
public class SchedulerDatabase { readonly SQLiteConnection _database;
public SchedulerDatabase(string dbPath) { _database = new SQLiteConnection(dbPath); _database.CreateTable<Appointment>(); }
//Get the list of appointments from the database public List<Appointment> GetSchedulerAppointment() { return _database.Table<Appointment>().ToList(); }
//Insert an appointment in the database public int SaveSchedulerAppointmentAsync(Appointment appointment) { if (appointment == null) { throw new Exception("Null"); }
return _database.InsertOrReplace(appointment); }
//Delete an appointment in the database public int DeleteSchedulerAppointmentAsync(Appointment appointment) { return _database.Delete(appointment); }
public int DeleteAllSchedulerAppointment() { return _database.DeleteAll<Appointment>(); } } |
Step 2: Initialize the database in the App.cs
public static SchedulerDatabase Database { get { if (database == null) { database = new SchedulerDatabase(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SchedulerDatabase.db3")); } return database; } } |
Step 3: Fetch the data and set to the scheduler AppointmentSource
public BusinessObjectViewModel() { var dataBaseAppointments = App.Database.GetSchedulerAppointment();
if (dataBaseAppointments != null) { Appointments = new ObservableCollection<SchedulerAppointment>(); foreach (Appointment appointment in dataBaseAppointments) { Appointments.Add(new SchedulerAppointment() { StartTime = appointment.From, EndTime = appointment.To, Subject = appointment.EventName, IsAllDay = appointment.AllDay, Id = appointment.ID }); } } } |
Step 4: Add or edit the appointment and save to the database
private void AppointmentDetails() { if (appointment == null) { appointment = new SchedulerAppointment(); appointment.Subject = this.eventNameText.Text; appointment.StartTime = this.startDate_picker.Date.Add(this.startTime_picker.Time); appointment.EndTime = this.endDate_picker.Date.Add(this.endTime_picker.Time); appointment.IsAllDay = this.switchAllDay.IsToggled; appointment.Notes = this.organizerText.Text;
if (this.scheduler.AppointmentsSource == null) { this.scheduler.AppointmentsSource = new ObservableCollection<SchedulerAppointment>(); }
appointment.Id = (this.scheduler.AppointmentsSource as ObservableCollection<SchedulerAppointment>).Count;
(this.scheduler.AppointmentsSource as ObservableCollection<SchedulerAppointment>).Add(appointment); } else { appointment.Subject = this.eventNameText.Text; appointment.StartTime = this.startDate_picker.Date.Add(this.startTime_picker.Time); appointment.EndTime = this.endDate_picker.Date.Add(this.endTime_picker.Time); appointment.IsAllDay = this.switchAllDay.IsToggled; appointment.Notes = this.organizerText.Text; }
//// - add or edit the appointment in the database collection var todoItem = new Appointment() { From = appointment.StartTime, To = appointment.EndTime, AllDay = appointment.IsAllDay, DescriptionNotes = appointment.Notes, EventName = appointment.Subject, ID = (int)appointment.Id }; App.Database.SaveSchedulerAppointmentAsync(todoItem);
this.Navigation.PopAsync(); } |
Step 5: Delete the appointment
private void DeleteButton_Clicked(object sender, EventArgs e) { (this.scheduler.AppointmentsSource as ObservableCollection<SchedulerAppointment>).Remove(this.appointment); var todoItem = new Appointment() { From = appointment.StartTime, To = appointment.EndTime, AllDay = appointment.IsAllDay, DescriptionNotes = appointment.Notes, EventName = appointment.Subject, ID = (int)appointment.Id }; App.Database.DeleteSchedulerAppointmentAsync(todoItem); this.Navigation.PopAsync(); } |
Please refer to the tested sample in the following locations.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SchedulerMAUI-1276392912
Please let us know if you have any concerns.
***** Stars....Syncfusion Support has exceeded my expectations again. Great answer.
FTS
Fritz,
We are glad to know that the provided solution is
resolved the query. Please let us know if you need any further
assistance.
SGS,
Just a quick question....is there a scheduler event, that can be used for tapping/clicking just the scheduler timeslot, rather than the whole scheduler?
Thanks,
FTs
Fitz,
Your requirement can be achieved by using element parameter in the tapped event. Inside the event, you can perform the code by checking the Scheduler element condition. Please refer to the following code snippet for your reference.
Code snippet
private void Scheduler_Tapped(object sender, SchedulerTappedEventArgs e) {
if (e.Element == SchedulerElement.SchedulerCell) { if (e.Appointments != null) { this.Navigation.PushAsync(new EditorPage((SchedulerAppointment)e.Appointments[0], (e.Appointments[0] as SchedulerAppointment).StartTime, this.Scheduler)); } else { this.Navigation.PushAsync(new EditorPage(null, (DateTime)e.Date, this.Scheduler)); } } } |
Please let us know if you have any concerns.