Skip to content

Commit

Permalink
Ajout d'événements pour remonter les ajouts, modifications, et suppre…
Browse files Browse the repository at this point in the history
…ssions d'éléments dans les différentes liste (dérivées d'ObjectList<T>)
  • Loading branch information
pantaflex44 committed Jun 27, 2021
1 parent f7e4caa commit d0a1f8d
Show file tree
Hide file tree
Showing 12 changed files with 1,292 additions and 78 deletions.
170 changes: 142 additions & 28 deletions Kotlib.test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,34 @@ public static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;

// Création d'une nouvelle identité
var me = new Identity(name: "Christophe LEMOINE")
{
Lastname = "LEMOINE",
Forname = "Christophe"
};

// Création d'un moyen de paiement de type 'Carte bancaire'
var bc = new BankCard(name: "CIC Mastercard Tof")
{
Number = "5135 1800 0000 0001",
CVV = "123",
Date = new CardDate(2025, 12)
};
bc.Name = "CIC Mastercard";


// Création d'un élément bancaire de type 'Portefeuille d'espèces'
var wl = new Wallet(name: "Portefeuille de Tof",
owner: me)
{
Electronic = false
};

// Création d'un élément bancaire de type 'Compte bancaire'
var ba = new BankAccount(name: "CIC Compte courant",
owner: me)
{
BankName = "CIC",
Iban = "FR76 1180 8009 1012 3456 7890 147",
Iban = "FR76 5896 1234 7852 1456 9856 147",
Bic = "CMCIFRPP",
Contact = new Identity(name: "CIC COUERON")
{
Expand All @@ -64,6 +73,9 @@ public static void Main(string[] args)
InitialAmount = 300.0d
};

//###############################################################################################################

// Création du dossier financier et ajout des informations liées
var fi = Financial.Create(
name: "Mon dossier financier",
owner: me,
Expand All @@ -74,9 +86,57 @@ public static void Main(string[] args)
);
Console.WriteLine();
Console.WriteLine("Creation d'un dossier financier nommé {0}", fi.Name);
fi.UpdatedEvent += (sender, e) => Console.WriteLine("fi1 updated " + sender.GetType().UnderlyingSystemType);
fi.SavedEvent += (sender, e) => Console.WriteLine("fi1 saved.");

// Abonnements aux événements
// dossier financier
fi.UpdatedEvent += (sender, e) => Console.WriteLine("fi1 - Modification d'une propriété de type: " + sender.GetType().Name);
fi.SavedEvent += (sender, e) => Console.WriteLine("fi1 - Sauvegardé.");
// événements programmés
fi.Events.PostEventAddedEvent += (postEvent) => Console.WriteLine("fi1 - Ajout de la programmation id {2}, '{0}' de type {1}", postEvent.Name, postEvent.GetType().Name, postEvent.Id);
fi.Events.PostEventUpdatedEvent += (postEvent) => Console.WriteLine("fi1 - Modification de la programmation id {1}, '{0}'", postEvent.Name, postEvent.Id);
fi.Events.PostEventRemovedEvent += (postEvent) => Console.WriteLine("fi1 - Suppression de la programmation id {1}, '{0}'", postEvent.Name, postEvent.Id);
fi.PostRaisedEvent += (date, postEvent) =>
{
Console.WriteLine("fi1 - L'occurence '{0}' programmée pour le {1} sur le compte {2} vient dêtre postée.",
postEvent.Name,
date.ToLongDateString(),
fi.Accounts.GetById(postEvent.AccountId).Name);
Console.WriteLine("dates restantes: {0}",
string.Join(", ", postEvent.GetNextCalendar().Select(d => d.ToLongDateString())));
Console.WriteLine("prochaine date: {0} ({1}/{2} occurences restantes)\r\n",
postEvent.NextDate.ToLongDateString(),
postEvent.Counter,
postEvent.RepeatCount);
};
// éléments bancaires
fi.Accounts.AccountAddedEvent += (account) => Console.WriteLine("fi1 - Ajout de l'élément bancaire id {2}, '{0}' de type {1}", account.Name, account.GetType().Name, account.Id);
fi.Accounts.AccountUpdatedEvent += (account) => Console.WriteLine("fi1 - Modification de l'élément bancaire id {1}, '{0}'", account.Name, account.Id);
fi.Accounts.AccountRemovedEvent += (account) => Console.WriteLine("fi1 - Suppression de l'élément bancaire id {1}, '{0}'", account.Name, account.Id);
// catégories
fi.Categories.CategoryAddedEvent += (category) => Console.WriteLine("fi1 - Ajout de la catégorie id {2}, '{0}' de type {1}", category.Name, category.GetType().Name, category.Id);
fi.Categories.CategoryUpdatedEvent += (category) => Console.WriteLine("fi1 - Modification de la catégorie id {1}, '{0}'", category.Name, category.Id);
fi.Categories.CategoryRemovedEvent += (category) => Console.WriteLine("fi1 - Suppression de la catégorie id {1}, '{0}'", category.Name, category.Id);
// moyens de paiements
fi.Paytypes.PaytypeAddedEvent += (paytype) => Console.WriteLine("fi1 - Ajout d'un moyen de paiements id {2}, '{0}' de type {1}", paytype.Name, paytype.GetType().Name, paytype.Id);
fi.Paytypes.PaytypeUpdatedEvent += (paytype) => Console.WriteLine("fi1 - Modification d'un moyen de paiements id {1}, '{0}'", paytype.Name, paytype.Id);
fi.Paytypes.PaytypeRemovedEvent += (paytype) => Console.WriteLine("fi1 - Suppression d'un moyen de paiements id {1}, '{0}'", paytype.Name, paytype.Id);
// tiers
fi.Thirdparties.ThirdpartyAddedEvent += (thirdparty) => Console.WriteLine("fi1 - Ajout d'un tiers id {2}, '{0}' de type {1}", thirdparty.Name, thirdparty.GetType().Name, thirdparty.Id);
fi.Thirdparties.ThirdpartyUpdatedEvent += (thirdparty) => Console.WriteLine("fi1 - Modification d'un tiers id {1}, '{0}'", thirdparty.Name, thirdparty.Id);
fi.Thirdparties.ThirdpartyRemovedEvent += (thirdparty) => Console.WriteLine("fi1 - Suppression d'un tiers id {1}, '{0}'", thirdparty.Name, thirdparty.Id);
// transferts
fi.Accounts.Transfers.TransferAddedEvent += (transfer) => Console.WriteLine("fi1 - Ajout d'un transfert id {2}, '{0}' de type {1}", transfer.Name, transfer.GetType().Name, transfer.Id);
fi.Accounts.Transfers.TransferUpdatedEvent += (transfer) => Console.WriteLine("fi1 - Modification d'un transfert id {1}, '{0}'", transfer.Name, transfer.Id);
fi.Accounts.Transfers.TransferRemovedEvent += (transfer) => Console.WriteLine("fi1 - Suppression d'un transfert id {1}, '{0}'", transfer.Name, transfer.Id);
// operations
fi.Accounts.Items.ForEach(a =>
{
a.Operations.OperationAddedEvent += (operation) => Console.WriteLine("fi1 - {0} - Ajout d'une opération id {3}, '{1}' de type {2}", a.Name, operation.Name, operation.GetType().Name, operation.Id);
a.Operations.OperationUpdatedEvent += (operation) => Console.WriteLine("fi1 - {0} - Modification d'une opération id {2}, '{1}'", a.Name, operation.Name, operation.Id);
a.Operations.OperationRemovedEvent += (operation) => Console.WriteLine("fi1 - {0} - Suppression d'une opération id {2}, '{1}'", a.Name, operation.Name, operation.Id);
});

// Création d'une nouvelle programmation
Console.WriteLine();
var p = new Event(name: "essai",
accountId: fi.Accounts[0].Id,
Expand All @@ -93,52 +153,106 @@ public static void Main(string[] args)
p.RepeatCount);
Console.WriteLine("dates restantes: {0}",
string.Join(", ", p.GetNextCalendar().Select(d => d.ToLongDateString())));

Console.WriteLine();
Console.WriteLine("Activation de la programmation");
p.Active = true;
fi.Events.Add(p);


// Ajout de l'élément bancaire 'Portefeuille d'espèces' au dossie financier
Console.WriteLine();
Console.WriteLine("Ajout d'un portefeuille d'èspèces...");
fi.Accounts.Add(wl);
Console.WriteLine("renommage du portefeuille d'espèces en 'Mon porte monnaie'...");
wl.Name = "Mon porte monnaie";

// Sauvegarde du dossier financier
Console.WriteLine();
Console.WriteLine("Enregistrement du dossier financier...");
string filepath = fi.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), password: "bob");


//###############################################################################################################

// Chargement du dossier financier précédement enregistré
Console.WriteLine();
Console.WriteLine("Rechargement du dossier financier...");
var fi2 = Financial.LoadFromFile(filepath, password: "bob");
fi2.UpdatedEvent += (sender, e) => Console.WriteLine("fi2 updated " + sender.GetType().UnderlyingSystemType);
byte[] datas2 = fi2.Serialize();

Console.WriteLine();
// Abonnements aux événements
// dossier financier
fi2.UpdatedEvent += (sender, e) => Console.WriteLine("fi2 - Modification d'une propriété de type: " + sender.GetType().Name);
fi.SavedEvent += (sender, e) => Console.WriteLine("fi2 - Sauvegardé.");
// événements programmés
fi2.Events.PostEventAddedEvent += (postEvent) => Console.WriteLine("fi2 - Ajout de la programmation id {2}, '{0}' de type {1}", postEvent.Name, postEvent.GetType().Name, postEvent.Id);
fi2.Events.PostEventUpdatedEvent += (postEvent) => Console.WriteLine("fi2 - Modification de la programmation id {1}, '{0}'", postEvent.Name, postEvent.Id);
fi2.Events.PostEventRemovedEvent += (postEvent) => Console.WriteLine("fi2 - Suppression de la programmation id {1}, '{0}'", postEvent.Name, postEvent.Id);
fi2.PostRaisedEvent += (date, postEvent) =>
{
Console.WriteLine("fi2 - L'occurence '{0}' programmée pour le {1} sur le compte {2} vient dêtre postée.",
postEvent.Name,
date.ToLongDateString(),
fi2.Accounts.GetById(postEvent.AccountId).Name);
Console.WriteLine("dates restantes: {0}",
string.Join(", ", postEvent.GetNextCalendar().Select(d => d.ToLongDateString())));
Console.WriteLine("prochaine date: {0} ({1}/{2} occurences restantes)\r\n",
postEvent.NextDate.ToLongDateString(),
postEvent.Counter,
postEvent.RepeatCount);
};
// éléments bancaires
fi2.Accounts.AccountAddedEvent += (account) => Console.WriteLine("fi2 - Ajout de l'élément bancaire id {2}, '{0}' de type {1}", account.Name, account.GetType().Name, account.Id);
fi2.Accounts.AccountUpdatedEvent += (account) => Console.WriteLine("fi2 - Modification de l'élément bancaire id {1}, '{0}'", account.Name, account.Id);
fi2.Accounts.AccountRemovedEvent += (account) => Console.WriteLine("fi2 - Suppression de l'élément bancaire id {1}, '{0}'", account.Name, account.Id);
// catégories
fi2.Categories.CategoryAddedEvent += (category) => Console.WriteLine("fi2 - Ajout de la catégorie id {2}, '{0}' de type {1}", category.Name, category.GetType().Name, category.Id);
fi2.Categories.CategoryUpdatedEvent += (category) => Console.WriteLine("fi2 - Modification de la catégorie id {1}, '{0}'", category.Name, category.Id);
fi2.Categories.CategoryRemovedEvent += (category) => Console.WriteLine("fi2 - Suppression de la catégorie id {1}, '{0}'", category.Name, category.Id);
// moyens de paiements
fi2.Paytypes.PaytypeAddedEvent += (paytype) => Console.WriteLine("fi2 - Ajout d'un moyen de paiements id {2}, '{0}' de type {1}", paytype.Name, paytype.GetType().Name, paytype.Id);
fi2.Paytypes.PaytypeUpdatedEvent += (paytype) => Console.WriteLine("fi2 - Modification d'un moyen de paiements id {1}, '{0}'", paytype.Name, paytype.Id);
fi2.Paytypes.PaytypeRemovedEvent += (paytype) => Console.WriteLine("fi2 - Suppression d'un moyen de paiements id {1}, '{0}'", paytype.Name, paytype.Id);
// tiers
fi2.Thirdparties.ThirdpartyAddedEvent += (thirdparty) => Console.WriteLine("fi2 - Ajout d'un tiers id {2}, '{0}' de type {1}", thirdparty.Name, thirdparty.GetType().Name, thirdparty.Id);
fi2.Thirdparties.ThirdpartyUpdatedEvent += (thirdparty) => Console.WriteLine("fi2 - Modification d'un tiers id {1}, '{0}'", thirdparty.Name, thirdparty.Id);
fi2.Thirdparties.ThirdpartyRemovedEvent += (thirdparty) => Console.WriteLine("fi2 - Suppression d'un tiers id {1}, '{0}'", thirdparty.Name, thirdparty.Id);
// transferts
fi2.Accounts.Transfers.TransferAddedEvent += (transfer) => Console.WriteLine("fi2 - Ajout d'un transfert id {2}, '{0}' de type {1}", transfer.Name, transfer.GetType().Name, transfer.Id);
fi2.Accounts.Transfers.TransferUpdatedEvent += (transfer) => Console.WriteLine("fi2 - Modification d'un transfert id {1}, '{0}'", transfer.Name, transfer.Id);
fi2.Accounts.Transfers.TransferRemovedEvent += (transfer) => Console.WriteLine("fi2 - Suppression d'un transfert id {1}, '{0}'", transfer.Name, transfer.Id);
// operations
fi2.Accounts.Items.ForEach(a =>
{
a.Operations.OperationAddedEvent += (operation) => Console.WriteLine("fi2 - {0} - Ajout d'une opération id {3}, '{1}' de type {2}", a.Name, operation.Name, operation.GetType().Name, operation.Id);
a.Operations.OperationUpdatedEvent += (operation) => Console.WriteLine("fi2 - {0} - Modification d'une opération id {2}, '{1}'", a.Name, operation.Name, operation.Id);
a.Operations.OperationRemovedEvent += (operation) => Console.WriteLine("fi2 - {0} - Suppression d'une opération id {2}, '{1}'", a.Name, operation.Name, operation.Id);
});

// Affichage pour l'exemple des données brutes du dossier financier
Console.WriteLine("Affichage du contenu brut:");
Console.WriteLine(Encoding.UTF8.GetString(datas2));
Console.WriteLine("------------------------------------------------------------------------------------------------------");
Console.WriteLine(Encoding.UTF8.GetString(fi2.Serialize()));
Console.WriteLine("------------------------------------------------------------------------------------------------------");

// Poste automatiquement toutes les occurences programmées en retard (jusqu'a ce jour)
Console.WriteLine();
Console.WriteLine("Postage automatique de toutes les occurences restantes en retard...\r\n");
fi2.AutoPostOverdue();


//###############################################################################################################

// Pour l'exemple, calcule et affichage formatté du solde total de tous les éléments bancaires
Console.WriteLine();
Console.WriteLine("Solde total: {0}", fi2.Currency.Format(fi2.AmountAt(DateTime.Now, addInitialAmount: true)));

// Pour l'exemple, liste toutes les monnaies disponibles et indique celle du systeme
Console.WriteLine();
foreach (var c in Currencies.Availlable.OrderBy(a => a.CultureFullname))
{
if (c.IsCurrentCulture)
Console.WriteLine("Culture système: {0} | Monnaie: {1} {2}", c.CultureFullname, c.Symbol, c.Name);
}

if (!fi2.Accounts.GetById(fi2.Events[0].AccountId).Equals(default(Account)))
{
Console.WriteLine();
Console.WriteLine("Postage des occurences passées pour le compte {0} depuis le {1}",
fi2.Accounts.GetById(fi2.Events[0].AccountId).Name,
fi2.Events[0].StartDate.ToLongDateString());
fi2.Events[0].PostOverdue();
Console.WriteLine("dates restantes: {0}",
string.Join(", ", fi2.Events[0].GetNextCalendar().Select(d => d.ToLongDateString())));
Console.WriteLine("prochaine date: {0} ({1}/{2} occurences restantes)",
fi2.Events[0].NextDate.ToLongDateString(),
fi2.Events[0].Counter,
fi2.Events[0].RepeatCount);
}
else
fi2.Events.Remove(fi2.Events[0]);


Console.ReadLine();
}
Expand Down
21 changes: 20 additions & 1 deletion Kotlib/Financial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ public void OnSaved(object sender, EventArgs e)
SavedEvent.Invoke(sender, e);
}

/// <summary>
/// Informe qu'un événement programmé vient d'être posté
/// </summary>
/// <param name="date">Date programmée</param>
/// <param name="postEvent">Evénement et ses détails</param>
public void OnPostRaised(DateTime date, Event postEvent)
{
if (PostRaisedEvent != null)
PostRaisedEvent(date, postEvent);
}

/// <summary>
/// S'execute lorsque qu'un événement est posté
/// </summary>
Expand All @@ -158,9 +169,12 @@ public void OnSaved(object sender, EventArgs e)
private void EventPosted(DateTime date, Event postEvent)
{
var account = Accounts.GetById(postEvent.AccountId);
if(!account.Equals(default(Account)))
if (!account.Equals(default(Account)))
{
//TODO: Traiter l'opération ou le transfert à poster


OnPostRaised(date, postEvent);
}
}

Expand All @@ -183,6 +197,11 @@ private void EventPosted(DateTime date, Event postEvent)
/// </summary>
public event EventHandler SavedEvent;

/// <summary>
/// Se produit lorsque qu'un événement programmé est posté
/// </summary>
public event Event.PostDelegate PostRaisedEvent;

#endregion

#region Propriétés publiques
Expand Down
Loading

0 comments on commit d0a1f8d

Please sign in to comment.