Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. class Book
  2.     {
  3.         // Book variables
  4.         string title, subtitle, author;
  5.         int id, part, pages;
  6.  
  7.         // Adds a new book to the memory stack
  8.         public Book(int id, string title, string subtitle, string author, int part, int pages)
  9.         {
  10.             this.id = id;
  11.             this.title = title;
  12.             this.subtitle = subtitle;
  13.             this.author = author;
  14.             this.part = part;
  15.             this.pages = pages;
  16.         }
  17.  
  18.         public string Title { get => title; set => title = value; }
  19.         public string Subtitle { get => subtitle; set => subtitle = value; }
  20.         public string Author { get => author; set => author = value; }
  21.         public int Id { get => id; set => id = value; }
  22.         public int Part { get => part; set => part = value; }
  23.         public int Pages { get => pages; set => pages = value; }
  24.  
  25.         // Object > XML
  26.         public void Book_Add(string path)
  27.         {
  28.             if (File.Exists(path))
  29.             {
  30.                 XElement root = XElement.Load(path);
  31.                 root.Add(
  32.                     new XElement("book",
  33.                         new XElement("id", id),
  34.                         new XElement("title", title),
  35.                         new XElement("subtitle", subtitle),
  36.                         new XElement("author", author),
  37.                         new XElement("part", part),
  38.                         new XElement("pages", pages)
  39.                     )
  40.                 );
  41.                 root.Save(path);
  42.             }
  43.  
  44.             else
  45.             {
  46.                 XDocument catalogus = new XDocument(
  47.                 new XDeclaration("1.0", "UTF-8", null),
  48.                 new XElement("books",
  49.                     new XElement("book",
  50.                         new XElement("id", id),
  51.                         new XElement("title", title),
  52.                         new XElement("subtitle", subtitle),
  53.                         new XElement("author", author),
  54.                         new XElement("part", part),
  55.                         new XElement("pages", pages)
  56.                     )
  57.                 )
  58.             );
  59.                 catalogus.Save(path);
  60.             }
  61.         }
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement