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