Пример #1
0
        //This function populates a list Book objects from the db that have the specified column name/value
        //the second set of name/value is optional and defaults to null
        public static void SelectAllByWildAttr(List<Book> bookList, string wildcard, string attribute, string wildcard2 = null, string attribute2 = null)
        {
            Database db = new Database();
            OleDbDataReader reader;

            db.Open();

            if(wildcard2 == null)
                reader = db.Read("select * from book_view where " + attribute + " like '%" + wildcard + "%'");
            else
                reader = db.Read("select * from book_view where " + attribute + " like '%" + wildcard + "%' AND " + attribute2 + " like '%" + wildcard2 + "%'");

            while (reader.Read())
            {
                Book tmpBook = new Book();
                tmpBook.isbn = reader.GetString(0).Trim();
                tmpBook.title = reader.GetString(1).Trim();
                tmpBook.l_name = reader.GetString(2).Trim();
                tmpBook.f_name = reader.GetString(3).Trim();
                tmpBook.qoh = Convert.ToInt32(reader.GetValue(4));
                tmpBook.retailPrice = String.Format("{0:F}", reader.GetValue(5));
                tmpBook.category = reader.GetString(6).Trim();
                tmpBook.filename = reader.GetString(7).Trim();
                tmpBook.description = reader.GetString(8).Trim();
                tmpBook.wholesalePrice = String.Format("{0:F}", reader.GetValue(9));
                tmpBook.percentProfit = String.Format("{0:F}", reader.GetValue(10));

                bookList.Add(tmpBook);
            }

            db.Close();
        }
Пример #2
0
        public JsonResult FindBook(string id)
        {
            //Create new book object and populate it, if a book can be found with a matching isbn
            Book book = new Book();
            book.SelectById(id);

            //Return the book, all vars will be null if the isbn wasn't found
            return Json(book, JsonRequestBehavior.AllowGet);
        }
Пример #3
0
        public static void SelectAllByAttr(string id, string attribute, List<Book> bookList)
        {
            Database db = new Database();
            OleDbDataReader reader;

            db.Open();
            reader = db.Read("select * from book_view where " + attribute + " = '" + id + "'");

            while (reader.Read())
            {
                Book tmpBook = new Book();
                tmpBook.isbn = reader.GetString(0).Trim();
                tmpBook.title = reader.GetString(1).Trim();
                tmpBook.l_name = reader.GetString(2).Trim();
                tmpBook.f_name = reader.GetString(3).Trim();
                tmpBook.qoh = Convert.ToInt32(reader.GetValue(4));
                tmpBook.retailPrice = String.Format("{0:F}", reader.GetValue(5));
                tmpBook.category = reader.GetString(6).Trim();
                tmpBook.filename = reader.GetString(7).Trim();
                tmpBook.description = reader.GetString(8).Trim();

                bookList.Add(tmpBook);
            }

            db.Close();
        }