コード例 #1
0
ファイル: topics.ascx.cs プロジェクト: ahsan-sally/demo
        /// <summary>
        /// The bind data.
        /// </summary>
        private void BindData()
        {
            var ds = this.Get <YafDbBroker>().BoardLayout(
                this.PageContext.PageBoardID,
                this.PageContext.PageUserID,
                this.PageContext.PageCategoryID,
                this.PageContext.PageForumID);

            if (ds.Tables["Forum"].HasRows())
            {
                this.ForumList.DataSource = ds.Tables["Forum"].Rows;
                this.SubForums.Visible    = true;
            }

            this.Pager.PageSize = this.Get <YafBoardSettings>().TopicsPerPage;

            // when userId is null it returns the count of all deleted messages

            /*int? userId = null;
             *
             * // get the userID to use for the deleted posts count...
             * if (!this.Get<YafBoardSettings>().ShowDeletedMessagesToAll)
             * {
             *  // only show deleted messages that belong to this user if they are not admin/mod
             *  if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess)
             *  {
             *      userId = this.PageContext.PageUserID;
             *  }
             * }*/

            int?userId = this.PageContext.PageUserID;

            var dt = LegacyDb.announcements_list(
                this.PageContext.PageForumID,
                userId,
                null,
                DateTime.UtcNow,
                0,
                10,
                this.Get <YafBoardSettings>().UseStyledNicks,
                true,
                this.Get <YafBoardSettings>().UseReadTrackingByDatabase);

            if (dt != null)
            {
                dt = this.StyleTransformDataTable(dt);
            }

            var baseSize = this.Get <YafBoardSettings>().TopicsPerPage;

            this.Announcements.DataSource = dt;

            /*if (!m_bIgnoreQueryString && Request.QueryString["p"] != null)
             *          {
             *                  // show specific page (p is 1 based)
             *                  int tPage = (int)Security.StringToLongOrRedirect(Request.QueryString["p"]);
             *
             *                  if (tPage > 0)
             *                  {
             *                          Pager.CurrentPageIndex = tPage - 1;
             *                  }
             *          }*/
            var pagerCurrentPageIndex = this.Pager.CurrentPageIndex;

            DataTable dtTopics;

            if (this._showTopicListSelected == 0)
            {
                dtTopics = LegacyDb.topic_list(
                    this.PageContext.PageForumID,
                    userId,
                    DateTimeHelper.SqlDbMinTime(),
                    DateTime.UtcNow,
                    pagerCurrentPageIndex,
                    baseSize,
                    this.Get <YafBoardSettings>().UseStyledNicks,
                    true,
                    this.Get <YafBoardSettings>().UseReadTrackingByDatabase);
                if (dtTopics != null)
                {
                    dtTopics = this.StyleTransformDataTable(dtTopics);
                }
            }
            else
            {
                int[] days = { 1, 2, 7, 14, 31, 2 * 31, 6 * 31, 356 };

                var date = DateTime.UtcNow.AddDays(-days[this._showTopicListSelected]);

                dtTopics = LegacyDb.topic_list(
                    this.PageContext.PageForumID,
                    userId,
                    date,
                    DateTime.UtcNow,
                    pagerCurrentPageIndex,
                    baseSize,
                    this.Get <YafBoardSettings>().UseStyledNicks,
                    true,
                    this.Get <YafBoardSettings>().UseReadTrackingByDatabase);

                if (dtTopics != null)
                {
                    dtTopics = this.StyleTransformDataTable(dtTopics);
                }
            }

            this.TopicList.DataSource = dtTopics;

            this.DataBind();

            // setup the show topic list selection after data binding
            this.ShowList.SelectedIndex       = this._showTopicListSelected;
            this.Get <IYafSession>().ShowList = this._showTopicListSelected;
            if (dtTopics != null && dtTopics.HasRows())
            {
                this.Pager.Count = dtTopics.AsEnumerable().First().Field <int>("TotalRows");
            }
        }