OfferProductSelectorDialog.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 » OfferProductSelectorDialog.aspx.cs
// Author:          Joe Audette
// Created:            2009-04-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.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using mojoPortal.Business.Commerce;
using mojoPortal.Web;
using mojoPortal.Web.Framework;
using WebStore.Business;
using WebStore.Helpers;
using Resources;

namespace WebStore.UI{
    public partial class OfferProductSelectorDialog : mojoDialogBasePage
    {
        private Store store = null;
        private Guid offerGuid = Guid.Empty;
        //private Offer offer = null;
        private int pageId = -1;
        private int moduleId = -1;
        private int pageNumber = 1;
        private int pageSize = 10;
        private int totalPages = 1;

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadParams();

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

            LoadSettings();
            PopulateLabels();
            SetupProductAddScript();
            PopulateControls();


        }

        private void PopulateControls()
        {
            if (!Page.IsPostBack)
            {
                BindProductList();
            }

        }



        private void BindProductList()
        {
            if (store == null) { return; }

            DataTable dt = Product.GetPageForAdminList(
                store.Guid,
                pageNumber,
                pageSize,
                out totalPages);

            pgrProduct.ShowFirstLast = true;
            pgrProduct.CurrentIndex = pageNumber;
            pgrProduct.PageSize = pageSize;
            pgrProduct.PageCount = totalPages;
            pgrProduct.Visible = (this.totalPages > 1);
           
            grdProduct.DataSource = dt;
            grdProduct.PageIndex = pageNumber;
            grdProduct.PageSize = pageSize;
            grdProduct.DataBind();

        }

        void pgrProduct_Command(object sender, CommandEventArgs e)
        {
            pageNumber = Convert.ToInt32(e.CommandArgument);
            pgrProduct.CurrentIndex = pageNumber;
            BindProductList();
            pnlPicker.Update();
        }


        void grdProduct_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Button btnAddProduct = (Button)e.Row.FindControl("btnAddProduct");
            if (btnAddProduct == null) { return; }

            string[] pair = btnAddProduct.CommandArgument.Split('|');
            if (pair.Length != 2) { return; }
            if (pair[0].Length != 36) { return; }

            Guid productGuid = new Guid(pair[0]);
            FulfillmentType fulfillmentType = Product.FulfillmentTypeFromString(pair[1]);
            if (fulfillmentType != FulfillmentType.Download)
            {
                btnAddProduct.Attributes.Add("onclick", GetClientScriptForButton(productGuid, fulfillmentType, Guid.Empty));
            }
           
           
        }

        void grdProduct_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //this should only fire for download products at leastif javascript is enabled
           
            if (e.CommandName != "addProduct") { return; }

            string[] pair = e.CommandArgument.ToString().Split('|');
            if (pair.Length != 2) { return; }
            if (pair[0].Length != 36) { return; }
            
            Guid productGuid = new Guid(pair[0]);
            FulfillmentType fulfillmentType = Product.FulfillmentTypeFromString(pair[1]);

           
            switch (fulfillmentType)
            {
                case FulfillmentType.None:
                case FulfillmentType.PhysicalShipment:

                    //TODO add product to offer as backup if javascript is disabled
                    


                    break;

                case FulfillmentType.Download:
                    ShowFulfillmentTermsPanel(productGuid, fulfillmentType);
                    break;
            }

            pnlPicker.Update();
            

        }

        void btnAddWithDownloadTerms_Click(object sender, EventArgs e)
        {
            // this shouldonly fire if javascript is disabled
            //TODO: add backup implementation to add product if js is disabled
        }

        private void ShowFulfillmentTermsPanel(Guid productGuid, FulfillmentType fulfillmentType)
        {
            pnlDownloadTerms.Visible = true;
            pnlGrid.Visible = false;
            hdnFulfillmentType.Value = ((byte)fulfillmentType).ToString();
            hdnProductGuid.Value = productGuid.ToString();

            Product product = new Product(productGuid);
            lblProduct.Text = product.Name;

            using (IDataReader reader = FullfillDownloadTerms.GetAll(store.Guid))
            {
                ddFulfillTerms.DataSource = reader;
                ddFulfillTerms.DataBind();
            }

        }

        private string GetClientScriptForButton(Guid productGuid, FulfillmentType fulfillmentType, Guid fulfillmentTermsGuid)
        {
            return "top.window.AddProduct('" + productGuid.ToString() 
                + "','" + ((byte)fulfillmentType).ToString() 
                + "','" + fulfillmentTermsGuid.ToString() + "');  return false;";

            
        }

        private void SetupProductAddScript()
        {
            StringBuilder script = new StringBuilder();

            script.Append("\n<script type='text/javascript'>");
            script.Append("function AddProduct() {");

            
            //script.Append("alert(productGuid);");

            script.Append("var hdnP = document.getElementById('" + this.hdnProductGuid.ClientID + "'); ");
            script.Append("var productGuid = hdnP.value; ");

            script.Append("var hdnFt = document.getElementById('" + this.hdnFulfillmentType.ClientID + "'); ");
            script.Append("var fulfillType = hdnFt.value; ");

            script.Append("var hdnFTG = document.getElementById('" + this.ddFulfillTerms.ClientID + "'); ");
            script.Append("var fulfillGuid = hdnFTG.options[hdnFTG.selectedIndex].value; ");


            script.Append("top.window.AddProduct(productGuid,fulfillType,fulfillGuid); ");

            script.Append("}");
            script.Append("</script>");


            Page.ClientScript.RegisterStartupScript(typeof(Page), "prodHandler", script.ToString());

        }

        private void PopulateLabels()
        {
            btnAddWithDownloadTerms.Text = WebStoreResources.AddProductToOfferGridButton;
            btnAddWithDownloadTerms.Attributes.Add("onclick", "AddProduct(); return false;");
            grdProduct.Columns[0].HeaderText = WebStoreResources.ProductModelNumberLabel;
            grdProduct.Columns[1].HeaderText = WebStoreResources.ProductNameLabel;
        }

        private void LoadSettings()
        {
            if (CurrentPage.ContainsModule(moduleId))
            {
                //store = StoreHelper.GetStore(siteSettings.SiteGuid, moduleId);
                store = StoreHelper.GetStore();
            }

            try
            {
                // this keeps the action from changing during ajax postback in folder based sites
                SiteUtils.SetFormAction(Page, Request.RawUrl);
            }
            catch (MissingMethodException)
            {
                //this method was introduced in .NET 3.5 SP1
            }
        }

        private void LoadParams()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", moduleId);
            offerGuid = WebUtils.ParseGuidFromQueryString("offer", offerGuid);

        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(Page_Load);
            grdProduct.RowDataBound += new GridViewRowEventHandler(grdProduct_RowDataBound);
            grdProduct.RowCommand += new GridViewCommandEventHandler(grdProduct_RowCommand);
            btnAddWithDownloadTerms.Click += new EventHandler(btnAddWithDownloadTerms_Click);
            pgrProduct.Command += new CommandEventHandler(pgrProduct_Command);
        }

        
        

        

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