添加消息通知功能,使用Handy Control的Grow来实现的
This commit is contained in:
77
Services/GrowlNotificationService.cs
Normal file
77
Services/GrowlNotificationService.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using HandyControl.Controls;
|
||||
using PMSWPF.Enums;
|
||||
using Notification = PMSWPF.Models.Notification;
|
||||
|
||||
namespace PMSWPF.Services;
|
||||
|
||||
public class GrowlNotificationService : INotificationService
|
||||
{
|
||||
public void Show(Notification notification)
|
||||
{
|
||||
if (notification == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (notification.IsGlobal)
|
||||
{
|
||||
switch (notification.Type)
|
||||
{
|
||||
case NotificationType.Info:
|
||||
Growl.InfoGlobal(notification.Message);
|
||||
break;
|
||||
case NotificationType.Error:
|
||||
Growl.ErrorGlobal(notification.Message);
|
||||
break;
|
||||
case NotificationType.Warning:
|
||||
Growl.WarningGlobal(notification.Message);
|
||||
break;
|
||||
case NotificationType.Success:
|
||||
Growl.SuccessGlobal(notification.Message);
|
||||
break;
|
||||
case NotificationType.Fatal:
|
||||
Growl.FatalGlobal(notification.Message);
|
||||
break;
|
||||
case NotificationType.Clear:
|
||||
Growl.ClearGlobal();
|
||||
break;
|
||||
default:
|
||||
Growl.InfoGlobal(notification.Message);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (notification.Type)
|
||||
{
|
||||
case NotificationType.Info:
|
||||
Growl.Info(notification.Message);
|
||||
break;
|
||||
case NotificationType.Error:
|
||||
Growl.Error(notification.Message);
|
||||
break;
|
||||
case NotificationType.Warning:
|
||||
Growl.Warning(notification.Message);
|
||||
break;
|
||||
case NotificationType.Success:
|
||||
Growl.Success(notification.Message);
|
||||
break;
|
||||
case NotificationType.Fatal:
|
||||
Growl.Fatal(notification.Message);
|
||||
break;
|
||||
case NotificationType.Clear:
|
||||
Growl.Clear();
|
||||
break;
|
||||
default:
|
||||
Growl.Info(notification.Message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Show(string message, NotificationType type=NotificationType.Info,bool IsGlobal=true)
|
||||
{
|
||||
Show(new Notification(){Message = message,Type = type,IsGlobal = IsGlobal});
|
||||
}
|
||||
}
|
||||
10
Services/INotificationService.cs
Normal file
10
Services/INotificationService.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using PMSWPF.Enums;
|
||||
using PMSWPF.Models;
|
||||
|
||||
namespace PMSWPF.Services;
|
||||
|
||||
public interface INotificationService
|
||||
{
|
||||
void Show(Notification notification);
|
||||
void Show(string message, NotificationType type, bool IsGlobal);
|
||||
}
|
||||
Reference in New Issue
Block a user