using Prism.Services.Dialogs;
using SKMC.Api.Client.Config;
using SKMC.Api.Client.Model;
using SKMC.Api.Common;
using SKMC.Api.Common.Exceptions;
using System;
using System.Windows;
namespace SKMC.Api.Client.UI
{
///
/// 提供异常、通知等对话弹窗
///
public class ClientDialogs
{
private readonly static CommonCacher commonCacher = ObjectFactory.Resolve();
private readonly static ClientCacher clientCacher = ObjectFactory.Resolve();
public const string DefaultViewName = ClientConstants.Views_CommonException;
public const string NoticeViewName = ClientConstants.Views_CommonNotification;
public static string CreateExceptionDialog(ExceptionShow exceptionShow, string dialogName = DefaultViewName)
{
if (exceptionShow == null) return null;
if (dialogName != null)
{
return clientCacher.ShowExceptionDialog(dialogName, exceptionShow);
}
else
{
CreateExceptionDialog(exceptionShow);
return null;
}
}
///
/// 创建一个异常弹窗
///
///
///
public static string CreateExceptionDialog(ExceptionBase exceptionBase, string dialogName = DefaultViewName)
{
if (exceptionBase == null) return null;
ExceptionShow exceptionShow = commonCacher.GetExceptionShow(exceptionBase);
return CreateExceptionDialog(exceptionShow, dialogName);
}
public static void CreateExceptionDialog(Exception exception)
{
MessageBox.Show($"出现未知异常: {exception.Message}, Detail: {exception.StackTrace}");
}
public static void CreateExceptionDialog(ExceptionShow exceptionShow)
{
MessageBox.Show($"出现异常, Code:{exceptionShow.Code}, Name: {exceptionShow.Name}, Level: {exceptionShow.Level}");
}
///
/// 创建一个提醒弹窗
///
/// 提醒标题
/// 提醒内容
public static string CreateNotificationDialog(string title, string message, byte level = 0)
{
DialogParameters parameters = new DialogParameters();
parameters.Add("model", new ClientNotification
{
Head = title,
Detail = message,
DateTime = DateTime.Now,
Level = level
});
return clientCacher.ShowCommonDialog(NoticeViewName, parameters, null, false);
}
public static bool IsDialogShow(string id) => clientCacher.IsDialogShow(id);
///
/// 关闭特定Id的对话框
///
///
public static void CloseDialog(string id) => clientCacher.CloseDialog(id);
///
/// 关闭所有对话框
///
public static void CloseAllDialogs() => clientCacher.CloseAllDialogs();
}
}