Ejemplo n.º 1
0
        public static IDCardClient ReadIDCardFrontSide(string data)
        {
            string patterIdCardNumber          = @"[0-9]{9}";
            string patternRegisterRecordNumber = @"[0-9]{13}";
            string patternDate = @"[0-9]{8}";

            int indexFind  = -1;
            int lengthFind = 0;

            IDCardClient client = new IDCardClient();

            Regex regexNoise = new Regex(patternNoise);

            data       = regexNoise.Replace(data, "");
            regexNoise = new Regex(patternCoretNoise);
            data       = regexNoise.Replace(data, "|");
            data       = DigitParser.Parse(data);

            MatchCollection matchesDate = new Regex(patternDate).Matches(data);
            var             tuple       = SelectCorrectDateAndIndexes(matchesDate, DateType.BirthDate);

            if (tuple.date != null)
            {
                client.BirthDate = tuple.date;
                data             = data.Remove(tuple.indexFind, tuple.lengthFind);
            }

            MatchCollection matchesCardsValidEnds = new Regex(patternDate).Matches(data);

            tuple = SelectCorrectDateAndIndexes(matchesCardsValidEnds, DateType.DateCardsValidEnds);
            if (tuple.date != null)
            {
                client.DateCardsValidEnds = tuple.date;
                data = data.Remove(tuple.indexFind, tuple.lengthFind);
            }

            MatchCollection matchesRegisterRecordNumber = new Regex(patternRegisterRecordNumber).Matches(data);

            if (matchesRegisterRecordNumber.Count > 0)
            {
                client.RegisterRecordNumber = matchesRegisterRecordNumber[0].Value.Insert(8, "-");
                indexFind  = matchesRegisterRecordNumber[0].Index;
                lengthFind = client.RegisterRecordNumber.Length;

                data = data.Remove(indexFind, lengthFind);
            }

            MatchCollection matchesIdCardNumber = new Regex(patterIdCardNumber, RegexOptions.RightToLeft).Matches(data);

            if (matchesIdCardNumber.Count > 0)
            {
                client.IdCardNumber = matchesIdCardNumber[0].Value;
                indexFind           = matchesIdCardNumber[0].Index;
                lengthFind          = client.IdCardNumber.Length;

                data = data.Remove(indexFind, lengthFind);
            }
            return(client);
        }
Ejemplo n.º 2
0
        private static Dictionary <string, string> ReadOtherInfoFromIDCardBackSide(string info)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();

            info = DigitParser.Parse(info);
            string   deliveryBy   = "";
            string   clientInn    = "";
            DateTime?deliveryDate = null;

            string patternDate     = @"[0-9]{8}";
            string patternDelivery = @"[0-9]{4}";
            string patternInn      = @"[0-9]{10}";

            int indexFind  = 0;
            int lengthFind = 0;

            MatchCollection matchesDeliveryDate = new Regex(patternDate).Matches(info);
            var             tuple = SelectCorrectDateAndIndexes(matchesDeliveryDate, DateType.PassportDeliveryDate);

            if (tuple.date != null)
            {
                deliveryDate = tuple.date;
                info         = info.Remove(tuple.indexFind, tuple.lengthFind);
                info         = info.Substring(tuple.indexFind);
            }

            MatchCollection matchesInn = new Regex(patternInn).Matches(info);

            if (matchesInn.Count > 0)
            {
                clientInn  = matchesInn[0].Value;
                indexFind  = matchesInn[0].Index;
                lengthFind = clientInn.Length;

                info = info.Remove(indexFind, lengthFind);
            }

            MatchCollection matchesDeliveryBy = new Regex(patternDelivery).Matches(info);

            if (matchesDeliveryBy.Count > 0)
            {
                deliveryBy = matchesDeliveryBy[0].Value;
            }
            result.Add("PassportDeliveryDate", deliveryDate.ToString());
            result.Add("PassportDeliveryBy", deliveryBy);
            result.Add("ClientInn", clientInn);
            return(result);
        }