文章出處
文章列表
通知模塊概述
1.支持 WinForms和ASP.NET程序.
2.支持調度模塊或自定義業務對象.
3.功能:在指定的時間,彈出一個窗口,用戶可以查看提醒.也可以取消或推遲.
如需演示項目的源碼,可以在留言中留下郵箱!
要使用通知模塊,需要使用下面的模塊.
第一步:
第二步:
第三步:
Windows Form下面的效果,在底部,出現下圖所示的小圖標:
在ASP.NET下效果如下:
如何使用自定義類實現通知?
1.假如下面是你的業務類:
[DefaultClassOptions] public class Task { [Browsable(false)] public int Id { get; private set; } public string Subject { get; set; } public DateTime DueDate { get; set; } }
先來實現ISupportNotifications 接口:
[DefaultClassOptions] public class Task : ISupportNotifications { // ... #region ISupportNotifications members private DateTime? alarmTime; [Browsable(false)] public DateTime? AlarmTime { get { return alarmTime; } set { alarmTime = value; if (value == null) { RemindIn = null; IsPostponed = false; } } } [Browsable(false)] public bool IsPostponed { get; set; } [Browsable(false), NotMapped] public string NotificationMessage { get { return Subject; } } public TimeSpan? RemindIn { get; set; } [Browsable(false), NotMapped] public object UniqueId { get { return Id; } } #endregion }
再來實現IXafEntityObject,在保存時設置AlarmTime
[DefaultClassOptions] public class Task : ISupportNotifications, IXafEntityObject { // ... #region IXafEntityObject members public void OnCreated() { } public void OnLoaded() { } public void OnSaving() { if (RemindIn.HasValue) { AlarmTime = DueDate - RemindIn.Value; } else { AlarmTime = null; } if (AlarmTime == null) { RemindIn = null; IsPostponed = false; } } #endregion }
運行,輸入數據:
效果:
如何讓為指定的用戶指定通知?
[DefaultClassOptions] public class Task : ISupportNotifications, IXafEntityObject { // ... public virtual Employee AssignedTo { get; set; } }
下面是員工對象,下面是EF的例子,xpo區別的也不大:
using System.ComponentModel; using DevExpress.Persistent.Base; // ... [DefaultClassOptions, DefaultProperty("UserName")] public class Employee : DevExpress.Persistent.BaseImpl.EF.User { public Employee() { Tasks = new List<Task>(); } public virtual IList<Task> Tasks { get; set; } }
using DevExpress.Data.Filtering; using DevExpress.ExpressApp.Notifications; using DevExpress.Persistent.Base.General; // ... public override void Setup(XafApplication application) { base.Setup(application); application.LoggedOn += new EventHandler<LogonEventArgs>(application_LoggedOn); } void application_LoggedOn(object sender, LogonEventArgs e) { NotificationsModule notificationsModule = Application.Modules.FindModule<NotificationsModule>(); DefaultNotificationsProvider notificationsProvider = notificationsModule.DefaultNotificationsProvider; notificationsProvider.CustomizeNotificationCollectionCriteria += notificationsProvider_CustomizeNotificationCollectionCriteria; } void notificationsProvider_CustomizeNotificationCollectionCriteria( object sender, CustomizeCollectionCriteriaEventArgs e) { if (e.Type == typeof(Task)) { e.Criteria = CriteriaOperator.Parse("AssignedTo is null || AssignedTo.Id == CurrentUserId()");
//可以看到,這里有個過濾條件,即,通知時,使用什么條件進行過濾. } }
如果使用調度模塊,則可以使用下面的代碼:
using DevExpress.ExpressApp.Scheduler; // ... void application_LoggedOn(object sender, LogonEventArgs e) { SchedulerModuleBase schedulerModule = Application.Modules.FindModule<SchedulerModuleBase>(); NotificationsProvider notificationsProvider = schedulerModule.NotificationsProvider; notificationsProvider.CustomizeNotificationCollectionCriteria += notificationsProvider_CustomizeNotificationCollectionCriteria; }
默認情況下,通知刷新間隔是 5 分鐘。出于測試目的,可以減少此時間間隔。
雙擊WIN應用程序項目的 WinApplication.cs(vb) 文件,在模塊部分的模塊設計器中選擇NotificationsModule。在屬性窗口中,將 NotificationsModule.NotificationsRefreshInterval 設置為 10 秒。
同樣的,在WEB項目的WebApplication.cs(vb) 文件中也需要做這個。
如需演示項目的源碼,可以在留言中留下郵箱!
文章列表
全站熱搜