Exemple #1
0
        public CardInfo Parse()
        {
            cardinfo = new CardInfo ();
            Dictionary<string,string> datadic = new Dictionary<string,string> ();
            Regex onlynumberformat = new Regex (@"^[0-9]+$");
            if(String.IsNullOrEmpty(nn_datastring)||onlynumberformat.Match (nn_datastring).Success||nn_datastring.Split ('\n').Length<=1){
                cardinfo.available = false;
                cardinfo.errormessage = "Failed to get complete info,Please re-scan";
            }
            else{
                cardinfo.available = true;
                cardinfo.errormessage = "";

                String[] elements = nn_datastring.Split ('\n');
                //shift to dictionary
                for (int i = 0; i < elements.Length; i++) {
                    if (elements [i].Contains ("ANSI")) {
                    }
                    else if (elements [i].Length > 3) {
                        Regex r = new Regex (@"\s{2,}");
                        elements [i] = r.Replace (elements [i], "");
                        string key = elements [i].Substring (0, 3);
                        string value = elements [i].Substring (3);
                        datadic.Add (key, value);

                    }
                }
                foreach(var entry in datadic){
                    switch(entry.Key){
                        case Country_Identification:
                            cardinfo.countrycode = entry.Value;
                            break;
                        case Jurisdction_Code:
                            cardinfo.provincecode = entry.Value;
                            break;
                        case City:
                            cardinfo.city = entry.Value;
                            break;
                        case Street_Address_1:
                            cardinfo.address1 = entry.Value;
                            break;
                        case Street_Address_2:
                            cardinfo.address2 = entry.Value;
                            break;
                        case Postal_Code:
                            cardinfo.zipcode = entry.Value;
                            break;
                        case Customer_Given_Name:
                            cardinfo.firstname = entry.Value;
                            break;
                        case Customer_Family_Name:
                            cardinfo.lastname= entry.Value;
                            break;
                        case Date_Of_Birth:
                            cardinfo.birthdate= entry.Value;
                            break;
                    }
                }//end of foreach
            }//end of else
            return cardinfo;
        }
Exemple #2
0
 public ScanParser(string scanedstring)
 {
     nn_datastring = scanedstring;
     cardinfo = new CardInfo ();
 }