示例#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);
     }
 }
示例#2
0
文件: Primary.cs 项目: aspistrel/test
 public bool AddBook(Book tmp)
 {
     try
     {
         db.AddBook(tmp);
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
示例#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);
            }
        }
示例#4
0
文件: Xml.cs 项目: aspistrel/test
        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);
        }
示例#5
0
文件: Primary.cs 项目: aspistrel/test
        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);
        }
示例#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;
        }
示例#7
0
文件: Xml.cs 项目: aspistrel/test
 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;
         }
     }
 }
示例#8
0
文件: Xml.cs 项目: aspistrel/test
        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;
        }
示例#9
0
文件: UI.cs 项目: 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");
        }