using System; using System.Data; using System.Text; using System.Data.SqlClient; namespace Mtxfw.DAL { /// /// 数据访问类:user_cart /// public partial class user_cart : Mtxfw.Utility.Myabstract { public user_cart() : base("user_cart") { } /// /// 增加一条数据 /// public int Add(Mtxfw.Model.user_cart model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into user_cart("); strSql.Append("poid,ProductID,ProductNum,selcolor,guige,CartId,ttype,gtype)"); strSql.Append(" values ("); strSql.Append("@poid,@ProductID,@ProductNum,@selcolor,@guige,@CartId,@ttype,@gtype)"); strSql.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters = { new SqlParameter("@poid", SqlDbType.Int), new SqlParameter("@ProductID", SqlDbType.Int), new SqlParameter("@ProductNum", SqlDbType.Int), new SqlParameter("@selcolor", SqlDbType.VarChar,2000), new SqlParameter("@guige", SqlDbType.VarChar,500), new SqlParameter("@CartId", SqlDbType.VarChar,50), new SqlParameter("@ttype", SqlDbType.Int), new SqlParameter("@gtype", SqlDbType.Int)}; parameters[0].Value = model.poid; parameters[1].Value = model.ProductID; parameters[2].Value = model.ProductNum; parameters[3].Value = model.selcolor; parameters[4].Value = model.guige; parameters[5].Value = model.CartId; parameters[6].Value = model.ttype; parameters[7].Value = model.gtype; object obj = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// ProductNum /// public int UpdateProductNum(int ProductNum, int Id) { String sql = "update user_cart set ProductNum=@ProductNum where Id=@Id"; SqlParameter[] para = { new SqlParameter("@ProductNum", SqlDbType.Int), new SqlParameter("@Id", SqlDbType.Int)}; para[0].Value = ProductNum; para[1].Value = Id; return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(sql, para); } /// /// ProductNum /// public int UpdateProductNum(int ProductNum, Int32 ProductID, string selcolor, string guige, string CartId) { String sql = "update user_cart set ProductNum=ProductNum+@ProductNum where ProductID=@ProductID And selcolor=@selcolor And guige=@guige And CartId=@CartId"; if (guige == "") { sql = "update user_cart set ProductNum=ProductNum+@ProductNum where ProductID=@ProductID And selcolor=@selcolor And CartId=@CartId"; } SqlParameter[] para = { new SqlParameter("@ProductNum", SqlDbType.Int), new SqlParameter("@ProductID", SqlDbType.Int), new SqlParameter("@selcolor", SqlDbType.VarChar,2000), new SqlParameter("@guige", SqlDbType.VarChar,500), new SqlParameter("@CartId", SqlDbType.VarChar,50)}; para[0].Value = ProductNum; para[1].Value = ProductID; para[2].Value = selcolor; para[3].Value = guige; para[4].Value = CartId; return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(sql, para); } /// /// ProductNum /// public int UpdateProductNum2(int ProductNum, Int32 ProductID, string selcolor, string guige, string CartId) { String sql = "update user_cart set ProductNum=@ProductNum where ProductID=@ProductID And selcolor=@selcolor And guige=@guige And CartId=@CartId"; if (guige == "") { sql = "update user_cart set ProductNum=@ProductNum where ProductID=@ProductID And selcolor=@selcolor And CartId=@CartId"; } SqlParameter[] para = { new SqlParameter("@ProductNum", SqlDbType.Int), new SqlParameter("@ProductID", SqlDbType.Int), new SqlParameter("@selcolor", SqlDbType.VarChar,2000), new SqlParameter("@guige", SqlDbType.VarChar,500), new SqlParameter("@CartId", SqlDbType.VarChar,50)}; para[0].Value = ProductNum; para[1].Value = ProductID; para[2].Value = selcolor; para[3].Value = guige; para[4].Value = CartId; return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(sql, para); } /// /// 删除一条数据 /// public bool Delete(long Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from user_cart "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.BigInt) }; parameters[0].Value = Id; int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool Delete() { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from user_cart "); strSql.Append(" where ProductNum<=0"); int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString()); if (rows > 0) { return true; } else { return false; } } /// /// 得到一个对象实体 /// public Mtxfw.Model.user_cart GetModel(long Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from user_cart "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.BigInt) }; parameters[0].Value = Id; Mtxfw.Model.user_cart model = new Mtxfw.Model.user_cart(); DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.Id = long.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); model.ProductID = int.Parse(ds.Tables[0].Rows[0]["ProductID"].ToString()); model.ProductNum = int.Parse(ds.Tables[0].Rows[0]["ProductNum"].ToString()); model.selcolor = ds.Tables[0].Rows[0]["selcolor"].ToString(); model.guige = ds.Tables[0].Rows[0]["guige"].ToString(); model.CartId = ds.Tables[0].Rows[0]["CartId"].ToString(); return model; } else { return null; } } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * "); strSql.Append(" FROM user_cart "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } /// /// 获得前几行数据 /// public DataSet GetList(int Top, string strWhere, string filedOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); if (Top > 0) { strSql.Append(" top " + Top.ToString()); } strSql.Append(" * "); strSql.Append(" FROM user_cart "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } } }