using System; using System.Data; using System.Text; using System.Data.SqlClient; namespace Basic.DAL { /// /// 友情链接 /// public partial class link { /// /// 增加一条数据 /// public int Add(Basic.Model.link model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_link("); strSql.Append("paixu,title,class_id,path,url,target,state,remark,add_time)"); strSql.Append(" values ("); strSql.Append("@paixu,@title,@class_id,@path,@url,@target,@state,@remark,@add_time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@paixu", SqlDbType.Int,10), new SqlParameter("@title", SqlDbType.NVarChar,255), new SqlParameter("@class_id", SqlDbType.Int,10), new SqlParameter("@path", SqlDbType.NVarChar,255), new SqlParameter("@url", SqlDbType.NVarChar,255), new SqlParameter("@target", SqlDbType.Int,10), new SqlParameter("@state", SqlDbType.Int,10), new SqlParameter("@remark", SqlDbType.NVarChar,500), new SqlParameter("@add_time", SqlDbType.DateTime,23)}; parameters[0].Value = model.paixu; parameters[1].Value = model.title; parameters[2].Value = model.class_id; parameters[3].Value = model.path; parameters[4].Value = model.url; parameters[5].Value = model.target; parameters[6].Value = model.state; parameters[7].Value = model.remark; parameters[8].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.link model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_link set "); strSql.Append("paixu=@paixu,"); strSql.Append("title=@title,"); strSql.Append("class_id=@class_id,"); strSql.Append("path=@path,"); strSql.Append("url=@url,"); strSql.Append("target=@target,"); strSql.Append("state=@state,"); strSql.Append("remark=@remark,"); strSql.Append("add_time=@add_time"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@paixu", SqlDbType.Int,10), new SqlParameter("@title", SqlDbType.NVarChar,255), new SqlParameter("@class_id", SqlDbType.Int,10), new SqlParameter("@path", SqlDbType.NVarChar,255), new SqlParameter("@url", SqlDbType.NVarChar,255), new SqlParameter("@target", SqlDbType.Int,10), new SqlParameter("@state", SqlDbType.Int,10), new SqlParameter("@remark", SqlDbType.NVarChar,500), new SqlParameter("@add_time", SqlDbType.DateTime,23), new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = model.paixu; parameters[1].Value = model.title; parameters[2].Value = model.class_id; parameters[3].Value = model.path; parameters[4].Value = model.url; parameters[5].Value = model.target; parameters[6].Value = model.state; parameters[7].Value = model.remark; parameters[8].Value = model.add_time; parameters[9].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_link"); 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.link GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,paixu,title,class_id,path,url,target,state,remark,add_time from tb_link"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; Basic.Model.link model = new Basic.Model.link(); 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]["paixu"].ToString())) { model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].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]["class_id"].ToString())) { model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].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]["url"].ToString())) { model.url = ds.Tables[0].Rows[0]["url"].ToString(); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["target"].ToString())) { model.target = int.Parse(ds.Tables[0].Rows[0]["target"].ToString()); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["state"].ToString())) { model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString()); } if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["remark"].ToString())) { model.remark = ds.Tables[0].Rows[0]["remark"].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 void UpdateField(int id, string strValue) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_link set " + strValue); strSql.Append(" where id=" + id); DbHelperSQL.ExecuteSql(strSql.ToString()); } } }