Пример #1
0
        //添加商品 -编辑
        public ActionResult AddGoods(string formVals = "{}")
        {
            var vmResult = new CommonAjaxResponseModel <bool>();

            try
            {
                t_goods model = formVals.ToModel <t_goods>();

                if (model.id != 0)
                {
                    GoodsDAL.UpdateGoods(model);

                    vmResult.BFlag = CommonResponseBFlag.Success;
                    vmResult.TData = true;
                }
                else
                {
                    //插入
                    model.status = 1;
                    GoodsDAL.AddGoods(model);
                    vmResult.BFlag = CommonResponseBFlag.Success;
                    vmResult.TData = true;
                }
            }
            catch (Exception ex)
            {
                vmResult.BFlag = CommonResponseBFlag.SysError;
                vmResult.Msg   = ex.Message;
            }
            return(Json(vmResult));
        }
Пример #2
0
        public ActionResult DeleteGoods(long id)
        {
            t_goods model    = new t_goods();
            var     vmResult = new CommonAjaxResponseModel <VMGDataGrid <t_goods> >();

            vmResult.TData = new VMGDataGrid <t_goods>();

            try
            {
                //删除
                int t1 = GoodsDAL.DeleteGoods(id);
                vmResult.BFlag           = CommonResponseBFlag.Success;
                vmResult.TData.data      = null;
                vmResult.TData.dataCount = 0;
                vmResult.Msg             = string.Format("删除产品成功。");
                return(Json(vmResult));
            }
            catch (Exception ex)
            {
                vmResult.BFlag           = CommonResponseBFlag.LogicError;
                vmResult.TData.data      = null;
                vmResult.TData.dataCount = 0;
                vmResult.Msg             = "编辑报错" + ex.Message;
            }

            return(Json(vmResult));
        }
Пример #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(t_goods model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_goods set ");
            strSql.Append("topType=@topType,");
            strSql.Append("type=@type,");
            strSql.Append("goodsName=@goodsName,");
            strSql.Append("minPrice=@minPrice,");
            strSql.Append("maxPrice=@maxPrice,");
            strSql.Append("sell_min_price=@sell_min_price,");
            strSql.Append("sell_max_price=@sell_max_price,");
            strSql.Append("describe=@describe,");
            strSql.Append("status=@status,");
            strSql.Append("createTime=@createTime,");
            strSql.Append("updateTime=@updateTime,");
            strSql.Append("url=@url");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@topType",        MySqlDbType.VarChar,   255),
                new MySqlParameter("@type",           MySqlDbType.VarChar,   255),
                new MySqlParameter("@goodsName",      MySqlDbType.VarChar,   255),
                new MySqlParameter("@minPrice",       MySqlDbType.Decimal,    10),
                new MySqlParameter("@maxPrice",       MySqlDbType.Decimal,    10),
                new MySqlParameter("@sell_min_price", MySqlDbType.Decimal,    10),
                new MySqlParameter("@sell_max_price", MySqlDbType.Decimal,    10),
                new MySqlParameter("@describe",       MySqlDbType.VarChar,   255),
                new MySqlParameter("@status",         MySqlDbType.Int32,      11),
                new MySqlParameter("@createTime",     MySqlDbType.DateTime),
                new MySqlParameter("@updateTime",     MySqlDbType.DateTime),
                new MySqlParameter("@url",            MySqlDbType.VarChar,   255),
                new MySqlParameter("@id",             MySqlDbType.Int32, 11)
            };
            parameters[0].Value  = model.topType;
            parameters[1].Value  = model.type;
            parameters[2].Value  = model.goodsName;
            parameters[3].Value  = model.minPrice;
            parameters[4].Value  = model.maxPrice;
            parameters[5].Value  = model.sell_min_price;
            parameters[6].Value  = model.sell_max_price;
            parameters[7].Value  = model.describe;
            parameters[8].Value  = model.status;
            parameters[9].Value  = model.createTime;
            parameters[10].Value = model.updateTime;
            parameters[11].Value = model.url;
            parameters[12].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(t_goods model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_goods(");
            strSql.Append("topType,type,goodsName,minPrice,maxPrice,sell_min_price,sell_max_price,describe,status,createTime,updateTime,url)");
            strSql.Append(" values (");
            strSql.Append("@topType,@type,@goodsName,@minPrice,@maxPrice,@sell_min_price,@sell_max_price,@describe,@status,@createTime,@updateTime,@url)");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@topType",        MySqlDbType.VarChar,   255),
                new MySqlParameter("@type",           MySqlDbType.VarChar,   255),
                new MySqlParameter("@goodsName",      MySqlDbType.VarChar,   255),
                new MySqlParameter("@minPrice",       MySqlDbType.Decimal,    10),
                new MySqlParameter("@maxPrice",       MySqlDbType.Decimal,    10),
                new MySqlParameter("@sell_min_price", MySqlDbType.Decimal,    10),
                new MySqlParameter("@sell_max_price", MySqlDbType.Decimal,    10),
                new MySqlParameter("@describe",       MySqlDbType.VarChar,   255),
                new MySqlParameter("@status",         MySqlDbType.Int32,      11),
                new MySqlParameter("@createTime",     MySqlDbType.DateTime),
                new MySqlParameter("@updateTime",     MySqlDbType.DateTime),
                new MySqlParameter("@url",            MySqlDbType.VarChar, 255)
            };
            parameters[0].Value  = model.topType;
            parameters[1].Value  = model.type;
            parameters[2].Value  = model.goodsName;
            parameters[3].Value  = model.minPrice;
            parameters[4].Value  = model.maxPrice;
            parameters[5].Value  = model.sell_min_price;
            parameters[6].Value  = model.sell_max_price;
            parameters[7].Value  = model.describe;
            parameters[8].Value  = model.status;
            parameters[9].Value  = model.createTime;
            parameters[10].Value = model.updateTime;
            parameters[11].Value = model.url;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #5
0
        public static int UpdateGoods(t_goods model)
        {
            string sql = @"
UPDATE `t_goods` SET  `topType`=@topType, `type`=@type, `goodsName`=@goodsName, `minPrice`=@minPrice, `maxPrice`=@maxPrice, `sell_min_price`=@sell_min_price, `sell_max_price`=@sell_max_price, `describe`=@describe, `updateTime`=now(), `url`=@url WHERE `id`=@id;";

            using (MySqlConnection sql_conn = new MySqlConnection(mysqlCon))
            {
                sql_conn.Open();
                MySqlCommand cmd = new MySqlCommand(sql, sql_conn);
                cmd.Parameters.AddWithValue("@topType", model.topType);
                cmd.Parameters.AddWithValue("@type", model.type);
                cmd.Parameters.AddWithValue("@goodsName", model.goodsName);
                cmd.Parameters.AddWithValue("@minPrice", model.minPrice);
                cmd.Parameters.AddWithValue("@maxPrice", model.maxPrice);
                cmd.Parameters.AddWithValue("@sell_min_price", model.sell_min_price);
                cmd.Parameters.AddWithValue("@sell_max_price", model.sell_max_price);
                cmd.Parameters.AddWithValue("@describe", model.describe);
                cmd.Parameters.AddWithValue("@url", model.url);
                cmd.Parameters.AddWithValue("@id", model.id);
                MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                int p = cmd.ExecuteNonQuery();
                return(p);
            }
        }
Пример #6
0
        public static int AddGoods(t_goods model)
        {
            string sql = @"
INSERT INTO `t_goods` ( `topType`, `type`, `goodsName`, `minPrice`, `maxPrice`, `sell_min_price`, `sell_max_price`,`describe`, `status`, `createTime`, `url`) select @topType, @type,@goodsName,@minPrice,@maxPrice,@sell_min_price,@sell_max_price,@describe,1,now(),@url";

            using (MySqlConnection sql_conn = new MySqlConnection(mysqlCon))
            {
                sql_conn.Open();
                MySqlCommand cmd = new MySqlCommand(sql, sql_conn);
                cmd.Parameters.AddWithValue("@topType", model.topType);
                cmd.Parameters.AddWithValue("@type", model.type);
                cmd.Parameters.AddWithValue("@goodsName", model.goodsName);
                cmd.Parameters.AddWithValue("@minPrice", model.minPrice);
                cmd.Parameters.AddWithValue("@maxPrice", model.maxPrice);
                cmd.Parameters.AddWithValue("@sell_min_price", model.sell_min_price);
                cmd.Parameters.AddWithValue("@sell_max_price", model.sell_max_price);

                cmd.Parameters.AddWithValue("@describe", model.describe);
                cmd.Parameters.AddWithValue("@url", model.url);
                MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                int p = cmd.ExecuteNonQuery();
                return(p);
            }
        }
Пример #7
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public t_goods GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id,topType,type,goodsName,minPrice,maxPrice,sell_min_price,sell_max_price,describe,status,createTime,updateTime,url from t_goods ");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

            t_goods model = new t_goods();
            DataSet ds    = DbHelperMySQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Пример #8
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(t_goods model)
 {
     return(dal.Update(model));
 }
Пример #9
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(t_goods model)
 {
     return(dal.Add(model));
 }
Пример #10
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public t_goods DataRowToModel(DataRow row)
        {
            t_goods model = new t_goods();

            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["topType"] != null)
                {
                    model.topType = row["topType"].ToString();
                }
                if (row["type"] != null)
                {
                    model.type = row["type"].ToString();
                }
                if (row["goodsName"] != null)
                {
                    model.goodsName = row["goodsName"].ToString();
                }
                if (row["minPrice"] != null && row["minPrice"].ToString() != "")
                {
                    model.minPrice = decimal.Parse(row["minPrice"].ToString());
                }
                if (row["maxPrice"] != null && row["maxPrice"].ToString() != "")
                {
                    model.maxPrice = decimal.Parse(row["maxPrice"].ToString());
                }
                if (row["sell_min_price"] != null && row["sell_min_price"].ToString() != "")
                {
                    model.sell_min_price = decimal.Parse(row["sell_min_price"].ToString());
                }
                if (row["sell_max_price"] != null && row["sell_max_price"].ToString() != "")
                {
                    model.sell_max_price = decimal.Parse(row["sell_max_price"].ToString());
                }
                if (row["describe"] != null)
                {
                    model.describe = row["describe"].ToString();
                }
                if (row["status"] != null && row["status"].ToString() != "")
                {
                    model.status = int.Parse(row["status"].ToString());
                }
                if (row["createTime"] != null && row["createTime"].ToString() != "")
                {
                    model.createTime = DateTime.Parse(row["createTime"].ToString());
                }
                if (row["updateTime"] != null && row["updateTime"].ToString() != "")
                {
                    model.updateTime = DateTime.Parse(row["updateTime"].ToString());
                }
                if (row["url"] != null)
                {
                    model.url = row["url"].ToString();
                }
            }
            return(model);
        }