using Model; using System; using System.Collections.Generic; using System.Diagnostics; using System.Formats.Asn1; using System.Globalization; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using static System.Net.Mime.MediaTypeNames; namespace Data { public static class LoadOperation { public static IList LoadOperationsFromOFX(string ofx) { IList lesComptes = new List(); Compte compteEnCoursDeSaisie = null; //détail d'une Operation string intituleOperation; double montant; DateTime dateOperation; MethodePayement modePayement; bool isDebit; //info compte string identifiantCompte=""; using (StreamReader reader = new StreamReader(ofx)) { if (reader != null) { string row; while ((row = reader.ReadLine()) != null) { if (row.Contains("")) { compteEnCoursDeSaisie = new Compte(identifiantCompte, identifiantCompte, 0); } else if (row.Contains("")){ lesComptes.Add(compteEnCoursDeSaisie); } else if (row.Contains("") || row.Contains("")) { compteEnCoursDeSaisie.Identifiant = CutRow(row).Last(); compteEnCoursDeSaisie.Nom = CutRow(row).Last(); } else if (row.Contains("")) { compteEnCoursDeSaisie.Solde = double.Parse(CutRow(row).Last(), CultureInfo.InvariantCulture); } else if (row.Contains("")) { row = ""; intituleOperation = ""; montant = 0; dateOperation = new DateTime(); modePayement = MethodePayement.None; isDebit = false; while ((row = reader.ReadLine()) != "") { if (row.Contains("")) { DateTime.TryParseExact(CutRow(row).Last(), "yyyyMMdd", null, DateTimeStyles.None, out dateOperation); } else if (row.Contains("")) { montant = double.Parse(CutRow(row).Last(), CultureInfo.InvariantCulture); if (montant < 0) { isDebit = true; montant = Math.Abs(montant); } } else if (row.Contains("")) { intituleOperation = CutRow(row).Last(); } else if (row.Contains("")) { if (row.Contains("PAIEMENT")) { modePayement = MethodePayement.CB; } else { modePayement = MethodePayement.None; } } else { row = ""; } } compteEnCoursDeSaisie.ajouterOperation(new Operation(intituleOperation, montant, dateOperation, modePayement, TagOperation.None, isDebit)); } else { row = ""; } } } } return lesComptes; } private static string[] CutRow(string row) { string[] cutRow; if (row == null) throw new ArgumentNullException(); cutRow = row.Split('>'); return cutRow; } } }