We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Add and Update Additional Appointments

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? 



10 Replies 1 reply marked as answer

FR Fritz February 11, 2023 05:53 PM UTC

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/




SS SaiGanesh Sakthivel Syncfusion Team February 13, 2023 12:34 PM UTC

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.


Feedback: https://www.syncfusion.com/feedback/37551/provide-built-in-appointment-editor-support-in-maui-scheduler


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



FR Fritz February 14, 2023 10:25 PM UTC

SaiGanesh ,


e.Appointments == null the first time app launched.  Nothing happens.


Fritz



SS SaiGanesh Sakthivel Syncfusion Team February 15, 2023 01:23 PM UTC

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.



FR Fritz replied to SaiGanesh Sakthivel February 15, 2023 02:20 PM UTC

SaiGanesh Sakthivel ,

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



SS SaiGanesh Sakthivel Syncfusion Team February 16, 2023 11:59 AM UTC

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.



FR Fritz replied to SaiGanesh Sakthivel February 16, 2023 10:06 PM UTC

 SaiGanesh Sakthivel,

*****  Stars....Syncfusion Support has exceeded my expectations again.  Great answer.

FTS




SS SaiGanesh Sakthivel Syncfusion Team February 17, 2023 05:09 AM UTC

Fritz,


We are glad to know that the provided solution is resolved the query. Please let us know if you need any further assistance. 



FR Fritz February 17, 2023 02:05 PM UTC

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



SS SaiGanesh Sakthivel Syncfusion Team February 20, 2023 11:13 AM UTC

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.


Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon