using JeuHoy_WPF; using System; using System.Collections.Generic; using System.IO; namespace JeuHoy_WPF_Natif.Model { public class GestionFichiersSorties : IGestionFichiers { public GestionFichiersSorties(){} public List ChargerCoordonnees(string fichier) { StreamReader lecteur = new StreamReader(fichier); List lstSql = new List(); string sLigne = ""; string[] sTabElements = null; if (!lecteur.EndOfStream) { sLigne = lecteur.ReadLine(); int nbElements = Convert.ToInt32(sLigne); sLigne = lecteur.ReadLine(); int nbAttributs = Convert.ToInt32(sLigne); for (int i = 0; i < nbElements; i++) { double[] doubles = new double[nbElements - 1]; sLigne = lecteur.ReadLine(); sTabElements = sLigne.Split('\t'); for (int j = 0; j < sTabElements.Length - 1; j++) { doubles[j] = Convert.ToDouble(sTabElements[j]); } string rep = Convert.ToInt32(sTabElements[sTabElements.Length - 1]).ToString(); lstSql.Add(new Squelette(doubles, rep)); } } return lstSql; } public int SauvegarderCoordonnees(string fichier, List lstData) { StreamWriter sw = null; try { sw = new StreamWriter(fichier); } catch { return CstApplication.ERREUR; } try { sw.WriteLine(lstData.Count); sw.WriteLine(CstApplication.SKELETONCOUNT); foreach (Squelette s in lstData) { foreach (double point in s.Points) { sw.Write(point.ToString() + "\t"); } sw.Write(s.Reponse + "\r\n"); } } catch { sw.Close(); return CstApplication.ERREUR; } sw.Flush(); sw.Close(); return CstApplication.OK; } } }