예제 #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Shop.Model.BookInfo DataRowToModel(DataRow row)
 {
     Shop.Model.BookInfo model = new Shop.Model.BookInfo();
     if (row != null)
     {
         if (row["Bid"] != null && row["Bid"].ToString() != "")
         {
             model.Bid = int.Parse(row["Bid"].ToString());
         }
         if (row["Title"] != null)
         {
             model.Title = row["Title"].ToString();
         }
         if (row["TitleHot"] != null)
         {
             model.TitleHot = row["TitleHot"].ToString();
         }
         if (row["PriceOld"] != null && row["PriceOld"].ToString() != "")
         {
             model.PriceOld = decimal.Parse(row["PriceOld"].ToString());
         }
         if (row["PriceNew"] != null && row["PriceNew"].ToString() != "")
         {
             model.PriceNew = decimal.Parse(row["PriceNew"].ToString());
         }
         if (row["Author"] != null)
         {
             model.Author = row["Author"].ToString();
         }
         if (row["Publisher"] != null)
         {
             model.Publisher = row["Publisher"].ToString();
         }
         if (row["PublishDate"] != null && row["PublishDate"].ToString() != "")
         {
             model.PublishDate = DateTime.Parse(row["PublishDate"].ToString());
         }
         if (row["OnSaleDate"] != null && row["OnSaleDate"].ToString() != "")
         {
             model.OnSaleDate = DateTime.Parse(row["OnSaleDate"].ToString());
         }
         if (row["ISBN"] != null)
         {
             model.ISBN = row["ISBN"].ToString();
         }
         if (row["TypeId"] != null)
         {
             model.TypeId = row["TypeId"].ToString();
         }
         if (row["Details"] != null)
         {
             model.Details = row["Details"].ToString();
         }
         if (row["ImgTitle"] != null)
         {
             model.ImgTitle = row["ImgTitle"].ToString();
         }
     }
     return(model);
 }
예제 #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Shop.Model.BookInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BookInfo set ");
            strSql.Append("Title=@Title,");
            strSql.Append("TitleHot=@TitleHot,");
            strSql.Append("PriceOld=@PriceOld,");
            strSql.Append("PriceNew=@PriceNew,");
            strSql.Append("Author=@Author,");
            strSql.Append("Publisher=@Publisher,");
            strSql.Append("PublishDate=@PublishDate,");
            strSql.Append("OnSaleDate=@OnSaleDate,");
            strSql.Append("ISBN=@ISBN,");
            strSql.Append("TypeId=@TypeId,");
            strSql.Append("Details=@Details,");
            strSql.Append("ImgTitle=@ImgTitle");
            strSql.Append(" where Bid=@Bid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",       SqlDbType.NVarChar,  50),
                new SqlParameter("@TitleHot",    SqlDbType.NVarChar, 100),
                new SqlParameter("@PriceOld",    SqlDbType.Decimal,    5),
                new SqlParameter("@PriceNew",    SqlDbType.Decimal,    5),
                new SqlParameter("@Author",      SqlDbType.NVarChar,  50),
                new SqlParameter("@Publisher",   SqlDbType.NVarChar,  50),
                new SqlParameter("@PublishDate", SqlDbType.Date,       3),
                new SqlParameter("@OnSaleDate",  SqlDbType.Date,       3),
                new SqlParameter("@ISBN",        SqlDbType.NVarChar,  50),
                new SqlParameter("@TypeId",      SqlDbType.NVarChar,  50),
                new SqlParameter("@Details",     SqlDbType.NVarChar,  -1),
                new SqlParameter("@ImgTitle",    SqlDbType.NVarChar,  50),
                new SqlParameter("@Bid",         SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.Title;
            parameters[1].Value  = model.TitleHot;
            parameters[2].Value  = model.PriceOld;
            parameters[3].Value  = model.PriceNew;
            parameters[4].Value  = model.Author;
            parameters[5].Value  = model.Publisher;
            parameters[6].Value  = model.PublishDate;
            parameters[7].Value  = model.OnSaleDate;
            parameters[8].Value  = model.ISBN;
            parameters[9].Value  = model.TypeId;
            parameters[10].Value = model.Details;
            parameters[11].Value = model.ImgTitle;
            parameters[12].Value = model.Bid;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Shop.Model.BookInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BookInfo(");
            strSql.Append("Title,TitleHot,PriceOld,PriceNew,Author,Publisher,PublishDate,OnSaleDate,ISBN,TypeId,Details,ImgTitle)");
            strSql.Append(" values (");
            strSql.Append("@Title,@TitleHot,@PriceOld,@PriceNew,@Author,@Publisher,@PublishDate,@OnSaleDate,@ISBN,@TypeId,@Details,@ImgTitle)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",       SqlDbType.NVarChar,  50),
                new SqlParameter("@TitleHot",    SqlDbType.NVarChar, 100),
                new SqlParameter("@PriceOld",    SqlDbType.Decimal,    5),
                new SqlParameter("@PriceNew",    SqlDbType.Decimal,    5),
                new SqlParameter("@Author",      SqlDbType.NVarChar,  50),
                new SqlParameter("@Publisher",   SqlDbType.NVarChar,  50),
                new SqlParameter("@PublishDate", SqlDbType.Date,       3),
                new SqlParameter("@OnSaleDate",  SqlDbType.Date,       3),
                new SqlParameter("@ISBN",        SqlDbType.NVarChar,  50),
                new SqlParameter("@TypeId",      SqlDbType.NVarChar,  50),
                new SqlParameter("@Details",     SqlDbType.NVarChar,  -1),
                new SqlParameter("@ImgTitle",    SqlDbType.NVarChar, 50)
            };
            parameters[0].Value  = model.Title;
            parameters[1].Value  = model.TitleHot;
            parameters[2].Value  = model.PriceOld;
            parameters[3].Value  = model.PriceNew;
            parameters[4].Value  = model.Author;
            parameters[5].Value  = model.Publisher;
            parameters[6].Value  = model.PublishDate;
            parameters[7].Value  = model.OnSaleDate;
            parameters[8].Value  = model.ISBN;
            parameters[9].Value  = model.TypeId;
            parameters[10].Value = model.Details;
            parameters[11].Value = model.ImgTitle;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #4
0
 private void ShowInfo(int Bid)
 {
     Shop.BLL.BookInfo   bll   = new Shop.BLL.BookInfo();
     Shop.Model.BookInfo model = bll.GetModel(Bid);
     this.lblBid.Text         = model.Bid.ToString();
     this.lblTitle.Text       = model.Title;
     this.lblTitleHot.Text    = model.TitleHot;
     this.lblPriceOld.Text    = model.PriceOld.ToString();
     this.lblPriceNew.Text    = model.PriceNew.ToString();
     this.lblAuthor.Text      = model.Author;
     this.lblPublisher.Text   = model.Publisher;
     this.lblPublishDate.Text = model.PublishDate.ToString();
     this.lblOnSaleDate.Text  = model.OnSaleDate.ToString();
     this.lblISBN.Text        = model.ISBN;
     this.lblTypeId.Text      = model.TypeId;
     this.lblDetails.Text     = model.Details;
     this.lblImgTitle.Text    = model.ImgTitle;
 }
예제 #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Shop.Model.BookInfo GetModel(int Bid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Bid,Title,TitleHot,PriceOld,PriceNew,Author,Publisher,PublishDate,OnSaleDate,ISBN,TypeId,Details,ImgTitle from BookInfo ");
            strSql.Append(" where Bid=@Bid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Bid", SqlDbType.Int, 4)
            };
            parameters[0].Value = Bid;

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

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

            if (this.txtTitle.Text.Trim().Length == 0)
            {
                strErr += "Title不能为空!\\n";
            }
            if (this.txtTitleHot.Text.Trim().Length == 0)
            {
                strErr += "TitleHot不能为空!\\n";
            }
            if (!PageValidate.IsDecimal(txtPriceOld.Text))
            {
                strErr += "PriceOld格式错误!\\n";
            }
            if (!PageValidate.IsDecimal(txtPriceNew.Text))
            {
                strErr += "PriceNew格式错误!\\n";
            }
            if (this.txtAuthor.Text.Trim().Length == 0)
            {
                strErr += "Author不能为空!\\n";
            }
            if (this.txtPublisher.Text.Trim().Length == 0)
            {
                strErr += "Publisher不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtPublishDate.Text))
            {
                strErr += "PublishDate格式错误!\\n";
            }
            if (!PageValidate.IsDateTime(txtOnSaleDate.Text))
            {
                strErr += "OnSaleDate格式错误!\\n";
            }
            if (this.txtISBN.Text.Trim().Length == 0)
            {
                strErr += "ISBN不能为空!\\n";
            }
            if (this.txtTypeId.Text.Trim().Length == 0)
            {
                strErr += "TypeId不能为空!\\n";
            }
            if (this.txtDetails.Text.Trim().Length == 0)
            {
                strErr += "Details不能为空!\\n";
            }
            if (this.txtImgTitle.Text.Trim().Length == 0)
            {
                strErr += "ImgTitle不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int      Bid         = int.Parse(this.lblBid.Text);
            string   Title       = this.txtTitle.Text;
            string   TitleHot    = this.txtTitleHot.Text;
            decimal  PriceOld    = decimal.Parse(this.txtPriceOld.Text);
            decimal  PriceNew    = decimal.Parse(this.txtPriceNew.Text);
            string   Author      = this.txtAuthor.Text;
            string   Publisher   = this.txtPublisher.Text;
            DateTime PublishDate = DateTime.Parse(this.txtPublishDate.Text);
            DateTime OnSaleDate  = DateTime.Parse(this.txtOnSaleDate.Text);
            string   ISBN        = this.txtISBN.Text;
            string   TypeId      = this.txtTypeId.Text;
            string   Details     = this.txtDetails.Text;
            string   ImgTitle    = this.txtImgTitle.Text;


            Shop.Model.BookInfo model = new Shop.Model.BookInfo();
            model.Bid         = Bid;
            model.Title       = Title;
            model.TitleHot    = TitleHot;
            model.PriceOld    = PriceOld;
            model.PriceNew    = PriceNew;
            model.Author      = Author;
            model.Publisher   = Publisher;
            model.PublishDate = PublishDate;
            model.OnSaleDate  = OnSaleDate;
            model.ISBN        = ISBN;
            model.TypeId      = TypeId;
            model.Details     = Details;
            model.ImgTitle    = ImgTitle;

            Shop.BLL.BookInfo bll = new Shop.BLL.BookInfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }