/// <summary> /// 得到一个对象实体 /// </summary> public Tea.Model.guige DataRowToModel(DataRow row) { Tea.Model.guige model = new Tea.Model.guige(); if (row != null) { if (row["guige_id"] != null && row["guige_id"].ToString() != "") { model.guige_id = int.Parse(row["guige_id"].ToString()); } if (row["guige_title"] != null) { model.guige_title = row["guige_title"].ToString(); } if (row["guige_content"] != null) { model.guige_content = row["guige_content"].ToString(); } if (row["guige_sort"] != null && row["guige_sort"].ToString() != "") { model.guige_sort = int.Parse(row["guige_sort"].ToString()); } if (row["guige_add_date"] != null && row["guige_add_date"].ToString() != "") { model.guige_add_date = DateTime.Parse(row["guige_add_date"].ToString()); } if (row["guige_web"] != null && row["guige_web"].ToString() != "") { model.guige_web = int.Parse(row["guige_web"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Tea.Model.guige model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "guige("); strSql.Append("guige_title,guige_content,guige_sort,guige_add_date,guige_web)"); strSql.Append(" values ("); strSql.Append("@guige_title,@guige_content,@guige_sort,@guige_add_date,@guige_web)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@guige_title", SqlDbType.NVarChar, 128), new SqlParameter("@guige_content", SqlDbType.NVarChar, 1024), new SqlParameter("@guige_sort", SqlDbType.Int, 4), new SqlParameter("@guige_add_date", SqlDbType.DateTime), new SqlParameter("@guige_web", SqlDbType.Int, 4) }; parameters[0].Value = model.guige_title; parameters[1].Value = model.guige_content; parameters[2].Value = model.guige_sort; parameters[3].Value = model.guige_add_date; parameters[4].Value = model.guige_web; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Tea.Model.guige model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "guige set "); strSql.Append("guige_title=@guige_title,"); strSql.Append("guige_content=@guige_content,"); strSql.Append("guige_sort=@guige_sort,"); strSql.Append("guige_add_date=@guige_add_date,"); strSql.Append("guige_web=@guige_web"); strSql.Append(" where guige_id=@guige_id"); SqlParameter[] parameters = { new SqlParameter("@guige_title", SqlDbType.NVarChar, 128), new SqlParameter("@guige_content", SqlDbType.NVarChar, 1024), new SqlParameter("@guige_sort", SqlDbType.Int, 4), new SqlParameter("@guige_add_date", SqlDbType.DateTime), new SqlParameter("@guige_web", SqlDbType.Int, 4), new SqlParameter("@guige_id", SqlDbType.Int, 4) }; parameters[0].Value = model.guige_title; parameters[1].Value = model.guige_content; parameters[2].Value = model.guige_sort; parameters[3].Value = model.guige_add_date; parameters[4].Value = model.guige_web; parameters[5].Value = model.guige_id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Tea.Model.guige GetModel(int guige_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 guige_id,guige_title,guige_content,guige_sort,guige_add_date,guige_web from " + databaseprefix + "guige "); strSql.Append(" where guige_id=@guige_id"); SqlParameter[] parameters = { new SqlParameter("@guige_id", SqlDbType.Int, 4) }; parameters[0].Value = guige_id; Tea.Model.guige model = new Tea.Model.guige(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }