Exemplo n.º 1
0
        //根据Id查询图书信息
        public static Books GetBooksById(int id)
        {
            int    PublisherId;
            int    CategoryId;
            string sql = "select * from Books where Id=" + id;

            try
            {
                SqlDataReader row = DBHelper.GetReader(sql);
                if (row.Read())
                {
                    Books book = new Books();
                    book.Id                 = (int)row["Id"];
                    book.Title              = (string)row["Title"];
                    book.Author             = (string)row["Author"];
                    book.AurhorDescription  = (string)row["AurhorDescription"];
                    book.ISBN               = (string)row["ISBN"];
                    book.TOC                = (string)row["TOC"];
                    book.ContentDescription = (string)row["ContentDescription"];
                    book.EditorComment      = (string)row["EditorComment"];
                    book.WordsCount         = (int)row["WordsCount"];
                    book.UnitPrice          = (decimal)row["UnitPrice"];
                    book.PublishDate        = (DateTime)row["PublishDate"];
                    book.Clicks             = (int)row["Clicks"];

                    PublisherId = (int)row["PublisherId"];
                    CategoryId  = (int)row["CategoryId"];
                    row.Close();

                    book.Publisher = PublisherService.GetPublishersById(PublisherId);
                    book.Catagorys = CatagoryService.GetCatagoryById(CategoryId);

                    return(book);
                }
                else
                {
                    row.Close();
                    return(null);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
Exemplo n.º 2
0
        //查询所有图书信息
        public static IList <Books> GetBooksAll()
        {
            IList <Books> list = new List <Books>();
            string        sql  = "select * from Books";

            try
            {
                DataTable table = DBHelper.GetDataSet(sql);
                foreach (DataRow row in table.Rows)
                {
                    Books book = new Books();
                    book.Id                 = (int)row["Id"];
                    book.Title              = (string)row["Title"];
                    book.Author             = (string)row["Author"];
                    book.AurhorDescription  = (string)row["AurhorDescription"];
                    book.ISBN               = (string)row["ISBN"];
                    book.TOC                = (string)row["TOC"];
                    book.ContentDescription = (string)row["ContentDescription"];
                    book.EditorComment      = (string)row["EditorComment"];
                    book.WordsCount         = (int)row["WordsCount"];
                    book.UnitPrice          = (decimal)row["UnitPrice"];
                    book.PublishDate        = (DateTime)row["PublishDate"];
                    book.Clicks             = (int)row["Clicks"];

                    book.Publisher = PublisherService.GetPublishersById((int)row["PublisherId"]);
                    book.Catagorys = CatagoryService.GetCatagoryById((int)row["CategoryId"]);

                    list.Add(book);
                }
                return(list);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }