PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/mojoPortal.Features.UI/Survey/Results.aspx.cs

#
C# | 259 lines | 177 code | 56 blank | 26 comment | 26 complexity | 93cc10d24217f4b8c39e99e895868a68 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: Rob Henry
  2. /// Created: 2007-10-18
  3. /// Last Modified: 2009-12-17
  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.Generic;
  14. using System.Globalization;
  15. using System.Web.UI;
  16. using mojoPortal.Web;
  17. using mojoPortal.Web.Framework;
  18. using mojoPortal.Business;
  19. using SurveyFeature.Business;
  20. using Resources;
  21. namespace SurveyFeature.UI
  22. {
  23. public partial class ResultsPage : NonCmsBasePage
  24. {
  25. private int pageId = -1;
  26. private int moduleId = -1;
  27. private Guid surveyGuid = Guid.Empty;
  28. private Guid responseGuid = Guid.Empty;
  29. private Survey survey = null;
  30. private SurveyResponse currentResponse;
  31. private SurveyResponse previousResponse;
  32. private SurveyResponse nextResponse;
  33. protected string DeleteLinkImage = "~/Data/SiteImages/" + WebConfigSettings.DeleteLinkImage;
  34. #region protected properties
  35. protected int PageId
  36. {
  37. get { return pageId; }
  38. }
  39. protected int ModuleId
  40. {
  41. get { return moduleId;}
  42. }
  43. #endregion
  44. protected void Page_Load(object sender, EventArgs e)
  45. {
  46. if (!Request.IsAuthenticated)
  47. {
  48. SiteUtils.RedirectToLoginPage(this);
  49. return;
  50. }
  51. SecurityHelper.DisableBrowserCache();
  52. LoadSettings();
  53. if (!UserCanEditModule(moduleId))
  54. {
  55. SiteUtils.RedirectToEditAccessDeniedPage();
  56. }
  57. PopulateLabels();
  58. PopulateControls();
  59. }
  60. private void PopulateControls()
  61. {
  62. if (survey == null) return;
  63. lnkResults.Text = string.Format(CultureInfo.InvariantCulture,
  64. SurveyResources.SurveyResultsFormatString,
  65. survey.SurveyName);
  66. heading.Text = lnkResults.Text;
  67. if (previousResponse != null)
  68. {
  69. lnkPreviousResponse.Visible = true;
  70. lnkPreviousResponse.NavigateUrl = SiteRoot + "/Survey/Results.aspx?SurveyGuid=" + surveyGuid +
  71. "&ResponseGuid=" + previousResponse.ResponseGuid.ToString() + "&pageid=" + pageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString();
  72. }
  73. else
  74. {
  75. lnkPreviousResponse.Visible = false;
  76. }
  77. if (nextResponse != null)
  78. {
  79. lnkNextResponse.Visible = true;
  80. lnkNextResponse.NavigateUrl = SiteRoot + "/Survey/Results.aspx?SurveyGuid=" + surveyGuid +
  81. "&ResponseGuid=" + nextResponse.ResponseGuid.ToString() + "&pageid=" + pageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString();
  82. }
  83. else
  84. {
  85. lnkNextResponse.Visible = false;
  86. }
  87. if (currentResponse == null) return;
  88. lblCompletionDate.Text = currentResponse.SubmissionDate.ToString();
  89. if (currentResponse.UserGuid != Guid.Empty)
  90. {
  91. SiteUser respondent = new SiteUser(siteSettings, currentResponse.UserGuid);
  92. if(respondent != null)
  93. lblRespondent.Text = respondent.LoginName;
  94. }
  95. BindGrid();
  96. }
  97. private void PopulateLabels()
  98. {
  99. Title = SiteUtils.FormatPageTitle(siteSettings, CurrentPage.PageName);
  100. lblRespondent.Text = Resources.SurveyResources.SurveyRespondentAnonymousText;
  101. lnkPageCrumb.Text = CurrentPage.PageName;
  102. lnkPageCrumb.NavigateUrl = SiteUtils.GetCurrentPageUrl();
  103. lnkSurveys.Text = SurveyResources.SurveyBreadCrumbText;
  104. lnkSurveys.NavigateUrl = SiteRoot + "/Survey/Surveys.aspx?pageid="
  105. + pageId.ToInvariantString()
  106. + "&mid=" + moduleId.ToInvariantString();
  107. lnkResults.Text = SurveyResources.SurveyResultsBreadCrumbText;
  108. lnkResults.NavigateUrl = SiteRoot + "/Survey/Results.aspx?SurveyGuid=" + surveyGuid.ToString()
  109. + "&pageid=" + pageId.ToInvariantString()
  110. + "&mid=" + moduleId.ToInvariantString();
  111. lnkNextResponse.Text = Resources.SurveyResources.ResponseGetNext;
  112. lnkNextResponse.ToolTip = Resources.SurveyResources.ResponseGetNextToolTip;
  113. lnkPreviousResponse.Text = Resources.SurveyResources.ResponseGetPrevious;
  114. lnkPreviousResponse.ToolTip = Resources.SurveyResources.ResponseGetPreviousToolTip;
  115. grdResults.Columns[0].HeaderText = SurveyResources.ResultsGridQuestionHeader;
  116. grdResults.Columns[1].HeaderText = SurveyResources.ResultsGridAnswerHeader;
  117. grdResults.Columns[2].HeaderText = SurveyResources.ResultsGridPageTitleHeader;
  118. btnDelete.ImageUrl = DeleteLinkImage;
  119. }
  120. private void LoadSettings()
  121. {
  122. surveyGuid = WebUtils.ParseGuidFromQueryString("SurveyGuid", Guid.Empty);
  123. pageId = WebUtils.ParseInt32FromQueryString("pageid", -1);
  124. moduleId = WebUtils.ParseInt32FromQueryString("mid", -1);
  125. responseGuid = WebUtils.ParseGuidFromQueryString("ResponseGuid", Guid.Empty);
  126. if (surveyGuid == Guid.Empty) return;
  127. if (responseGuid == Guid.Empty)
  128. {
  129. SurveyResponse response = SurveyResponse.GetFirst(surveyGuid);
  130. if (response == null)
  131. {
  132. WebUtils.SetupRedirect(this, SiteRoot + "/Survey/Surveys.aspx?pageid=" + pageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString());
  133. }
  134. else
  135. {
  136. WebUtils.SetupRedirect(this, SiteRoot + "/Survey/Results.aspx?SurveyGuid=" + surveyGuid.ToString() +
  137. "&ResponseGuid=" + response.ResponseGuid.ToString() + "&pageid=" + pageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString());
  138. }
  139. }
  140. else
  141. {
  142. currentResponse = new SurveyResponse(responseGuid);
  143. previousResponse = SurveyResponse.GetPrevious(responseGuid);
  144. nextResponse = SurveyResponse.GetNext(responseGuid);
  145. }
  146. if (surveyGuid != Guid.Empty)
  147. {
  148. survey = new Survey(surveyGuid);
  149. if (survey.SiteGuid != siteSettings.SiteGuid)
  150. {
  151. surveyGuid = Guid.Empty;
  152. survey = null;
  153. responseGuid = Guid.Empty;
  154. currentResponse = null;
  155. previousResponse = null;
  156. nextResponse = null;
  157. }
  158. }
  159. AddClassToBody("surveyresults");
  160. }
  161. private void BindGrid()
  162. {
  163. if (currentResponse == null) return;
  164. List<Result> results;
  165. results = Survey.GetResults(currentResponse.ResponseGuid);
  166. grdResults.DataSource = results;
  167. grdResults.DataBind();
  168. }
  169. #region Events
  170. void btnDelete_Click(object sender, ImageClickEventArgs e)
  171. {
  172. SurveyResponse.Delete(responseGuid);
  173. WebUtils.SetupRedirect(this, SiteRoot + "/Survey/Results.aspx?SurveyGuid=" + surveyGuid.ToString()
  174. + "&pageid=" + pageId.ToInvariantString()
  175. + "&mid=" + moduleId.ToInvariantString());
  176. //if (nextResponse != null)
  177. //{
  178. // WebUtils.SetupRedirect(this, SiteRoot + "/Survey/Results.aspx?SurveyGuid=" + surveyGuid +
  179. // "&ResponseGuid=" + nextResponse.ResponseGuid + "&PageId=" + pageId + "&mid=" + moduleId);
  180. //}
  181. //else if (previousResponse != null)
  182. //{
  183. // WebUtils.SetupRedirect(this, SiteRoot + "/Survey/Results.aspx?SurveyGuid=" + surveyGuid +
  184. // "&ResponseGuid=" + previousResponse.ResponseGuid + "&PageId=" + pageId + "&mid=" + moduleId);
  185. //}
  186. //else
  187. //{
  188. // //no more responses left so direct to the Surveys page
  189. // WebUtils.SetupRedirect(this, SiteRoot + "/Survey/Surveys.aspx?PageId=" + pageId + "&mid=" + moduleId);
  190. //}
  191. }
  192. #endregion
  193. #region OnInit
  194. override protected void OnInit(EventArgs e)
  195. {
  196. base.OnInit(e);
  197. this.Load += new EventHandler(this.Page_Load);
  198. this.btnDelete.Click += new ImageClickEventHandler(btnDelete_Click);
  199. SuppressPageMenu();
  200. }
  201. #endregion
  202. }
  203. }