/// <summary> /// 更新一条数据 /// </summary> public bool Update(Tea.Model.link model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "link set "); strSql.Append("title=@title,"); strSql.Append("user_name=@user_name,"); strSql.Append("user_tel=@user_tel,"); strSql.Append("email=@email,"); strSql.Append("site_url=@site_url,"); strSql.Append("img_url=@img_url,"); strSql.Append("is_image=@is_image,"); strSql.Append("sort_id=@sort_id,"); strSql.Append("is_red=@is_red,"); strSql.Append("is_lock=@is_lock,"); strSql.Append("add_time=@add_time"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.NVarChar, 255), new SqlParameter("@user_name", SqlDbType.NVarChar, 50), new SqlParameter("@user_tel", SqlDbType.NVarChar, 20), new SqlParameter("@email", SqlDbType.NVarChar, 50), new SqlParameter("@site_url", SqlDbType.NVarChar, 255), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@is_image", SqlDbType.Int, 4), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@is_red", SqlDbType.TinyInt, 1), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.title; parameters[1].Value = model.user_name; parameters[2].Value = model.user_tel; parameters[3].Value = model.email; parameters[4].Value = model.site_url; parameters[5].Value = model.img_url; parameters[6].Value = model.is_image; parameters[7].Value = model.sort_id; parameters[8].Value = model.is_red; parameters[9].Value = model.is_lock; parameters[10].Value = model.add_time; parameters[11].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Tea.Model.link DataRowToModel(DataRow row) { Tea.Model.link model = new Tea.Model.link(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["user_name"] != null) { model.user_name = row["user_name"].ToString(); } if (row["user_tel"] != null) { model.user_tel = row["user_tel"].ToString(); } if (row["email"] != null) { model.email = row["email"].ToString(); } if (row["site_url"] != null) { model.site_url = row["site_url"].ToString(); } if (row["img_url"] != null) { model.img_url = row["img_url"].ToString(); } if (row["is_image"] != null && row["is_image"].ToString() != "") { model.is_image = int.Parse(row["is_image"].ToString()); } if (row["sort_id"] != null && row["sort_id"].ToString() != "") { model.sort_id = int.Parse(row["sort_id"].ToString()); } if (row["is_red"] != null && row["is_red"].ToString() != "") { model.is_red = int.Parse(row["is_red"].ToString()); } if (row["is_lock"] != null && row["is_lock"].ToString() != "") { model.is_lock = int.Parse(row["is_lock"].ToString()); } if (row["add_time"] != null && row["add_time"].ToString() != "") { model.add_time = DateTime.Parse(row["add_time"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Tea.Model.link model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "link("); strSql.Append("title,user_name,user_tel,email,site_url,img_url,is_image,sort_id,is_red,is_lock,add_time)"); strSql.Append(" values ("); strSql.Append("@title,@user_name,@user_tel,@email,@site_url,@img_url,@is_image,@sort_id,@is_red,@is_lock,@add_time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.NVarChar, 255), new SqlParameter("@user_name", SqlDbType.NVarChar, 50), new SqlParameter("@user_tel", SqlDbType.NVarChar, 20), new SqlParameter("@email", SqlDbType.NVarChar, 50), new SqlParameter("@site_url", SqlDbType.NVarChar, 255), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@is_image", SqlDbType.Int, 4), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@is_red", SqlDbType.TinyInt, 1), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.title; parameters[1].Value = model.user_name; parameters[2].Value = model.user_tel; parameters[3].Value = model.email; parameters[4].Value = model.site_url; parameters[5].Value = model.img_url; parameters[6].Value = model.is_image; parameters[7].Value = model.sort_id; parameters[8].Value = model.is_red; parameters[9].Value = model.is_lock; parameters[10].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Tea.Model.link GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,title,user_name,user_tel,email,site_url,img_url,is_image,sort_id,is_red,is_lock,add_time from " + databaseprefix + "link "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Tea.Model.link model = new Tea.Model.link(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }