You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Collections;
namespace Übungen_LF6_WinFormanwendung
{
public partial class BLZChecker : Form
{
//Datenspeicher
Dictionary<string, Bank> BANKDATEN= new Dictionary<string,Bank>();
public BLZChecker()
{
InitializeComponent();
}
private void button_ende_Click(object sender, EventArgs e)
{
this.Close();
}
private void button_prüfen_Click(object sender, EventArgs e)
{
//Initialisieren
textBox_confirm.Text = "";
textBox_NameBank.Text = "";
textBox_Ort.Text = "";
Bank tmpBank = new Bank();
if (BANKDATEN.ContainsKey(textBox_blz.Text))
{
BANKDATEN.TryGetValue(textBox_blz.Text, out tmpBank);
textBox_confirm.Text = "OK";
textBox_NameBank.Text = tmpBank.BANKNAME;
textBox_Ort.Text = tmpBank.SITZ;
}
else
{
textBox_confirm.Text = "Nicht enthalten";
}
}
private void button_suchen_einlesen_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "CSV-Datei (*.csv)|*.csv|Textdatei (*.txt)|*.txt|Alle Dateien(*.*)|*.*";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
textBox_einlesen.Text = openFileDialog1.FileName;
textBox_processed.Text = einlesen(openFileDialog1.FileName).ToString();
}
}
public int einlesen(string filePath)
{
int anzahlDatensätze = 0;
try
{
//Dateileseroutine
StreamReader tr = new StreamReader(filePath);
// Header überlesen
tr.ReadLine();
while (!tr.EndOfStream)
{
string zeile = tr.ReadLine();
string[] CSVREADLINE = zeile.Split(';');
Bank obj = new Bank(CSVREADLINE);
//Wenn Key bereits vorhanden dann wird übersprungen ansonsten neuer eintrag in der Datenbank
if (!BANKDATEN.ContainsKey(obj.BLZ))
{
anzahlDatensätze += 1;
Console.WriteLine(obj.BLZ);
BANKDATEN.Add(obj.BLZ, obj);
}
}
// close the stream
tr.Close();
}
catch (Exception e)
{
Console.WriteLine("Fehler: {0}", e.ToString());
}
return anzahlDatensätze;
}
}
}