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) { List lstSql = new List(); string sLigne = ""; string[] sTabAttributs = null; if (!File.Exists(fichier)) return lstSql; StreamReader lecteur = new StreamReader(fichier); 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[nbAttributs]; sLigne = lecteur.ReadLine(); sTabAttributs = sLigne.Split('\t'); for (int j = 0; j < sTabAttributs.Length - 1; j++) { doubles[j] = Convert.ToDouble(sTabAttributs[j]); } string rep = Convert.ToInt32(sTabAttributs[sTabAttributs.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 * 2); 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; } } }