Die hier vorgestellte Klasse überprüft mithilfe des Bankleitzahlenverzeichnisses der Bundesbank eine übergebene BLZ auf Gültigkeit. Im Konstruktor der Klasse “blz” wird das BLZ-Verzeichnis eingelesen und zu einem Array aus Instituten konvertiert. Das Bankleitzahl-Verzeichnis, enthält mehrere Felder von denen ich hier nur den Namen der Bank, die Bankleitzahl, die PLZ, den Ort und die BIC auslese. Die Methode “Suche” erwartet als Übergabewert den Anfang einer BLZ und liefert alle Institute, die diesem Muster entsprechen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | using System; using System.IO; namespace Bankleitzahlen { class blz { private int iMax = 0; //Anzahl Institue private Institute[] iInstitute; //Institutsliste public blz() { //Einlesen des BLZ Verzeichnisses string sBankleitzahl, sBezeichnung, sPLZ, sOrt, sBIC; StreamReader reader = new StreamReader(@"C:\blz.txt", System.Text.Encoding.Default); string sFileInhalt = reader.ReadToEnd(); reader.Close(); char[] delimiterChars = { '\r' }; string[] arrInhalt = sFileInhalt.Replace("\r\n", "\r").Split(delimiterChars); iMax = arrInhalt.Length - 1; iInstitute = new Institute[iMax]; //Erstellen eines Array's aus Instituten for (int i = 0; i < iMax; i++) { sBankleitzahl = arrInhalt[i].Substring(0, 8).Trim(); sBezeichnung = arrInhalt[i].Substring(09, 58).Trim(); sPLZ = arrInhalt[i].Substring(67, 5).Trim(); sOrt = arrInhalt[i].Substring(72, 35).Trim(); sBIC = arrInhalt[i].Substring(139, 11).Trim(); iInstitute[i] = new Institute(sBankleitzahl, sBezeichnung, sPLZ, sOrt, sBIC); } } public Institute[] Suche(string sBLZ) { int treffer=0; int lenSuche=sBLZ.Length; Institute[] rInstitut = new Institute[0]; ; if (lenSuche<=8) { foreach (Institute tmpInstitut in iInstitute) { if (tmpInstitut.Bankleitzahl.Substring(0, lenSuche) == sBLZ) { treffer++; Array.Resize(ref rInstitut, treffer); rInstitut[treffer - 1] = tmpInstitut; } } } return rInstitut; } } class Institute { public string Bankleitzahl; public string Bezeichnung; public string PLZ; public string Ort; public string BIC; public Institute(string bankleitzahl, string bezeichnung, string plz, string ort, string bic) { this.Bankleitzahl = bankleitzahl; this.Bezeichnung = bezeichnung; this.PLZ = plz; this.Ort = ort; this.BIC = bic; } } } |
In diesem Projekt gibt es eine Textbox “txtBankleitzahlen” mit einem TextChanged Event, und eine Listview “listView1″. Um die benötigte Rechenleistung klein zu halten, startet die Suche erst ab der zweiten Zahl.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | public partial class Form1 : Form { blz myblz = new blz(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void txtBankleitzahl_TextChanged(object sender, EventArgs e) { if (txtBankleitzahl.Text.Length > 1) { Institute[] Institute = myblz.Suche(txtBankleitzahl.Text); listView1.Items.Clear(); foreach (Institute Institut in Institute) { ListViewItem ls = new ListViewItem(Institut.Bankleitzahl); ls.SubItems.Add(Institut.Bezeichnung); ls.SubItems.Add(Institut.PLZ); ls.SubItems.Add(Institut.Ort); ls.SubItems.Add(Institut.BIC); listView1.Items.Add(ls); } } } } |
Tags: Bankleitzahl, BIC, BLZ, Kontonummer, PAN