示例#1
0
        /// <summary>
        /// 更新一条数据(所有字段)
        /// </summary>
        public int Update(DBHelper myHelperMySQL, Fm.Entity.shop_cart model, string strWhere)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update shop_cart set ");

            strSql.Append(" Cartid = @Cartid , ");
            strSql.Append(" UserId = @UserId , ");
            strSql.Append(" ProductId = @ProductId , ");
            strSql.Append(" CartNum = @CartNum  ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@Cartid",    model.Cartid),
                new MySqlParameter("@UserId",    model.UserId),
                new MySqlParameter("@ProductId", model.ProductId),
                new MySqlParameter("@CartNum",   model.CartNum)
            };

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }

            int rows = myHelperMySQL.ExecuteNonQuery(strSql.ToString(), parameters);

            return(rows);
        }
示例#2
0
        public void Add(Fm.Entity.shop_cart model)
        {
            DBHelper myHelperMySQL = new DBHelper();

            myHelperMySQL.connectionStr = MySQLConfig.ConnStringCenter;
            dal.Add(myHelperMySQL, model);
        }
示例#3
0
        /// <summary>
        /// 得到一个对象实体(List类型),数据连接类用myHelperMySQL(非静态)
        /// 表:MessageBoard
        /// <param name="myHelperMySQL">myHelperMySQL实例(数据访问类).</param>
        /// <param name="Top">记录数.</param>
        /// <param name="filedSelect">自定义字段.</param>
        /// <param name="strWhere">条件.</param>
        /// <param name="filedOrder">排序字段.</param>
        /// <param name="parameters">参数(若条件中未使用参数可为null).</param>
        /// </summary>
        public List <Fm.Entity.shop_cart> GetList(DBHelper myHelperMySQL, int Top, string filedSelect, string strWhere, string filedOrder, MySqlParameter[] parameters)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ");
            //自定义字段
            strSql.Append(" " + filedSelect);
            strSql.Append("  FROM shop_cart a  ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" WHERE " + strWhere);
            }
            if (filedOrder.Trim() != "")
            {
                strSql.Append(" ORDER BY " + filedOrder);
            }
            if (Top > 0)
            {
                strSql.Append(" limit " + Top.ToString());
            }
            List <Fm.Entity.shop_cart> myList = new List <Fm.Entity.shop_cart>();

            using (MySqlDataReader dr = myHelperMySQL.ExecuteReader(strSql.ToString(), parameters))
            {
                while (dr.Read())
                {
                    Fm.Entity.shop_cart model = new Fm.Entity.shop_cart();

                    if (filedSelect.ToLower().Split(',').Where(x => x.Trim() == "a.cartid").Count() > 0)
                    {
                        if (dr["Cartid"].ToString() != "")
                        {
                            model.Cartid = int.Parse(dr["Cartid"].ToString());
                        }
                    }
                    if (filedSelect.ToLower().Split(',').Where(x => x.Trim() == "a.userid").Count() > 0)
                    {
                        model.UserId = dr["UserId"].ToString();
                    }
                    if (filedSelect.ToLower().Split(',').Where(x => x.Trim() == "a.productid").Count() > 0)
                    {
                        model.ProductId = dr["ProductId"].ToString();
                    }
                    if (filedSelect.ToLower().Split(',').Where(x => x.Trim() == "a.cartnum").Count() > 0)
                    {
                        if (dr["CartNum"].ToString() != "")
                        {
                            model.CartNum = int.Parse(dr["CartNum"].ToString());
                        }
                    }

                    myList.Add(model);
                }
                dr.Close();
            }
            return(myList);
        }
示例#4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(DBHelper myHelperMySQL, Fm.Entity.shop_cart model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into shop_cart(");
            strSql.Append("Cartid,UserId,ProductId,CartNum");
            strSql.Append(") values (");
            strSql.Append("@Cartid,@UserId,@ProductId,@CartNum");
            strSql.Append(") ");

            MySqlParameter[] parameters =
            {
                new MySqlParameter("@Cartid",    model.Cartid),
                new MySqlParameter("@UserId",    model.UserId),
                new MySqlParameter("@ProductId", model.ProductId),
                new MySqlParameter("@CartNum",   model.CartNum)
            };

            myHelperMySQL.ExecuteNonQuery(strSql.ToString(), parameters);
        }