AdminStoreSettings.aspx.cs :  » Content-Management-Systems-CMS » mojoPortal » WebStore » 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 » WebStore » UI » AdminStoreSettings.aspx.cs
/// Author:          Joe Audette
/// Created:        2007-02-15
/// Last Modified:        2009-09-02
/// 
/// 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.Data;
using System.Collections.Generic;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
using mojoPortal.Web;
using mojoPortal.Web.Editor;
using mojoPortal.Web.Framework;
using mojoPortal.Web.UI;
using mojoPortal.Business;
using WebStore.Business;
using WebStore.Helpers;
using Resources;

namespace WebStore.UI{
    public partial class AdminStoreSettingsPage : mojoBasePage
    {
        private int pageId = -1;
        private int moduleId = -1;
        private Store store;
        private Module module;
        private SiteUser currentUser = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (SiteUtils.SslIsAvailable()) SiteUtils.ForceSsl();

            LoadSettings();

            if (!UserCanEditModule(moduleId))
            {
                SiteUtils.RedirectToAccessDeniedPage();
                return;
            }

            PopulateLabels();

            if (!Page.IsPostBack)
            {
                BindDropdownLists();
                PopulateControls();
            }

        }

        private void PopulateControls()
        {
            //Store store = new Store(siteSettings.SiteGuid, moduleId);
            //Module module = new Module(moduleId);
            if (store == null) return;
            if (module == null) return;
            if (module.ModuleId == -1) return;

            txtName.Text = module.ModuleTitle;
            edDescription.Text = store.Description;
            txtOwnerName.Text = store.OwnerName;
            txtOwnerEmail.Text = store.OwnerEmail;

            ListItem listItem = ddCountryGuid.Items.FindByValue(store.CountryGuid.ToString());
            if (listItem != null)
            {
                ddCountryGuid.ClearSelection();
                listItem.Selected = true;
                BindZoneList();
            }

            txtAddress.Text = store.Address;
            txtCity.Text = store.City;

            listItem = ddZoneGuid.Items.FindByValue(store.ZoneGuid.ToString());
            if (listItem != null)
            {
                ddZoneGuid.ClearSelection();
                listItem.Selected = true;
            }

            txtPostalCode.Text = store.PostalCode;
            txtPhone.Text = store.Phone;
            txtFax.Text = store.Fax;
            txtSalesEmail.Text = store.SalesEmail;
            txtSupportEmail.Text = store.SupportEmail;
            txtEmailFrom.Text = store.EmailFrom;
            txtOrderBCCEmail.Text = store.OrderBccEmail;

            
            chkIsClosed.Checked = store.IsClosed;
            edClosedMessage.Text = store.ClosedMessage;
            
            

        }

        private void BindDropdownLists()
        {
            BindCountryList();
            BindZoneList();
            
        }

        private void BindCountryList()
        {
            DataTable dataTable = GeoCountry.GetList();
            ddCountryGuid.DataSource = dataTable;
            ddCountryGuid.DataBind();
        }

        private void ddCountryGuid_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindZoneList();
        }

        private void BindZoneList()
        {
            if (ddCountryGuid.SelectedIndex > -1)
            {
                Guid countryGuid = new Guid(ddCountryGuid.SelectedValue);
                using (IDataReader reader = GeoZone.GetByCountry(countryGuid))
                {
                    ddZoneGuid.DataSource = reader;
                    ddZoneGuid.DataBind();
                }
            }
        }

        


        private void btnSave_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if ((Page.IsValid)&&(store != null))
            {
              
                SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
                
                if (store.SiteGuid == Guid.Empty)
                {
                    store.SiteGuid = siteSettings.SiteGuid;
                }
                if (store.ModuleId == -1)
                {
                    store.ModuleId = moduleId;
                }

                Module module = new Module(moduleId);
                module.ModuleTitle = txtName.Text;
                module.Save();
                
                store.Name = txtName.Text;
                store.Description = edDescription.Text;
                store.OwnerName = txtOwnerName.Text;
                store.OwnerEmail = txtOwnerEmail.Text;
                store.SalesEmail = txtSalesEmail.Text;
                store.SupportEmail = txtSupportEmail.Text;
                store.EmailFrom = txtEmailFrom.Text;
                store.OrderBccEmail = txtOrderBCCEmail.Text;
                store.Phone = txtPhone.Text;
                store.Fax = txtFax.Text;
                store.Address = txtAddress.Text;
                store.City = txtCity.Text;

                if (!String.IsNullOrEmpty(ddZoneGuid.SelectedValue))
                {
                    store.ZoneGuid = new Guid(ddZoneGuid.SelectedValue);
                }

                store.PostalCode = txtPostalCode.Text;

                if (!String.IsNullOrEmpty(ddCountryGuid.SelectedValue))
                {
                    store.CountryGuid = new Guid(ddCountryGuid.SelectedValue); 
                }

                store.IsClosed = chkIsClosed.Checked;
                store.ClosedMessage = edClosedMessage.Text;
                

                if (store.Guid == Guid.Empty)
                {
                    store.Created = DateTime.UtcNow;
                    store.CreatedBy = siteUser.UserGuid;
                    
                }

                store.Save();

                List<TaxClass> taxClasses = TaxClass.GetList(siteSettings.SiteGuid);

                if (taxClasses.Count == 0)
                {
                    TaxClass taxClass = new TaxClass();
                    taxClass.SiteGuid = siteSettings.SiteGuid;
                    taxClass.Title = WebStoreResources.TaxClassTaxable;
                    taxClass.Description = WebStoreResources.TaxClassTaxable;
                    taxClass.Save();

                    taxClass = new TaxClass();
                    taxClass.SiteGuid = siteSettings.SiteGuid;
                    taxClass.Title = WebStoreResources.TaxClassNotTaxable;
                    taxClass.Description = WebStoreResources.TaxClassNotTaxable;
                    taxClass.Save();


                }

                List<FullfillDownloadTerms> downloadTerms = FullfillDownloadTerms.GetList(store.Guid);
                if (downloadTerms.Count == 0)
                {
                    if(currentUser == null)currentUser = SiteUtils.GetCurrentSiteUser();
                    if (currentUser != null)
                    {
                        FullfillDownloadTerms term = new FullfillDownloadTerms();
                        term.Name = WebStoreResources.DownloadUnlimited;
                        term.Description = WebStoreResources.DownloadUnlimited;
                        term.CreatedBy = currentUser.UserGuid;
                        term.CreatedFromIP = SiteUtils.GetIP4Address();
                        term.StoreGuid = store.Guid;
                        term.Save();
                        
                    }

                }

                WebUtils.SetupRedirect(this, Request.RawUrl);


            }
        }


        private void PopulateLabels()
        {
            Control c = Master.FindControl("Breadcrumbs");
            if ((c != null)&&(store != null))
            {
                BreadcrumbsControl crumbs = (BreadcrumbsControl)c;
                crumbs.ForceShowBreadcrumbs = true;
                crumbs.AddedCrumbs
                    = "<a href='" + SiteRoot
                    + "/WebStore/AdminDashboard.aspx?pageid=" 
                    + pageId.ToString(CultureInfo.InvariantCulture)
                    + "&amp;mid=" + moduleId.ToString(CultureInfo.InvariantCulture)
                    + "' class='unselectedcrumb'>" + WebStoreResources.StoreManagerLink
                    + "</a>";
            }

            Title = SiteUtils.FormatPageTitle(siteSettings, WebStoreResources.StoreSettingsLink);

            litHeading.Text = WebStoreResources.StoreSettingsLink;
            btnSave.Text = WebStoreResources.StoreSettingsSaveButton;
            litSettingsTab.Text = WebStoreResources.StoreContactInfoTab;
            litDescriptionTab.Text = WebStoreResources.StoreDescriptionTab;
            litClosedTab.Text = WebStoreResources.StoreOpenClosedTab;
           
            edDescription.WebEditor.ToolBar = ToolBar.Full;
            edDescription.WebEditor.Height = Unit.Parse("220px");

            edClosedMessage.WebEditor.ToolBar = ToolBar.Full;
            edClosedMessage.WebEditor.Height = Unit.Parse("220px");

        }

        private void LoadSettings()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", -1);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", -1);
            
            if (CurrentPage.ContainsModule(moduleId))
            {
                store = StoreHelper.GetStore();
            }

            if ((moduleId > -1)&&(store.ModuleId == moduleId))
            {
                module = new Module(moduleId);

            }
        }


        #region OnInit

        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);
            
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(this.Page_Load);
            this.btnSave.Click += new EventHandler(btnSave_Click);
            this.ddCountryGuid.SelectedIndexChanged += new EventHandler(ddCountryGuid_SelectedIndexChanged);
            SuppressPageMenu();
            SuppressGoogleAds();
            SiteUtils.SetupEditor(edDescription);
            SiteUtils.SetupEditor(edClosedMessage);
            
        }

        

        

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