/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.CMS_FriendLink model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CMS_FriendLink("); strSql.Append("Title,IsPic,PicUrl,SiteUrl,Sort)"); strSql.Append(" values ("); strSql.Append("@Title,@IsPic,@PicUrl,@SiteUrl,@Sort)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 50), new SqlParameter("@IsPic", SqlDbType.Bit, 1), new SqlParameter("@PicUrl", SqlDbType.VarChar, 100), new SqlParameter("@SiteUrl", SqlDbType.VarChar, 100), new SqlParameter("@Sort", SqlDbType.Int, 4) }; parameters[0].Value = model.Title; parameters[1].Value = model.IsPic; parameters[2].Value = model.PicUrl; parameters[3].Value = model.SiteUrl; parameters[4].Value = model.Sort; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.CMS_FriendLink GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Title,IsPic,PicUrl,SiteUrl,Sort from CMS_FriendLink "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Maticsoft.Model.CMS_FriendLink model = new Maticsoft.Model.CMS_FriendLink(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); if (ds.Tables[0].Rows[0]["IsPic"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsPic"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsPic"].ToString().ToLower() == "true")) { model.IsPic = true; } else { model.IsPic = false; } } model.PicUrl = ds.Tables[0].Rows[0]["PicUrl"].ToString(); model.SiteUrl = ds.Tables[0].Rows[0]["SiteUrl"].ToString(); if (ds.Tables[0].Rows[0]["Sort"].ToString() != "") { model.Sort = int.Parse(ds.Tables[0].Rows[0]["Sort"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.CMS_FriendLink model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CMS_FriendLink set "); strSql.Append("Title=@Title,"); strSql.Append("IsPic=@IsPic,"); strSql.Append("PicUrl=@PicUrl,"); strSql.Append("SiteUrl=@SiteUrl,"); strSql.Append("Sort=@Sort"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 50), new SqlParameter("@IsPic", SqlDbType.Bit, 1), new SqlParameter("@PicUrl", SqlDbType.VarChar, 100), new SqlParameter("@SiteUrl", SqlDbType.VarChar, 100), new SqlParameter("@Sort", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.Title; parameters[1].Value = model.IsPic; parameters[2].Value = model.PicUrl; parameters[3].Value = model.SiteUrl; parameters[4].Value = model.Sort; parameters[5].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }