123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using System;
- using System.ComponentModel;
- using WMS.Info;
- namespace WMS.BZServices
- {
- /// <summary>
- /// 描 述:消息类型
- /// </summary>
- [Description("异常类型")]
- public enum ESysExType
- {
- /// <summary>
- /// 登录IP限制
- /// </summary>
- [Description("登录时间限制")]
- FilterTimeError = -9,
- /// <summary>
- /// 登录IP限制
- /// </summary>
- [Description("登录IP限制")]
- FilterIPError = -8,
- /// <summary>
- /// 数据库连接配置异常
- /// </summary>
- [Description("数据库连接配置异常")]
- DbSetError = -7,
- /// <summary>
- /// 数据库连接异常
- /// </summary>
- [Description("数据库连接异常")]
- DbConnError = -6,
- /// <summary>
- /// 数据库连接异常
- /// </summary>
- [Description("密码初始化")]
- PwdInit = -5,
- /// <summary>
- /// 密码错误
- /// </summary>
- [Description("密码错误")]
- PwdError = -4,
- /// <summary>
- /// 密码过期
- /// </summary>
- [Description("密码过期")]
- PwdExpiration = -3,
- /// <summary>
- /// 密码过期
- /// </summary>
- [Description("登录超时")]
- LoginTimeout = -2,
- /// <summary>
- /// 异常清息
- /// </summary>
- [Description("异常清息")]
- Exception = -1,
- /// <summary>
- /// 失败清息
- /// </summary>
- [Description("失败清息")]
- Fail = 0,
- }
- public class BZSysExCore : Exception
- {
- /// <summary>
- /// 异常消息
- /// </summary>
- public string ExMsg { get; private set; }
- /// <summary>
- /// 内部异常
- /// </summary>
- public Exception Ex { get; private set; }
- /// <summary>
- /// 消息类型
- /// </summary>
- public ESysExType SysExType { get; private set; } = ESysExType.Exception;
- //带有一个字符串参数和一个内部异常信息参数的构造函数
- public BZSysExCore(ESysExType sysExType, string exMsg, Exception innerException) : base(exMsg, innerException)
- {
- Ex = innerException;
- ExMsg = exMsg;
- SysExType = sysExType;
- }
- public BZSysExCore(ESysExType sysExType, string exMsg) : base(exMsg)
- {
- ExMsg = exMsg;
- SysExType = sysExType;
- }
- /// <summary>
- /// 错误提示信息
- /// </summary>
- public static BZSysExCore ThrowFailException(string exMsg)
- {
- return new BZSysExCore(ESysExType.Fail, exMsg);
- }
- /// <summary>
- /// 错误提示信息
- /// </summary>
- public static BZSysExCore ThrowInEmpty()
- {
- return new BZSysExCore(ESysExType.Fail, "请求数据为空。");
- }
- /// <summary>
- /// token无效
- /// </summary>
- public static BZSysExCore ThrowToken()
- {
- return new BZSysExCore(ESysExType.LoginTimeout, "当前登录token无效,请重新登录后再操作。");
- }
- /// <summary>
- /// 登录超时
- /// </summary>
- public static BZSysExCore ThrowLoginTimeout()
- {
- return new BZSysExCore(ESysExType.LoginTimeout, "登录超时,请重新登录!");
- }
- /// <summary>
- /// 密码过期
- /// </summary>
- public static BZSysExCore ThrowPwdExpiration()
- {
- return new BZSysExCore(ESysExType.PwdExpiration, "用户密码已过期。");
- }
- /// <summary>
- /// 数据库连接配置文件异常
- /// </summary>
- public static BZSysExCore ThrowDbSetError()
- {
- return new BZSysExCore(ESysExType.DbSetError, "数据库连接配置文件异常,请联系管理员。");
- }
- /// <summary>
- /// 数据库连接配置文件异常
- /// </summary>
- public static BZSysExCore ThrowDbConnError(Exception ex)
- {
- return new BZSysExCore(ESysExType.DbConnError, ex.Message, ex);
- }
- public static BZSysExCore GetSysExCore(Exception ex)
- {
- if (ex is BZSysExCore)
- {
- return ex as BZSysExCore;
- }
- else
- {
- return new BZSysExCore(ESysExType.Exception, ex.Message, ex);
- }
- }
- public static ResInfo GetResErr(Exception ex, object data = null)
- {
- BZSysExCore ec;
- if (ex is BZSysExCore)
- {
- ec = ex as BZSysExCore;
- }
- else
- {
- ec = new BZSysExCore(ESysExType.Exception, ex.Message, ex);
- }
- EResponseCode rescode = EResponseCode.Fail;
- if (ec.SysExType == ESysExType.Exception)
- {
- rescode = EResponseCode.Exception;
- }
- else if (ec.SysExType == ESysExType.LoginTimeout)
- {
- rescode = EResponseCode.LoginTimeout;
- }
- else if (ec.SysExType == ESysExType.PwdExpiration)
- {
- rescode = EResponseCode.PwdExpiration;
- }
- else if (ec.SysExType == ESysExType.PwdInit)
- {
- rescode = EResponseCode.PwdInit;
- }
- else if (ec.SysExType == ESysExType.FilterIPError)
- {
- rescode = EResponseCode.FilterIPError;
- }
- else if (ec.SysExType == ESysExType.FilterTimeError)
- {
- rescode = EResponseCode.FilterTimeError;
- }
- ResInfo infos = new ResInfo();
- infos.code = rescode;
- infos.info = ex.Message;
- infos.data = data;
- return infos;
- //return new ResInfo() { code = rescode, info = ex.Message, data = data };
- }
- public static ResInfo GetResSucc(string Msg="", object data = null)
- {
- return new ResInfo() { code = EResponseCode.Success, data = data, info = string.IsNullOrWhiteSpace(Msg) ? "响应成功" : Msg };
- }
- }
- }
|