DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

DevExpress WinForms Scheduler组件中文教程 - 如何与Office 365双向同步?

来源:   发布时间:2023-07-26   浏览:252次

随着DevExpress WinForms最近的更新,用户可以无缝同步DevExpress WinForms Scheduler与Office 365事件/日程的数据。您可以将用户日程从WinForms Scheduler中导出到Office 365日历,或将Office 365事件/日程导入到Scheduler控件。在同步钱修改用户事件/日程,将用户日程与Microsoft 365日历合并,解决合并冲突,并将更改保存到数据库中。

DevExpress WinForms Scheduler组件中文教程 - 如何与Office 365双向同步?

DevExpress WinForms 拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!

获取DevExpress v23.1正式版下载

DevExpress技术交流群8:523159565      欢迎一起进群讨论

必需的依赖项

安装以下依赖库(NuGet包):

入门指南

WinForms Scheduler控件放到窗体上,打开其智能标签菜单并选择"Sync with Microsoft 365 Calendar",这将创建DXOutlook365Sync组件。

DevExpress WinForms Scheduler组件中文教程 - 如何与Office 365双向同步?
合并基本数据字段和设置自定义映射

如果您需要在应用程序和Microsoft Office 365日历同步之后保存对数据库的更改,DXOutlook365Sync组件需要五个特定字段(在您的数据源中)来存储Microsoft 365事件的唯一标识符并记录用户事件/约会的最后修改日期。

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))
});

定义到这些字段的自定义映射,来完成数据源设置。

// 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"));
初始化同步API

在使用DXOutlook365Sync组件的API之前,必须初始化它,使用它的InitAsync()方法,此方法打开"Sign in to your account"窗口(需要登录Microsoft Office 365)。

DevExpress WinForms Scheduler组件中文教程 - 如何与Office 365双向同步?
private async void initBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) {
await dxOutlook365Sync1.InitAsync();
}
选择要同步的Microsoft 365日历

DXOutlook365Sync组件可以将WinForms Scheduler控件中的用户日程与所有(或特定)Office 365日历中的事件同步,它的日历集合包含与Office365日历对应的OutlookCalendarItem对象。

日历具有OutlookCalendarItem.EnableSynchronization设置,该设置指定是否将其事件与WinForms Scheduler控件中的用户日程同步。

导入Microsoft 365事件

使用ImportOutlookToSchedulerAsync(Boolean)方法将Office 365日历中的事件导入到WinForms Scheduler控件中。

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;
}
导出用户日程到Microsoft 365日历中

使用ExportSchedulerToOutlookAsync(Boolean)方法从DevExpress Scheduler控件导出用户日程到Office 365日历。

自定义同步前的日程或事件

以下事件允许您在同步之前自定义用户日程或事件:

合并日历和解决合并冲突

DXOutlook365Sync API允许您将用户日程与Office 365事件合并,您可以合并所有事件/日程,也可以定义跳过某些事件/日程的规则(基于特定条件)。

同步API允许您根据需要轻松解决合并冲突。


更多DevExpress线上公开课、中文教程资讯请上中文网获取

DevExpress企业定制服务
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/3948.html

相关产品: DevExpress Universal Subscription,

在线
客服
微信
QQ 电话
023-68661681
返回
顶部