zoukankan      html  css  js  c++  java
  • 定义一个返回结果类型的类[原创] [小例子]

    工作中,因为有好多的返回结果,而且都有着不同的结果和意义,于是就用了数据字典来定义了部分。
    详见代码。其中只列出了部分类型。

     1using System;
     2using System.Collections.Generic;
     3using System.Text;
     4
     5namespace AFC.BOM.Constants.Prompt
     6{
     7    /// <summary>
     8    /// ACC 认证返回结果 后四位 (LLLL代码)类型定义
     9    /// </summary>

    10    public class ACCValidateLastResult
    11    {
    12        private static Dictionary<int,string> accValidateLastResult = new Dictionary<int,string>();
    13
    14        /// <summary>
    15        /// 私有构造函数,以防止创建该类的实例
    16        /// </summary>

    17        private ACCValidateLastResult()
    18        
    19        }

    20
    21        /// <summary>
    22        /// 类的构造函数,在类(而不是实例)首次使用时调用,且在类的生命周期中仅调用一次
    23        /// </summary>

    24        static ACCValidateLastResult()
    25        {
    26            if (!InitACCValidateLastResult())
    27                throw new Exception();
    28        }

    29
    30        /// <summary>
    31        /// 初始化各种操作结果对应的中文信息
    32        /// </summary>
    33        /// <returns></returns>

    34        private static bool InitACCValidateLastResult()
    35        {
    36            try
    37            {
    38                /*
    39                 * LLLL代码含义    LLLL    说明                   
    40                 * */

    41                accValidateLastResult.Add(0"认证成功!");
    42                accValidateLastResult.Add(5"等待超时!");
    43                accValidateLastResult.Add(0x6283,"选择文件无效,文件或密钥校验错误,可能不是一票通sam卡!");
    44                accValidateLastResult.Add(0x6581,"写EEPROM不成功  ");       
    45                accValidateLastResult.Add(0x6983,"密钥被锁死!");
    46                accValidateLastResult.Add(0x9302,"MAC错误!");
    47                accValidateLastResult.Add(0x9403,"密钥未找到!");
    48                accValidateLastResult.Add(0x9406,"所需MAC不可用!");
    49                accValidateLastResult.Add(0xFEFC,"网络收发超时!"); 
    50                accValidateLastResult.Add(0xFEFB,"Sam卡已列入黑名单!");
    51                accValidateLastResult.Add(0xFEFA,"Sam卡不存在!");
    52            }

    53            catch
    54            {
    55                return false;
    56            }

    57
    58            return true;
    59        }

    60
    61        /// <summary>
    62        /// 通过索引来返回错误提示信息
    63        /// </summary>
    64        /// <param name="index">错误索引</param>
    65        /// <returns></returns>

    66        public static string GetaccValidateLastResultInfo(int index)
    67        {
    68            try
    69            {
    70                if (accValidateLastResult.ContainsKey(index))
    71                    return accValidateLastResult[index];            
    72            }

    73            catch
    74            {}
    75            return "其他错误(" + index.ToString("X4"+ ")!";
    76        }

    77    }

    78}

    79
  • 相关阅读:
    jquery toggle(listenerOdd, listenerEven)
    struts quick start
    hdu 1518 Square (dfs)
    hdu 2544 最短路 (最短路径)
    hdu 1754 I Hate It (线段树)
    hdu 1856 More is better (并查集)
    hdu 1358 Period (KMP)
    hdu 2616 Kill the monster (DFS)
    hdu 2579 Dating with girls(2) (bfs)
    zoj 2110 Tempter of the Bone (dfs)
  • 原文地址:https://www.cnblogs.com/winnxm/p/958403.html
Copyright © 2011-2022 走看看