/projects/PigeonCms.Core/Modules/PigeonCms.Photogallery/PhotogalleryControl.cs

http://pigeoncms.googlecode.com/ · C# · 249 lines · 211 code · 33 blank · 5 comment · 10 complexity · 2c681cbe6f992af64d35d5a61ac51f18 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. namespace PigeonCms
  17. {
  18. public class PhotogalleryControl: PigeonCms.BaseModuleControl
  19. {
  20. #region private fields
  21. private PhotogalleryControl.SourceTypeEnum sourceType = SourceTypeEnum.FolderSource;
  22. private bool showChildList = false;
  23. private string basePath = "";
  24. private string folderName = "";
  25. private int sectionId = 0;
  26. private int categoryId = 0;
  27. private int itemId = 0;
  28. private string layoutCssFile = "";
  29. private string headerText = "";
  30. private string footerText = "";
  31. private string errorText = "";
  32. List<FileMetaInfo> imagesList = new List<FileMetaInfo>();
  33. #endregion
  34. public struct LinksList
  35. {
  36. public int Id;
  37. public string Title;
  38. public LinksList(int id, string title)
  39. {
  40. this.Id = id;
  41. this.Title = title;
  42. }
  43. }
  44. public enum SourceTypeEnum
  45. {
  46. FolderSource = 0,
  47. SectionSource = 1,
  48. CategorySource = 2,
  49. ItemSource = 3
  50. }
  51. #region public fields
  52. public PhotogalleryControl.SourceTypeEnum SourceType
  53. {
  54. get
  55. {
  56. int res = 0;
  57. res = GetIntParam("SourceType", res);
  58. return (SourceTypeEnum)res;
  59. }
  60. set { sourceType = value; }
  61. }
  62. public bool StaticFilesTracking
  63. {
  64. get
  65. {
  66. int staticFilesTracking = (int)Utility.TristateBool.NotSet;
  67. bool res = false;
  68. staticFilesTracking = GetIntParam("StaticFilesTracking", staticFilesTracking);
  69. if ((Utility.TristateBool)staticFilesTracking == Utility.TristateBool.True)
  70. res = true;
  71. else if ((Utility.TristateBool)staticFilesTracking == Utility.TristateBool.NotSet)
  72. {
  73. bool.TryParse(AppSettingsManager.GetValue("StaticFilesTracking"), out res);
  74. }
  75. return res;
  76. }
  77. }
  78. public bool ShowChildList
  79. {
  80. get { return GetBoolParam("ShowChildList", showChildList); }
  81. set { showChildList = value; }
  82. }
  83. /// <summary>
  84. /// folder taht contains images
  85. /// </summary>
  86. public string BasePath
  87. {
  88. get { return GetStringParam("BasePath", basePath); }
  89. set { basePath = value; }
  90. }
  91. public string FolderName
  92. {
  93. get { return GetStringParam("FolderName", folderName); }
  94. set { folderName = value; }
  95. }
  96. public int SectionId
  97. {
  98. get { return GetIntParam("SectionId", sectionId); }
  99. set { sectionId = value; }
  100. }
  101. public int CategoryId
  102. {
  103. get { return GetIntParam("CategoryId", categoryId); }
  104. set { categoryId = value; }
  105. }
  106. public int ItemId
  107. {
  108. get { return GetIntParam("ItemId", itemId); }
  109. set { itemId = value; }
  110. }
  111. public string HeaderText
  112. {
  113. get { return GetStringParam("HeaderText", headerText); }
  114. set { headerText = value; }
  115. }
  116. public string FooterText
  117. {
  118. get { return GetStringParam("FooterText", footerText); }
  119. set { footerText = value; }
  120. }
  121. public string ErrorText
  122. {
  123. get { return GetStringParam("ErrorText", errorText); }
  124. set { errorText = value; }
  125. }
  126. public List<FileMetaInfo> ImagesList
  127. {
  128. get
  129. {
  130. switch (this.SourceType)
  131. {
  132. case SourceTypeEnum.FolderSource:
  133. imagesList = new Photogallery(this.BasePath, this.FolderName).GetAll();
  134. break;
  135. case SourceTypeEnum.SectionSource:
  136. if (this.ShowChildList)
  137. imagesList = new Photogallery("", "categories/" + this.CategoryId).GetAll();
  138. else
  139. imagesList = new Photogallery("", "sections/"+ this.SectionId).GetAll();
  140. break;
  141. case SourceTypeEnum.CategorySource:
  142. if (this.ShowChildList)
  143. imagesList = new Photogallery("", "items/" + this.ItemId).GetAll();
  144. else
  145. imagesList = new Photogallery("", "categories/" + this.CategoryId).GetAll();
  146. break;
  147. case SourceTypeEnum.ItemSource:
  148. imagesList = new Photogallery("", "items/" + this.ItemId).GetAll();
  149. break;
  150. default:
  151. break;
  152. }
  153. return imagesList;
  154. }
  155. }
  156. public List<LinksList> ChildList
  157. {
  158. get
  159. {
  160. List<LinksList> res = new List<LinksList>();
  161. if (this.ShowChildList)
  162. {
  163. switch (this.SourceType)
  164. {
  165. case SourceTypeEnum.FolderSource:
  166. break;
  167. case SourceTypeEnum.SectionSource:
  168. res = getCategoriesList();
  169. break;
  170. case SourceTypeEnum.CategorySource:
  171. res = getItemsList();
  172. break;
  173. case SourceTypeEnum.ItemSource:
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179. return res;
  180. }
  181. }
  182. #endregion
  183. protected void Page_Load(object sender, EventArgs e)
  184. { }
  185. private List<LinksList> getCategoriesList()
  186. {
  187. List<LinksList> res = new List<LinksList>();
  188. List<Category>list = new List<Category>();
  189. CategoriesFilter filter = new CategoriesFilter();
  190. filter.Enabled = Utility.TristateBool.True;
  191. filter.SectionId = this.SectionId;
  192. list = new CategoriesManager().GetByFilter(filter, "");
  193. foreach (Category item in list)
  194. {
  195. res.Add(new LinksList(item.Id, item.Title));
  196. //res.Add(item.Title);
  197. }
  198. return res;
  199. }
  200. private List<LinksList> getItemsList()
  201. {
  202. List<LinksList> res = new List<LinksList>();
  203. List<Item> list = new List<Item>();
  204. ItemsFilter filter = new ItemsFilter();
  205. filter.Enabled = Utility.TristateBool.True;
  206. filter.CategoryId = this.CategoryId;
  207. list = new ItemsManager<Item,ItemsFilter>().GetByFilter(filter, "");
  208. foreach (Item item in list)
  209. {
  210. res.Add(new LinksList(item.Id, item.Title));
  211. //res.Add(item.Title);
  212. }
  213. return res;
  214. }
  215. }
  216. }