热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

地区代码表(利用Hashtable实现)

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Collections;**
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
/**
 * 功能:通过两位地区码得到对应的地区简称、全称
 **/
namespace GetIDCardInfoDemo
{
    class DistrictCodeTable
    {
        /// 
        /// 地区代码表(默认为空,需初始化:简称、全称)
        /// 
        public Hashtable m_DistrictTB = new Hashtable();

        /// 
        /// 初始化:地区代码:简称
        /// 
        public void InitDistrictTable_Short()
        {
            m_DistrictTB.Clear();
            //11-15 京、津、冀、晋、蒙 
            m_DistrictTB.Add("11", "");
            m_DistrictTB.Add("12", "");
            m_DistrictTB.Add("13", "");
            m_DistrictTB.Add("14", "");
            m_DistrictTB.Add("15", "");
            //21-23 辽、吉、黑 
            m_DistrictTB.Add("21", "");
            m_DistrictTB.Add("22", "");
            m_DistrictTB.Add("23", "");
            //31-37 沪、苏、浙、皖、闽、赣、鲁 
            m_DistrictTB.Add("31", "");
            m_DistrictTB.Add("32", "");
            m_DistrictTB.Add("33", "");
            m_DistrictTB.Add("34", "");
            m_DistrictTB.Add("35", "");
            m_DistrictTB.Add("36", "");
            m_DistrictTB.Add("37", "");
            //41-46 豫、鄂、湘、粤、桂、琼 
            m_DistrictTB.Add("41", "");
            m_DistrictTB.Add("42", "");
            m_DistrictTB.Add("43", "");
            m_DistrictTB.Add("44", "");
            m_DistrictTB.Add("45", "");
            m_DistrictTB.Add("46", "");
            //50-54 渝、川、贵、云、藏 
            m_DistrictTB.Add("50", "");
            m_DistrictTB.Add("51", "");
            m_DistrictTB.Add("52", "");
            m_DistrictTB.Add("53", "");
            m_DistrictTB.Add("54", "");
            //61-65 陕、甘、青、宁、新 
            m_DistrictTB.Add("61", "");
            m_DistrictTB.Add("62", "");
            m_DistrictTB.Add("63", "");
            m_DistrictTB.Add("64", "");
            m_DistrictTB.Add("65", "");
            //71 台湾
            m_DistrictTB.Add("71", "");
            //81-82 港、澳 
            m_DistrictTB.Add("81", "");
            m_DistrictTB.Add("82", "");
            //91 国外
            m_DistrictTB.Add("91", "");
        }

        /// 
        /// 初始化:地区代码:全称
        /// 
        public void InitDistrictTable_Full()
        {
            m_DistrictTB.Clear();
            //11-15 京、津、冀、晋、蒙 
            m_DistrictTB.Add("11", "北京");
            m_DistrictTB.Add("12", "天津");
            m_DistrictTB.Add("13", "河北");
            m_DistrictTB.Add("14", "山西");
            m_DistrictTB.Add("15", "内蒙古");
            //21-23 辽、吉、黑 
            m_DistrictTB.Add("21", "辽宁");
            m_DistrictTB.Add("22", "吉林");
            m_DistrictTB.Add("23", "黑龙江");
            //31-37 沪、苏、浙、皖、闽、赣、鲁 
            m_DistrictTB.Add("31", "上海");
            m_DistrictTB.Add("32", "江苏");
            m_DistrictTB.Add("33", "浙江");
            m_DistrictTB.Add("34", "安徽");
            m_DistrictTB.Add("35", "福建");
            m_DistrictTB.Add("36", "江西");
            m_DistrictTB.Add("37", "山东");
            //41-46 豫、鄂、湘、粤、桂、琼 
            m_DistrictTB.Add("41", "河南");
            m_DistrictTB.Add("42", "湖北");
            m_DistrictTB.Add("43", "湖南");
            m_DistrictTB.Add("44", "广东");
            m_DistrictTB.Add("45", "广西");
            m_DistrictTB.Add("46", "海南");
            //50-54 渝、川、贵、云、藏 
            m_DistrictTB.Add("50", "重庆");
            m_DistrictTB.Add("51", "四川");
            m_DistrictTB.Add("52", "贵州");
            m_DistrictTB.Add("53", "云南");
            m_DistrictTB.Add("54", "西藏");
            //61-65 陕、甘、青、宁、新 
            m_DistrictTB.Add("61", "陕西");
            m_DistrictTB.Add("62", "甘肃");
            m_DistrictTB.Add("63", "青海");
            m_DistrictTB.Add("64", "宁夏");
            m_DistrictTB.Add("65", "新疆");
            //71 台湾
            m_DistrictTB.Add("71", "台湾");
            //81-82 港、澳 
            m_DistrictTB.Add("81", "香港");
            m_DistrictTB.Add("82", "澳门");
            //91 国外
            m_DistrictTB.Add("91", "国外");
        }

        /// 
        /// 地区代码返回结果类型:Full(全称)、Short(简称)
        /// 
        public enum DistrictResultType
        {
            /// 
            /// 全称
            /// 
            Full,
            /// 
            /// 简称
            /// 
            Short
        }

        /// 
        /// 通过两位地区码得到对应的地区名称
        /// 
        /// 两位地区码
        /// 返回类型:Full(全称)、Short(简称)
        /// 对应的地区名称
        public string GetDistrictCode(string code, int resType)
        {
            try
            {
                string codeStr = "错误地区";
                if (code.Length == 2)
                {
                    //初始化:全称
                    if (resType == (int)DistrictResultType.Full)
                    {
                        InitDistrictTable_Full();
                    }
                    //初始化:简称
                    if (resType == (int)DistrictResultType.Short)
                    {
                        InitDistrictTable_Short();
                    }
                    //获取对应键值的结果
                    if (m_DistrictTB.ContainsKey(code))
                    {
                        codeStr = m_DistrictTB[code].ToString();
                    }
                }
                return codeStr;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

 


推荐阅读
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 模板引擎StringTemplate的使用方法和特点
    本文介绍了模板引擎StringTemplate的使用方法和特点,包括强制Model和View的分离、Lazy-Evaluation、Recursive enable等。同时,还介绍了StringTemplate语法中的属性和普通字符的使用方法,并提供了向模板填充属性的示例代码。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 个人学习使用:谨慎参考1Client类importcom.thoughtworks.gauge.Step;importcom.thoughtworks.gauge.T ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 第四章高阶函数(参数传递、高阶函数、lambda表达式)(python进阶)的讲解和应用
    本文主要讲解了第四章高阶函数(参数传递、高阶函数、lambda表达式)的相关知识,包括函数参数传递机制和赋值机制、引用传递的概念和应用、默认参数的定义和使用等内容。同时介绍了高阶函数和lambda表达式的概念,并给出了一些实例代码进行演示。对于想要进一步提升python编程能力的读者来说,本文将是一个不错的学习资料。 ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • 本文介绍了一个适用于PHP应用快速接入TRX和TRC20数字资产的开发包,该开发包支持使用自有Tron区块链节点的应用场景,也支持基于Tron官方公共API服务的轻量级部署场景。提供的功能包括生成地址、验证地址、查询余额、交易转账、查询最新区块和查询交易信息等。详细信息可参考tron-php的Github地址:https://github.com/Fenguoz/tron-php。 ... [详细]
  • Android自定义控件绘图篇之Paint函数大汇总
    本文介绍了Android自定义控件绘图篇中的Paint函数大汇总,包括重置画笔、设置颜色、设置透明度、设置样式、设置宽度、设置抗锯齿等功能。通过学习这些函数,可以更好地掌握Paint的用法。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • 开发笔记:Java是如何读取和写入浏览器Cookies的
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了Java是如何读取和写入浏览器Cookies的相关的知识,希望对你有一定的参考价值。首先我 ... [详细]
  • GreenDAO快速入门
    前言之前在自己做项目的时候,用到了GreenDAO数据库,其实对于数据库辅助工具库从OrmLite,到litePal再到GreenDAO,总是在不停的切换,但是没有真正去了解他们的 ... [详细]
author-avatar
蕊蕊宝宝妈妈_534
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有