dmdb/view/frmEnterBlzKto.cs

86 lines
2.7 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
using dezentrale.model.money;
namespace dezentrale.view
{
public class frmEnterBlzKto : FormWithActionButtons
{
private TextBox tbBlz;
private TextBox tbKtoNummer;
private Label lblCcPz;
private string cc;
public string Iban
{
get
{
return BankTransfer.GetIbanFromKtoBlz("DE", tbBlz.Text, tbKtoNummer.Text);
}
set
{
cc = BankTransfer.GetCCodeFromIban(value);
lblCcPz.Text = cc + BankTransfer.CalcPz(value);
tbBlz.Text = BankTransfer.GetBlzFromIban(value);
tbKtoNummer.Text = BankTransfer.GetKtoFromIban(value);
}
}
public frmEnterBlzKto(string ibanInput)
{
DialogResult = DialogResult.Cancel;
this.StartPosition = FormStartPosition.CenterParent;
this.Size = new System.Drawing.Size(370, 90);
this.Text = "dezentrale-members :: Enter BLZ/KTO";
this.Controls.Add(tbBlz = new TextBox()
{
Location = new Point(lm + 113, 0 * line + tm),
Width = 80,
});
tbBlz.TextChanged += tbBlzKto_Changed;
this.Controls.Add(tbKtoNummer = new TextBox()
{
Location = new Point(lm + 203, 0 * line + tm),
Width = 100,
});
tbKtoNummer.TextChanged += tbBlzKto_Changed;
this.Controls.Add(lblCcPz = new Label()
{
Location = new Point(lm + 5, 0 * line + tm),
TextAlign = ContentAlignment.MiddleRight,
});
try { Iban = ibanInput; } catch (Exception) { }
AddButton("Apply", btnApply_Click);
AddButton("Cancel", btnCancel_Click);
}
private void tbBlzKto_Changed(object sender, EventArgs e)
{
try
{
string iban = BankTransfer.GetIbanFromKtoBlz(cc, tbBlz.Text, tbKtoNummer.Text);
lblCcPz.Text = cc + BankTransfer.CalcPz(iban);
lblCcPz.BackColor = SystemColors.Control;
} catch(Exception ex)
{
lblCcPz.Text = $"ERROR\r\n{ex.Message}";
lblCcPz.BackColor = Color.LightPink;
}
}
private void btnApply_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}