예제 #1
0
 public static bool TryParse(string id, out IdCardNo idCardNo)
 {
     try
     {
         idCardNo = Parse(id);
         return(true);
     }
     catch
     {
         idCardNo = null;
         return(false);
     }
 }
예제 #2
0
 public static bool TryParse(string id, out IdCardNo idCardNo)
 {
     try
     {
         idCardNo = Parse(id);
         return true;
     }
     catch
     {
         idCardNo = null;
         return false;
     }
 }
예제 #3
0
        public static IdCardNo Parse(string id)
        {
            string error;
            string region_code;
            string str_birthday;
            int    gender_code;

            if (!TryCheck(id, out error))
            {
                throw new ArgumentException(error, "id");
            }

            if (id.Length == 15)
            {
                region_code  = id.Substring(0, 6);
                str_birthday = "19" + id.Substring(6, 6);
                gender_code  = id[14] - '0';
            }
            else
            {
                region_code  = id.Substring(0, 6);
                str_birthday = id.Substring(6, 8);
                gender_code  = id[16] - '0';
            }

            string   province, prefecture, contry, gender;
            DateTime birthday;

            contry     = s_County[region_code];
            prefecture = s_Prefecture[region_code.Substring(0, 4)];
            province   = s_Province[region_code.Substring(0, 2)];
            birthday   = DateTime.ParseExact(str_birthday, "yyyyMMdd", null);
            gender     = gender_code % 2 == 0 ? "F" : "M";
            IdCardNo idCardNo = new IdCardNo();

            idCardNo.County     = contry;
            idCardNo.Prefecture = prefecture;
            idCardNo.Province   = province;
            idCardNo.Birthday   = birthday;
            idCardNo.Gender     = gender;
            return(idCardNo);
        }
예제 #4
0
        public static IdCardNo Parse(string id)
        {
            string error;
            string region_code;
            string str_birthday;
            int gender_code;

            if (!TryCheck(id, out error))
            {
                throw new ArgumentException(error, "id");
            }

            if (id.Length == 15)
            {
                region_code = id.Substring(0, 6);
                str_birthday = "19" + id.Substring(6, 6);
                gender_code = id[14]-'0';
            }
            else
            {
                region_code = id.Substring(0, 6);
                str_birthday = id.Substring(6, 8);
                gender_code = id[16]- '0';
            }

            string province, prefecture, contry, gender;
            DateTime birthday;
            contry = s_County[region_code];
            prefecture = s_Prefecture[region_code.Substring(0, 4)];
            province = s_Province[region_code.Substring(0, 2)];
            birthday = DateTime.ParseExact(str_birthday, "yyyyMMdd", null);
            gender = gender_code % 2 == 0 ? "F" : "M";
            IdCardNo idCardNo = new IdCardNo();
            idCardNo.County = contry;
            idCardNo.Prefecture = prefecture;
            idCardNo.Province = province;
            idCardNo.Birthday = birthday;
            idCardNo.Gender = gender;
            return idCardNo;
        }