显示众多结果信息方法[原]
常常项目中,需要显示一些返回的正确或错误信息,常用的方法有:
1
using System;
2
using System.Collections.Generic;
3
using System.Reflection;
4
using System.Text;
5![]()
6
namespace AFC.WorkStation.Comm
7
{
8
public static class WinSockErrorCode
9
{
10
// Return code/value ;
11
public const int WSA_INVALID_HANDLE = 6;
12
public const int WSA_NOT_ENOUGH_MEMORY = 8;
13
public const int WSA_INVALID_PARAMETER = 87;
14
public const int WSA_OPERATION_ABORTED = 995;
15
public const int WSA_IO_INCOMPLETE = 996;
16
public const int WSA_IO_PENDING = 997;
17
public const int WSAEINTR = 10004;
18
public const int WSAEBADF = 10009;
19
public const int WSAEACCES = 10013;
20
public const int WSAEFAULT = 10014;
21
public const int WSAEINVAL = 10022;
22
public const int WSAEMFILE = 10024;
23
public const int WSA_QOS_BAD_OBJECT = 11013;
24
public const int WSA_QOS_TRAFFIC_CTRL_ERROR = 11014;
25
public const int WSA_QOS_GENERIC_ERROR = 11015;
26
public const int WSA_QOS_ESERVICETYPE = 11016;
27
public const int WSA_QOS_EFLOWSPEC = 11017;
28
public const int WSA_QOS_EPROVSPECBUF = 11018;
29
public const int WSA_QOS_EFILTERSTYLE = 11019;
30
public const int WSA_QOS_EFILTERTYPE = 11020;
31
public const int WSA_QOS_EFILTERCOUNT = 11021;
32
public const int WSA_QOS_EOBJLENGTH = 11022;
33
public const int WSA_QOS_EFLOWCOUNT = 11023;
34
public const int WSA_QOS_EUNKOWNPSOBJ = 11024;
35
public const int WSA_QOS_EPOLICYOBJ = 11025;
36
public const int WSA_QOS_EFLOWDESC = 11026;
37
public const int WSA_QOS_EPSFLOWSPEC = 11027;
38
public const int WSA_QOS_EPSFILTERSPEC = 11028;
39
public const int WSA_QOS_ESDMODEOBJ = 11029;
40
public const int WSA_QOS_ESHAPERATEOBJ = 11030;
41
public const int WSA_QOS_RESERVED_PETYPE = 11031;
42
43
public static string GetErrorCodeName(int retcode)
44
{
45
Type constType = typeof(WinSockErrorCode);
46![]()
47
FieldInfo[] fields = constType.GetFields();
48![]()
49
for (int i = 0; i < fields.Length; i++)
50
{
51
FieldInfo info = fields[i];
52
if (info.FieldType == typeof(int) &&
53
retcode.Equals(info.GetValue(null)))
54
return info.Name;
55
}
56![]()
57
return "WSA_UNKOWN_ERROR";
58
}
59
}
60
}
61![]()
或者如下方式:
using System;2
using System.Collections.Generic;3
using System.Reflection;4
using System.Text;5

6
namespace AFC.WorkStation.Comm7
{8
public static class WinSockErrorCode9
{10
// Return code/value ;11
public const int WSA_INVALID_HANDLE = 6;12
public const int WSA_NOT_ENOUGH_MEMORY = 8;13
public const int WSA_INVALID_PARAMETER = 87;14
public const int WSA_OPERATION_ABORTED = 995;15
public const int WSA_IO_INCOMPLETE = 996;16
public const int WSA_IO_PENDING = 997;17
public const int WSAEINTR = 10004;18
public const int WSAEBADF = 10009;19
public const int WSAEACCES = 10013;20
public const int WSAEFAULT = 10014;21
public const int WSAEINVAL = 10022;22
public const int WSAEMFILE = 10024; 23
public const int WSA_QOS_BAD_OBJECT = 11013;24
public const int WSA_QOS_TRAFFIC_CTRL_ERROR = 11014;25
public const int WSA_QOS_GENERIC_ERROR = 11015;26
public const int WSA_QOS_ESERVICETYPE = 11016;27
public const int WSA_QOS_EFLOWSPEC = 11017;28
public const int WSA_QOS_EPROVSPECBUF = 11018;29
public const int WSA_QOS_EFILTERSTYLE = 11019;30
public const int WSA_QOS_EFILTERTYPE = 11020;31
public const int WSA_QOS_EFILTERCOUNT = 11021;32
public const int WSA_QOS_EOBJLENGTH = 11022;33
public const int WSA_QOS_EFLOWCOUNT = 11023;34
public const int WSA_QOS_EUNKOWNPSOBJ = 11024;35
public const int WSA_QOS_EPOLICYOBJ = 11025;36
public const int WSA_QOS_EFLOWDESC = 11026;37
public const int WSA_QOS_EPSFLOWSPEC = 11027;38
public const int WSA_QOS_EPSFILTERSPEC = 11028;39
public const int WSA_QOS_ESDMODEOBJ = 11029;40
public const int WSA_QOS_ESHAPERATEOBJ = 11030;41
public const int WSA_QOS_RESERVED_PETYPE = 11031;42
43
public static string GetErrorCodeName(int retcode)44
{45
Type constType = typeof(WinSockErrorCode);46

47
FieldInfo[] fields = constType.GetFields();48

49
for (int i = 0; i < fields.Length; i++)50
{51
FieldInfo info = fields[i];52
if (info.FieldType == typeof(int) &&53
retcode.Equals(info.GetValue(null)))54
return info.Name;55
}56

57
return "WSA_UNKOWN_ERROR";58
}59
}60
}61

1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4![]()
5
namespace AFC.BOM.Constants.Prompt
6
{
7
public class OCTErrorResultCode
8
{
9
private static Dictionary<int,string> OCTResultCode = new Dictionary<int,string>();
10![]()
11
/// <summary>
12
/// 私有构造函数,以防止创建该类的实例
13
/// </summary>
14
private OCTErrorResultCode()
15
{
16
}
17![]()
18
/// <summary>
19
/// 类的构造函数,在类(而不是实例)首次使用时调用,且在类的生命周期中仅调用一次
20
/// </summary>
21
static OCTErrorResultCode()
22
{
23
if (!InitOCTErrorResultCode())
24
throw new Exception();
25
}
26![]()
27
/// <summary>
28
/// 初始化各种操作结果对应的中文信息
29
/// </summary>
30
/// <returns></returns>
31
private static bool InitOCTErrorResultCode()
32
{
33
try
34
{
35
/*
36
* HHHH代码含义 HHHH 说明
37
* */
38
OCTResultCode.Add(0x01, "无效的消息类型码!");
39
OCTResultCode.Add(0x02, "无效的消息版本 !");
40
OCTResultCode.Add(0x03, "报文格式错误 !");
41
OCTResultCode.Add(0x04, "报文长度无效!");
42
OCTResultCode.Add(0x05, "无效的加密压缩算法!");
43
OCTResultCode.Add(0x06, "通讯MAC错!");
44
OCTResultCode.Add(0x07, "通讯目标节点不可到达!");
45
OCTResultCode.Add(0x08, "通讯超时!");
46
OCTResultCode.Add(0x09, "操作员不存在!");
47
OCTResultCode.Add(0x0A, "操作员口令错误!");
48
OCTResultCode.Add(0x0B, "POS机号不存在!");
49
OCTResultCode.Add(0x0C, "POS机已禁用!");
50
OCTResultCode.Add(0x0D, "SAM卡号不存在!");
51
OCTResultCode.Add(0x0E, "SAM卡号已禁用!");
52
OCTResultCode.Add(0x12, "操作员无权操作SAM卡!");
53
OCTResultCode.Add(0x13, "SAM卡与POS机对应关系错!");
54
OCTResultCode.Add(0x14, "SAM卡尚未签退!");
55
OCTResultCode.Add(0x15, "SAM卡尚未签到!");
56
OCTResultCode.Add(0x16, "上一日充值交易未上送完毕未及时上传交易!");
57
OCTResultCode.Add(0x1D, "无效的参数代码!");
58
OCTResultCode.Add(0x1E, "参数不允许下载!");
59
OCTResultCode.Add(0x23, "其它未定义的错误!");
60
OCTResultCode.Add(0x24, "参数未下载!");
61
OCTResultCode.Add(0x25, "审核数据认证失败!");
62
OCTResultCode.Add(0x28, "程序未升级!");
63
OCTResultCode.Add(0x51, "初始化读卡器通讯端口失败!");
64
OCTResultCode.Add(0x52, "创建SOCKET失败!");
65
OCTResultCode.Add(0x53, "读ISAM卡号失败!");
66
OCTResultCode.Add(0x54, "SOCKET发送失败!");
67
OCTResultCode.Add(0x55, "SOCKET接收失败!");
68
OCTResultCode.Add(0x56, "关闭端口失败!");
69
OCTResultCode.Add(0x57, "签退计算审核数据失败!");
70
OCTResultCode.Add(0x58, "签退SAM复位失败!");
71
OCTResultCode.Add(0x59, "签到认证失败!");
72
OCTResultCode.Add(0x60, "参数下载失败!");
73
OCTResultCode.Add(0x61, "加载读写器驱动库ACC.DLL失败!");
74
OCTResultCode.Add(0x62, "接收无效的消息类型码!");
75
OCTResultCode.Add(0x63, "本地签到数据表为空!");
76
OCTResultCode.Add(0x64, "代码异常!");
77
}
78
catch
79
{
80
return false;
81
}
82![]()
83
return true;
84
}
85![]()
86
/// <summary>
87
/// 通过索引来返回错误提示信息
88
/// </summary>
89
/// <param name="index">错误索引</param>
90
/// <returns></returns>
91
public static string GetOCTResultCodeInfo(int index)
92
{
93
try
94
{
95
if (OCTResultCode.ContainsKey(index))
96
return OCTResultCode[index];
97
}
98
catch
99
{}
100
return "严重错误,不可重试!";
101![]()
102
}
103
}
104
}
105![]()
using System;2
using System.Collections.Generic;3
using System.Text;4

5
namespace AFC.BOM.Constants.Prompt6
{7
public class OCTErrorResultCode8
{9
private static Dictionary<int,string> OCTResultCode = new Dictionary<int,string>();10

11
/// <summary>12
/// 私有构造函数,以防止创建该类的实例13
/// </summary>14
private OCTErrorResultCode()15
{ 16
}17

18
/// <summary>19
/// 类的构造函数,在类(而不是实例)首次使用时调用,且在类的生命周期中仅调用一次20
/// </summary>21
static OCTErrorResultCode()22
{23
if (!InitOCTErrorResultCode())24
throw new Exception();25
}26

27
/// <summary>28
/// 初始化各种操作结果对应的中文信息29
/// </summary>30
/// <returns></returns>31
private static bool InitOCTErrorResultCode()32
{33
try34
{35
/*36
* HHHH代码含义 HHHH 说明 37
* */38
OCTResultCode.Add(0x01, "无效的消息类型码!");39
OCTResultCode.Add(0x02, "无效的消息版本 !");40
OCTResultCode.Add(0x03, "报文格式错误 !");41
OCTResultCode.Add(0x04, "报文长度无效!");42
OCTResultCode.Add(0x05, "无效的加密压缩算法!");43
OCTResultCode.Add(0x06, "通讯MAC错!");44
OCTResultCode.Add(0x07, "通讯目标节点不可到达!");45
OCTResultCode.Add(0x08, "通讯超时!");46
OCTResultCode.Add(0x09, "操作员不存在!");47
OCTResultCode.Add(0x0A, "操作员口令错误!");48
OCTResultCode.Add(0x0B, "POS机号不存在!");49
OCTResultCode.Add(0x0C, "POS机已禁用!");50
OCTResultCode.Add(0x0D, "SAM卡号不存在!");51
OCTResultCode.Add(0x0E, "SAM卡号已禁用!");52
OCTResultCode.Add(0x12, "操作员无权操作SAM卡!");53
OCTResultCode.Add(0x13, "SAM卡与POS机对应关系错!");54
OCTResultCode.Add(0x14, "SAM卡尚未签退!");55
OCTResultCode.Add(0x15, "SAM卡尚未签到!");56
OCTResultCode.Add(0x16, "上一日充值交易未上送完毕未及时上传交易!");57
OCTResultCode.Add(0x1D, "无效的参数代码!");58
OCTResultCode.Add(0x1E, "参数不允许下载!");59
OCTResultCode.Add(0x23, "其它未定义的错误!");60
OCTResultCode.Add(0x24, "参数未下载!");61
OCTResultCode.Add(0x25, "审核数据认证失败!");62
OCTResultCode.Add(0x28, "程序未升级!");63
OCTResultCode.Add(0x51, "初始化读卡器通讯端口失败!");64
OCTResultCode.Add(0x52, "创建SOCKET失败!");65
OCTResultCode.Add(0x53, "读ISAM卡号失败!");66
OCTResultCode.Add(0x54, "SOCKET发送失败!");67
OCTResultCode.Add(0x55, "SOCKET接收失败!");68
OCTResultCode.Add(0x56, "关闭端口失败!");69
OCTResultCode.Add(0x57, "签退计算审核数据失败!");70
OCTResultCode.Add(0x58, "签退SAM复位失败!");71
OCTResultCode.Add(0x59, "签到认证失败!");72
OCTResultCode.Add(0x60, "参数下载失败!");73
OCTResultCode.Add(0x61, "加载读写器驱动库ACC.DLL失败!");74
OCTResultCode.Add(0x62, "接收无效的消息类型码!");75
OCTResultCode.Add(0x63, "本地签到数据表为空!");76
OCTResultCode.Add(0x64, "代码异常!");77
}78
catch79
{80
return false;81
}82

83
return true;84
}85

86
/// <summary>87
/// 通过索引来返回错误提示信息88
/// </summary>89
/// <param name="index">错误索引</param>90
/// <returns></returns>91
public static string GetOCTResultCodeInfo(int index)92
{93
try94
{95
if (OCTResultCode.ContainsKey(index))96
return OCTResultCode[index]; 97
}98
catch99
{}100
return "严重错误,不可重试!";101

102
}103
}104
}105



浙公网安备 33010602011771号