public void TestComputeIBANFromBankAccount()
        {
            Debug.WriteLine("ComputeIBANFromBankAccount");

            string prefix = "19";
            string number = "2000145399";
            string bank = "0800";
            CzechBankAccount account = new CzechBankAccount(prefix, number, bank);
            string expResult = "CZ6508000000192000145399";
            string result = account.ToIBANFromCzechBankAccount();

            Assert.AreEqual(expResult, result);
        }
        public void TestComputeIBANFromBankAccount2()
        {
            Debug.WriteLine("ComputeIBANFromBankAccount2");

            string prefix = "178124";
            string number = "4159";
            string bank = "0710";
            CzechBankAccount account = new CzechBankAccount(prefix, number, bank);
            string expResult = "CZ6907101781240000004159";
            string result = account.ToIBANFromCzechBankAccount();

            Assert.AreEqual(expResult, result);
        }
Beispiel #3
0
        /// <summary>
        /// Computes the IBAN number from a given Czech account information.
        /// </summary>
        /// <param name="account">A Czech account model class.</param>
        /// <returns>An IBAN number.</returns>
        public static string ToIBANFromCzechBankAccount(this CzechBankAccount account)
        {
            // preprocess the numbers
            string prefix = string.Format("{0:000000}", long.Parse(account.Prefix));
            string number = string.Format("{0:0000000000}", long.Parse(account.Number));
            string bank   = string.Format("{0:0000}", long.Parse(account.BankCode));

            // calculate the check sum
            string buf   = bank + prefix + number + "123500";
            int    index = 0;
            long   pz    = -1;

            while (index <= buf.Length)
            {
                string dividend;
                if (pz < 0)
                {
                    dividend = buf.Substring(index, Math.Min(9, buf.Length - index));
                    index   += 9;
                }
                else if (pz >= 0 && pz <= 9)
                {
                    dividend = pz + buf.Substring(index, Math.Min(8, buf.Length - index));
                    index   += 8;
                }
                else
                {
                    dividend = pz + buf.Substring(index, Math.Min(7, buf.Length - index));
                    index   += 7;
                }
                pz = long.Parse(dividend) % 97;
            }
            pz = 98 - pz;

            // assign the checksum
            string checksum = string.Format("{0:00}", pz);

            // build the IBAN number
            return("CZ" + checksum + bank + prefix + number);
        }