PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/WebStore.UI/WebStore/Controls/ProductListControl.ascx.cs

#
C# | 242 lines | 176 code | 53 blank | 13 comment | 25 complexity | 8c20dab6e3e78ad7e3a64f23da41eb15 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: 2008-10-19
  3. /// Last Modified: 2011-11-26
  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. using System;
  13. using System.Collections;
  14. using System.Data;
  15. using System.Globalization;
  16. using System.Web.UI;
  17. using System.Web.UI.WebControls;
  18. using mojoPortal.Business;
  19. using mojoPortal.Business.WebHelpers;
  20. using mojoPortal.Web;
  21. using mojoPortal.Web.Framework;
  22. using WebStore.Business;
  23. namespace WebStore.UI
  24. {
  25. //http://schema.org/Product
  26. //http://schema.org/Offer
  27. public partial class ProductListControl : UserControl
  28. {
  29. #region Private Properties
  30. private int pageId = -1;
  31. private int moduleId = -1;
  32. private int pageNumber = 1;
  33. private int totalPages = 1;
  34. private int pageSize = 10;
  35. private Store store = null;
  36. private string siteRoot = string.Empty;
  37. protected string teaserFileBaseUrl = string.Empty;
  38. private CultureInfo currencyCulture = CultureInfo.CurrentCulture;
  39. private DataSet dsProducts = null;
  40. private bool enableRatings = false;
  41. private bool enableRatingComments = false;
  42. private Hashtable settings = null;
  43. #endregion
  44. #region Public Properties
  45. public int PageId
  46. {
  47. get { return pageId; }
  48. set { pageId = value; }
  49. }
  50. public int ModuleId
  51. {
  52. get { return moduleId; }
  53. set { moduleId = value; }
  54. }
  55. public Store Store
  56. {
  57. get { return store; }
  58. set { store = value; }
  59. }
  60. public string SiteRoot
  61. {
  62. get { return siteRoot; }
  63. set { siteRoot = value; }
  64. }
  65. public CultureInfo CurrencyCulture
  66. {
  67. get { return currencyCulture; }
  68. set { currencyCulture = value; }
  69. }
  70. public bool EnableRatings
  71. {
  72. get { return enableRatings; }
  73. set { enableRatings = value; }
  74. }
  75. public bool EnableRatingComments
  76. {
  77. get { return enableRatingComments; }
  78. set { enableRatingComments = value; }
  79. }
  80. public Hashtable Settings
  81. {
  82. get { return settings; }
  83. set { settings = value; }
  84. }
  85. #endregion
  86. protected void Page_Load(object sender, EventArgs e)
  87. {
  88. if (!this.Visible) { return; }
  89. LoadSettings();
  90. if ((!Page.IsPostBack) && (ParamsAreValid()))
  91. {
  92. BindProducts();
  93. }
  94. }
  95. private void BindProducts()
  96. {
  97. dsProducts = store.GetProductPageWithOffers(
  98. pageNumber,
  99. pageSize,
  100. out totalPages);
  101. string pageUrl = SiteUtils.GetNavigationSiteRoot() + "/WebStore/ProductList.aspx"
  102. + "?pageid=" + pageId.ToInvariantString()
  103. + "&mid=" + moduleId.ToInvariantString()
  104. + "&pagenumber={0}";
  105. pgr.PageURLFormat = pageUrl;
  106. pgr.ShowFirstLast = true;
  107. pgr.CurrentIndex = pageNumber;
  108. pgr.PageSize = pageSize;
  109. pgr.PageCount = totalPages;
  110. pgr.Visible = (totalPages > 1);
  111. rptProducts.DataSource = dsProducts.Tables["Products"];
  112. rptProducts.DataBind();
  113. }
  114. void rptProducts_ItemDataBound(object sender, RepeaterItemEventArgs e)
  115. {
  116. if (dsProducts == null) { return; }
  117. if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  118. {
  119. string productGuid = ((DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString();
  120. Repeater rptOffers = (Repeater)e.Item.FindControl("rptOffers");
  121. if (rptOffers == null) { return; }
  122. string whereClause = string.Format("ProductGuid = '{0}'", productGuid);
  123. DataView dv = new DataView(dsProducts.Tables["ProductOffers"], whereClause, "", DataViewRowState.CurrentRows);
  124. rptOffers.DataSource = dv;
  125. rptOffers.DataBind();
  126. }
  127. }
  128. private void LoadSettings()
  129. {
  130. pageNumber = WebUtils.ParseInt32FromQueryString("pagenumber", pageNumber);
  131. if (Page is mojoBasePage)
  132. {
  133. mojoBasePage basePage = Page as mojoBasePage;
  134. if (displaySettings.UsejPlayerForMediaTeasers)
  135. {
  136. basePage.ScriptConfig.IncludejPlayer = true;
  137. basePage.ScriptConfig.IncludejPlayerPlaylist = true;
  138. }
  139. else
  140. {
  141. basePage.ScriptConfig.IncludeYahooMediaPlayer = true;
  142. }
  143. }
  144. SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
  145. if (siteSettings == null) { return; }
  146. teaserFileBaseUrl = WebUtils.GetSiteRoot() + "/Data/Sites/" + siteSettings.SiteId.ToString()
  147. + "/webstoreproductpreviewfiles/";
  148. if (Settings != null)
  149. {
  150. pageSize = WebUtils.ParseInt32FromHashtable(Settings, "ProductListPageSize", pageSize);
  151. }
  152. }
  153. protected string FormatProductUrl(string productGuid, string url)
  154. {
  155. if (WebConfigSettings.UseUrlReWriting)
  156. {
  157. return siteRoot + url;
  158. }
  159. return siteRoot + "/WebStore/ProductDetail.aspx?pageid="
  160. + pageId.ToInvariantString()
  161. + "&mid=" + moduleId.ToInvariantString()
  162. + "&product=" + productGuid;
  163. }
  164. protected string FormatOfferUrl(string offerGuid, string url)
  165. {
  166. if (WebConfigSettings.UseUrlReWriting)
  167. {
  168. return siteRoot + url;
  169. }
  170. return siteRoot + "/WebStore/OfferDetail.aspx?pageid="
  171. + pageId.ToInvariantString()
  172. + "&mid=" + moduleId.ToInvariantString()
  173. + "&offer=" + offerGuid;
  174. }
  175. private bool ParamsAreValid()
  176. {
  177. if (store == null) { return false; }
  178. if (pageId == -1) { return false; }
  179. if (moduleId == -1) { return false; }
  180. return true;
  181. }
  182. protected override void OnInit(EventArgs e)
  183. {
  184. base.OnInit(e);
  185. this.Load += new EventHandler(Page_Load);
  186. rptProducts.ItemDataBound += new RepeaterItemEventHandler(rptProducts_ItemDataBound);
  187. }
  188. }
  189. }