Esempio n. 1
0
 public void EditBook(Book tmpBook)
 {
     using (var sw = new StreamWriter (Config.dir
                                      + (Config.tmpId).ToString()
                                      + Config.type))
     {
         sw.WriteLine(tmpBook.title);
         sw.WriteLine(tmpBook.author);
         sw.WriteLine(tmpBook.year);
     }
 }
Esempio n. 2
0
 public bool AddBook(Book tmp)
 {
     try
     {
         db.AddBook(tmp);
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
Esempio n. 3
0
        public void AddBook(Book tmp)
        {
            GetLastBookId();

            Config.gid+=1;
            tmp.id = Config.gid;

            using(var sw = new StreamWriter (Config.dir
                                            + tmp.id.ToString()
                                            + Config.type))
            {
                sw.WriteLine(tmp.title);
                sw.WriteLine(tmp.author);
                sw.WriteLine(tmp.year);
            }
        }
Esempio n. 4
0
        public void AddBook(Book tmpBook)
        {
            GetLastBookId();

              Config.gid+=1;
              tmpBook.id = Config.gid;

              XElement book = new XElement("book",
               new XAttribute("id", Config.gid),
               new XElement("title", tmpBook.title),
               new XElement("author", tmpBook.author),
               new XElement("year", tmpBook.year));

               library.Add(book);
               library.Save(Config.dirXml);
        }
Esempio n. 5
0
        public void EditBook(int mode, 
		                     string content)
        {
            var tmpBook = new Book();

            tmpBook = db.ReadBook(Config.tmpId);

            switch(mode)
            {
                case 1: tmpBook.title = content;
                    break;
                case 2: tmpBook.author = content;
                    break;
                case 3: tmpBook.year = Int32.Parse(content);
                    break;
            }

            db.EditBook(tmpBook);
        }
Esempio n. 6
0
        public Book ReadBook(int id)
        {
            var tmpBook = new Book();

            using(var sr = new StreamReader(Config.dir
                                            + id.ToString()
                                            + Config.type))
            {
                tmpBook.id = id;
                tmpBook.title = sr.ReadLine();
                tmpBook.author = sr.ReadLine();
                tmpBook.year = Int32.Parse(sr.ReadLine());
            }

            return tmpBook;
        }
Esempio n. 7
0
 public void EditBook(Book tmpBook)
 {
     foreach (XElement el in xdoc.Root.Elements())
     {
         if (Int32.Parse(el.Attribute("id").Value) == Config.tmpId)
         {
             el.Element("title").Value = tmpBook.title;
             el.Element("author").Value = tmpBook.author;
             el.Element("year").Value = tmpBook.year.ToString();
             library.Save(Config.dirXml);
             break;
         }
     }
 }
Esempio n. 8
0
        public Book ReadBook(int id)
        {
            Book tmpBook = new Book();

            foreach (XElement el in xdoc.Root.Elements())
            {
                if (Int32.Parse(el.Attribute("id").Value) == id)
                {
                    tmpBook.id = id;
                    tmpBook.title = el.Element("title").Value;
                    tmpBook.author = el.Element("author").Value;
                    tmpBook.year = Int32.Parse(el.Element("year").Value);
                    break;
                }
            }

            return tmpBook;
        }
Esempio n. 9
0
File: UI.cs Progetto: aspistrel/test
        /*
         * Добавить книгу
         */
        void UIAddBook()
        {
            Book tmp = new Book();

            Console.WriteLine ("Введите название книги");
            tmp.title = Console.ReadLine();

            Console.WriteLine ("Введите автора книги");
            tmp.author = Console.ReadLine();

            Console.WriteLine ("Введите год издания книги");
            tmp.year = Int32.Parse(Console.ReadLine());

            if(prim.AddBook(tmp))
                Console.WriteLine ("Книга с id "
                                  + tmp.id
                                  + " добавлена" );
            else
                Console.WriteLine ("ERROR");
        }