PageRenderTime 195ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/CMSModules/EventManager/Controls/EventList.ascx.cs

https://bitbucket.org/kudutest2/kenticogit
C# | 379 lines | 277 code | 62 blank | 40 comment | 31 complexity | 9421f82325557ba29cf8dc5664142235 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using CMS.UIControls;
  9. using CMS.GlobalHelper;
  10. using CMS.SettingsProvider;
  11. using CMS.SiteProvider;
  12. using CMS.CMSHelper;
  13. using CMS.ExtendedControls;
  14. using CMS.TreeEngine;
  15. using TimeZoneInfo = CMS.SiteProvider.TimeZoneInfo;
  16. public partial class CMSModules_EventManager_Controls_EventList : CMSAdminControl
  17. {
  18. #region "Private variables"
  19. private UserInfo currentUserInfo = null;
  20. private SiteInfo currentSiteInfo = null;
  21. private bool mUsePostBack = false;
  22. private int mSelectedEventID = 0;
  23. private string mOrderBy = "EventDate DESC";
  24. private string mItemsPerPage = String.Empty;
  25. private string mEventScope = "all";
  26. private string mSiteName = String.Empty;
  27. #endregion
  28. #region "Properties"
  29. /// <summary>
  30. /// Indicates whether change location or postback if edit.
  31. /// </summary>
  32. public bool UsePostBack
  33. {
  34. get
  35. {
  36. return mUsePostBack;
  37. }
  38. set
  39. {
  40. mUsePostBack = value;
  41. }
  42. }
  43. /// <summary>
  44. /// Site name filter.
  45. /// </summary>
  46. public string SiteName
  47. {
  48. get
  49. {
  50. return mSiteName;
  51. }
  52. set
  53. {
  54. mSiteName = value;
  55. }
  56. }
  57. /// <summary>
  58. /// ID of selected event.
  59. /// </summary>
  60. public int SelectedEventID
  61. {
  62. get
  63. {
  64. return mSelectedEventID;
  65. }
  66. set
  67. {
  68. mSelectedEventID = value;
  69. }
  70. }
  71. /// <summary>
  72. /// Gets or sets the order by condition.
  73. /// </summary>
  74. public string OrderBy
  75. {
  76. get
  77. {
  78. return mOrderBy;
  79. }
  80. set
  81. {
  82. mOrderBy = value;
  83. }
  84. }
  85. /// <summary>
  86. /// Gets or sets the value of items per page.
  87. /// </summary>
  88. public string ItemsPerPage
  89. {
  90. get
  91. {
  92. return mItemsPerPage;
  93. }
  94. set
  95. {
  96. mItemsPerPage = value;
  97. }
  98. }
  99. /// <summary>
  100. /// Gets or sets event date filter.
  101. /// </summary>
  102. public string EventScope
  103. {
  104. get
  105. {
  106. return mEventScope;
  107. }
  108. set
  109. {
  110. mEventScope = value;
  111. }
  112. }
  113. /// <summary>
  114. /// Stop processing.
  115. /// </summary>
  116. public override bool StopProcessing
  117. {
  118. get
  119. {
  120. return base.StopProcessing;
  121. }
  122. set
  123. {
  124. base.StopProcessing = value;
  125. gridElem.StopProcessing = value;
  126. }
  127. }
  128. #endregion
  129. #region "Page events"
  130. protected void Page_Load(object sender, EventArgs e)
  131. {
  132. if (!URLHelper.IsPostback())
  133. {
  134. this.drpEventScope.Items.Add(new ListItem(GetString("general.selectall"), "all"));
  135. this.drpEventScope.Items.Add(new ListItem(GetString("eventmanager.eventscopeupcoming"), "upcoming"));
  136. this.drpEventScope.SelectedValue = QueryHelper.GetString("scope", "all");
  137. }
  138. this.EventScope = drpEventScope.SelectedValue;
  139. this.btnFilter.Text = GetString("general.show");
  140. gridElem.HideControlForZeroRows = false;
  141. gridElem.ZeroRowsText = GetString("Events_List.NoBookingEvent");
  142. gridElem.OnAction += new OnActionEventHandler(gridElem_OnAction);
  143. if ((!RequestHelper.IsPostBack()) && (!string.IsNullOrEmpty(ItemsPerPage)))
  144. {
  145. gridElem.Pager.DefaultPageSize = ValidationHelper.GetInteger(ItemsPerPage, -1);
  146. }
  147. gridElem.OrderBy = OrderBy;
  148. gridElem.OnExternalDataBound += new OnExternalDataBoundEventHandler(gridElem_OnExternalDataBound);
  149. if (UsePostBack)
  150. {
  151. gridElem.GridName = "~/CMSModules/EventManager/Controls/Events_List_Control.xml";
  152. }
  153. else
  154. {
  155. gridElem.GridName = "~/CMSModules/EventManager/Controls/Events_List.xml";
  156. }
  157. SetWhereCondition();
  158. ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "editEventScript", ScriptHelper.GetScript("function EditEvent(eventId) { location.replace('Events_Edit.aspx?eventId=' + eventId); }"));
  159. }
  160. #endregion
  161. #region "Methods"
  162. /// <summary>
  163. /// Reloads data.
  164. /// </summary>
  165. public override void ReloadData()
  166. {
  167. SetWhereCondition();
  168. gridElem.ReloadData();
  169. base.ReloadData();
  170. }
  171. private void SetWhereCondition()
  172. {
  173. // Check existence of CMS.BookingEvent dataclass
  174. if (DataClassInfoProvider.GetDataClass("CMS.BookingEvent") != null)
  175. {
  176. // Filter site name
  177. string siteName = SiteName;
  178. if (siteName == String.Empty)
  179. {
  180. siteName = CMSContext.CurrentSiteName;
  181. }
  182. // If not show all
  183. if (siteName != TreeProvider.ALL_SITES)
  184. {
  185. gridElem.WhereCondition = "(NodeLinkedNodeID IS NULL AND SiteName LIKE '" + siteName + "')";
  186. }
  187. else
  188. {
  189. gridElem.WhereCondition = "NodeLinkedNodeID IS NULL";
  190. }
  191. // Filter time interval
  192. if (EventScope != "all")
  193. {
  194. if (EventScope == "upcoming")
  195. {
  196. gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, "EventDate >= @Date");
  197. }
  198. else
  199. {
  200. gridElem.WhereCondition = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, "EventDate <= @Date");
  201. }
  202. QueryDataParameters parameters = new QueryDataParameters();
  203. parameters.Add("@Date", DateTime.Now);
  204. gridElem.QueryParameters = parameters;
  205. }
  206. }
  207. else
  208. {
  209. // Document type with code name 'CMS.BookingEvent' does not exist
  210. lblError.Visible = true;
  211. lblError.Text = GetString("Events_List.NoBookingEventClass");
  212. }
  213. }
  214. #endregion
  215. #region "Grid events"
  216. /// <summary>
  217. /// Manage if user edit event.
  218. /// </summary>
  219. /// <param name="actionName">Edit</param>
  220. /// <param name="actionArgument">Id of event</param>
  221. protected void gridElem_OnAction(string actionName, object actionArgument)
  222. {
  223. switch (actionName.ToLower())
  224. {
  225. case "view":
  226. SelectedEventID = Convert.ToInt32(actionArgument);
  227. break;
  228. }
  229. }
  230. /// <summary>
  231. /// Handles data bound event.
  232. /// </summary>
  233. protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
  234. {
  235. string result = string.Empty;
  236. DataRowView data = null;
  237. switch (sourceName.ToLower())
  238. {
  239. // Create link to event document
  240. case "documentname":
  241. {
  242. data = (DataRowView)parameter;
  243. string siteName = ValidationHelper.GetString(data["SiteName"], String.Empty);
  244. string documentName = ValidationHelper.GetString(data["DocumentName"], String.Empty);
  245. string culture = ValidationHelper.GetString(data["DocumentCulture"], String.Empty);
  246. int nodeID = ValidationHelper.GetInteger(data["NodeID"], 0);
  247. SiteInfo si = SiteInfoProvider.GetSiteInfo(siteName);
  248. if (si != null)
  249. {
  250. // Get current app path
  251. string appPath = URLHelper.ApplicationPath.TrimEnd('/');
  252. string domain = si.DomainName;
  253. // If domain contains app path donnt add it
  254. if (domain.Contains("/"))
  255. {
  256. appPath = null;
  257. }
  258. string path = URLHelper.ResolveUrl("~/CMSDesk/default.aspx?section=content&action=edit&nodeid=" + nodeID + "&culture=" + culture);
  259. return "<a target=\"_top\" href=\'" + path + "'\" >" + HTMLHelper.HTMLEncode(documentName) + "</a>";
  260. }
  261. }
  262. return HTMLHelper.HTMLEncode(parameter.ToString());
  263. case "eventtooltip":
  264. data = (DataRowView)parameter;
  265. return UniGridFunctions.DocumentNameTooltip(data);
  266. case "eventdate":
  267. case "eventopenfrom":
  268. case "eventopento":
  269. case "eventdatetooltip":
  270. case "eventopenfromtooltip":
  271. case "eventopentotooltip":
  272. if (!String.IsNullOrEmpty(parameter.ToString()))
  273. {
  274. if (currentUserInfo == null)
  275. {
  276. currentUserInfo = CMSContext.CurrentUser;
  277. }
  278. if (currentSiteInfo == null)
  279. {
  280. currentSiteInfo = CMSContext.CurrentSite;
  281. }
  282. bool displayGMT = sourceName.EndsWith("tooltip");
  283. DateTime time = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME);
  284. return TimeZoneHelper.ConvertToUserTimeZone(time, displayGMT, currentUserInfo, currentSiteInfo);
  285. }
  286. return result;
  287. case "eventenddate":
  288. case "eventenddatetooltip":
  289. data = (DataRowView)parameter;
  290. try
  291. {
  292. parameter = data["eventenddate"];
  293. }
  294. catch
  295. {
  296. parameter = null;
  297. }
  298. if ((parameter != null) && !String.IsNullOrEmpty(parameter.ToString()))
  299. {
  300. if (currentUserInfo == null)
  301. {
  302. currentUserInfo = CMSContext.CurrentUser;
  303. }
  304. if (currentSiteInfo == null)
  305. {
  306. currentSiteInfo = CMSContext.CurrentSite;
  307. }
  308. bool displayGMT = sourceName.EndsWith("tooltip");
  309. DateTime time = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME);
  310. return TimeZoneHelper.ConvertToUserTimeZone(time, displayGMT, currentUserInfo, currentSiteInfo);
  311. }
  312. return result;
  313. }
  314. return parameter;
  315. }
  316. #endregion
  317. }