using System; using System.Data; using System.Text; using System.Data.SqlClient; namespace Basic.DAL { /// /// 最终内容 /// public partial class about { /// /// 增加一条数据 /// public int Add(Basic.Model.about model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_about("); strSql.Append("class_id,parent_id,guid,title,url,path,fujian,seo_title,seo_keywords,seo_description,content,paixu,hits,status,user_id,add_time)"); strSql.Append(" values ("); strSql.Append("@class_id,@parent_id,@guid,@title,@url,@path,@fujian,@seo_title,@seo_keywords,@seo_description,@content,@paixu,@hits,@status,@user_id,@add_time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@class_id", SqlDbType.Int,10), new SqlParameter("@parent_id", SqlDbType.Int,10), new SqlParameter("@guid", SqlDbType.NVarChar,50), new SqlParameter("@title", SqlDbType.NVarChar,100), new SqlParameter("@url", SqlDbType.NVarChar,255), new SqlParameter("@path", SqlDbType.NVarChar,255), new SqlParameter("@fujian", SqlDbType.NVarChar,255), new SqlParameter("@seo_title", SqlDbType.NVarChar,255), new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255), new SqlParameter("@seo_description", SqlDbType.NVarChar,255), new SqlParameter("@content", SqlDbType.NText,1073741823), new SqlParameter("@paixu", SqlDbType.Int,10), new SqlParameter("@hits", SqlDbType.Int,10), new SqlParameter("@status", SqlDbType.Int,10), new SqlParameter("@user_id", SqlDbType.Int,10), new SqlParameter("@add_time", SqlDbType.DateTime,23)}; parameters[0].Value = model.class_id; parameters[1].Value = model.parent_id; parameters[2].Value = model.guid; parameters[3].Value = model.title; parameters[4].Value = model.url; parameters[5].Value = model.path; parameters[6].Value = model.fujian; parameters[7].Value = model.seo_title; parameters[8].Value = model.seo_keywords; parameters[9].Value = model.seo_description; parameters[10].Value = model.content; parameters[11].Value = model.paixu; parameters[12].Value = model.hits; parameters[13].Value = model.status; parameters[14].Value = model.user_id; parameters[15].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// 更新一条数据 /// public bool Update(Basic.Model.about model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_about set "); strSql.Append("class_id=@class_id,"); strSql.Append("parent_id=@parent_id,"); strSql.Append("guid=@guid,"); strSql.Append("title=@title,"); strSql.Append("url=@url,"); strSql.Append("path=@path,"); strSql.Append("fujian=@fujian,"); strSql.Append("seo_title=@seo_title,"); strSql.Append("seo_keywords=@seo_keywords,"); strSql.Append("seo_description=@seo_description,"); strSql.Append("content=@content,"); strSql.Append("paixu=@paixu,"); strSql.Append("hits=@hits,"); strSql.Append("status=@status,"); strSql.Append("user_id=@user_id,"); strSql.Append("add_time=@add_time"); strSql.Append(" where class_id=@class_id"); SqlParameter[] parameters = { new SqlParameter("@class_id", SqlDbType.Int,10), new SqlParameter("@parent_id", SqlDbType.Int,10), new SqlParameter("@guid", SqlDbType.NVarChar,50), new SqlParameter("@title", SqlDbType.NVarChar,100), new SqlParameter("@url", SqlDbType.NVarChar,255), new SqlParameter("@path", SqlDbType.NVarChar,255), new SqlParameter("@fujian", SqlDbType.NVarChar,255), new SqlParameter("@seo_title", SqlDbType.NVarChar,255), new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255), new SqlParameter("@seo_description", SqlDbType.NVarChar,255), new SqlParameter("@content", SqlDbType.NText,1073741823), new SqlParameter("@paixu", SqlDbType.Int,10), new SqlParameter("@hits", SqlDbType.Int,10), new SqlParameter("@status", SqlDbType.Int,10), new SqlParameter("@user_id", SqlDbType.Int,10), new SqlParameter("@add_time", SqlDbType.DateTime,23), new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = model.class_id; parameters[1].Value = model.parent_id; parameters[2].Value = model.guid; parameters[3].Value = model.title; parameters[4].Value = model.url; parameters[5].Value = model.path; parameters[6].Value = model.fujian; parameters[7].Value = model.seo_title; parameters[8].Value = model.seo_keywords; parameters[9].Value = model.seo_description; parameters[10].Value = model.content; parameters[11].Value = model.paixu; parameters[12].Value = model.hits; parameters[13].Value = model.status; parameters[14].Value = model.user_id; parameters[15].Value = model.add_time; parameters[16].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool Delete(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from tb_about"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 得到一个对象实体 /// public Basic.Model.about GetModel(int class_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,class_id,parent_id,guid,title,url,path,fujian,seo_title,seo_keywords,seo_description,content,paixu,hits,status,user_id,add_time from tb_about"); strSql.Append(" where class_id=@class_id"); SqlParameter[] parameters = { new SqlParameter("@class_id", SqlDbType.Int,4)}; parameters[0].Value = class_id; Basic.Model.about model = new Basic.Model.about(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString())) { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString())) { model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString()); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["parent_id"].ToString())) { model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString()); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["guid"].ToString())) { model.guid = ds.Tables[0].Rows[0]["guid"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString())) { model.title = ds.Tables[0].Rows[0]["title"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["url"].ToString())) { model.url = ds.Tables[0].Rows[0]["url"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString())) { model.path = ds.Tables[0].Rows[0]["path"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["fujian"].ToString())) { model.fujian = ds.Tables[0].Rows[0]["fujian"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_title"].ToString())) { model.seo_title = ds.Tables[0].Rows[0]["seo_title"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_keywords"].ToString())) { model.seo_keywords = ds.Tables[0].Rows[0]["seo_keywords"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_description"].ToString())) { model.seo_description = ds.Tables[0].Rows[0]["seo_description"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString())) { model.content = ds.Tables[0].Rows[0]["content"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString())) { model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString()); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["hits"].ToString())) { model.hits = int.Parse(ds.Tables[0].Rows[0]["hits"].ToString()); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString())) { model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString()); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString())) { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString())) { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } return model; } else { return null; } } /// /// 获得前几行数据 /// public DataSet GetList(int Top, string strWhere, string filedOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); if (Top > 0) { strSql.Append(" top " + Top.ToString()); } strSql.Append("id,class_id,parent_id,guid,title,url,path,fujian,seo_title,seo_keywords,seo_description,content,paixu,hits,status,user_id,add_time"); strSql.Append(" from tb_about"); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); return DbHelperSQL.Query(strSql.ToString()); } /// /// 是否存在该记录 /// public bool Exists(int class_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from tb_about"); strSql.Append(" where class_id=@class_id"); SqlParameter[] parameters = { new SqlParameter("@class_id", SqlDbType.Int,4)}; parameters[0].Value = class_id; return DbHelperSQL.Exists(strSql.ToString(), parameters); } } }