Example #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public BookShop.Model.Book DataRowToModel(DataRow row)
 {
     BookShop.Model.Book model = new BookShop.Model.Book();
     if (row != null)
     {
         if (row["ISBN"] != null)
         {
             model.ISBN = row["ISBN"].ToString();
         }
         if (row["bookTitle"] != null)
         {
             model.bookTitle = row["bookTitle"].ToString();
         }
         if (row["author"] != null)
         {
             model.author = row["author"].ToString();
         }
         if (row["publishDate"] != null && row["publishDate"].ToString() != "")
         {
             model.publishDate = DateTime.Parse(row["publishDate"].ToString());
         }
         if (row["version"] != null && row["version"].ToString() != "")
         {
             model.version = int.Parse(row["version"].ToString());
         }
         if (row["stockNumber"] != null && row["stockNumber"].ToString() != "")
         {
             model.stockNumber = int.Parse(row["stockNumber"].ToString());
         }
         if (row["price"] != null && row["price"].ToString() != "")
         {
             model.price = decimal.Parse(row["price"].ToString());
         }
         if (row["salePrice"] != null && row["salePrice"].ToString() != "")
         {
             model.salePrice = decimal.Parse(row["salePrice"].ToString());
         }
         if (row["introduction"] != null)
         {
             model.introduction = row["introduction"].ToString();
         }
         if (row["catalog"] != null)
         {
             model.catalog = row["catalog"].ToString();
         }
         if (row["categoryId"] != null && row["categoryId"].ToString() != "")
         {
             model.categoryId = int.Parse(row["categoryId"].ToString());
         }
         if (row["pressNo"] != null && row["pressNo"].ToString() != "")
         {
             model.pressNo = int.Parse(row["pressNo"].ToString());
         }
     }
     return(model);
 }
Example #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BookShop.Model.Book model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Book set ");
            strSql.Append("bookTitle=@bookTitle,");
            strSql.Append("author=@author,");
            strSql.Append("publishDate=@publishDate,");
            strSql.Append("version=@version,");
            strSql.Append("stockNumber=@stockNumber,");
            strSql.Append("price=@price,");
            strSql.Append("salePrice=@salePrice,");
            strSql.Append("introduction=@introduction,");
            strSql.Append("catalog=@catalog,");
            strSql.Append("categoryId=@categoryId,");
            strSql.Append("pressNo=@pressNo");
            strSql.Append(" where ISBN=@ISBN ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@bookTitle",    SqlDbType.NVarChar,  200),
                new SqlParameter("@author",       SqlDbType.NVarChar,  200),
                new SqlParameter("@publishDate",  SqlDbType.DateTime),
                new SqlParameter("@version",      SqlDbType.Int,         4),
                new SqlParameter("@stockNumber",  SqlDbType.Int,         4),
                new SqlParameter("@price",        SqlDbType.Money,       8),
                new SqlParameter("@salePrice",    SqlDbType.Money,       8),
                new SqlParameter("@introduction", SqlDbType.NVarChar,   -1),
                new SqlParameter("@catalog",      SqlDbType.NVarChar,   -1),
                new SqlParameter("@categoryId",   SqlDbType.Int,         4),
                new SqlParameter("@pressNo",      SqlDbType.Int,         4),
                new SqlParameter("@ISBN",         SqlDbType.NVarChar, 50)
            };
            parameters[0].Value  = model.bookTitle;
            parameters[1].Value  = model.author;
            parameters[2].Value  = model.publishDate;
            parameters[3].Value  = model.version;
            parameters[4].Value  = model.stockNumber;
            parameters[5].Value  = model.price;
            parameters[6].Value  = model.salePrice;
            parameters[7].Value  = model.introduction;
            parameters[8].Value  = model.catalog;
            parameters[9].Value  = model.categoryId;
            parameters[10].Value = model.pressNo;
            parameters[11].Value = model.ISBN;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(BookShop.Model.Book model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Books set ");
            strSql.Append("Title=@Title,");
            strSql.Append("Author=@Author,");
            strSql.Append("PublisherId=@PublisherId,");
            strSql.Append("PublishDate=@PublishDate,");
            strSql.Append("ISBN=@ISBN,");
            strSql.Append("WordsCount=@WordsCount,");
            strSql.Append("UnitPrice=@UnitPrice,");
            strSql.Append("ContentDescription=@ContentDescription,");
            strSql.Append("AurhorDescription=@AurhorDescription,");
            strSql.Append("EditorComment=@EditorComment,");
            strSql.Append("TOC=@TOC,");
            strSql.Append("CategoryId=@CategoryId,");
            strSql.Append("Clicks=@Clicks");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id",                 SqlDbType.Int,         4),
                new SqlParameter("@Title",              SqlDbType.NVarChar,  200),
                new SqlParameter("@Author",             SqlDbType.NVarChar,  200),
                new SqlParameter("@PublisherId",        SqlDbType.Int,         4),
                new SqlParameter("@PublishDate",        SqlDbType.DateTime),
                new SqlParameter("@ISBN",               SqlDbType.NVarChar,   50),
                new SqlParameter("@WordsCount",         SqlDbType.Int,         4),
                new SqlParameter("@UnitPrice",          SqlDbType.Money,       8),
                new SqlParameter("@ContentDescription", SqlDbType.NVarChar),
                new SqlParameter("@AurhorDescription",  SqlDbType.NVarChar),
                new SqlParameter("@EditorComment",      SqlDbType.NVarChar),
                new SqlParameter("@TOC",                SqlDbType.NVarChar),
                new SqlParameter("@CategoryId",         SqlDbType.Int,         4),
                new SqlParameter("@Clicks",             SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.Id;
            parameters[1].Value  = model.Title;
            parameters[2].Value  = model.Author;
            parameters[3].Value  = model.Publisher.Id;
            parameters[4].Value  = model.PublishDate;
            parameters[5].Value  = model.ISBN;
            parameters[6].Value  = model.WordsCount;
            parameters[7].Value  = model.UnitPrice;
            parameters[8].Value  = model.ContentDescription;
            parameters[9].Value  = model.AurhorDescription;
            parameters[10].Value = model.EditorComment;
            parameters[11].Value = model.TOC;
            parameters[12].Value = model.Category.Id;
            parameters[13].Value = model.Clicks;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Example #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BookShop.Model.Book model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Books(");
            strSql.Append("Title,Author,PublisherId,PublishDate,ISBN,WordsCount,UnitPrice,ContentDescription,AurhorDescription,EditorComment,TOC,CategoryId,Clicks)");
            strSql.Append(" values (");
            strSql.Append("@Title,@Author,@PublisherId,@PublishDate,@ISBN,@WordsCount,@UnitPrice,@ContentDescription,@AurhorDescription,@EditorComment,@TOC,@CategoryId,@Clicks)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",              SqlDbType.NVarChar,  200),
                new SqlParameter("@Author",             SqlDbType.NVarChar,  200),
                new SqlParameter("@PublisherId",        SqlDbType.Int,         4),
                new SqlParameter("@PublishDate",        SqlDbType.DateTime),
                new SqlParameter("@ISBN",               SqlDbType.NVarChar,   50),
                new SqlParameter("@WordsCount",         SqlDbType.Int,         4),
                new SqlParameter("@UnitPrice",          SqlDbType.Money,       8),
                new SqlParameter("@ContentDescription", SqlDbType.NVarChar),
                new SqlParameter("@AurhorDescription",  SqlDbType.NVarChar),
                new SqlParameter("@EditorComment",      SqlDbType.NVarChar),
                new SqlParameter("@TOC",                SqlDbType.NVarChar),
                new SqlParameter("@CategoryId",         SqlDbType.Int,         4),
                new SqlParameter("@Clicks",             SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.Title;
            parameters[1].Value  = model.Author;
            parameters[2].Value  = 35;
            parameters[3].Value  = model.PublishDate;
            parameters[4].Value  = model.ISBN;
            parameters[5].Value  = model.WordsCount;
            parameters[6].Value  = model.UnitPrice;
            parameters[7].Value  = model.ContentDescription;
            parameters[8].Value  = model.AurhorDescription;
            parameters[9].Value  = model.EditorComment;
            parameters[10].Value = model.TOC;
            parameters[11].Value = 1;
            parameters[12].Value = model.Clicks;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);


            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(BookShop.Model.Book model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Book(");
            strSql.Append("ISBN,bookTitle,author,publishDate,version,stockNumber,price,salePrice,introduction,catalog,categoryId,pressNo)");
            strSql.Append(" values (");
            strSql.Append("@ISBN,@bookTitle,@author,@publishDate,@version,@stockNumber,@price,@salePrice,@introduction,@catalog,@categoryId,@pressNo)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ISBN",         SqlDbType.NVarChar,   50),
                new SqlParameter("@bookTitle",    SqlDbType.NVarChar,  200),
                new SqlParameter("@author",       SqlDbType.NVarChar,  200),
                new SqlParameter("@publishDate",  SqlDbType.DateTime),
                new SqlParameter("@version",      SqlDbType.Int,         4),
                new SqlParameter("@stockNumber",  SqlDbType.Int,         4),
                new SqlParameter("@price",        SqlDbType.Money,       8),
                new SqlParameter("@salePrice",    SqlDbType.Money,       8),
                new SqlParameter("@introduction", SqlDbType.NVarChar,   -1),
                new SqlParameter("@catalog",      SqlDbType.NVarChar,   -1),
                new SqlParameter("@categoryId",   SqlDbType.Int,         4),
                new SqlParameter("@pressNo",      SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.ISBN;
            parameters[1].Value  = model.bookTitle;
            parameters[2].Value  = model.author;
            parameters[3].Value  = model.publishDate;
            parameters[4].Value  = model.version;
            parameters[5].Value  = model.stockNumber;
            parameters[6].Value  = model.price;
            parameters[7].Value  = model.salePrice;
            parameters[8].Value  = model.introduction;
            parameters[9].Value  = model.catalog;
            parameters[10].Value = model.categoryId;
            parameters[11].Value = model.pressNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #6
0
 private void ShowInfo(string ISBN)
 {
     BookShop.BLL.Book   bll   = new BookShop.BLL.Book();
     BookShop.Model.Book model = bll.GetModel(ISBN);
     this.lblISBN.Text         = model.ISBN;
     this.txtbookTitle.Text    = model.bookTitle;
     this.txtauthor.Text       = model.author;
     this.txtpublishDate.Text  = model.publishDate.ToString();
     this.txtversion.Text      = model.version.ToString();
     this.txtstockNumber.Text  = model.stockNumber.ToString();
     this.txtprice.Text        = model.price.ToString();
     this.txtsalePrice.Text    = model.salePrice.ToString();
     this.txtintroduction.Text = model.introduction;
     this.txtcatalog.Text      = model.catalog;
     this.txtcategoryId.Text   = model.categoryId.ToString();
     this.txtpressNo.Text      = model.pressNo.ToString();
 }
Example #7
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookShop.Model.Book GetModel(string ISBN)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ISBN,bookTitle,author,publishDate,version,stockNumber,price,salePrice,introduction,catalog,categoryId,pressNo from Book ");
            strSql.Append(" where ISBN=@ISBN ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ISBN", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = ISBN;

            BookShop.Model.Book model = new BookShop.Model.Book();
            DataSet             ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Example #8
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtbookTitle.Text.Trim().Length == 0)
            {
                strErr += "bookTitle不能为空!\\n";
            }
            if (this.txtauthor.Text.Trim().Length == 0)
            {
                strErr += "author不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtpublishDate.Text))
            {
                strErr += "publishDate格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtversion.Text))
            {
                strErr += "version格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtstockNumber.Text))
            {
                strErr += "stockNumber格式错误!\\n";
            }
            if (!PageValidate.IsDecimal(txtprice.Text))
            {
                strErr += "price格式错误!\\n";
            }
            if (!PageValidate.IsDecimal(txtsalePrice.Text))
            {
                strErr += "salePrice格式错误!\\n";
            }
            if (this.txtintroduction.Text.Trim().Length == 0)
            {
                strErr += "introduction不能为空!\\n";
            }
            if (this.txtcatalog.Text.Trim().Length == 0)
            {
                strErr += "catalog不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtcategoryId.Text))
            {
                strErr += "categoryId格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtpressNo.Text))
            {
                strErr += "pressNo格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string   ISBN         = this.lblISBN.Text;
            string   bookTitle    = this.txtbookTitle.Text;
            string   author       = this.txtauthor.Text;
            DateTime publishDate  = DateTime.Parse(this.txtpublishDate.Text);
            int      version      = int.Parse(this.txtversion.Text);
            int      stockNumber  = int.Parse(this.txtstockNumber.Text);
            decimal  price        = decimal.Parse(this.txtprice.Text);
            decimal  salePrice    = decimal.Parse(this.txtsalePrice.Text);
            string   introduction = this.txtintroduction.Text;
            string   catalog      = this.txtcatalog.Text;
            int      categoryId   = int.Parse(this.txtcategoryId.Text);
            int      pressNo      = int.Parse(this.txtpressNo.Text);


            BookShop.Model.Book model = new BookShop.Model.Book();
            model.ISBN         = ISBN;
            model.bookTitle    = bookTitle;
            model.author       = author;
            model.publishDate  = publishDate;
            model.version      = version;
            model.stockNumber  = stockNumber;
            model.price        = price;
            model.salePrice    = salePrice;
            model.introduction = introduction;
            model.catalog      = catalog;
            model.categoryId   = categoryId;
            model.pressNo      = pressNo;

            BookShop.BLL.Book bll = new BookShop.BLL.Book();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
Example #9
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookShop.Model.Book GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,Title,Author,PublisherId,PublishDate,ISBN,WordsCount,UnitPrice,ContentDescription,AurhorDescription,EditorComment,TOC,CategoryId,Clicks from Books ");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            BookShop.Model.Book model = new BookShop.Model.Book();
            DataSet             ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                model.Title  = ds.Tables[0].Rows[0]["Title"].ToString();
                model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
                if (ds.Tables[0].Rows[0]["PublisherId"].ToString() != "")
                {
                    //  model.PublisherId = int.Parse(ds.Tables[0].Rows[0]["PublisherId"].ToString());
                    int PublisherId = int.Parse(ds.Tables[0].Rows[0]["PublisherId"].ToString());
                    model.Publisher = publisherServices.GetModel(PublisherId);
                }
                if (ds.Tables[0].Rows[0]["PublishDate"].ToString() != "")
                {
                    model.PublishDate = DateTime.Parse(ds.Tables[0].Rows[0]["PublishDate"].ToString());
                }
                model.ISBN = ds.Tables[0].Rows[0]["ISBN"].ToString();
                if (ds.Tables[0].Rows[0]["WordsCount"].ToString() != "")
                {
                    model.WordsCount = int.Parse(ds.Tables[0].Rows[0]["WordsCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UnitPrice"].ToString() != "")
                {
                    model.UnitPrice = decimal.Parse(ds.Tables[0].Rows[0]["UnitPrice"].ToString());
                }
                model.ContentDescription = ds.Tables[0].Rows[0]["ContentDescription"].ToString();
                model.AurhorDescription  = ds.Tables[0].Rows[0]["AurhorDescription"].ToString();
                model.EditorComment      = ds.Tables[0].Rows[0]["EditorComment"].ToString();
                model.TOC = ds.Tables[0].Rows[0]["TOC"].ToString();
                if (ds.Tables[0].Rows[0]["CategoryId"].ToString() != "")
                {
                    int CategoryId = int.Parse(ds.Tables[0].Rows[0]["CategoryId"].ToString());
                    model.Category = categoryServices.GetModel(CategoryId);
                }
                if (ds.Tables[0].Rows[0]["Clicks"].ToString() != "")
                {
                    model.Clicks = int.Parse(ds.Tables[0].Rows[0]["Clicks"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }