Example #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public MyEasyBuy.Model.eb_goods DataRowToModel(DataRow row)
 {
     MyEasyBuy.Model.eb_goods model = new MyEasyBuy.Model.eb_goods();
     if (row != null)
     {
         if (row["gid"] != null && row["gid"].ToString() != "")
         {
             model.gid = int.Parse(row["gid"].ToString());
         }
         if (row["gname"] != null)
         {
             model.gname = row["gname"].ToString();
         }
         if (row["price"] != null && row["price"].ToString() != "")
         {
             model.price = decimal.Parse(row["price"].ToString());
         }
         if (row["offset"] != null && row["offset"].ToString() != "")
         {
             model.offset = decimal.Parse(row["offset"].ToString());
         }
         if (row["publishTime"] != null && row["publishTime"].ToString() != "")
         {
             model.publishTime = DateTime.Parse(row["publishTime"].ToString());
         }
         if (row["total"] != null && row["total"].ToString() != "")
         {
             model.total = int.Parse(row["total"].ToString());
         }
         if (row["cid"] != null && row["cid"].ToString() != "")
         {
             model.cid = int.Parse(row["cid"].ToString());
         }
         if (row["goodsimg"] != null && !string.IsNullOrEmpty(row["goodsimg"].ToString()))
         {
             model.goodsimg = row["goodsimg"].ToString();
         }
         else
         {
             //如果商品没有图片,我们就添加默认的图片
             model.goodsimg = Maticsoft.Common.ConfigHelper.GetConfigString("DefaultGoodsPic");
         }
     }
     return(model);
 }
Example #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(MyEasyBuy.Model.eb_goods model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update eb_goods set ");
            strSql.Append("gname=@gname,");
            strSql.Append("price=@price,");
            strSql.Append("offset=@offset,");
            strSql.Append("publishTime=@publishTime,");
            strSql.Append("total=@total,");
            strSql.Append("cid=@cid,");
            strSql.Append("goodsimg=@goodsimg");
            strSql.Append(" where gid=@gid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@gname",       SqlDbType.NVarChar,  50),
                new SqlParameter("@price",       SqlDbType.Float,      8),
                new SqlParameter("@offset",      SqlDbType.Float,      8),
                new SqlParameter("@publishTime", SqlDbType.DateTime),
                new SqlParameter("@total",       SqlDbType.Int,        4),
                new SqlParameter("@cid",         SqlDbType.Int,        4),
                new SqlParameter("@goodsimg",    SqlDbType.NVarChar,  -1),
                new SqlParameter("@gid",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.gname;
            parameters[1].Value = model.price;
            parameters[2].Value = model.offset;
            parameters[3].Value = model.publishTime;
            parameters[4].Value = model.total;
            parameters[5].Value = model.cid;
            parameters[6].Value = model.goodsimg;
            parameters[7].Value = model.gid;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(MyEasyBuy.Model.eb_goods model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into eb_goods(");
            strSql.Append("gname,price,offset,publishTime,total,cid,goodsimg)");
            strSql.Append(" values (");
            strSql.Append("@gname,@price,@offset,@publishTime,@total,@cid,@goodsimg)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@gname",       SqlDbType.NVarChar,  50),
                new SqlParameter("@price",       SqlDbType.Float,      8),
                new SqlParameter("@offset",      SqlDbType.Float,      8),
                new SqlParameter("@publishTime", SqlDbType.DateTime),
                new SqlParameter("@total",       SqlDbType.Int,        4),
                new SqlParameter("@cid",         SqlDbType.Int,        4),
                new SqlParameter("@goodsimg",    SqlDbType.NVarChar, -1)
            };
            parameters[0].Value = model.gname;
            parameters[1].Value = model.price;
            parameters[2].Value = model.offset;
            parameters[3].Value = model.publishTime;
            parameters[4].Value = model.total;
            parameters[5].Value = model.cid;
            parameters[6].Value = model.goodsimg;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public MyEasyBuy.Model.eb_goods GetModel(int gid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 gid,gname,price,offset,publishTime,total,cid,goodsimg from eb_goods ");
            strSql.Append(" where gid=@gid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@gid", SqlDbType.Int, 4)
            };
            parameters[0].Value = gid;

            MyEasyBuy.Model.eb_goods model = new MyEasyBuy.Model.eb_goods();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }