| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- //----------------------------------------------------------------
- //Module Name: ErrorManager
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime Author Description
- //----------------------------------------------------------------
- //2014-03-31 deng.yinping Create
- //----------------------------------------------------------------
- using Muchinfo.MTPClient.CustomException;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.WPF.Controls.Windows;
- using System;
- using System.Windows;
- using Muchinfo.MTPClient.Infrastructure.MessageBox;
- namespace Muchinfo.MTPClient.Infrastructure.Utilities
- {
- public class ErrorManager
- {
- /// <summary>
- /// 显示错误码对应错误信息
- /// </summary>
- /// <param name="returnCode">The return code.</param>
- /// <param name="caption">The caption.</param>
- /// <param name="isLogin">if set to <c>true</c> [is login].</param>
- public static void ShowReturnError(int returnCode, string caption, bool isLogin = false)
- {
- ShowReturnError(Application.Current.MainWindow, returnCode, caption, isLogin);
- }
- /// <summary>
- /// 显示错误码对应错误信息
- /// </summary>
- /// <param name="returnCode">The return code.</param>
- /// <param name="caption">The caption.</param>
- /// <param name="isLogin">if set to <c>true</c> [is login].</param>
- public static void ShowReturnError(ErrorEntity errorEntity, string caption, bool isLogin = false)
- {
- var message= FormatErrorMsg(errorEntity);
- MessageBoxHelper.ShowInfo(Application.Current.MainWindow, message, caption, isLogin);
-
- }
- /// <summary>
- /// Shows the return error.
- /// </summary>
- /// <param name="owner">The owner.</param>
- /// <param name="returnCode">The return code.</param>
- /// <param name="caption">The caption.</param>
- /// <param name="isLogin">if set to <c>true</c> [is login].</param>
- public static void ShowReturnError(Window owner, int returnCode, string caption, bool isLogin = false)
- {
- var message = MuchinfoException.ErrorDesc(returnCode );
- if (string.IsNullOrWhiteSpace(message))
- {
- message = Environment.NewLine + Client_Resource.Infrastructure_UnknowErrorCode + returnCode;
- }
- else
- {
- message += Environment.NewLine + Client_Resource.Infrastructure_ErrorCode + returnCode;
- }
- MessageBoxHelper.ShowInfo(owner, message, caption, isLogin);
- }
- /// <summary>
- /// 转换
- /// </summary>
- /// <param name="errorEntity"></param>
- /// <returns></returns>
- public static string FormatErrorMsg(ErrorEntity errorEntity)
- {
- if (errorEntity == null) return string.Empty;
- if (errorEntity.ReturnDesc.ToLower().Contains("check"))//临时方案,以后服务端去掉返回信息!
- {
- errorEntity.ReturnDesc = "";
- }
-
- //var message = string.IsNullOrWhiteSpace(errorEntity.ReturnDesc) ? MuchinfoException.ErrorDesc(errorEntity.ReturnCode ) : errorEntity.ReturnDesc;
- var message = MuchinfoException.ErrorDesc(errorEntity.ReturnCode);
- if (string.IsNullOrEmpty(message))
- {
- message = errorEntity.ReturnDesc;
- }
- if (string.IsNullOrWhiteSpace(message))
- {
- message =
- message = Client_Resource.CustomException_UnknowCode + errorEntity.ReturnCode;
- }
- else
- {
- message += Environment.NewLine + Client_Resource.CustomException_Code + errorEntity.ReturnCode;
- if (!string.IsNullOrWhiteSpace(errorEntity.RequestFunc))
- {
- message += Environment.NewLine + errorEntity.RequestFunc;//请求方法描述
- }
- }
- return message;
- }
- }
- }
|