1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| /// <summary>
/// Enregistre les données du paramètrage
/// </summary>
public void enregistrer()
{
// Mise à jour de l'état du paramétrage
verifierParametragePasserelle();
// Enregistrement du paramétrage
String nomFichier = new StringBuilder(Application.RepertoireApplication).Append(Constantes.REPERTOIRE_DONNEES).Append("\\parametrageAcheterLouerFr.bin").ToString();
Stream fluxSortie = File.Open(nomFichier, FileMode.OpenOrCreate);
BinaryFormatter sortie = new BinaryFormatter();
sortie.Serialize(fluxSortie, this);
fluxSortie.Close();
}
/// <summary>
/// Charge le dernier paramètrage enregistré
/// </summary>
/// <returns>Paramètrage (null en cas d'erreur)</returns>
public static Parametrage charger()
{
try
{
String nomFichier = new StringBuilder(Application.RepertoireApplication).Append(Constantes.REPERTOIRE_DONNEES).Append("\\parametrageAcheterLouerFr.bin").ToString();
if (File.Exists(nomFichier))
{
Stream fluxEntree = File.OpenRead(nomFichier);
BinaryFormatter entree = new BinaryFormatter();
Parametrage parametrage = (Parametrage)entree.Deserialize(fluxEntree);
fluxEntree.Close();
return parametrage;
}
else
return new Parametrage();
}
catch (Exception e)
{
Evenement.enregistrerEvenement(System.Diagnostics.TraceEventType.Error, ConstantesEvenements.ERREUR_TRAITEMENT, "Parametrage.charger", e);
return null;
}
} |
Partager