Esempio n. 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(cn.itcast.bookshop.Model.Cart model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Cart set ");
            strSql.Append("UserId=@UserId,");
            strSql.Append("BookId=@BookId,");
            strSql.Append("Count=@Count");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId", SqlDbType.Int, 4),
                new SqlParameter("@BookId", SqlDbType.Int, 4),
                new SqlParameter("@Count",  SqlDbType.Int, 4),
                new SqlParameter("@Id",     SqlDbType.Int, 4)
            };
            parameters[0].Value = model.UserId;
            parameters[1].Value = model.BookId;
            parameters[2].Value = model.Count;
            parameters[3].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(cn.itcast.bookshop.Model.Cart model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Cart(");
            strSql.Append("UserId,BookId,Count)");
            strSql.Append(" values (");
            strSql.Append("@UserId,@BookId,@Count)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId", SqlDbType.Int, 4),
                new SqlParameter("@BookId", SqlDbType.Int, 4),
                new SqlParameter("@Count",  SqlDbType.Int, 4)
            };
            parameters[0].Value = model.UserId;
            parameters[1].Value = model.BookId;
            parameters[2].Value = model.Count;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public cn.itcast.bookshop.Model.Cart DataRowToModel(DataRow row)
 {
     cn.itcast.bookshop.Model.Cart model = new cn.itcast.bookshop.Model.Cart();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["UserId"] != null && row["UserId"].ToString() != "")
         {
             model.UserId = int.Parse(row["UserId"].ToString());
         }
         if (row["BookId"] != null && row["BookId"].ToString() != "")
         {
             model.BookId = int.Parse(row["BookId"].ToString());
         }
         if (row["Count"] != null && row["Count"].ToString() != "")
         {
             model.Count = int.Parse(row["Count"].ToString());
         }
     }
     return(model);
 }
Esempio n. 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public cn.itcast.bookshop.Model.Cart GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,UserId,BookId,Count from Cart ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            cn.itcast.bookshop.Model.Cart model = new cn.itcast.bookshop.Model.Cart();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

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