Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Serialization;
  8.  
  9. namespace Michaล‚_Baran
  10. {
  11.     [Serializable]
  12.     class ListaOgloszen
  13.     {
  14.         public string nazwa;
  15.         public Stack<Ogloszenie> ogloszenia;
  16.  
  17.         public ListaOgloszen(string nazwa)
  18.         {
  19.             this.nazwa = nazwa;
  20.             ogloszenia = new Stack<Ogloszenie>();
  21.         }
  22.  
  23.         public ListaOgloszen()
  24.         {
  25.             ogloszenia = new Stack<Ogloszenie>();
  26.         }
  27.  
  28.         public string Nazwa { get => nazwa; set => nazwa = value; }
  29.  
  30.         public void DodajOgloszenie(Ogloszenie o)
  31.         {
  32.             ogloszenia.Push(o);
  33.  
  34.         }
  35.  
  36.         public string PodajOstatnie(int liczba)
  37.         {
  38.             Stack<Ogloszenie> wynik = new Stack<Ogloszenie>();
  39.             int x = ogloszenia.Count;
  40.  
  41.             for (int i = 0; i <= x; i++)
  42.             {
  43.                 var item = ogloszenia.ElementAt(x);
  44.                 wynik.Push(item);
  45.             }
  46.  
  47.             StringBuilder sb = new StringBuilder();
  48.  
  49.  
  50.             foreach (Ogloszenie o in wynik)
  51.             {
  52.                 sb.AppendLine(o.ToString());
  53.             }
  54.             return sb.ToString();
  55.  
  56.  
  57.         }
  58.  
  59.         //public string ZnajdzOgloszenie(string slowo)
  60.         //{
  61.         //   return ogloszenia.First<>
  62.         //}
  63.  
  64.         public override string ToString()
  65.         {
  66.             StringBuilder sb = new StringBuilder();
  67.             foreach (Ogloszenie o in ogloszenia)
  68.             {
  69.                 sb.AppendLine(o.ToString());
  70.             }
  71.             return sb.ToString();
  72.         }
  73.  
  74.         public static void ZapiszXML(string nazwa, ListaOgloszen z)
  75.         {
  76.             XmlSerializer serializer = new XmlSerializer(typeof(ListaOgloszen));
  77.             StreamWriter writer = new StreamWriter(nazwa);
  78.             serializer.Serialize(writer, z);
  79.             writer.Close();
  80.         }
  81.  
  82.         public static ListaOgloszen OdczytajXML(string nazwa)
  83.         {
  84.             XmlSerializer serializer = new XmlSerializer(typeof(ListaOgloszen));
  85.  
  86.             using (StreamReader reader = new StreamReader(nazwa))
  87.             {
  88.                 ListaOgloszen wynik = serializer.Deserialize(reader) as ListaOgloszen;
  89.                 return wynik;
  90.             }
  91.  
  92.  
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement