/// <summary> /// 增加一条数据 /// </summary> public bool Add(Model.chest model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into chest("); strSql.Append("chest_name,chest_remain_volume,chest_remain_seat,chest_create_time,chest_type,chest_belong_storage)"); strSql.Append(" values ("); strSql.Append("@chest_name,@chest_remain_volume,@chest_remain_seat,@chest_create_time,@chest_type,@chest_belong_storage)"); MySqlParameter[] parameters = { new MySqlParameter("@chest_name", MySqlDbType.VarChar, 32), new MySqlParameter("@chest_remain_volume", MySqlDbType.Float, 128), new MySqlParameter("@chest_remain_seat", MySqlDbType.Int32, 32), new MySqlParameter("@chest_create_time", MySqlDbType.DateTime), new MySqlParameter("@chest_type", MySqlDbType.Int32, 32), new MySqlParameter("@chest_belong_storage", MySqlDbType.Int32, 32) }; parameters[0].Value = model.chest_name; parameters[1].Value = model.chest_remain_volume; parameters[2].Value = model.chest_remain_seat; parameters[3].Value = model.chest_create_time; parameters[4].Value = model.chest_type; parameters[5].Value = model.chest_belong_storage; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.chest model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update chest set "); strSql.Append("chest_name=@chest_name,"); strSql.Append("chest_remain_volume=@chest_remain_volume,"); strSql.Append("chest_remain_seat=@chest_remain_seat,"); strSql.Append("chest_create_time=@chest_create_time,"); strSql.Append("chest_type=@chest_type,"); strSql.Append("chest_belong_storage=@chest_belong_storage"); strSql.Append(" where chest_id=@chest_id"); MySqlParameter[] parameters = { new MySqlParameter("@chest_name", MySqlDbType.VarChar, 32), new MySqlParameter("@chest_remain_volume", MySqlDbType.Float, 128), new MySqlParameter("@chest_remain_seat", MySqlDbType.Int32, 32), new MySqlParameter("@chest_create_time", MySqlDbType.DateTime), new MySqlParameter("@chest_type", MySqlDbType.Int32, 32), new MySqlParameter("@chest_belong_storage", MySqlDbType.Int32, 32), new MySqlParameter("@chest_id", MySqlDbType.Int32, 32) }; parameters[0].Value = model.chest_name; parameters[1].Value = model.chest_remain_volume; parameters[2].Value = model.chest_remain_seat; parameters[3].Value = model.chest_create_time; parameters[4].Value = model.chest_type; parameters[5].Value = model.chest_belong_storage; parameters[6].Value = model.chest_id; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.chest DataRowToModel(DataRow row) { Model.chest model = new Model.chest(); if (row != null) { if (row["chest_id"] != null && row["chest_id"].ToString() != "") { model.chest_id = int.Parse(row["chest_id"].ToString()); } if (row["chest_name"] != null) { model.chest_name = row["chest_name"].ToString(); } if (row["chest_remain_volume"] != null && row["chest_remain_volume"].ToString() != "") { model.chest_remain_volume = decimal.Parse(row["chest_remain_volume"].ToString()); } if (row["chest_remain_seat"] != null && row["chest_remain_seat"].ToString() != "") { model.chest_remain_seat = int.Parse(row["chest_remain_seat"].ToString()); } if (row["chest_create_time"] != null && row["chest_create_time"].ToString() != "") { model.chest_create_time = DateTime.Parse(row["chest_create_time"].ToString()); } if (row["chest_type"] != null && row["chest_type"].ToString() != "") { model.chest_type = int.Parse(row["chest_type"].ToString()); } if (row["chest_belong_storage"] != null && row["chest_belong_storage"].ToString() != "") { model.chest_belong_storage = int.Parse(row["chest_belong_storage"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.chest GetModel(int chest_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select chest_id,chest_name,chest_remain_volume,chest_remain_seat,chest_create_time,chest_type,chest_belong_storage from chest "); strSql.Append(" where chest_id=@chest_id"); MySqlParameter[] parameters = { new MySqlParameter("@chest_id", MySqlDbType.Int32) }; parameters[0].Value = chest_id; Model.chest model = new Model.chest(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }