ClientDialogs.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using Prism.Services.Dialogs;
  2. using SKMC.Api.Client.Config;
  3. using SKMC.Api.Client.Model;
  4. using SKMC.Api.Core;
  5. using SKMC.Api.Core.Exceptions;
  6. using System;
  7. using System.Windows;
  8. namespace SKMC.Api.Client.UI
  9. {
  10. /// <summary>
  11. /// 提供异常、通知等对话弹窗
  12. /// </summary>
  13. public class ClientDialogs
  14. {
  15. private readonly static ExceptionCacher commonCacher = ObjectFactory.Resolve<ExceptionCacher>();
  16. private readonly static ClientCacher clientCacher = ObjectFactory.Resolve<ClientCacher>();
  17. public const string DefaultViewName = ClientConstants.Views_CommonException;
  18. public const string NoticeViewName = ClientConstants.Views_CommonNotification;
  19. public static string CreateExceptionDialog(ExceptionShow exceptionShow, string dialogName = DefaultViewName)
  20. {
  21. if (exceptionShow == null) return null;
  22. if (dialogName != null)
  23. {
  24. return clientCacher.ShowExceptionDialog(dialogName, exceptionShow);
  25. }
  26. else
  27. {
  28. CreateExceptionDialog(exceptionShow);
  29. return null;
  30. }
  31. }
  32. /// <summary>
  33. /// 创建一个异常弹窗
  34. /// </summary>
  35. /// <param name="exceptionBase"></param>
  36. /// <param name="dialogName"></param>
  37. public static string CreateExceptionDialog(ExceptionBase exceptionBase, string dialogName = DefaultViewName)
  38. {
  39. if (exceptionBase == null) return null;
  40. ExceptionShow exceptionShow = commonCacher.GetExceptionShow(exceptionBase);
  41. return CreateExceptionDialog(exceptionShow, dialogName);
  42. }
  43. public static void CreateExceptionDialog(Exception exception)
  44. {
  45. MessageBox.Show($"出现未知异常: {exception.Message}, Detail: {exception.StackTrace}");
  46. }
  47. public static void CreateExceptionDialog(ExceptionShow exceptionShow)
  48. {
  49. MessageBox.Show($"出现异常, Code:{exceptionShow.Code}, Name: {exceptionShow.Name}, Level: {exceptionShow.Level}");
  50. }
  51. /// <summary>
  52. /// 创建一个提醒弹窗
  53. /// </summary>
  54. /// <param name="title">提醒标题</param>
  55. /// <param name="message">提醒内容</param>
  56. public static string CreateNotificationDialog(string title, string message, byte level = 0)
  57. {
  58. DialogParameters parameters = new DialogParameters();
  59. parameters.Add("model", new ClientNotification
  60. {
  61. Head = title,
  62. Detail = message,
  63. DateTime = DateTime.Now,
  64. Level = level
  65. });
  66. return clientCacher.ShowCommonDialog(NoticeViewName, parameters, null, false);
  67. }
  68. public static bool IsDialogShow(string id) => clientCacher.IsDialogShow(id);
  69. /// <summary>
  70. /// 关闭特定Id的对话框
  71. /// </summary>
  72. /// <param name="id"></param>
  73. public static void CloseDialog(string id) => clientCacher.CloseDialog(id);
  74. /// <summary>
  75. /// 关闭所有对话框
  76. /// </summary>
  77. public static void CloseAllDialogs() => clientCacher.CloseAllDialogs();
  78. }
  79. }