XAF-通知模块概述 web+win

通知模块概述

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) 文件中也需要做这个

如需演示项目的源码,可以在留言中留下邮箱!

posted @ 2017-04-04 19:38  code first life  阅读(1679)  评论(3编辑  收藏  举报