/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.ProductGoods model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ProductGoods set "); strSql.Append("productId=@productId,"); strSql.Append("quantityGoods=@quantityGoods,"); strSql.Append("brandGoods=@brandGoods,"); strSql.Append("priceGoods=@priceGoods,"); strSql.Append("setGoods=@setGoods,"); strSql.Append("beautifulGoods=@beautifulGoods,"); strSql.Append("otherGoods=@otherGoods,"); strSql.Append("status=@status,"); strSql.Append("remark=@remark,"); strSql.Append("infoType=@infoType"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@productId", SqlDbType.Int, 4), new SqlParameter("@quantityGoods", SqlDbType.Int, 4), new SqlParameter("@brandGoods", SqlDbType.Int, 4), new SqlParameter("@priceGoods", SqlDbType.Int, 4), new SqlParameter("@setGoods", SqlDbType.Int, 4), new SqlParameter("@beautifulGoods", SqlDbType.Int, 4), new SqlParameter("@otherGoods", SqlDbType.Int, 4), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@remark", SqlDbType.VarChar, 50), new SqlParameter("@infoType", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.productId; parameters[1].Value = model.quantityGoods; parameters[2].Value = model.brandGoods; parameters[3].Value = model.priceGoods; parameters[4].Value = model.setGoods; parameters[5].Value = model.beautifulGoods; parameters[6].Value = model.otherGoods; parameters[7].Value = model.status; parameters[8].Value = model.remark; parameters[9].Value = model.infoType; parameters[10].Value = model.id; int rows = DBHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public static Model.ProductGoods DataRowToModel(DataRow row) { Model.ProductGoods model = new Model.ProductGoods(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["productId"] != null && row["productId"].ToString() != "") { model.productId = int.Parse(row["productId"].ToString()); } if (row["quantityGoods"] != null && row["quantityGoods"].ToString() != "") { model.quantityGoods = int.Parse(row["quantityGoods"].ToString()); } if (row["brandGoods"] != null && row["brandGoods"].ToString() != "") { model.brandGoods = int.Parse(row["brandGoods"].ToString()); } if (row["priceGoods"] != null && row["priceGoods"].ToString() != "") { model.priceGoods = int.Parse(row["priceGoods"].ToString()); } if (row["setGoods"] != null && row["setGoods"].ToString() != "") { model.setGoods = int.Parse(row["setGoods"].ToString()); } if (row["beautifulGoods"] != null && row["beautifulGoods"].ToString() != "") { model.beautifulGoods = int.Parse(row["beautifulGoods"].ToString()); } if (row["otherGoods"] != null && row["otherGoods"].ToString() != "") { model.otherGoods = int.Parse(row["otherGoods"].ToString()); } if (row["status"] != null && row["status"].ToString() != "") { model.status = int.Parse(row["status"].ToString()); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } if (row["infoType"] != null && row["infoType"].ToString() != "") { model.infoType = int.Parse(row["infoType"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public static int Add(Model.ProductGoods model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ProductGoods("); strSql.Append("productId,quantityGoods,brandGoods,priceGoods,setGoods,beautifulGoods,otherGoods,status,remark,infoType)"); strSql.Append(" values ("); strSql.Append("@productId,@quantityGoods,@brandGoods,@priceGoods,@setGoods,@beautifulGoods,@otherGoods,@status,@remark,@infoType)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@productId", SqlDbType.Int, 4), new SqlParameter("@quantityGoods", SqlDbType.Int, 4), new SqlParameter("@brandGoods", SqlDbType.Int, 4), new SqlParameter("@priceGoods", SqlDbType.Int, 4), new SqlParameter("@setGoods", SqlDbType.Int, 4), new SqlParameter("@beautifulGoods", SqlDbType.Int, 4), new SqlParameter("@otherGoods", SqlDbType.Int, 4), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@remark", SqlDbType.VarChar, 50), new SqlParameter("@infoType", SqlDbType.Int, 4) }; parameters[0].Value = model.productId; parameters[1].Value = model.quantityGoods; parameters[2].Value = model.brandGoods; parameters[3].Value = model.priceGoods; parameters[4].Value = model.setGoods; parameters[5].Value = model.beautifulGoods; parameters[6].Value = model.otherGoods; parameters[7].Value = model.status; parameters[8].Value = model.remark; parameters[9].Value = model.infoType; object obj = DBHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public static Model.ProductGoods GetModel(int productId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,productId,quantityGoods,brandGoods,priceGoods,setGoods,beautifulGoods,otherGoods,status,remark,infoType from ProductGoods "); strSql.Append(" where productId=@productId"); SqlParameter[] parameters = { new SqlParameter("@productId", SqlDbType.Int, 4) }; parameters[0].Value = productId; Model.ProductGoods model = new Model.ProductGoods(); DataSet ds = DBHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }