Book.cs
上传用户:gooyliu
上传日期:2018-09-29
资源大小:5816k
文件大小:3k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using Model;
  7. namespace DataAccessLayer
  8. {
  9.    public  class DALBook
  10.     {
  11.         public DALBook()
  12.         {
  13.         }
  14.         public bool AddBook(BookInfo bkInfo)
  15.         {
  16.             DataBase db = new DataBase();
  17.             SqlParameter[] param = new SqlParameter[]{
  18.             new SqlParameter("@bookID",bkInfo.BookID ),  
  19.             new SqlParameter("@bookName",bkInfo.BookName ),
  20.             new SqlParameter("@bookIndex",bkInfo.BookIndex ),
  21.             new SqlParameter("@bookTypeID",bkInfo .BookTypeID ),
  22.             new SqlParameter("@author",bkInfo .Author ),
  23.             new SqlParameter("@publish",bkInfo .Publish ),
  24.             new SqlParameter("@price",bkInfo.Price ),
  25.             new SqlParameter("@publishDate",bkInfo.PublishDate ),
  26.             new SqlParameter("@abstract",bkInfo .Abstrac ),
  27.             new SqlParameter("@keyword",bkInfo .Keyword ),
  28.             new SqlParameter("@status",bkInfo.BookStatus),
  29.             new SqlParameter("@registeDate",bkInfo.RegisteDate ) };
  30.             int linecount=db.RunProc("Proc_AddBook", param);
  31.             if (linecount == -1)
  32.                 return false;
  33.             else
  34.                 return true; 
  35.         }
  36.        public DataSet SearchBook(int typeID, string queryByCol, string content)
  37.        {
  38.            DataSet ds = new DataSet();
  39.            DataBase db = new DataBase();
  40.            SqlParameter[] Params = new SqlParameter[3];
  41.            Params[0] = db.MakeInParam("@bookTypeID",SqlDbType.Int , 20, typeID);
  42.            Params[1] = db.MakeInParam("@queryByCol",SqlDbType .NVarChar, 50,queryByCol);
  43.            Params[2] = db.MakeInParam("@Content", SqlDbType .NVarChar ,50 ,content);
  44.            ds=db.GetDataSet("Proc_SearchBook", Params);
  45.            return ds;
  46.        }
  47.        public DataSet GetBookInfoByID(string XBookID)
  48.        {
  49.            DataSet ds = new DataSet();
  50.            DataBase db = new DataBase();
  51.            SqlParameter[] param = new SqlParameter[1];
  52.            param[0] = db.MakeInParam("@bookID", SqlDbType.NVarChar, 50, XBookID);
  53.            ds=db.GetDataSet("Proc_GetBookInfoByID", param);
  54.            return ds;
  55.        }
  56.        //更新一本书的信息,status和registerdate是不可更该的
  57.        public bool updateBook(BookInfo bkInfo)
  58.        {
  59.            DataBase db = new DataBase();
  60.            SqlParameter[] param = new SqlParameter[]{
  61.             new SqlParameter("@bookID",bkInfo.BookID), 
  62.             new SqlParameter("@bookName",bkInfo.BookName ),
  63.             new SqlParameter("@bookIndex",bkInfo.BookIndex ),
  64.             new SqlParameter("@bookTypeID",bkInfo .BookTypeID ),
  65.             new SqlParameter("@author",bkInfo .Author ),
  66.             new SqlParameter("@publish",bkInfo .Publish ),
  67.             new SqlParameter("@price",bkInfo.Price ),
  68.             new SqlParameter("@publishDate",bkInfo.PublishDate ),
  69.             new SqlParameter("@abstract",bkInfo .Abstrac ),
  70.             new SqlParameter("@keyword",bkInfo .Keyword )};
  71.            int linecount = db.RunProc("Proc_UpdateBookByID", param);
  72.            if (linecount == -1)
  73.                return false;
  74.            else
  75.                return true;
  76.        }
  77.     }
  78. }