/// <summary> /// 更新一条数据 /// </summary> public bool Update(EShop.Model.Account_Cart model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Account_Cart set "); strSql.Append("UserCode=@UserCode,"); strSql.Append("GoodsCode=@GoodsCode,"); strSql.Append("MarketPrice=@MarketPrice,"); strSql.Append("OurPrice=@OurPrice,"); strSql.Append("BuyCount=@BuyCount,"); strSql.Append("SubTotal=@SubTotal,"); strSql.Append("Status=@Status"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@UserCode", SqlDbType.VarChar, 50), new SqlParameter("@GoodsCode", SqlDbType.VarChar, 50), new SqlParameter("@MarketPrice", SqlDbType.Decimal, 9), new SqlParameter("@OurPrice", SqlDbType.Decimal, 9), new SqlParameter("@BuyCount", SqlDbType.Int, 4), new SqlParameter("@SubTotal", SqlDbType.Decimal, 9), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.UserCode; parameters[1].Value = model.GoodsCode; parameters[2].Value = model.MarketPrice; parameters[3].Value = model.OurPrice; parameters[4].Value = model.BuyCount; parameters[5].Value = model.SubTotal; parameters[6].Value = model.Status; parameters[7].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public EShop.Model.Account_Cart DataRowToModel(DataRow row) { EShop.Model.Account_Cart model = new EShop.Model.Account_Cart(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["UserCode"] != null) { model.UserCode = row["UserCode"].ToString(); } if (row["GoodsCode"] != null) { model.GoodsCode = row["GoodsCode"].ToString(); } if (row["MarketPrice"] != null && row["MarketPrice"].ToString() != "") { model.MarketPrice = decimal.Parse(row["MarketPrice"].ToString()); } if (row["OurPrice"] != null && row["OurPrice"].ToString() != "") { model.OurPrice = decimal.Parse(row["OurPrice"].ToString()); } if (row["BuyCount"] != null && row["BuyCount"].ToString() != "") { model.BuyCount = int.Parse(row["BuyCount"].ToString()); } if (row["SubTotal"] != null && row["SubTotal"].ToString() != "") { model.SubTotal = decimal.Parse(row["SubTotal"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = int.Parse(row["Status"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(EShop.Model.Account_Cart model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Account_Cart("); strSql.Append("UserCode,GoodsCode,MarketPrice,OurPrice,BuyCount,SubTotal,Status)"); strSql.Append(" values ("); strSql.Append("@UserCode,@GoodsCode,@MarketPrice,@OurPrice,@BuyCount,@SubTotal,@Status)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserCode", SqlDbType.VarChar, 50), new SqlParameter("@GoodsCode", SqlDbType.VarChar, 50), new SqlParameter("@MarketPrice", SqlDbType.Decimal, 9), new SqlParameter("@OurPrice", SqlDbType.Decimal, 9), new SqlParameter("@BuyCount", SqlDbType.Int, 4), new SqlParameter("@SubTotal", SqlDbType.Decimal, 9), new SqlParameter("@Status", SqlDbType.Int, 4) }; parameters[0].Value = model.UserCode; parameters[1].Value = model.GoodsCode; parameters[2].Value = model.MarketPrice; parameters[3].Value = model.OurPrice; parameters[4].Value = model.BuyCount; parameters[5].Value = model.SubTotal; parameters[6].Value = model.Status; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public EShop.Model.Account_Cart GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,UserCode,GoodsCode,MarketPrice,OurPrice,BuyCount,SubTotal,Status from Account_Cart "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; EShop.Model.Account_Cart model = new EShop.Model.Account_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); } }