Ce logiciel a été réalisé avec Visual Studio en C# et utilise les formulaires Windows Form dans le cadre d'un TP.
Il s'agit d'un logiciel back-end qui permet la gestion de comptes bancaires.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO ;
using System.Runtime.Serialization.Formatters.Binary ;
using Banque.Modele;
using Banque.Controleur;
namespace Banque.Vue
{
[Serializable]
public partial class Gestion : Form
{
public List lstcpt = new List();
public Gestion()
{
InitializeComponent();
}
private void crediterToolStripMenuItem_Click(object sender, EventArgs e)
{
lab.Visible = true;
lab.Text = "Montant à créditer";
bouton.Visible = true;
bouton.Text = "Valider le crédit";
tb.Visible = true;
}
private void debiterToolStripMenuItem_Click(object sender, EventArgs e)
{
lab.Visible = true;
lab.Text = "Montant à débiter";
bouton.Visible = true;
bouton.Text = "Valider le débit";
tb.Visible = true;
}
private void bouton_Click(object sender, EventArgs e)
{
try
{
int i;
i = lBox.SelectedIndex;
Compte c = (Compte)lBox.SelectedItem;
if (bouton.Text == "Valider le crédit")
{
Mgr.crediter(c, Convert.ToDouble(tb.Text));
}
if (bouton.Text == "Valider le débit")
{
/*
if (!c.debiter(Convert.ToDouble(tb.Text))) { MessageBox.Show("Debit interdit"); }
*/
Mgr.debiter(c, Convert.ToDouble(tb.Text));
tb.Clear();
}
if (bouton.Text == "Valider le découvert")
{
if (c.GetType().Name == "CompteCourant")
{
if (!((CompteCourant)c).setDecouv(Convert.ToDouble(tb.Text))) { MessageBox.Show("découvert interdit"); }
}
}
rafraichirListBox();
}
catch (DebitException Ex)
{
MessageBox.Show("" + Ex.Message);
}
catch (Exception Ex)
{
MessageBox.Show("" + Ex.Message);
}
}
private void découvertToolStripMenuItem_Click(object sender, EventArgs e)
{
lab.Visible = true;
lab.Text = "Montant du nouveau découvert";
bouton.Visible = true;
bouton.Text = "Valider le découvert";
tb.Visible = true;
}
private void rafraichirListBox()
{
lBox.DataSource = null;
lBox.DataSource = lstcpt;
lBox.DisplayMember = "Description";
}
private void Gestion_Load(object sender, EventArgs e)
{
/*Client cl1 = new Client(1, "Dupont", "toto", "Créteil");
Client cl2 = new Client(2, "Abdala", "momo", "Cachan");
Compte c1 = new CompteCourant(12, cl1);
Compte c2 = new CompteCourant(12, cl1);
Compte c3 = new CompteEpargne(11, cl2,1.2);
Compte c4 = new CompteCourant(9, cl1);
lstcpt.Add(c1);
lstcpt.Add(c3);
lstcpt.Add(c4);
*/
Serialise.chargement();
lstcpt = Serialise.Lstcpt;
rafraichirListBox();
}
private void clientToolStripMenuItem_Click(object sender, EventArgs e)
{
Compte c = (Compte)lBox.SelectedItem;
Client cl = c.Propriétaire;
FormClient fc = new FormClient(cl);
fc.ShowDialog();
rafraichirListBox();
}
private void Gestion_FormClosing(object sender, FormClosingEventArgs e)
{
Serialise.sauvegarde(lstcpt);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Banque.Modele;
namespace Banque.Vue
{
public partial class FormClient : Form
{
private Client c;
public FormClient(Client unClient)
{
InitializeComponent();
this.c = unClient;
}
public FormClient()
{
InitializeComponent();
}
private void FormClient_Load(object sender, EventArgs e)
{
tbNum.Text = c.Num.ToString();
tbNom.Text = c.Nom;
tbPrenom.Text = c.Prenom;
tbAdresse.Text = c.Adresse;
}
private void button1_Click(object sender, EventArgs e)
{
c.Adresse = tbAdresse.Text;
this.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Banque.Modele
{
[Serializable]
public class Client
{
private int num;
private string nom;
private string prenom;
private string adresse;
private List comptes = new List();
public Client(int num, string nom, string prenom, string ad)
{
this.num = num;
this.nom = nom;
this.prenom = prenom;
this.adresse = ad;
}
public string Nom { get => nom; }
public string Prenom { get => prenom; }
public string Adresse { get => adresse; set => adresse = value; }
public int Num { get => num; }
public override string ToString()
{
return (this.Num + " " + this.Nom + " " + this.prenom + " " + this.Adresse);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Banque.Modele
{
[Serializable]
public abstract class Compte
{
protected int num;
protected Client proprio;
private double solde = 0;
public int Num { get => num; }
public Compte(int n, Client c)
{
this.num = n;
this.solde =0;
this.proprio = c;
}
public virtual string Description
{
get => "Compte n° " + num + " " + " Client : " + proprio + " " + " solde : " + solde + " €" ;
}
public Client Propriétaire
{
get { return proprio; }
}
public double Solde { get => solde; set => solde = value; }
public void crediter(double mont)
{
if (mont >= 0) solde = solde + mont;
else throw (new Exception("Pas de valeur negative en entree"));
solde = solde+mont;
}
public abstract void debiter(double mont);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Banque.Modele
{
[Serializable]
public class CompteCourant : Compte
{
private double decouv = 0;
public CompteCourant(int n, Client c) : base (n,c)
{
}
public bool setDecouv(double value)
{
bool res = false;
if (this.Solde > -value)
{
decouv = value;
res = true;
}
else
{
// Propager une exception
}
return (res);
}
public double Decouv
{
get => decouv;
set
{
if (this.Solde >= (-value)) { decouv = value; }
else
{
// Propager une exception
}
}
}
public override void debiter(double mont)
{
if (Solde - mont < -decouv)
{
throw (new DebitException("impossible de débiter avec ce montant"));
}
else
{
Solde = Solde - mont;
}
}
public override string Description
{
get => base.Description + " - decouvert : " + this.decouv;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Banque.Modele
{
[Serializable]
public class CompteEpargne : Compte
{
static double taux;
public CompteEpargne(int n, Client c, double unTaux) : base(n, c)
{
CompteEpargne.taux = unTaux;
}
public override void debiter(double mont)
{
if (Solde - mont < 0)
{
throw (new DebitException("impossible de débiter avec ce montant sur un compte epargne"));
}
else
{
Solde = Solde - mont;
}
}
public override string Description
{
get => base.Description + " taux : " + CompteEpargne.taux ;
}
}
}
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Banque.Modele;
namespace UnitTestBanqueGraphique
{
[TestClass]
public class UnitTest1
{
private double unCredit;
private double unDecouvert;
private double unDebit;
private int unNum;
private string unNom;
private string uneAdresse;
private string unPrenom;
Client unClient;
CompteCourant c1;
CompteEpargne c2;
[TestMethod]
public void TestMethod1()
{
unNum = 1;
unNom = "Morgat";
unPrenom = "Mathieu";
uneAdresse = "27 Rue du test";
unClient = new Client(unNum,unNom,unPrenom,uneAdresse);
c1 = new CompteCourant(11,unClient);
c2 = new CompteEpargne(12,unClient,200);
c1.crediter(200);
Assert.AreEqual(200, c1.Solde,"erreur");
c1.Decouv = 500;
Assert.AreEqual(500,c1.Decouv,"erreur");
c1.debiter(100);
Assert.AreEqual(100 ,c1.Solde ,"erreur");
c2.crediter(200);
Assert.AreEqual(200, c2.Solde, "erreur");
c2.debiter(100);
Assert.AreEqual(100, c2.Solde, "erreur");
}
[TestMethod]
public void TestMethod2()
{
unNum = 1;
unNom = "Morgat";
unPrenom = "Mathieu";
uneAdresse = "27 Rue du test";
unClient = new Client(unNum, unNom, unPrenom, uneAdresse);
c1 = new CompteCourant(11, unClient);
var ex = Assert.ThrowsException(() => c1.crediter(-50));
Assert.AreEqual("Pas de valeur negative en entree", ex.Message);
}
}
}