ErrorManager.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //----------------------------------------------------------------
  2. //Module Name: ErrorManager
  3. //Purpose:
  4. //CopyRight: Muchinfo
  5. //History:
  6. //----------------------------------------------------------------
  7. //DateTime Author Description
  8. //----------------------------------------------------------------
  9. //2014-03-31 deng.yinping Create
  10. //----------------------------------------------------------------
  11. using Muchinfo.MTPClient.CustomException;
  12. using Muchinfo.MTPClient.Data;
  13. using Muchinfo.MTPClient.Resources;
  14. using Muchinfo.WPF.Controls.Windows;
  15. using System;
  16. using System.Windows;
  17. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  18. namespace Muchinfo.MTPClient.Infrastructure.Utilities
  19. {
  20. public class ErrorManager
  21. {
  22. /// <summary>
  23. /// 显示错误码对应错误信息
  24. /// </summary>
  25. /// <param name="returnCode">The return code.</param>
  26. /// <param name="caption">The caption.</param>
  27. /// <param name="isLogin">if set to <c>true</c> [is login].</param>
  28. public static void ShowReturnError(int returnCode, string caption, bool isLogin = false)
  29. {
  30. ShowReturnError(Application.Current.MainWindow, returnCode, caption, isLogin);
  31. }
  32. /// <summary>
  33. /// 显示错误码对应错误信息
  34. /// </summary>
  35. /// <param name="returnCode">The return code.</param>
  36. /// <param name="caption">The caption.</param>
  37. /// <param name="isLogin">if set to <c>true</c> [is login].</param>
  38. public static void ShowReturnError(ErrorEntity errorEntity, string caption, bool isLogin = false)
  39. {
  40. var message= FormatErrorMsg(errorEntity);
  41. MessageBoxHelper.ShowInfo(Application.Current.MainWindow, message, caption, isLogin);
  42. }
  43. /// <summary>
  44. /// Shows the return error.
  45. /// </summary>
  46. /// <param name="owner">The owner.</param>
  47. /// <param name="returnCode">The return code.</param>
  48. /// <param name="caption">The caption.</param>
  49. /// <param name="isLogin">if set to <c>true</c> [is login].</param>
  50. public static void ShowReturnError(Window owner, int returnCode, string caption, bool isLogin = false)
  51. {
  52. var message = MuchinfoException.ErrorDesc(returnCode );
  53. if (string.IsNullOrWhiteSpace(message))
  54. {
  55. message = Environment.NewLine + Client_Resource.Infrastructure_UnknowErrorCode + returnCode;
  56. }
  57. else
  58. {
  59. message += Environment.NewLine + Client_Resource.Infrastructure_ErrorCode + returnCode;
  60. }
  61. MessageBoxHelper.ShowInfo(owner, message, caption, isLogin);
  62. }
  63. /// <summary>
  64. /// 转换
  65. /// </summary>
  66. /// <param name="errorEntity"></param>
  67. /// <returns></returns>
  68. public static string FormatErrorMsg(ErrorEntity errorEntity)
  69. {
  70. if (errorEntity == null) return string.Empty;
  71. if (errorEntity.ReturnDesc.ToLower().Contains("check"))//临时方案,以后服务端去掉返回信息!
  72. {
  73. errorEntity.ReturnDesc = "";
  74. }
  75. //var message = string.IsNullOrWhiteSpace(errorEntity.ReturnDesc) ? MuchinfoException.ErrorDesc(errorEntity.ReturnCode ) : errorEntity.ReturnDesc;
  76. var message = MuchinfoException.ErrorDesc(errorEntity.ReturnCode);
  77. if (string.IsNullOrEmpty(message))
  78. {
  79. message = errorEntity.ReturnDesc;
  80. }
  81. if (string.IsNullOrWhiteSpace(message))
  82. {
  83. message =
  84. message = Client_Resource.CustomException_UnknowCode + errorEntity.ReturnCode;
  85. }
  86. else
  87. {
  88. message += Environment.NewLine + Client_Resource.CustomException_Code + errorEntity.ReturnCode;
  89. if (!string.IsNullOrWhiteSpace(errorEntity.RequestFunc))
  90. {
  91. message += Environment.NewLine + errorEntity.RequestFunc;//请求方法描述
  92. }
  93. }
  94. return message;
  95. }
  96. }
  97. }