Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(book_shop.Model.OrderBookModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update OrderBook set ");
            strSql.Append("OrderID=@OrderID,");
            strSql.Append("BookID=@BookID,");
            strSql.Append("Quantity=@Quantity,");
            strSql.Append("UnitPrice=@UnitPrice");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@OrderID",   SqlDbType.NVarChar, 50),
                new SqlParameter("@BookID",    SqlDbType.Int,       4),
                new SqlParameter("@Quantity",  SqlDbType.Int,       4),
                new SqlParameter("@UnitPrice", SqlDbType.Decimal,   9),
                new SqlParameter("@Id",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.OrderID;
            parameters[1].Value = model.BookID;
            parameters[2].Value = model.Quantity;
            parameters[3].Value = model.UnitPrice;
            parameters[4].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public book_shop.Model.OrderBookModel DataRowToModel(DataRow row)
 {
     book_shop.Model.OrderBookModel model = new book_shop.Model.OrderBookModel();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["OrderID"] != null)
         {
             model.OrderID = row["OrderID"].ToString();
         }
         if (row["BookID"] != null && row["BookID"].ToString() != "")
         {
             model.BookID = int.Parse(row["BookID"].ToString());
         }
         if (row["Quantity"] != null && row["Quantity"].ToString() != "")
         {
             model.Quantity = int.Parse(row["Quantity"].ToString());
         }
         if (row["UnitPrice"] != null && row["UnitPrice"].ToString() != "")
         {
             model.UnitPrice = decimal.Parse(row["UnitPrice"].ToString());
         }
     }
     return(model);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(book_shop.Model.OrderBookModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into OrderBook(");
            strSql.Append("OrderID,BookID,Quantity,UnitPrice)");
            strSql.Append(" values (");
            strSql.Append("@OrderID,@BookID,@Quantity,@UnitPrice)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@OrderID",   SqlDbType.NVarChar, 50),
                new SqlParameter("@BookID",    SqlDbType.Int,       4),
                new SqlParameter("@Quantity",  SqlDbType.Int,       4),
                new SqlParameter("@UnitPrice", SqlDbType.Decimal, 9)
            };
            parameters[0].Value = model.OrderID;
            parameters[1].Value = model.BookID;
            parameters[2].Value = model.Quantity;
            parameters[3].Value = model.UnitPrice;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public book_shop.Model.OrderBookModel GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,OrderID,BookID,Quantity,UnitPrice from OrderBook ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }