Esempio n. 1
0
        /// <summary>
        /// 批量生成身份证
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public static List <IDCardNumber> Radom(int count)
        {
            List <IDCardNumber> list = new List <IDCardNumber>();
            string cardNumber;
            bool   isExits;

            for (int i = 0; i < count; i++)
            {
                do
                {
                    isExits = false;
                    int tick = (int)DateTime.Now.Ticks;
                    cardNumber = IDCardNumber._radomCardNumber(tick * (i + 1));
                    foreach (IDCardNumber c in list)
                    {
                        if (c.CardNumber == cardNumber)
                        {
                            isExits = true;
                            break;
                        }
                    }
                } while (isExits);
                list.Add(new IDCardNumber(cardNumber));
            }
            return(list);
        }
Esempio n. 2
0
        /// <summary>
        /// 解析身份证信息
        /// </summary>
        /// <param name="idCardNumber"></param>
        public static IDCardNumber Get(string idCardNumber)
        {
            if (IDCardNumber.Areas.Count < 1)
            {
                IDCardNumber.FillAreas();
            }
            if (!IDCardNumber.CheckIDCardNumber(idCardNumber))
            {
                throw new Exception("非法的身份证号码");
            }
            //
            IDCardNumber cardInfo = new IDCardNumber(idCardNumber);

            return(cardInfo);
        }
Esempio n. 3
0
        /// <summary>
        /// 生成随身份证号
        /// </summary>
        /// <param name="seed">随机数种子</param>
        /// <returns></returns>
        private static string _radomCardNumber(int seed)
        {
            if (IDCardNumber.Areas.Count < 1)
            {
                IDCardNumber.FillAreas();
            }
            System.Random rd = new System.Random(seed);
            //随机生成发证地
            string area = "";

            do
            {
                area = IDCardNumber.Areas[rd.Next(0, IDCardNumber.Areas.Count - 1)][0];
            } while (area.Substring(4, 2) == "00");
            //随机出生日期
            DateTime birthday = DateTime.Now;

            birthday = birthday.AddYears(-rd.Next(16, 60));
            birthday = birthday.AddMonths(-rd.Next(0, 12));
            birthday = birthday.AddDays(-rd.Next(0, 31));
            //随机码
            string code = rd.Next(1000, 9999).ToString("####");
            //生成完整身份证号
            string codeNumber = area + birthday.ToString("yyyyMMdd") + code;
            double sum        = 0;
            string checkCode  = null;

            for (int i = 2; i <= 18; i++)
            {
                sum += int.Parse(codeNumber[18 - i].ToString(), NumberStyles.HexNumber) * (Math.Pow(2, i - 1) % 11);
            }
            string[] checkCodes = { "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2" };
            checkCode  = checkCodes[(int)sum % 11];
            codeNumber = codeNumber.Substring(0, 17) + checkCode;
            //
            return(codeNumber);
        }