Init
This commit is contained in:
171
WGneu/BankDetailsWindow.xaml.cs
Normal file
171
WGneu/BankDetailsWindow.xaml.cs
Normal file
@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WGneu
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für BankDetailsWindow.xaml
|
||||
/// </summary>
|
||||
public partial class BankDetailsWindow : Window
|
||||
{
|
||||
public BankDetailsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Iban_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
string iban = "";
|
||||
int pos = Iban.CaretIndex;
|
||||
for (int i = 0, v = 0; i < Iban.Text.Length && v < 34; i++)
|
||||
{
|
||||
char ch = Iban.Text[i];
|
||||
if (Char.IsLetterOrDigit(ch) && Char.IsAscii(ch))
|
||||
{
|
||||
if (v != 0 && v % 4 == 0)
|
||||
iban += ' ';
|
||||
v++;
|
||||
iban += Char.ToUpper(ch);
|
||||
}
|
||||
if (i == Iban.CaretIndex - 1)
|
||||
pos = iban.Length;
|
||||
if (iban.StartsWith("AT") && v >= 20)
|
||||
break;
|
||||
}
|
||||
Iban.Text = iban;
|
||||
Iban.CaretIndex = pos;
|
||||
|
||||
if (Iban.IsFocused)
|
||||
GenerateBankDetails();
|
||||
}
|
||||
|
||||
private void Iban_LostFocus(object sender, EventArgs e)
|
||||
{
|
||||
// TODO vaildate checksum
|
||||
}
|
||||
|
||||
private void BankCode_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
string cc = "AT";
|
||||
string code = "";
|
||||
int pos = BankCode.CaretIndex;
|
||||
|
||||
if (cc == "AT")
|
||||
{
|
||||
|
||||
for (int i = 0, v = 0; i < BankCode.Text.Length && v < 5; i++)
|
||||
{
|
||||
char ch = BankCode.Text[i];
|
||||
if (Char.IsDigit(ch))
|
||||
{
|
||||
v++;
|
||||
code += ch;
|
||||
}
|
||||
if (i == BankCode.CaretIndex - 1)
|
||||
pos = code.Length;
|
||||
}
|
||||
}
|
||||
|
||||
BankCode.Text = code;
|
||||
BankCode.CaretIndex = pos;
|
||||
|
||||
if (BankCode.IsFocused)
|
||||
GenerateIban();
|
||||
}
|
||||
|
||||
private void AccountNumber_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
string cc = "AT";
|
||||
string num = "";
|
||||
int pos = AccountNumber.CaretIndex;
|
||||
|
||||
if (cc == "AT")
|
||||
{
|
||||
for (int i = 0, v = 0; i < AccountNumber.Text.Length && v < 11; i++)
|
||||
{
|
||||
char ch = AccountNumber.Text[i];
|
||||
if (Char.IsLetterOrDigit(ch) && Char.IsAscii(ch))
|
||||
{
|
||||
v++;
|
||||
num += ch;
|
||||
}
|
||||
if (i == AccountNumber.CaretIndex - 1)
|
||||
pos = num.Length;
|
||||
}
|
||||
}
|
||||
|
||||
AccountNumber.Text = num;
|
||||
AccountNumber.CaretIndex = pos;
|
||||
|
||||
if (AccountNumber.IsFocused)
|
||||
GenerateIban();
|
||||
}
|
||||
|
||||
private void GenerateIban()
|
||||
{
|
||||
string cc = "AT";
|
||||
string iban = cc + "00";
|
||||
|
||||
if (cc == "AT")
|
||||
{
|
||||
iban += BankCode.Text.PadLeft(5, '0') + AccountNumber.Text.PadLeft(11, '0');
|
||||
}
|
||||
|
||||
// TODO calculate checksum
|
||||
|
||||
Iban.Text = iban;
|
||||
Iban.CaretIndex = iban.Length;
|
||||
}
|
||||
|
||||
private void GenerateBankDetails()
|
||||
{
|
||||
BankCode.Text = "";
|
||||
AccountNumber.Text = "";
|
||||
|
||||
string iban = Iban.Text.Replace(" ", "");
|
||||
if (iban.Length <= 2)
|
||||
return;
|
||||
|
||||
string cc = iban.Substring(0, 2);
|
||||
if (cc == "AT")
|
||||
{
|
||||
if (iban.Length > 4)
|
||||
{
|
||||
string bankCodeStr = iban.Substring(4, Math.Min(5, iban.Length - 4));
|
||||
if (bankCodeStr.All(Char.IsDigit))
|
||||
{
|
||||
int bankCode = int.Parse(bankCodeStr);
|
||||
BankCode.Text = bankCode.ToString();
|
||||
}
|
||||
if (iban.Length > 9)
|
||||
{
|
||||
string accNumStr = iban.Substring(9, Math.Min(11, iban.Length - 9));
|
||||
if (accNumStr.All(Char.IsDigit))
|
||||
{
|
||||
int accNum = int.Parse(accNumStr);
|
||||
AccountNumber.Text = (accNum != 0) ? accNum.ToString() : "";
|
||||
}
|
||||
else
|
||||
{
|
||||
AccountNumber.Text = accNumStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BankCode.CaretIndex = BankCode.Text.Length;
|
||||
AccountNumber.CaretIndex = AccountNumber.Text.Length;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user