//----------------------------------------------------------------
//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
{
///
/// 显示错误码对应错误信息
///
/// The return code.
/// The caption.
/// if set to true [is login].
public static void ShowReturnError(int returnCode, string caption, bool isLogin = false)
{
ShowReturnError(Application.Current.MainWindow, returnCode, caption, isLogin);
}
///
/// 显示错误码对应错误信息
///
/// The return code.
/// The caption.
/// if set to true [is login].
public static void ShowReturnError(ErrorEntity errorEntity, string caption, bool isLogin = false)
{
var message= FormatErrorMsg(errorEntity);
MessageBoxHelper.ShowInfo(Application.Current.MainWindow, message, caption, isLogin);
}
///
/// Shows the return error.
///
/// The owner.
/// The return code.
/// The caption.
/// if set to true [is login].
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);
}
///
/// 转换
///
///
///
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;
}
}
}