/// <summary> /// 更新一条数据 /// </summary> public bool Update(EShop.Model.Goods_Coupon model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Goods_Coupon set "); strSql.Append("CouponCode=@CouponCode,"); strSql.Append("CouponName=@CouponName,"); strSql.Append("Price=@Price,"); strSql.Append("MinOrPrice=@MinOrPrice,"); strSql.Append("AbortUseDate=@AbortUseDate,"); strSql.Append("Status=@Status"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@CouponCode", SqlDbType.VarChar, 50), new SqlParameter("@CouponName", SqlDbType.VarChar, 50), new SqlParameter("@Price", SqlDbType.Decimal, 9), new SqlParameter("@MinOrPrice", SqlDbType.Decimal, 9), new SqlParameter("@AbortUseDate", SqlDbType.Date, 3), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.CouponCode; parameters[1].Value = model.CouponName; parameters[2].Value = model.Price; parameters[3].Value = model.MinOrPrice; parameters[4].Value = model.AbortUseDate; 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_Coupon DataRowToModel(DataRow row) { EShop.Model.Goods_Coupon model = new EShop.Model.Goods_Coupon(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["CouponCode"] != null) { model.CouponCode = row["CouponCode"].ToString(); } if (row["CouponName"] != null) { model.CouponName = row["CouponName"].ToString(); } if (row["Price"] != null && row["Price"].ToString() != "") { model.Price = decimal.Parse(row["Price"].ToString()); } if (row["MinOrPrice"] != null && row["MinOrPrice"].ToString() != "") { model.MinOrPrice = decimal.Parse(row["MinOrPrice"].ToString()); } if (row["AbortUseDate"] != null && row["AbortUseDate"].ToString() != "") { model.AbortUseDate = DateTime.Parse(row["AbortUseDate"].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_Coupon model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Goods_Coupon("); strSql.Append("CouponCode,CouponName,Price,MinOrPrice,AbortUseDate,Status)"); strSql.Append(" values ("); strSql.Append("@CouponCode,@CouponName,@Price,@MinOrPrice,@AbortUseDate,@Status)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CouponCode", SqlDbType.VarChar, 50), new SqlParameter("@CouponName", SqlDbType.VarChar, 50), new SqlParameter("@Price", SqlDbType.Decimal, 9), new SqlParameter("@MinOrPrice", SqlDbType.Decimal, 9), new SqlParameter("@AbortUseDate", SqlDbType.Date, 3), new SqlParameter("@Status", SqlDbType.Int, 4) }; parameters[0].Value = model.CouponCode; parameters[1].Value = model.CouponName; parameters[2].Value = model.Price; parameters[3].Value = model.MinOrPrice; parameters[4].Value = model.AbortUseDate; 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_Coupon GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,CouponCode,CouponName,Price,MinOrPrice,AbortUseDate,Status from Goods_Coupon "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; EShop.Model.Goods_Coupon model = new EShop.Model.Goods_Coupon(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }