/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.orderdetail model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update orderdetail set "); strSql.Append("OrderId=@OrderId,"); strSql.Append("AlbumId=@AlbumId,"); strSql.Append("Quantity=@Quantity,"); strSql.Append("UnitPrice=@UnitPrice"); strSql.Append(" where OrderDetailId=@OrderDetailId "); MySqlParameter[] parameters = { new MySqlParameter("@OrderId", MySqlDbType.Int32, 11), new MySqlParameter("@AlbumId", MySqlDbType.Int32, 11), new MySqlParameter("@Quantity", MySqlDbType.Int32, 11), new MySqlParameter("@UnitPrice", MySqlDbType.Decimal, 10), new MySqlParameter("@OrderDetailId", MySqlDbType.Int32, 11) }; parameters[0].Value = model.OrderId; parameters[1].Value = model.AlbumId; parameters[2].Value = model.Quantity; parameters[3].Value = model.UnitPrice; parameters[4].Value = model.OrderDetailId; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.orderdetail DataRowToModel(DataRow row) { Maticsoft.Model.orderdetail model = new Maticsoft.Model.orderdetail(); if (row != null) { if (row["OrderDetailId"] != null && row["OrderDetailId"].ToString() != "") { model.OrderDetailId = int.Parse(row["OrderDetailId"].ToString()); } if (row["OrderId"] != null && row["OrderId"].ToString() != "") { model.OrderId = int.Parse(row["OrderId"].ToString()); } if (row["AlbumId"] != null && row["AlbumId"].ToString() != "") { model.AlbumId = int.Parse(row["AlbumId"].ToString()); } if (row["Quantity"] != null && row["Quantity"].ToString() != "") { model.Quantity = int.Parse(row["Quantity"].ToString()); } if (row["UnitPrice"] != null && row["UnitPrice"].ToString() != "") { model.UnitPrice = decimal.Parse(row["UnitPrice"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.orderdetail model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into orderdetail("); strSql.Append("OrderDetailId,OrderId,AlbumId,Quantity,UnitPrice)"); strSql.Append(" values ("); strSql.Append("@OrderDetailId,@OrderId,@AlbumId,@Quantity,@UnitPrice)"); MySqlParameter[] parameters = { new MySqlParameter("@OrderDetailId", MySqlDbType.Int32, 11), new MySqlParameter("@OrderId", MySqlDbType.Int32, 11), new MySqlParameter("@AlbumId", MySqlDbType.Int32, 11), new MySqlParameter("@Quantity", MySqlDbType.Int32, 11), new MySqlParameter("@UnitPrice", MySqlDbType.Decimal, 10) }; parameters[0].Value = model.OrderDetailId; parameters[1].Value = model.OrderId; parameters[2].Value = model.AlbumId; parameters[3].Value = model.Quantity; parameters[4].Value = model.UnitPrice; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.orderdetail GetModel(int OrderDetailId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select OrderDetailId,OrderId,AlbumId,Quantity,UnitPrice from orderdetail "); strSql.Append(" where OrderDetailId=@OrderDetailId "); MySqlParameter[] parameters = { new MySqlParameter("@OrderDetailId", MySqlDbType.Int32, 11) }; parameters[0].Value = OrderDetailId; Maticsoft.Model.orderdetail model = new Maticsoft.Model.orderdetail(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }