/// <summary> /// 得到一个对象实体 /// </summary> public Topicsys.Model.t_notice DataRowToModel(DataRow row) { Topicsys.Model.t_notice model = new Topicsys.Model.t_notice(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["notice_type"] != null && row["notice_type"].ToString() != "") { model.notice_type = int.Parse(row["notice_type"].ToString()); } if (row["notice_title"] != null) { model.notice_title = row["notice_title"].ToString(); } if (row["notice_body"] != null) { model.notice_body = row["notice_body"].ToString(); } if (row["notice_user_name"] != null) { model.notice_user_name = row["notice_user_name"].ToString(); } if (row["notice_date"] != null && row["notice_date"].ToString() != "") { model.notice_date = DateTime.Parse(row["notice_date"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Topicsys.Model.t_notice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_notice("); strSql.Append("notice_type,notice_title,notice_body,notice_user_name,notice_date)"); strSql.Append(" values ("); strSql.Append("@notice_type,@notice_title,@notice_body,@notice_user_name,@notice_date)"); MySqlParameter[] parameters = { new MySqlParameter("@notice_type", MySqlDbType.Int32, 1), new MySqlParameter("@notice_title", MySqlDbType.VarChar, 64), new MySqlParameter("@notice_body", MySqlDbType.Text, body_size), new MySqlParameter("@notice_user_name", MySqlDbType.VarChar, 32), new MySqlParameter("@notice_date", MySqlDbType.DateTime) }; parameters[0].Value = model.notice_type; parameters[1].Value = model.notice_title; parameters[2].Value = model.notice_body; parameters[3].Value = model.notice_user_name; parameters[4].Value = model.notice_date; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Topicsys.Model.t_notice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_notice set "); strSql.Append("notice_type=@notice_type,"); strSql.Append("notice_title=@notice_title,"); strSql.Append("notice_body=@notice_body,"); strSql.Append("notice_user_name=@notice_user_name,"); strSql.Append("notice_date=@notice_date"); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@notice_type", MySqlDbType.Int32, 1), new MySqlParameter("@notice_title", MySqlDbType.VarChar, 64), new MySqlParameter("@notice_body", MySqlDbType.Text, body_size), new MySqlParameter("@notice_user_name", MySqlDbType.VarChar, 32), new MySqlParameter("@notice_date", MySqlDbType.DateTime), new MySqlParameter("@id", MySqlDbType.Int32, 11) }; parameters[0].Value = model.notice_type; parameters[1].Value = model.notice_title; parameters[2].Value = model.notice_body; parameters[3].Value = model.notice_user_name; parameters[4].Value = model.notice_date; parameters[5].Value = model.id; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Topicsys.Model.t_notice GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,notice_type,notice_title,notice_body,notice_user_name,notice_date from t_notice "); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.Int32) }; parameters[0].Value = id; Topicsys.Model.t_notice model = new Topicsys.Model.t_notice(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }