SurveyModule.ascx.cs :  » Content-Management-Systems-CMS » mojoPortal » SurveyFeature » UI » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » mojoPortal 
mojoPortal » SurveyFeature » UI » SurveyModule.ascx.cs
/// Author:          Rob Henry
/// Created:        2007-08-24
/// Last Modified:      2009-01-19
/// 
/// The use and distribution terms for this software are covered by the 
/// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
/// which can be found in the file CPL.TXT at the root of this distribution.
/// By using this software in any fashion, you are agreeing to be bound by 
/// the terms of this license.
///
/// You must not remove this notice, or any other, from this software.

using System;
using System.Web;
using mojoPortal.Web;
using mojoPortal.Web.Framework;
using mojoPortal.Business;
using SurveyFeature.Business;

namespace SurveyFeature.UI{
    public partial class SurveyModule : SiteModuleControl
    {
        #region OnInit

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(Page_Load);
            this.btnStartSurvey.Click += new EventHandler(btnStartSurvey_Click);
        }
        #endregion

        private Guid surveyGuid = Guid.Empty;
        private Guid surveyPageGuid;
        private Guid surveyResponse = Guid.Empty;
        Survey survey;
        SurveyManager manager;

        #region public properties

        public Guid SurveyGuid
        {
            get
            {
                return surveyGuid;
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadParameters();
            manager = new SurveyManager(surveyGuid);
            surveyPageGuid = manager.GetSurveyFirstSurveyPageGuid(surveyGuid);
            survey = new Survey(surveyGuid);      
            PopulateLabels();
        }

        private void PopulateLabels()
        {
            TitleControl.EditUrl = SiteRoot + "/Survey/Surveys.aspx";
            TitleControl.EditText = Resources.SurveyResources.SurveyModuleEditText;
            TitleControl.Visible = !this.RenderInWebPartMode;
            if (this.ModuleConfiguration != null)
            {
                this.Title = this.ModuleConfiguration.ModuleTitle;
                this.Description = this.ModuleConfiguration.FeatureName;
            }

            if (surveyGuid == Guid.Empty)
            {
                litSurveyMessage.Text = Resources.SurveyResources.SurveyNoneSelected;
                btnStartSurvey.Visible = false;
            }
            else if(surveyResponse != Guid.Empty)
            {
                litSurveyMessage.Text = survey.EndPageText;
                btnStartSurvey.Visible = false;
                litOldResponses.Visible = false;
            }
            else if(SurveyHasNoPages())
            {
                litSurveyMessage.Text = Resources.SurveyResources.SurveyHasNoPagesWarning;
                btnStartSurvey.Visible = false;
            }
            else
            {
                litSurveyMessage.Text = survey.StartPageText;
                btnStartSurvey.Text = Resources.SurveyResources.SurveyStartText;

                if (PartialSurveyExists())
                {
                    litOldResponses.Text = Resources.SurveyResources.SurveyPartialAnswersExist;
                    chkUseOldResponses.Visible = true;
                }
            }
        }

        private void LoadParameters()
        {
            surveyGuid = Survey.GetModulesCurrentSurvey(ModuleId);
            surveyResponse = WebUtils.ParseGuidFromQueryString("SurveyEnd", Guid.Empty);
        }

        private bool PartialSurveyExists()
        {
            return (Request.Cookies["mojoSurvey"] != null && Request.Cookies["mojoSurvey"].Values[surveyGuid.ToString()] != null);
        }

        private bool SurveyHasNoPages()
        {
            return surveyPageGuid == Guid.Empty;
        }

        private Guid GetCurrentResponseGuid()
        {
            Guid responseGuid = Guid.Empty;

            if (Request.Cookies["mojoSurvey"] != null)
            {
                string stringGuid = Request.Cookies["mojoSurvey"].Values[survey.SurveyGuid.ToString()];

                if (stringGuid != null)
                {
                    try
                    {
                        responseGuid = new Guid(stringGuid);
                    }
                    catch (OverflowException)
                    {
                        //problem parsing guid from cookie - cookie may be corrupt so delete
                        Response.Cookies.Remove("mojoSurvey");
                    }
                    catch (FormatException)
                    {
                        //problem parsing guid from cookie - cookie may be corrupt so delete
                        Response.Cookies.Remove("mojoSurvey");
                    }
                }
            }

            return responseGuid;
        }

        private void SetCookie(Guid responseGuid)
        {
            if (Request.Cookies["mojoSurvey"] == null)
            {
                HttpCookie cookie = new HttpCookie("mojoSurvey");
                Response.Cookies.Add(cookie);
            }

            if (responseGuid == Guid.Empty)
            {
                Response.Cookies["mojoSurvey"].Values.Remove(surveyGuid.ToString());
            }
            else
            {
                Response.Cookies["mojoSurvey"].Values.Set(surveyGuid.ToString(), responseGuid.ToString());
            }
        }

        #region Events
        
        void btnStartSurvey_Click(object sender, EventArgs e)
        {
            Guid currentResponseGuid = GetCurrentResponseGuid();

            if (!chkUseOldResponses.Checked)
            {
                if (currentResponseGuid != Guid.Empty)
                {
                    SurveyResponse.Delete(currentResponseGuid);
                }

                SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

                SurveyResponse response = new SurveyResponse();
                response.Complete = false;
                response.SurveyGuid = survey.SurveyGuid;

                if (siteUser != null)
                    response.UserGuid = siteUser.UserGuid;
                response.Save();

                currentResponseGuid = response.ResponseGuid;
            }

            SetCookie(currentResponseGuid);

            WebUtils.SetupRedirect(this, SiteRoot + "/Survey/CompleteSurvey.aspx?SurveyGuid=" + surveyGuid.ToString() + "&pageid="
                + PageId.ToInvariantString() + "&mid=" + ModuleId.ToInvariantString() + "&SurveyPageGuid=" + surveyPageGuid.ToString());
        }
        
        #endregion

    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.