/// <summary> /// 添加Book数据,传入刚刚的Book实体 /// </summary> /// <param name="books"></param> /// <returns>返回成功传入的数量</returns> public static bool add(YF.Model.Books books) { bool res = false; // 向数据库添加,其中id是自增的,不需要写 string strsql = "insert into t_book(isbn,price,num,img,detail,state,adddate,bookname) values('" + books.Isbn + "'," + books.Price + "," + books.Num + ",'" + books.Img + "','" + books.Detail + "'," + books.State + ",'" + books.Adddate + "', '" + books.Bookname + "')"; int i = 0; i = YF.MsSqlHelper.YFMsSqlHelper.ExecuteSql(strsql); // 如果sql语句执行成功的话,会返回影响行数,因为是插入一行,所以会返回1 if (i > 0) { res = true; } return(res); }
public static List <YF.Model.Cart> Dotolist(DataTable dt) { List <YF.Model.Cart> list = new List <Model.Cart>();//空的泛型对象 转换 for (int i = 0; i < dt.Rows.Count; i++) { YF.Model.Cart cart = new Model.Cart(); // 购物车空对象 cart.Id = int.Parse(dt.Rows[i]["id"].ToString()); //当前商品 YF.Model.Books books = YF.DAL.Books.GetBooks(int.Parse(dt.Rows[i]["bookid"].ToString())); //通过id 得到商品实列对象 //当前用户 YF.Model.User user = YF.DAL.User.Getuser(int.Parse(dt.Rows[i]["userid"].ToString())); //通过id 得到用户实列对象 cart.Books = books; //商品赋值=上面的books cart.User = user; //商品赋值=上面的user cart.Num = int.Parse(dt.Rows[i]["num"].ToString()); cart.State = int.Parse(dt.Rows[i]["state"].ToString()); cart.Adddate = DateTime.Parse(dt.Rows[i]["adddate"].ToString()); list.Add(cart); //空的泛型对象+数据 } return(list); }