翻譯|使用教程|編輯:龔雪|2023-07-26 10:54:11.207|閱讀 103 次
概述:本文將介紹在使用DevExpress WinForms Scheduler組件時如何實現與Office 365的雙向同步,歡迎下載相關組件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
隨著DevExpress WinForms最近的更新,用戶可以無縫同步DevExpress WinForms Scheduler與Office 365事件/日程的數據。您可以將用戶日程從WinForms Scheduler中導出到Office 365日歷,或將Office 365事件/日程導入到Scheduler控件。在同步錢修改用戶事件/日程,將用戶日程與Microsoft 365日歷合并,解決合并沖突,并將更改保存到數據庫中。
DevExpress WinForms 擁有180+組件和UI庫,能為Windows Forms平臺創建具有影響力的業務解決方案。DevExpress WinForms能完美構建流暢、美觀且易于使用的應用程序,無論是Office風格的界面,還是分析處理大批量的業務數據,它都能輕松勝任!
DevExpress技術交流群8:523159565 歡迎一起進群討論
安裝以下依賴庫(NuGet包):
將WinForms Scheduler控件放到窗體上,打開其智能標簽菜單并選擇"Sync with Microsoft 365 Calendar",這將創建DXOutlook365Sync組件。
如果您需要在應用程序和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"));
在使用DXOutlook365Sync組件的API之前,必須初始化它,使用它的InitAsync()方法,此方法打開"Sign in to your account"窗口(需要登錄Microsoft Office 365)。
private async void initBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { await dxOutlook365Sync1.InitAsync(); }
DXOutlook365Sync組件可以將WinForms Scheduler控件中的用戶日程與所有(或特定)Office 365日歷中的事件同步,它的日歷集合包含與Office365日歷對應的OutlookCalendarItem對象。
日歷具有OutlookCalendarItem.EnableSynchronization設置,該設置指定是否將其事件與WinForms Scheduler控件中的用戶日程同步。
使用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; }
使用ExportSchedulerToOutlookAsync(Boolean)方法從DevExpress Scheduler控件導出用戶日程到Office 365日歷。
以下事件允許您在同步之前自定義用戶日程或事件:
DXOutlook365Sync API允許您將用戶日程與Office 365事件合并,您可以合并所有事件/日程,也可以定義跳過某些事件/日程的規則(基于特定條件)。
同步API允許您根據需要輕松解決合并沖突。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網