/// <summary> /// 判断当前节点是否已存在相同的 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int ExistNum(WeiXinQNewsEntity entity) { ///id=0,判断总数,ID>0判断除自己之外的总数 string sql = @"Select count(1) from dbo.[WeiXinQNews] WITH(NOLOCK) "; string where = "where "; if (entity.Id == 0) { } else { } sql = sql + where; DbCommand cmd = db.GetSqlStringCommand(sql); if (entity.Id > 0) { db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); } object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 根据主键值读取记录。如果数据库不存在这条数据将返回null /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public WeiXinQNewsEntity GetWeiXinQNews(int id) { string sql = @"SELECT [Id],[Title],[ShortTitle],[NewsContent],[CreateTime],[HasShow],[NewsType],FromUrl FROM dbo.[WeiXinQNews] WITH(NOLOCK) WHERE [Id]=@id" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, id); WeiXinQNewsEntity entity = new WeiXinQNewsEntity(); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Title = StringUtils.GetDbString(reader["Title"]); entity.ShortTitle = StringUtils.GetDbString(reader["ShortTitle"]); entity.NewsContent = StringUtils.GetDbString(reader["NewsContent"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entity.HasShow = StringUtils.GetDbInt(reader["HasShow"]); entity.NewsType = StringUtils.GetDbInt(reader["NewsType"]); entity.FromUrl = StringUtils.GetDbString(reader["FromUrl"]); } } return(entity); }
/// <summary> /// 插入一条记录到表WeiXinQNews,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="weiXinQNews">要添加的WeiXinQNews数据实体对象</param> public int AddWeiXinQNews(WeiXinQNewsEntity weiXinQNews) { if (weiXinQNews.Id > 0) { return(UpdateWeiXinQNews(weiXinQNews)); } return(WeiXinQNewsDA.Instance.AddWeiXinQNews(weiXinQNews)); }
public ActionResult WeiXinQNewsEdit() { int _id = QueryString.IntSafeQ("id", 0); WeiXinQNewsEntity _entity = WeiXinQNewsBLL.Instance.GetWeiXinQNews(_id); ViewBag.Entity = _entity; return(View()); }
/// <summary> /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。 /// 如果数据库有数据被更新了则返回True,否则返回False /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="weiXinQNews">待更新的实体对象</param> public int UpdateWeiXinQNews(WeiXinQNewsEntity entity) { string sql = @" UPDATE dbo.[WeiXinQNews] SET [Title]=@Title,[ShortTitle]=@ShortTitle,[NewsContent]=@NewsContent,[CreateTime]=@CreateTime,[HasShow]=@HasShow,[NewsType]=@NewsType,FromUrl=@FromUrl WHERE [Id]=@id"; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); db.AddInParameter(cmd, "@Title", DbType.String, entity.Title); db.AddInParameter(cmd, "@ShortTitle", DbType.String, entity.ShortTitle); db.AddInParameter(cmd, "@NewsContent", DbType.String, entity.NewsContent); db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime); db.AddInParameter(cmd, "@HasShow", DbType.Int32, entity.HasShow); db.AddInParameter(cmd, "@NewsType", DbType.Int32, entity.NewsType); db.AddInParameter(cmd, "@FromUrl", DbType.String, entity.FromUrl); return(db.ExecuteNonQuery(cmd)); }
/// <summary> /// 插入一条记录到表WeiXinQNews,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="weiXinQNews">待插入的实体对象</param> public int AddWeiXinQNews(WeiXinQNewsEntity entity) { string sql = @"insert into WeiXinQNews( [Title],[ShortTitle],[NewsContent],[CreateTime],[HasShow],[NewsType],FromUrl)VALUES ( @Title,@ShortTitle,@NewsContent,@CreateTime,@HasShow,@NewsType,@FromUrl); SELECT SCOPE_IDENTITY();" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Title", DbType.String, entity.Title); db.AddInParameter(cmd, "@ShortTitle", DbType.String, entity.ShortTitle); db.AddInParameter(cmd, "@NewsContent", DbType.String, entity.NewsContent); db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime); db.AddInParameter(cmd, "@HasShow", DbType.Int32, entity.HasShow); db.AddInParameter(cmd, "@NewsType", DbType.Int32, entity.NewsType); db.AddInParameter(cmd, "@FromUrl", DbType.String, entity.FromUrl); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
public int WeiXinQNewsSubmit() { int _id = FormString.IntSafeQ("_id"); string _title = FormString.SafeQ("_title", 200); string _content = FormString.SafeQNo("_content", 1000000); int _sort = FormString.IntSafeQ("_sort"); int _isactive = FormString.IntSafeQ("_isactive"); int _systemtype = FormString.IntSafeQ("_systemtype"); int _noticetype = FormString.IntSafeQ("_noticetype"); string _FromUrl = FormString.SafeQ("FromUrl", 200); WeiXinQNewsEntity _entity = WeiXinQNewsBLL.Instance.GetWeiXinQNews(_id); _entity.Id = _id; _entity.Title = _title; _entity.NewsContent = _content; _entity.CreateTime = StringUtils.GetDbDateTime(FormString.SafeQ("_creatime")); _entity.NewsType = _noticetype; _entity.FromUrl = _FromUrl; int _result = WeiXinQNewsBLL.Instance.AddWeiXinQNews(_entity); return(_result); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <WeiXinQNewsEntity> GetWeiXinQNewsAll() { string sql = @"SELECT [Id],[Title],[ShortTitle],[NewsContent],[CreateTime],[HasShow],[NewsType] from dbo.[WeiXinQNews] WITH(NOLOCK) "; IList <WeiXinQNewsEntity> entityList = new List <WeiXinQNewsEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { WeiXinQNewsEntity entity = new WeiXinQNewsEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Title = StringUtils.GetDbString(reader["Title"]); entity.ShortTitle = StringUtils.GetDbString(reader["ShortTitle"]); entity.NewsContent = StringUtils.GetDbString(reader["NewsContent"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entity.HasShow = StringUtils.GetDbInt(reader["HasShow"]); entity.NewsType = StringUtils.GetDbInt(reader["NewsType"]); entityList.Add(entity); } } return(entityList); }
/// <summary> /// 更新一条WeiXinQNews记录。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="weiXinQNews">待更新的实体对象</param> /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param> public int UpdateWeiXinQNews(WeiXinQNewsEntity weiXinQNews) { return(WeiXinQNewsDA.Instance.UpdateWeiXinQNews(weiXinQNews)); }
/// <summary> /// 判断对象是否存在 /// </summary> /// <param name="dicEnum"></param> /// <returns></returns> public bool IsExist(WeiXinQNewsEntity weiXinQNews) { return(WeiXinQNewsDA.Instance.ExistNum(weiXinQNews) > 0); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <WeiXinQNewsEntity> GetWeiXinQNewsList(int pagesize, int pageindex, ref int recordCount, int newstype, string key) { string where = " where 1=1 "; if (newstype > 0) { where += " and NewsType=@NewsType "; } if (!string.IsNullOrEmpty(key)) { where += " and ShortTitle like @Key "; } string sql = @"SELECT [Id],[Title],[ShortTitle],[NewsContent],[CreateTime],[HasShow],[NewsType],FromUrl FROM (SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER, [Id],[Title],[ShortTitle],[NewsContent],[CreateTime],[HasShow],[NewsType],FromUrl from dbo.[WeiXinQNews] WITH(NOLOCK) " + where + @" ) as temp where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize" ; string sql2 = @"Select count(1) from dbo.[WeiXinQNews] with (nolock) " + where; IList <WeiXinQNewsEntity> entityList = new List <WeiXinQNewsEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex); db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize); if (newstype > 0) { db.AddInParameter(cmd, "@NewsType", DbType.Int32, newstype); } if (!string.IsNullOrEmpty(key)) { db.AddInParameter(cmd, "@Key", DbType.String, "%" + key + "%"); } using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { WeiXinQNewsEntity entity = new WeiXinQNewsEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Title = StringUtils.GetDbString(reader["Title"]); entity.ShortTitle = StringUtils.GetDbString(reader["ShortTitle"]); entity.NewsContent = StringUtils.GetDbString(reader["NewsContent"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entity.HasShow = StringUtils.GetDbInt(reader["HasShow"]); entity.NewsType = StringUtils.GetDbInt(reader["NewsType"]); entity.FromUrl = StringUtils.GetDbString(reader["FromUrl"]); entityList.Add(entity); } } cmd = db.GetSqlStringCommand(sql2); if (newstype > 0) { db.AddInParameter(cmd, "@NewsType", DbType.Int32, newstype); } if (!string.IsNullOrEmpty(key)) { db.AddInParameter(cmd, "@Key", DbType.String, "%" + key + "%"); } using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { recordCount = StringUtils.GetDbInt(reader[0]); } else { recordCount = 0; } } return(entityList); }