PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/mojoPortal.Features.UI/Forums/Controls/UserThreadList.ascx.cs

#
C# | 147 lines | 109 code | 26 blank | 12 comment | 5 complexity | 25c75badb3a0baaa2fc3e6300f951245 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause, CPL-1.0, CC-BY-SA-3.0, GPL-2.0
  1. // Author: Joe Audette
  2. // Created: 2011-06-27
  3. // Last Modified: 2011-06-28
  4. //
  5. // The use and distribution terms for this software are covered by the
  6. // Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
  7. // which can be found in the file CPL.TXT at the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by
  9. // the terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. using System;
  14. using System.Data;
  15. using System.Globalization;
  16. using System.Web.UI;
  17. using mojoPortal.Business;
  18. using mojoPortal.Business.WebHelpers;
  19. using mojoPortal.Web;
  20. using mojoPortal.Web.Framework;
  21. using Resources;
  22. namespace mojoPortal.Web.ForumUI
  23. {
  24. public partial class UserThreadList : UserControl
  25. {
  26. private int userId = -1;
  27. private int pageNumber = 1;
  28. private int pageSize = 20;
  29. private int totalPages = 1;
  30. protected Double timeOffset = 0;
  31. private SiteUser forumUser = null;
  32. private SiteSettings siteSettings = null;
  33. private string siteRoot = string.Empty;
  34. private string imageSiteRoot = string.Empty;
  35. public string SiteRoot
  36. {
  37. get { return siteRoot; }
  38. set { siteRoot = value; }
  39. }
  40. public string ImageSiteRoot
  41. {
  42. get { return imageSiteRoot; }
  43. set { imageSiteRoot = value; }
  44. }
  45. public SiteSettings SiteSettings
  46. {
  47. set { siteSettings = value; }
  48. }
  49. public SiteUser ForumUser
  50. {
  51. set { forumUser = value; }
  52. }
  53. public int PageNumber
  54. {
  55. set { pageNumber = value; }
  56. }
  57. protected void Page_Load(object sender, EventArgs e)
  58. {
  59. if (!Visible) { return; }
  60. LoadSettings();
  61. PopulateLabels();
  62. PopulateControls();
  63. }
  64. private void PopulateControls()
  65. {
  66. if (forumUser == null) return;
  67. using (IDataReader reader = ForumThread.GetPageByUser(
  68. userId,
  69. pageNumber,
  70. pageSize,
  71. out totalPages))
  72. {
  73. string pageUrl = SiteRoot
  74. + "/Forums/UserThreads.aspx?"
  75. + "userid=" + userId.ToInvariantString()
  76. + "&pagenumber={0}";
  77. pgrTop.PageURLFormat = pageUrl;
  78. pgrTop.ShowFirstLast = true;
  79. pgrTop.CurrentIndex = pageNumber;
  80. pgrTop.PageSize = pageSize;
  81. pgrTop.PageCount = totalPages;
  82. pgrTop.Visible = (pgrTop.PageCount > 1);
  83. pgrBottom.PageURLFormat = pageUrl;
  84. pgrBottom.ShowFirstLast = true;
  85. pgrBottom.CurrentIndex = pageNumber;
  86. pgrBottom.PageSize = pageSize;
  87. pgrBottom.PageCount = totalPages;
  88. pgrBottom.Visible = (pgrBottom.PageCount > 1);
  89. rptForums.DataSource = reader;
  90. rptForums.DataBind();
  91. }
  92. }
  93. private void PopulateLabels()
  94. {
  95. pgrTop.NavigateToPageText = ForumResources.CutePagerNavigateToPageText;
  96. pgrTop.BackToFirstClause = ForumResources.CutePagerBackToFirstClause;
  97. pgrTop.GoToLastClause = ForumResources.CutePagerGoToLastClause;
  98. pgrTop.BackToPageClause = ForumResources.CutePagerBackToPageClause;
  99. pgrTop.NextToPageClause = ForumResources.CutePagerNextToPageClause;
  100. pgrTop.PageClause = ForumResources.CutePagerPageClause;
  101. pgrTop.OfClause = ForumResources.CutePagerOfClause;
  102. pgrBottom.NavigateToPageText = ForumResources.CutePagerNavigateToPageText;
  103. pgrBottom.BackToFirstClause = ForumResources.CutePagerBackToFirstClause;
  104. pgrBottom.GoToLastClause = ForumResources.CutePagerGoToLastClause;
  105. pgrBottom.BackToPageClause = ForumResources.CutePagerBackToPageClause;
  106. pgrBottom.NextToPageClause = ForumResources.CutePagerNextToPageClause;
  107. pgrBottom.PageClause = ForumResources.CutePagerPageClause;
  108. pgrBottom.OfClause = ForumResources.CutePagerOfClause;
  109. }
  110. private void LoadSettings()
  111. {
  112. timeOffset = SiteUtils.GetUserTimeOffset();
  113. if (forumUser != null) { userId = forumUser.UserId; }
  114. }
  115. protected override void OnInit(EventArgs e)
  116. {
  117. base.OnInit(e);
  118. Load += new EventHandler(Page_Load);
  119. }
  120. }
  121. }