| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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
- {
- /// <summary>
- /// 提供异常、通知等对话弹窗
- /// </summary>
- public class ClientDialogs
- {
- private readonly static CommonCacher commonCacher = ObjectFactory.Resolve<CommonCacher>();
- private readonly static ClientCacher clientCacher = ObjectFactory.Resolve<ClientCacher>();
- 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;
- }
- }
- /// <summary>
- /// 创建一个异常弹窗
- /// </summary>
- /// <param name="exceptionBase"></param>
- /// <param name="dialogName"></param>
- 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}");
- }
- /// <summary>
- /// 创建一个提醒弹窗
- /// </summary>
- /// <param name="title">提醒标题</param>
- /// <param name="message">提醒内容</param>
- 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);
- /// <summary>
- /// 关闭特定Id的对话框
- /// </summary>
- /// <param name="id"></param>
- public static void CloseDialog(string id) => clientCacher.CloseDialog(id);
- /// <summary>
- /// 关闭所有对话框
- /// </summary>
- public static void CloseAllDialogs() => clientCacher.CloseAllDialogs();
- }
- }
|