/projects/PigeonCms.Core/Modules/PigeonCms.Categories/CategoriesControl.cs

http://pigeoncms.googlecode.com/ · C# · 162 lines · 142 code · 20 blank · 0 comment · 7 complexity · 4e71b696bc497794dfd380a9f15746e5 MD5 · raw file

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Diagnostics;
  11. using System.ComponentModel;
  12. using System.IO;
  13. using System.Collections.Generic;
  14. using System.Threading;
  15. using PigeonCms;
  16. using System.Web.Routing;
  17. namespace PigeonCms
  18. {
  19. public class CategoriesControl: PigeonCms.BaseModuleControl
  20. {
  21. private PigeonCms.Menu menuTarget = null;
  22. #region public fields
  23. private int sectionId = 0;
  24. public int SectionId
  25. {
  26. get
  27. {
  28. return GetIntParam("SectionId", sectionId);
  29. }
  30. set { sectionId = value; }
  31. }
  32. private int itemsListTarget = 0;
  33. public int ItemsListTarget
  34. {
  35. get { return GetIntParam("ItemsListTarget", itemsListTarget); }
  36. set { itemsListTarget = value; }
  37. }
  38. private bool showImages = false;
  39. public bool ShowImages
  40. {
  41. get { return GetBoolParam("ShowImages", showImages); }
  42. set { showImages = value; }
  43. }
  44. private string previewSize = "s";
  45. public string PreviewSize
  46. {
  47. get { return GetStringParam("PreviewSize", previewSize); }
  48. set { previewSize = value; }
  49. }
  50. private int customWidth = 0;
  51. public int CustomWidth
  52. {
  53. get { return GetIntParam("CustomWidth", customWidth); }
  54. set { customWidth = value; }
  55. }
  56. private int customHeight = 0;
  57. public int CustomHeight
  58. {
  59. get { return GetIntParam("CustomHeight", customHeight); }
  60. set { customHeight = value; }
  61. }
  62. bool showDescription = false;
  63. public bool ShowDescription
  64. {
  65. get { return GetBoolParam("ShowDescription", showDescription); }
  66. set { showDescription = value; }
  67. }
  68. private int shortDescLen = 0;
  69. public int ShortDescLen
  70. {
  71. get { return GetIntParam("ShortDescLen", shortDescLen); }
  72. set { shortDescLen = value; }
  73. }
  74. private string headerText = "";
  75. public string HeaderText
  76. {
  77. get { return GetStringParam("HeaderText", headerText); }
  78. set { headerText = value; }
  79. }
  80. private string footerText = "";
  81. public string FooterText
  82. {
  83. get { return GetStringParam("FooterText", footerText); }
  84. set { footerText = value; }
  85. }
  86. public List<Category> CategoriesList
  87. {
  88. get
  89. {
  90. var res = new List<Category>();
  91. var filter = new CategoriesFilter();
  92. filter.Enabled = Utility.TristateBool.True;
  93. filter.SectionId = this.SectionId;
  94. res = new CategoriesManager().GetByFilter(filter, "");
  95. foreach (var item in res)
  96. {
  97. if (!this.ShowImages)
  98. item.Images.Clear();
  99. if (!this.ShowDescription)
  100. item.DescriptionTranslations.Clear();
  101. }
  102. return res;
  103. }
  104. }
  105. #endregion
  106. protected string GetLinkAddress(Category item)
  107. {
  108. string res = "javascript:void(0);";
  109. if (this.ItemsListTarget > 0)
  110. {
  111. if (menuTarget == null)
  112. {
  113. menuTarget = new MenuManager().GetByKey(this.ItemsListTarget);
  114. }
  115. try
  116. {
  117. if (menuTarget.RoutePattern.Contains("categoryname"))
  118. {
  119. string name = item.Alias;
  120. if (string.IsNullOrEmpty(name))
  121. item.TitleTranslations.TryGetValue(Config.CultureDefault, out name);
  122. res = Utility.GetRoutedUrl(
  123. menuTarget, new RouteValueDictionary { { "categoryname", name } }, "", true);
  124. }
  125. else
  126. {
  127. res = Utility.GetRoutedUrl(
  128. menuTarget, new RouteValueDictionary { { "categoryid", item.Id } }, "", true);
  129. }
  130. }
  131. catch (Exception ex)
  132. {
  133. Tracer.Log("GetLinkAddress(): " + ex.ToString(), TracerItemType.Error);
  134. }
  135. }
  136. return res;
  137. }
  138. protected void Page_Load(object sender, EventArgs e)
  139. {
  140. }
  141. }
  142. }