mirror of
https://github.com/Alvin-Zilverstand/ict-algemeen-opdrachten.git
synced 2026-03-06 21:29:36 +01:00
Update project configuration to target .NET 6.0 and enable Windows Forms support
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
class Bankrekening
|
||||
{
|
||||
public string Rekeningnummer { get; }
|
||||
private decimal saldo;
|
||||
private List<Transactie> transacties;
|
||||
|
||||
public Bankrekening(decimal beginsaldo)
|
||||
public Bankrekening(string rekeningnummer, decimal beginsaldo)
|
||||
{
|
||||
Rekeningnummer = rekeningnummer;
|
||||
saldo = beginsaldo;
|
||||
transacties = new List<Transactie>();
|
||||
}
|
||||
|
||||
public void Storten(decimal bedrag)
|
||||
@@ -15,6 +20,7 @@ class Bankrekening
|
||||
if (bedrag > 0)
|
||||
{
|
||||
saldo += bedrag;
|
||||
transacties.Add(new Transactie(bedrag, "Storting"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -27,6 +33,7 @@ class Bankrekening
|
||||
if (bedrag > 0 && bedrag <= saldo)
|
||||
{
|
||||
saldo -= bedrag;
|
||||
transacties.Add(new Transactie(-bedrag, "Opname"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -38,6 +45,25 @@ class Bankrekening
|
||||
{
|
||||
return saldo;
|
||||
}
|
||||
|
||||
public List<Transactie> GetTransactieGeschiedenis()
|
||||
{
|
||||
return transacties;
|
||||
}
|
||||
}
|
||||
|
||||
class Transactie
|
||||
{
|
||||
public decimal Bedrag { get; }
|
||||
public string Beschrijving { get; }
|
||||
public DateTime Datum { get; }
|
||||
|
||||
public Transactie(decimal bedrag, string beschrijving)
|
||||
{
|
||||
Bedrag = bedrag;
|
||||
Beschrijving = beschrijving;
|
||||
Datum = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
public class MainForm : Form
|
||||
@@ -47,23 +73,27 @@ public class MainForm : Form
|
||||
private TextBox bedragTextBox;
|
||||
private Button stortenButton;
|
||||
private Button opnemenButton;
|
||||
private Button transactieGeschiedenisButton;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
mijnRekening = new Bankrekening(1000);
|
||||
mijnRekening = new Bankrekening("NL01BANK0123456789", 1000);
|
||||
|
||||
saldoLabel = new Label() { Text = $"Saldo: {mijnRekening.ControleerSaldo()}", Top = 20, Left = 20, Width = 200 };
|
||||
bedragTextBox = new TextBox() { Top = 50, Left = 20, Width = 200 };
|
||||
stortenButton = new Button() { Text = "Storten", Top = 80, Left = 20 };
|
||||
opnemenButton = new Button() { Text = "Opnemen", Top = 110, Left = 20 };
|
||||
transactieGeschiedenisButton = new Button() { Text = "Transactiegeschiedenis", Top = 140, Left = 20 };
|
||||
|
||||
stortenButton.Click += StortenButton_Click;
|
||||
opnemenButton.Click += OpnemenButton_Click;
|
||||
transactieGeschiedenisButton.Click += TransactieGeschiedenisButton_Click;
|
||||
|
||||
Controls.Add(saldoLabel);
|
||||
Controls.Add(bedragTextBox);
|
||||
Controls.Add(stortenButton);
|
||||
Controls.Add(opnemenButton);
|
||||
Controls.Add(transactieGeschiedenisButton);
|
||||
}
|
||||
|
||||
private void StortenButton_Click(object sender, EventArgs e)
|
||||
@@ -93,13 +123,33 @@ public class MainForm : Form
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void TransactieGeschiedenisButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var transactieGeschiedenis = mijnRekening.GetTransactieGeschiedenis();
|
||||
string geschiedenis = "Transactiegeschiedenis:\n";
|
||||
foreach (var transactie in transactieGeschiedenis)
|
||||
{
|
||||
geschiedenis += $"{transactie.Datum}: {transactie.Beschrijving} - {transactie.Bedrag:C}\n";
|
||||
}
|
||||
MessageBox.Show(geschiedenis);
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
var mijnRekening = new Bankrekening("NL01BANK0123456789", 1000);
|
||||
mijnRekening.Storten(100.00m);
|
||||
mijnRekening.Opnemen(50.00m);
|
||||
|
||||
Console.WriteLine("Transactiegeschiedenis:");
|
||||
foreach (var transactie in mijnRekening.GetTransactieGeschiedenis())
|
||||
{
|
||||
Console.WriteLine($"{transactie.Datum}: {transactie.Beschrijving} - {transactie.Bedrag:C}");
|
||||
}
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new MainForm());
|
||||
|
||||
Reference in New Issue
Block a user