/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebApi_Model.T_Product_Ext model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Product_Ext set "); strSql.Append("ProductID=@ProductID,"); strSql.Append("Price=@Price,"); strSql.Append("PropertyA=@PropertyA,"); strSql.Append("PropertyB=@PropertyB,"); strSql.Append("PropertyC=@PropertyC,"); strSql.Append("Stock=@Stock,"); strSql.Append("Property=@Property"); strSql.Append(" where ProductExtID=@ProductExtID"); SqlParameter[] parameters = { new SqlParameter("@ProductID", SqlDbType.Int, 4), new SqlParameter("@Price", SqlDbType.Decimal, 9), new SqlParameter("@PropertyA", SqlDbType.Int, 4), new SqlParameter("@PropertyB", SqlDbType.Int, 4), new SqlParameter("@PropertyC", SqlDbType.Int, 4), new SqlParameter("@Stock", SqlDbType.Int, 4), new SqlParameter("@Property", SqlDbType.NVarChar, 50), new SqlParameter("@ProductExtID", SqlDbType.Int, 4) }; parameters[0].Value = model.ProductID; parameters[1].Value = model.Price; parameters[2].Value = model.PropertyA; parameters[3].Value = model.PropertyB; parameters[4].Value = model.PropertyC; parameters[5].Value = model.Stock; parameters[6].Value = model.Property; parameters[7].Value = model.ProductExtID; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Product_Ext DataRowToModel(DataRow row) { WebApi_Model.T_Product_Ext model = new WebApi_Model.T_Product_Ext(); if (row != null) { if (row["ProductExtID"] != null && row["ProductExtID"].ToString() != "") { model.ProductExtID = int.Parse(row["ProductExtID"].ToString()); } if (row["ProductID"] != null && row["ProductID"].ToString() != "") { model.ProductID = int.Parse(row["ProductID"].ToString()); } if (row["Price"] != null && row["Price"].ToString() != "") { model.Price = decimal.Parse(row["Price"].ToString()); } if (row["PropertyA"] != null && row["PropertyA"].ToString() != "") { model.PropertyA = int.Parse(row["PropertyA"].ToString()); } if (row["PropertyB"] != null && row["PropertyB"].ToString() != "") { model.PropertyB = int.Parse(row["PropertyB"].ToString()); } if (row["PropertyC"] != null && row["PropertyC"].ToString() != "") { model.PropertyC = int.Parse(row["PropertyC"].ToString()); } if (row["Stock"] != null && row["Stock"].ToString() != "") { model.Stock = int.Parse(row["Stock"].ToString()); } if (row["Property"] != null) { model.Property = row["Property"].ToString(); } //model.HasProperty = } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WebApi_Model.T_Product_Ext model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Product_Ext("); strSql.Append("ProductID,Price,PropertyA,PropertyB,PropertyC,Stock,Property)"); strSql.Append(" values ("); strSql.Append("@ProductID,@Price,@PropertyA,@PropertyB,@PropertyC,@Stock,@Property)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ProductID", SqlDbType.Int, 4), new SqlParameter("@Price", SqlDbType.Decimal, 9), new SqlParameter("@PropertyA", SqlDbType.Int, 4), new SqlParameter("@PropertyB", SqlDbType.Int, 4), new SqlParameter("@PropertyC", SqlDbType.Int, 4), new SqlParameter("@Stock", SqlDbType.Int, 4), new SqlParameter("@Property", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.ProductID; parameters[1].Value = model.Price; parameters[2].Value = model.PropertyA; parameters[3].Value = model.PropertyB; parameters[4].Value = model.PropertyC; parameters[5].Value = model.Stock; parameters[6].Value = model.Property; object obj = DBHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Product_Ext GetModel(int ProductExtID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ProductExtID,ProductID,Price,PropertyA,PropertyB,PropertyC,Stock,Property from T_Product_Ext "); strSql.Append(" where ProductExtID=@ProductExtID"); SqlParameter[] parameters = { new SqlParameter("@ProductExtID", SqlDbType.Int, 4) }; parameters[0].Value = ProductExtID; WebApi_Model.T_Product_Ext model = new WebApi_Model.T_Product_Ext(); DataSet ds = DBHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }