Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.IO;
- using System.Xml;
- using System.Xml.Serialization;
- /// <summary>
- /// Summary description for Book
- /// </summary>
- [XmlRoot("BookStore")]
- public class BookStore
- {
- LinkedList<Book> booksList;
- public BookStore(){
- booksList = new LinkedList<Book>();
- }
- public void SaveToXML(string path)
- {
- XmlSerializer s = new XmlSerializer(typeof(BookStore));
- TextWriter w = new StreamWriter(path);
- s.Serialize(w, booksList);
- w.Close();
- }
- public void LoadFromXML(string path)
- {
- XmlSerializer s = new XmlSerializer(typeof(BookStore));
- TextReader r = new StreamReader(path);
- booksList = ((BookStore)s.Deserialize(r)).BooksList;
- r.Close();
- }
- public override string ToString()
- {
- string s = "";
- LinkedListNode<Book> l = booksList.First;
- while (l != null)
- {
- s += l.Value.Name + "; ";
- l = l.Next;
- }
- return s;
- }
- public void AddBook(Book book)
- {
- booksList.AddFirst(book);
- }
- public void RemoveBook(Book book)
- {
- booksList.Remove(book);
- }
- [XmlElement("Book")]
- public LinkedList<Book> BooksList
- {
- get { return booksList; }
- set { booksList = value; }
- }
- }
- public class Book
- {
- [XmlAttribute("name")]
- private string name;
- [XmlAttribute("imageurl")]
- private string imageurl;
- [XmlAttribute("subject")]
- private string subject;
- [XmlAttribute("author")]
- private string author;
- [XmlAttribute("level")]
- private int level;
- [XmlAttribute("year")]
- private int year;
- [XmlAttribute("price")]
- private double price;
- public Book()
- {
- }
- public Book(string name, string imageurl, string subject, string author, int level, int year, double price)
- {
- this.name = name;
- this.imageurl = imageurl;
- this.subject = subject;
- this.author = author;
- this.level = level;
- this.year = year;
- this.price = price;
- }
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- public string Imageurl
- {
- get { return imageurl; }
- set { imageurl = value; }
- }
- public string Subject
- {
- get { return subject; }
- set { subject = value; }
- }
- public string Author
- {
- get { return author; }
- set { author = value; }
- }
- public int Level
- {
- get { return level; }
- set { if (value > 0) level = value; }
- }
- public int Year
- {
- get { return year; }
- set { if ((value > 1900) && (value <= DateTime.Now.Year)) year = value; }
- }
- public double Price
- {
- get { return price; }
- set { if (value >= 0) price = value; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement