コード例 #1
0
ファイル: Program.cs プロジェクト: morefun0302/WPC
        static void Main(string[] args)
        {
            IIN iins = new IIN();

            while (true)
            {
                // Get the card number from the user.
                Console.Write("Enter a card number (press Q to quit) : ");
                string cardNumber = Console.ReadLine();

                // Do we want to quit?
                if (cardNumber.ToLower() == "q") break;

                // Skip if no card number was entered.
                if (cardNumber.Trim().Length == 0) continue;

                bool isLuhnValid = false;

                // Check the IIN against the valid list.
                IINResult result;
                string issuer = iins.GetIINIssuer(cardNumber, out result);
                if (issuer.Length > 0)
                {
                    // If it's appropriate to do the Luhn validation,
                    // do it.  Otherwise just say that it's valid.
                    if (result != IINResult.ValidIINButNoLuhnValidation)
                        isLuhnValid = Luhn.Modulus10Check(cardNumber);
                    else
                        isLuhnValid = true;
                }

                // Display the result.
                if (issuer.Length > 0 && isLuhnValid)
                {
                    Console.WriteLine("VALID   Card number {0} is a valid card number.  Issuer = {1}.", cardNumber, issuer);
                }
                else
                {
                    if (issuer.Length == 0)
                    {
                        if (result == IINResult.InvalidIIN)
                            Console.WriteLine("INVALID Card number {0} - IIN check failed.", cardNumber);
                        else if (result == IINResult.ValidIINButInactive)
                            Console.WriteLine("INVALID Card number {0} - Valid IIN but inactive.", cardNumber);
                        else
                            Console.WriteLine("INVALID Card number {0} - Valid IIN but card number wrong length.", cardNumber);
                    }
                    else
                        Console.WriteLine("INVALID Card number {0} - Luhn check failed.", cardNumber);
                }
                string dash = string.Empty.PadLeft(99, '-');
                Console.WriteLine(dash);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: panchul/WPC
        static void Main(string[] args)
        {
            IIN iins = new IIN();

            while (true)
            {
                // Get the card number from the user.
                Console.Write("Enter a card number (press Q to quit) : ");
                string cardNumber = Console.ReadLine();

                // Do we want to quit?
                if (cardNumber.ToLower() == "q")
                {
                    break;
                }

                // Skip if no card number was entered.
                if (cardNumber.Trim().Length == 0)
                {
                    continue;
                }

                bool isLuhnValid = false;

                // Check the IIN against the valid list.
                IINResult result;
                string    issuer = iins.GetIINIssuer(cardNumber, out result);
                if (issuer.Length > 0)
                {
                    // If it's appropriate to do the Luhn validation,
                    // do it.  Otherwise just say that it's valid.
                    if (result != IINResult.ValidIINButNoLuhnValidation)
                    {
                        isLuhnValid = Luhn.Modulus10Check(cardNumber);
                    }
                    else
                    {
                        isLuhnValid = true;
                    }
                }

                // Display the result.
                if (issuer.Length > 0 && isLuhnValid)
                {
                    Console.WriteLine("VALID   Card number {0} is a valid card number.  Issuer = {1}.", cardNumber, issuer);
                }
                else
                {
                    if (issuer.Length == 0)
                    {
                        if (result == IINResult.InvalidIIN)
                        {
                            Console.WriteLine("INVALID Card number {0} - IIN check failed.", cardNumber);
                        }
                        else if (result == IINResult.ValidIINButInactive)
                        {
                            Console.WriteLine("INVALID Card number {0} - Valid IIN but inactive.", cardNumber);
                        }
                        else
                        {
                            Console.WriteLine("INVALID Card number {0} - Valid IIN but card number wrong length.", cardNumber);
                        }
                    }
                    else
                    {
                        Console.WriteLine("INVALID Card number {0} - Luhn check failed.", cardNumber);
                    }
                }
                string dash = string.Empty.PadLeft(99, '-');
                Console.WriteLine(dash);
            }
        }