예제 #1
0
        /// <summary>
        /// 获取头条新闻
        /// </summary>
        /// <param name="Count"></param>
        /// <returns></returns>
        public List <Archives> GetHeadline(int Count)
        {
            List <Archives> Result = new List <Archives>();

            try
            {
                log.SaveLog("开始获取数据!");
                AccountProvider _AccountProvider = new AccountProvider();
                //获取访问权限
                int VewBrowsePermissions = _AccountProvider.GetBrowsePermissions();
                //生成检索语句
                string sql = string.Format("select * from de2_archives where  flag like '%h%' and arcrank!=-1 and( arcrank=0 or arcrank={0} )order by sortrank desc limit @limit", VewBrowsePermissions);

                MySqlClient _client = new MySqlClient();
                log.SaveLog("开始执行SQL!");
                Result = _client.ExecuteQuery <Archives>(sql, new MySqlParameter("@limit", Count));
                log.SaveLog("完成SQL!");
                Result = FromateLitpic(Result);
            }
            catch (Exception ex)
            {
                log.SaveLog("执行错误!" + ex.Message);
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "获取头条新闻", "GetHeadline", ex);
            }
            return(Result);
        }
예제 #2
0
        /// <summary>
        /// 根据新闻类型获取新闻列表
        /// </summary>
        /// <param name="StartRow"></param>
        /// <param name="PageSize"></param>
        /// <param name="TypeID"></param>
        /// <param name="Author"></param>
        /// <returns></returns>
        public BaseResopne <List <Archives> > GetNewsByTypeID(int StartRow, int PageSize, string TypeID, string SearchKey)
        {
            BaseResopne <List <Archives> > Result = new BaseResopne <List <Archives> >();

            try
            {
                AccountProvider _AccountProvider = new AccountProvider();
                //获取访问权限
                int VewBrowsePermissions = _AccountProvider.GetBrowsePermissions();

                //生成检索语句
                StringBuilder sql      = new StringBuilder();
                StringBuilder countsql = new StringBuilder();
                sql.AppendLine("select * from de2_archives where arcrank!=-1 and ( arcrank=0 or arcrank=@Permissions)");
                countsql.AppendLine("select count(id) from de2_archives where arcrank!=-1 and ( arcrank=0 or arcrank=@Permissions)");
                if (!string.IsNullOrEmpty(TypeID))
                {
                    if (TypeID.IndexOf(",") > 0)
                    {
                        sql.AppendLine("and typeid in (" + TypeID + ")");
                        countsql.AppendLine("and typeid in (" + TypeID + ")");
                    }
                    else
                    {
                        sql.AppendLine(" and typeid=@typeid ");
                        countsql.AppendLine(" and typeid=@typeid ");
                    }
                }
                if (!string.IsNullOrEmpty(SearchKey))
                {
                    sql.AppendLine(" and (writer like @SearchKey or  title like @SearchKey or  keywords like @SearchKey)");
                    countsql.AppendLine(" and (writer like @SearchKey or  title like @SearchKey or  keywords like @SearchKey) ");
                }

                sql.AppendLine(" order by sortrank desc");
                sql.AppendLine(" limit @start,@count ");
                MySqlClient _client = new MySqlClient();
                Result.Total = Convert.ToInt32(_client.ExecuteScalar(countsql.ToString(),
                                                                     new MySqlParameter("@start", StartRow),
                                                                     new MySqlParameter("@count", PageSize),
                                                                     new MySqlParameter("@Permissions", VewBrowsePermissions),
                                                                     new MySqlParameter("@typeid", TypeID),
                                                                     new MySqlParameter("@SearchKey", "%" + SearchKey + "%")));

                Result.Data = _client.ExecuteQuery <Archives>(sql.ToString(),
                                                              new MySqlParameter("@start", StartRow),
                                                              new MySqlParameter("@count", PageSize),
                                                              new MySqlParameter("@Permissions", VewBrowsePermissions),
                                                              new MySqlParameter("@typeid", TypeID),
                                                              new MySqlParameter("@SearchKey", "%" + SearchKey + "%"));

                Result.Data = FromateLitpic(Result.Data);
            }
            catch (Exception ex)
            {
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "根据新闻类型获取新闻列表", "GetNewsByTypeID", ex);
                Result.IsSuccess = false;
                Result.Error     = ex.Message;
            }
            return(Result);
        }