Zaibon

Untitled

Jun 13th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Runtime.Serialization.Formatters.Binary;
  7.  
  8. namespace activite
  9. {
  10.     [Serializable()]
  11.     public class Agenda
  12.     {
  13.         [NonSerialized]private String name;
  14.         private List<Activite> listeActivite;
  15.  
  16.         public Agenda()
  17.         {
  18.             setAgenda("Inconnu", null);
  19.         }
  20.  
  21.         public Agenda(String n)
  22.         {
  23.             nom = n;
  24.             listAct = new List<Activite>();
  25.         }
  26.  
  27.         //public Agenda(String n, List<Activite> l)
  28.         //{
  29.         //    setAgenda(n, l);
  30.         //}
  31.  
  32.         private void setAgenda(String n , List<Activite> l)
  33.         {
  34.             nom = n;
  35.             listAct = l;
  36.         }
  37.  
  38.  
  39.         //propriétés
  40.         public String nom
  41.         {
  42.             set { name = value; }
  43.             get { return name; }
  44.         }
  45.  
  46.         public List<Activite> listAct
  47.         {
  48.             set { listeActivite = value; }
  49.             get { return listeActivite; }
  50.         }
  51.  
  52.         /*public void load()
  53.         {
  54.             string path = @"C:\agenda\agendas\" + nom + ".age";
  55.             load(path);
  56.         }*/
  57.  
  58.         public void load(string filePath)
  59.         {
  60.             Stream stream = File.Open(filePath, FileMode.Open);
  61.             BinaryFormatter formater = new BinaryFormatter();
  62.  
  63.             Agenda obj = (Agenda)formater.Deserialize(stream);
  64.  
  65.             this.listAct = obj.listAct;
  66.  
  67.             stream.Close();
  68.         }
  69.  
  70.         /*public void save()
  71.         {
  72.             string path = @"C:\agenda\agendas\" + nom + ".age";
  73.             save(path);
  74.         }*/
  75.  
  76.         public void save(string filePath)
  77.         {
  78.             Stream stream = File.Open(filePath, FileMode.Create);
  79.             BinaryFormatter formater = new BinaryFormatter();
  80.  
  81.             formater.Serialize(stream,this);
  82.             stream.Close();
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment