Guest User

Untitled

a guest
May 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.17 KB | None | 0 0
  1.    public class Ksiazka : Publikacje
  2.  
  3.     {
  4.          public string nazwawydawnictwa { set; get; }
  5.  
  6.           public Ksiazka()
  7.         {
  8.         }
  9.         public Ksiazka(string autor, string tytul, int rokwydania, string nazwawydawnictwa, string metki)
  10.         {
  11.             this.autor = autor;
  12.             this.tytul = tytul;
  13.             this.rokwydania = rokwydania;
  14.             this.nazwawydawnictwa = nazwawydawnictwa;
  15.             this.metki = metki;
  16.         }
  17.         public void wyswietlanie()
  18.         {
  19.             serializacja master = new serializacja();
  20.             master.Parts.Add(new Ksiazka());
  21.             List<Type> partTypes = new List<Type>();
  22.             foreach (Type type in typeof(Publikacje).Assembly.GetTypes())
  23.                 {
  24.  
  25.                     if (type.IsSubclassOf(typeof(Publikacje)))
  26.  
  27.                         partTypes.Add(type);
  28.  
  29.                 }
  30.             FileStream fileStream = new FileStream("data.xml", FileMode.Open);
  31.             XmlSerializer xs = new XmlSerializer(master.GetType(), partTypes.ToArray());
  32.             master = xs.Deserialize(fileStream) as List<serializacja>;
  33.            
  34.            
  35.             fileStream.Close();
  36.             Console.ReadLine();
  37.                            
  38.    
  39.         }
  40.         public override void  pobierzdane()
  41.         {
  42.             Console.WriteLine("Podaj imiona i nazwiska autora(ów): ");
  43.             this.autor = Console.ReadLine();
  44.             Console.WriteLine("Podaj tytuł książki: ");
  45.             this.tytul = Console.ReadLine();
  46.             Console.WriteLine("Podaj rok wydania: ");
  47.             do
  48.             {
  49.                 try
  50.                 {
  51.                    
  52.                     this.rokwydania = Convert.ToInt32(Console.ReadLine());
  53.                 }
  54.                 catch (Exception)
  55.                 {
  56.                     Console.WriteLine("Rok musi być liczbą, podaj rok wydania jeszcze raz");
  57.  
  58.                 }
  59.  
  60.             } while (rokwydania == 0);
  61.             Console.WriteLine("Podaj nazwę wydawnictwa: ");
  62.             this.nazwawydawnictwa = Console.ReadLine();
  63.             Console.WriteLine("Podaj słowa kluczowe(metki): ");
  64.             this.metki = Console.ReadLine();
  65.             Ksiazka dane = new Ksiazka(this.autor,this.tytul,this.rokwydania,this.nazwawydawnictwa,this.metki);
  66.             {
  67.  
  68.                 serializacja master = new serializacja();
  69.  
  70.  
  71.                 master.Parts.Add(dane);
  72.  
  73.                
  74.  
  75.  
  76.                 List<Type> partTypes = new List<Type>();
  77.  
  78.                 foreach (Type type in typeof(Publikacje).Assembly.GetTypes())
  79.                 {
  80.  
  81.                     if (type.IsSubclassOf(typeof(Publikacje)))
  82.  
  83.                         partTypes.Add(type);
  84.  
  85.                 }
  86.  
  87.               FileStream fileStream = new FileStream("data.xml", FileMode.Append);
  88.               XmlSerializer xs = new XmlSerializer(master.GetType(), partTypes.ToArray());
  89.  
  90.                xs.Serialize(fileStream, master);
  91.                fileStream.Close();
  92.                 Console.ReadLine();
  93.      
  94.  
  95.             }
  96.            
  97.          
  98.          
  99.            
  100.            
  101.            
  102.         }
  103.      
  104.     }
  105. }
Add Comment
Please, Sign In to add comment