Files
Hoy/JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/GestionFichiersSorties.cs
MarcEricMartel c494485a05 Gestion Fichiers
2023-05-03 11:26:33 -04:00

67 lines
2.0 KiB
C#

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<Squelette> ChargerCoordonnees(string fichier)
{
StreamReader lecteur = new StreamReader(fichier);
string sLigne = "";
List<Squelette> lstSql = new List<Squelette>();
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<Squelette> lstData)
{
StreamWriter sw = new StreamWriter(fichier);
sw.WriteLine(lstData.Count);
sw.WriteLine(CstApplication.SKELETONCOUNT);
try {
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;
}
}
}