SurveyPages.aspx.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 » SurveyPages.aspx.cs
/// Author:          Rob Henry
/// Created:        2007-09-25
/// Last Modified:      2009-12-17
/// 
/// 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.Configuration;
using System.Collections.Generic;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
using mojoPortal.Web;
using mojoPortal.Web.Framework;
using SurveyFeature.Business;
using Resources;

namespace SurveyFeature.UI{
    public partial class SurveyPagesPage : mojoBasePage
    {

        private Guid surveyGuid = Guid.Empty;
        private Survey survey = null;
        private string editContentImage = WebConfigSettings.EditContentImage;
        protected string DeleteLinkImage = "~/Data/SiteImages/" + WebConfigSettings.DeleteLinkImage;
        private int pageId;
        private int moduleId;
        private mojoPortal.Business.Module currentModule = null;

        #region protected properties

        protected int PageId
        {
            get { return pageId; }
        }

        protected int ModuleId
        {
            get { return moduleId; }
        }

        protected string EditContentImage
        {
            get { return editContentImage; }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                SiteUtils.RedirectToLoginPage(this);
                return;
            }

            SecurityHelper.DisableBrowserCache();

            LoadSettings();

            if (!UserCanEditModule(moduleId))
            {
                SiteUtils.RedirectToEditAccessDeniedPage();
            }

            PopulateLabels();
            PopulateControls();

            
        }

        private void PopulateControls()
        {

            if (survey == null) return;

            lnkPages.Text = string.Format(CultureInfo.InvariantCulture,
                SurveyResources.SurveyPagesLabelFormatString,
                survey.SurveyName);

            Title = SiteUtils.FormatPageTitle(siteSettings, lnkPages.Text);

            litHeading.Text = lnkPages.Text;

            if (currentModule != null)
            {

                lnkSurveys.Text = string.Format(CultureInfo.InvariantCulture,
                    SurveyResources.ChooseActiveSurveyFormatString,
                    currentModule.ModuleTitle);
            }



            if (Page.IsPostBack) return;
            

            BindGrid();
               
        }

        private void PopulateLabels()
        {
            lnkPageCrumb.Text = CurrentPage.PageName;
            lnkPageCrumb.NavigateUrl = SiteUtils.GetCurrentPageUrl();

            lnkSurveys.Text = SurveyResources.ChooseActiveSurveyLink;
            lnkSurveys.NavigateUrl = SiteRoot + "/Survey/Surveys.aspx?pageid="
                + pageId.ToInvariantString() + "&mid="
                + ModuleId.ToInvariantString();


            lnkPages.Text = SurveyResources.SurveyPagesBreadCrumbText;
            lnkPages.NavigateUrl = Request.RawUrl;

            lnkAddNew.Text = Resources.SurveyResources.PageAddButton;
            //lnkAddNew.ToolTip = Resources.SurveyResources.PageAddButtonToolTip;

            
            lnkAddNew.NavigateUrl = SiteRoot + "/Survey/SurveyPageEdit.aspx?SurveyGuid=" + surveyGuid.ToString() 
                + "&pageid=" + pageId.ToInvariantString()
                + "&mid=" + ModuleId.ToInvariantString();

            grdSurveyPages.Columns[0].HeaderText = SurveyResources.PagesGridEditDeleteHeader;
            grdSurveyPages.Columns[1].HeaderText = SurveyResources.PagesGridPageTitleHeader;
            grdSurveyPages.Columns[2].HeaderText = SurveyResources.PagesGridPageEnabledHeader;
            grdSurveyPages.Columns[3].HeaderText = SurveyResources.PagesGridQuestionCountHeader;
            grdSurveyPages.Columns[4].HeaderText = SurveyResources.PagesGridMoveUpOrDownHeader;
            

        }

        private void LoadSettings()
        {
            surveyGuid = WebUtils.ParseGuidFromQueryString("SurveyGuid", Guid.Empty);
            pageId = WebUtils.ParseInt32FromQueryString("pageid", -1);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", true, -1);

            if (CurrentPage.ContainsModule(moduleId))
            {
                currentModule = new mojoPortal.Business.Module(moduleId);
                
            }

            if(surveyGuid != Guid.Empty)
            {
                survey = new Survey(surveyGuid);
                if(survey.SiteGuid != siteSettings.SiteGuid)
                {
                    surveyGuid = Guid.Empty;
                    survey = null;
                }
            }

        }

        //private void SetupBreadCrumb()
        //{
        //    lnkSurveys.NavigateUrl = "~/Survey/Surveys.aspx?PageId=" + pageId + "&mid=" + ModuleId ;
        //}

        private void BindGrid()
        {
            List<SurveyFeature.Business.Page> pages = SurveyFeature.Business.Page.GetAll(surveyGuid);
            grdSurveyPages.DataSource = pages;
            grdSurveyPages.DataBind();

            //hide the grid and display a message if no questions have been added.

            if (pages.Count == 0)
            {
                grdSurveyPages.Visible = false;
                lblMessages.Text = Resources.SurveyResources.SurveyHasNoPagesWarning;
            }
            else
            {
                grdSurveyPages.Visible = true;
            }

        }

        public Guid SurveyGuid
        {
            get { return surveyGuid; }
        }

        #region Events

        void grdSurveyPages_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer)
            {
                GridViewRow row = e.Row;
                ImageButton deleteButton = (ImageButton)row.FindControl("btnDelete");
                UIHelper.AddConfirmationDialog(deleteButton, Resources.SurveyResources.PageDeleteDeletesAllQuestionsWarning);

                
            }
            

        }

        void grdSurveyPages_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            

        }

        

        void grdSurveyPages_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            List<SurveyFeature.Business.Page> pages = SurveyFeature.Business.Page.GetAll(surveyGuid);
            Guid currentPageGuid = new Guid(e.CommandArgument.ToString());

            SurveyFeature.Business.Page currentPage = null;

            SurveyFeature.Business.Page swapPage;

            int currentItemIndex = -1;
            int i = 0;

            foreach (SurveyFeature.Business.Page p in pages)
            {
                if (p.SurveyPageGuid == currentPageGuid)
                {
                    currentPage = p;
                    currentItemIndex = i;
                }

                i += 1;
                    

            }

            if(currentPage == null)return;
           
            switch (e.CommandName)
            {
                case "up":

                    if (currentItemIndex > 0)
                    {
                        
                        swapPage = pages[currentItemIndex - 1];

                        currentPage.PageOrder = currentItemIndex - 1;
                        swapPage.PageOrder = currentItemIndex;

                        currentPage.Save();
                        swapPage.Save();
                    }

                    break;

                case "down":

                    if (currentItemIndex < pages.Count - 1)
                    {
                     
                        swapPage = pages[currentItemIndex + 1];

                        currentPage.PageOrder = currentItemIndex + 1;
                        swapPage.PageOrder = currentItemIndex;

                        currentPage.Save();
                        swapPage.Save();
                    }

                    break;
                case "delete":
                    //ImageButton button = (ImageButton)e.CommandSource;
                    SurveyFeature.Business.Page.Delete(currentPageGuid);
                    break;
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);
            //BindGrid();

        }
        
        //protected void RptPages_ItemDataBound(object sender, RepeaterItemEventArgs e)
        //{
        //    if (e == null)
        //    {
        //        throw new ArgumentNullException("e");
        //    }

        //    if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
        //    {
        //        RepeaterItem item = e.Item;
        //        ImageButton deleteButton = (ImageButton)item.FindControl("btnDelete");
        //        UIHelper.AddConfirmationDialog(deleteButton, Resources.SurveyResources.PageDeleteDeletesAllQuestionsWarning);

        //        // Not good to make a db hit for each row here - JA
        //        //HyperLink link = (HyperLink)item.FindControl("questionsLink");
        //        //link.Text = SurveyFeature.Business.Page.QuestionCount(new Guid(deleteButton.CommandArgument)).ToString(CultureInfo.CurrentCulture);
            
        //    }
        //}

        //protected void RptPages_ItemCommand(object sender, RepeaterCommandEventArgs e)
        //{
        //    if (e == null)
        //    {
        //        throw new ArgumentNullException("e");
        //    }

        //    //deal with up, down or delete statements
        //    int currentItemIndex = e.Item.ItemIndex;

        //    switch (e.CommandName)
        //    {
        //        case "up":

        //            if (currentItemIndex > 0)
        //            {
        //                SurveyFeature.Business.Page currentPage = new SurveyFeature.Business.Page(new Guid(e.CommandArgument.ToString()));

        //                RepeaterItem aboveRowItem = rptPages.Items[currentItemIndex - 1];
        //                ImageButton upImageButton = (ImageButton)aboveRowItem.FindControl("btnUp");
        //                SurveyFeature.Business.Page swapPage = new SurveyFeature.Business.Page(new Guid(upImageButton.CommandArgument));

        //                currentPage.PageOrder = currentItemIndex - 1;
        //                swapPage.PageOrder = currentItemIndex;

        //                currentPage.Save();
        //                swapPage.Save();
        //            }

        //            break;
        //        case "down":

        //            if (currentItemIndex < rptPages.Items.Count - 1)
        //            {
        //                SurveyFeature.Business.Page currentPage = new SurveyFeature.Business.Page(new Guid(e.CommandArgument.ToString()));

        //                RepeaterItem belowRowItem = rptPages.Items[currentItemIndex + 1];
        //                ImageButton downImageButton = (ImageButton)belowRowItem.FindControl("btnDown");
        //                SurveyFeature.Business.Page swapPage = new SurveyFeature.Business.Page(new Guid(downImageButton.CommandArgument));

        //                currentPage.PageOrder = currentItemIndex + 1;
        //                swapPage.PageOrder = currentItemIndex;

        //                currentPage.Save();
        //                swapPage.Save();
        //            }

        //            break;
        //        case "delete":
        //            ImageButton button = (ImageButton)e.CommandSource;
        //            SurveyFeature.Business.Page.Delete(new Guid(button.CommandArgument));
        //            break;
        //    }

        //    BindGrid();
        //}

        //protected void BtnAddNewSurveyPage_Click(object sender, ImageClickEventArgs e)
        //{
        //    WebUtils.SetupRedirect(this, "~/Survey/SurveyPageEdit.aspx?SurveyGuid=" + surveyGuid + "&PageId=" + pageId + "&mid=" + ModuleId);
        //}

        #endregion

        #region OnInit

        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);

            this.Load += new EventHandler(this.Page_Load);
            this.grdSurveyPages.RowCommand += new GridViewCommandEventHandler(grdSurveyPages_RowCommand);
            this.grdSurveyPages.RowDeleting += new GridViewDeleteEventHandler(grdSurveyPages_RowDeleting);
            this.grdSurveyPages.RowDataBound += new GridViewRowEventHandler(grdSurveyPages_RowDataBound);
            
            //btnAddNewSurveyPage.Click += new ImageClickEventHandler(BtnAddNewSurveyPage_Click);
            //rptPages.ItemDataBound += new RepeaterItemEventHandler(RptPages_ItemDataBound);
            //rptPages.ItemCommand += new RepeaterCommandEventHandler(RptPages_ItemCommand);
            SuppressPageMenu();
            
        }

        

        

        #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.