DevExpress WinForms Scheduler component Chinese tutorial - how to synchronize with Office 365?

With the recent update of DevExpress WinForms , users can seamlessly sync DevExpress WinForms Scheduler with Office 365 event/schedule data. You can export user schedules from WinForms Scheduler to Office 365 calendar, or import Office 365 events/schedules to Scheduler control. Modify user events/schedules while syncing, merge user schedules with Microsoft 365 calendar, resolve merge conflicts, and save changes to the database.

DevExpress WinForms Scheduler component Chinese tutorial - how to synchronize with Office 365?

DevExpress WinForms  has 180+ components and UI libraries to create impactful business solutions for the Windows Forms platform. DevExpress WinForms can perfectly build smooth, beautiful and easy-to-use applications, whether it is an Office-style interface or analyzing and processing large quantities of business data, it can easily do it!

Get the official version of DevExpress v23.1 download (Q technical exchange: 523159565)

required dependencies

Install the following dependencies (NuGet packages):

getting started guide

Drop the WinForms  Scheduler control on the form, open its smart tag menu and select "Sync with Microsoft 365 Calendar", this will create the DXOutlook365Sync component.

DevExpress WinForms Scheduler component Chinese tutorial - how to synchronize with Office 365?

Merge base data fields and set custom mappings

If you need to save changes to the database after the application and the Microsoft Office 365 calendar are synchronized, the DXOutlook365Sync component requires five specific fields (in your data source) to store the unique identifier for the Microsoft 365 event and record the user event/appointment's Last modified date.

DataTable source = new DataTable();
source.Columns.AddRange(new DataColumn[] {
new DataColumn("Subject", typeof(string)),
new DataColumn("Description", typeof(string)),
new DataColumn("Start", typeof(DateTime)),
new DataColumn("End", typeof(DateTime)),
// Special data fields.
new DataColumn("Outlook365CalendarId", typeof(string)),
new DataColumn("Outlook365EventId", typeof(string)),
new DataColumn("Outlook365EventUniqId", typeof(string)),
new DataColumn("Outlook365LastChangedUTC", typeof(DateTime)),
new DataColumn("SchedulerLastChangedUTC", typeof(DateTime))
});

Define custom mappings to these fields to complete the data source setup.

// Defines custom mappings.
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("outlook365_calendar_id", "Outlook365CalendarId"));
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("outlook365_event_id", "Outlook365EventId"));
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("outlook365_event_ICalUId", "Outlook365EventUniqId"));
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("outlook365_lastChangedUTC", "Outlook365LastChangedUTC"));
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("scheduler_lastChangedUTC", "SchedulerLastChangedUTC"));
Initialize the synchronous API

Before using the API of the DXOutlook365Sync component, it must be initialized, using its InitAsync() method, this method opens the "Sign in to your account" window (login to Microsoft Office 365 is required).

DevExpress WinForms Scheduler component Chinese tutorial - how to synchronize with Office 365?

private async void initBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) {
await dxOutlook365Sync1.InitAsync();
}
Choose which Microsoft 365 calendars to sync

The DXOutlook365Sync component can synchronize the user's schedule in the WinForms  Scheduler control with events in all (or specific) Office 365 calendars, and its calendar collection contains OutlookCalendarItem objects corresponding to Office365 calendars.

The calendar has an OutlookCalendarItem.EnableSynchronization setting that specifies whether to synchronize its events with the user's schedule in the WinForms Scheduler control.

Import Microsoft 365 events

Use the ImportOutlookToSchedulerAsync(Boolean) method to import events from the Office 365 calendar into the WinForms Scheduler control.

using DevExpress.XtraScheduler.Microsoft365Calendar;

private async void importEventsButton_Click(object sender, EventArgs e) {
// Checks whether the initialization of 'dxOutlook365Sync1' failed.
if(!await InitOutlook365Sync(dxOutlook365Sync1)) return;
// Displays the wait form.
splashScreenManager1.ShowWaitForm();
// Imports Outlook 365 events to the Scheduler control.
await dxOutlook365Sync1.ImportOutlookToSchedulerAsync(false);
// Hides the wait form.
splashScreenManager1.CloseWaitForm();
}
private async Task<bool> InitOutlook365Sync(DXOutlook365Sync outlook365sync) {
// Initializes the 'dxOutlook365Sync1' component.
InitStatus status = await outlook365sync.InitAsync();
// Returns false and displays a message box if the initialization of 'dxOutlook365Sync1' failed.
if(status == InitStatus.Error) {
XtraMessageBox.Show("Initialization of DXOutlook365Sync failed.", "Error", MessageBoxButtons.OK);
return false;
}
return true;
}
Export user schedules to Microsoft 365 calendar

Use the ExportSchedulerToOutlookAsync(Boolean) method to export the user schedule from the DevExpress  Scheduler control to the Office 365 calendar.

Customize the schedule or event before synchronization

The following events allow you to customize user schedules or events prior to synchronization:

Merging Calendars and Resolving Merge Conflicts

DXOutlook365Sync API allows you to merge user calendars with Office 365 events, you can merge all events/schedules and also define rules to skip some events/schedules (based on certain conditions).

The synchronous API allows you to easily resolve merge conflicts as needed.

Guess you like

Origin blog.csdn.net/AABBbaby/article/details/131955308