Powered By

WebStun Technologies

dotnetnuke store product search module - part 1

Posted on 2:12:00 PM In: ,

DotNetNuke® is the ideal platform for building professional websites and web applications with dynamic content and interactive features. DotNetNuke store module is an ecommerce module which is running on DNN platform. This module contains lots of features. But I saw there was not a product search module. The module team leader Gilles Le Pigocher and Benoit Sarton helped me to develop this feature. Gilles Le Pigocher has added this to his long to do list. So this will be available in the future with a future store version. But until then this will be useful to all of you. Still you can use the store module with the search module what I have given. As you know this module contains 21 projects. Then I have added only source file codes with my modified codes. If you have any questions I am ready to help you. Once again my special thanks to my two French friends Gilles Le Pigocherand BenoĆ®t Sarton for their effort and all the advices.


Catalog.ascx.cs

using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Security;
using DotNetNuke.Modules.Store.Admin;
using DotNetNuke.Modules.Store.Catalog;
using DotNetNuke.Modules.Store.Components;
using System.Web;

namespace DotNetNuke.Modules.Store.WebControls
{
 public enum ProductListTypes
 {
        New,
  Featured,
  Popular,
  Category,

        MySearchResult
 }

 /// 
 /// Summary description for Media.
 /// 
 public partial class Catalog : PortalModuleBase, IActionable
 {
  #region Private Members

        private ModuleSettings moduleSettings;
        private StoreInfo storeInfo;
        private string templatesPath = "";
  private CatalogNavigation catalogNav;
  private CategoryInfo categoryInfo = new CategoryInfo();
  private ProductInfo productInfo = new ProductInfo();
        private string npTitle = null;
        private string fpTitle = null;

        private string MSTitle = null;

        private string ppTitle = null;
        private string cpTitle = null;
        private enum MetaTags
        {
            Title = 1,
            Keywords,
            Description,
        }
        private Regex regTokens = new Regex("\\[\\w+\\]", RegexOptions.IgnoreCase | RegexOptions.Compiled);

        #endregion

  #region Public Properties

  public ModuleSettings ModuleSettings
  {
   get{return moduleSettings;}
  }

  public Int32 CategoryID
  {
   get {return catalogNav.CategoryID;}
  }

  public Int32 ProductID
  {
   get {return catalogNav.ProductID;}
  }

        public DotNetNuke.Framework.CDefault BasePage
        {
            get { return (DotNetNuke.Framework.CDefault)this.Page; }
        }

        #endregion

  #region Web Form Designer generated code

  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);

        }
  
  /// 
  ///  Required method for Designer support - do not modify
  ///  the contents of this method with the code editor.
  /// 
  private void InitializeComponent()
  {
            if (storeInfo == null)
            {
                StoreController storeController = new StoreController();
                storeInfo = storeController.GetStoreInfo(PortalId);
            }
        }

  #endregion

  #region Events

  protected void Page_Load(object sender, System.EventArgs e)
  {
            if (storeInfo != null)
            {
                npTitle = Localization.GetString("NPTitle.Text", this.LocalResourceFile);
                fpTitle = Localization.GetString("FPTitle.Text", this.LocalResourceFile);

                MSTitle = Localization.GetString("MSTitle.Text", this.LocalResourceFile);

                ppTitle = Localization.GetString("PPTitle.Text", this.LocalResourceFile);
                cpTitle = Localization.GetString("CPTitle.Text", this.LocalResourceFile);

                try
                {
                    if (storeInfo.PortalTemplates)
                    {
                        templatesPath = PortalSettings.HomeDirectoryMapPath + "Store\\";
                        CssTools.AddCss(this.Page, PortalSettings.HomeDirectory + "Store", PortalId);
                    }
                    else
                    {
                        templatesPath = MapPath(ModulePath) + "\\";
                        CssTools.AddCss(this.Page, this.TemplateSourceDirectory, PortalId);
                    }

                    moduleSettings = new ModuleSettings(this.ModuleId, this.TabId);

                    catalogNav = new CatalogNavigation(Request.QueryString);

                    if (catalogNav.CategoryID == Null.NullInteger)
                    {
                        if (bool.Parse(moduleSettings.General.UseDefaultCategory))
                        {
                            catalogNav.CategoryID = int.Parse(moduleSettings.General.DefaultCategoryID);
                            Response.Redirect(catalogNav.GetNavigationUrl(), true);
                        }
                    }

                    if (catalogNav.ProductID != Null.NullInteger)
                    {
                        ProductController productController = new ProductController();
                        productInfo = productController.GetProduct(PortalId, catalogNav.ProductID);
                        catalogNav.CategoryID = productInfo.CategoryID;
                    }

                    if (catalogNav.CategoryID != Null.NullInteger)
                    {
                        CategoryController categoryController = new CategoryController();
                        categoryInfo = categoryController.GetCategory(catalogNav.CategoryID);
                    }

                    if (storeInfo.SEOFeature)
                    {
                        BasePage.Title = SEO(Localization.GetString("ListSEOTitle", this.LocalResourceFile), MetaTags.Title);
                        BasePage.Description = SEO(Localization.GetString("ListSEODescription", this.LocalResourceFile), MetaTags.Description);
                        BasePage.KeyWords = SEO(Localization.GetString("ListSEOKeywords", this.LocalResourceFile), MetaTags.Keywords);
                    }

                    this.Controls.Add(TemplateController.ParseTemplate(templatesPath, moduleSettings.General.Template, new ProcessTokenDelegate(processToken)));
                }
                catch (Exception ex)
                {
                    Exceptions.ProcessModuleLoadException(this, ex);
                }
            }
            else
            {
                string ErrorSettings = Localization.GetString("ErrorSettings", this.LocalResourceFile);
                string ErrorSettingsHeading = Localization.GetString("ErrorSettingsHeading", this.LocalResourceFile);
                DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, ErrorSettingsHeading, ErrorSettings, DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning);
            }
        }

  #endregion

  #region Private Functions

  private Control processToken(string tokenName)
  {
   ProductController productController = new ProductController();
   ArrayList productList = new ArrayList();

   switch (tokenName.ToUpper())
   {
    case "MESSAGE":
                    if (bool.Parse(moduleSettings.General.ShowMessage) && categoryInfo != null)
                    {
                        Panel pnlMessage = new Panel();
                        pnlMessage.CssClass = "StoreMessage";
                        if (categoryInfo != null)
                        {
                            string message = Server.HtmlDecode(categoryInfo.Message);
                            if (message != Null.NullString)
                            {
                                Panel pnlCategoryMessage = new Panel();
                                pnlCategoryMessage.CssClass = "StoreCategoryMessage";
                                Literal litCategoryMessage = new Literal();
                                litCategoryMessage.Text = System.Web.HttpUtility.HtmlDecode(message);
                                pnlCategoryMessage.Controls.Add(litCategoryMessage);
                                pnlMessage.Controls.Add(pnlCategoryMessage);
                            }
                        }

                        if (catalogNav.CategoryID != Null.NullInteger)
                        {
                            //sub categories...
                            CategoryController controller = new CategoryController();
                            ArrayList subCategories = controller.GetCategories(PortalId, false, catalogNav.CategoryID);
                            if (subCategories.Count > 0)
                            {
                                HtmlGenericControl pSubCategories = new HtmlGenericControl("p");
                                pSubCategories.Attributes.Add("class", "StoreSubCategories");

                                LiteralControl BreakRow = new LiteralControl(Localization.GetString("BeforeSubCategories", this.LocalResourceFile));
                                pSubCategories.Controls.Add(BreakRow);

                                Boolean bIsFirst = true;
                                foreach (CategoryInfo category in subCategories)
                                {
                                    if (bIsFirst)
                                    {
                                        bIsFirst = false;
                                    }
                                    else
                                    {
                                        LiteralControl BreakRow2 = new LiteralControl(Localization.GetString("BetweenSubCategories", this.LocalResourceFile));
                                        pSubCategories.Controls.Add(BreakRow2);
                                    }
                                    HyperLink link = new HyperLink();
                                    link.Text = category.CategoryName;
                                    link.CssClass = "StoreSubCategoryItem";
                                    StringDictionary replaceParams = new StringDictionary();
                                    replaceParams["CategoryID"] = category.CategoryID.ToString();
                                    replaceParams["ProductID"] = Null.NullString;
                                    replaceParams["PageIndex"] = Null.NullString;
                                    link.NavigateUrl = catalogNav.GetNavigationUrl(replaceParams, storeInfo.StorePageID);
                                    pSubCategories.Controls.Add(link);
                                }
                                BreakRow = new LiteralControl(Localization.GetString("AfterSubCategories", this.LocalResourceFile));
                                pSubCategories.Controls.Add(BreakRow);
                                pnlMessage.Controls.Add(pSubCategories);
                            }
                        }
                        return pnlMessage;
                    }
                    else
                        return null;

                case "NEW":
                    if (bool.Parse(moduleSettings.General.ShowNewProducts))
                    {
                        if (catalogNav.CategoryID != Null.NullInteger)
                        {
                            GetNewProducts(catalogNav.CategoryID, productList);
                            productList = TruncateList(productList, int.Parse(moduleSettings.NewProducts.RowCount) * int.Parse(moduleSettings.NewProducts.ColumnCount));
                            return LoadProductList(productList, ProductListTypes.New);
                        }
                        else
                        {
                            GetPortalNewProducts(PortalId, productList);
                            productList = TruncateList(productList, int.Parse(moduleSettings.NewProducts.RowCount) * int.Parse(moduleSettings.NewProducts.ColumnCount));
                            return LoadProductList(productList, ProductListTypes.New);
                        }
                    }
                    else
                    {
                        return null;
                    }

    case "FEATURED":
     if (bool.Parse(moduleSettings.General.ShowFeaturedProducts))
     {
      if(catalogNav.CategoryID != Null.NullInteger)
      {
                            GetFeaturedProducts(catalogNav.CategoryID, productList);
       productList = TruncateList(productList, int.Parse(moduleSettings.FeaturedProducts.RowCount) * int.Parse(moduleSettings.FeaturedProducts.ColumnCount));
       return LoadProductList(productList, ProductListTypes.Featured);
      }
      else
      {
                            GetPortalFeaturedProducts(PortalId, productList);
       productList = TruncateList(productList, int.Parse(moduleSettings.FeaturedProducts.RowCount) * int.Parse(moduleSettings.FeaturedProducts.ColumnCount));
       return LoadProductList(productList, ProductListTypes.Featured);
      }
     }
     else
     {
      return null;
     }


                case "MYSEARCHRESULT":

                    if (bool.Parse(moduleSettings.General.ShowMYSEARCHProducts))
                    {

                        if (catalogNav.CategoryID != Null.NullInteger)
                        {
                            GetMYSEARCHProducts(catalogNav.CategoryID, productList, catalogNav.SearchText, catalogNav.SearchField);
                            productList = TruncateList(productList, int.Parse(moduleSettings.MYSEARCHProducts.RowCount) * int.Parse(moduleSettings.MYSEARCHProducts.ColumnCount));
                            return LoadProductList(productList, ProductListTypes.MySearchResult);
                        }
                        else
                        {
                            GetPortalMYSEARCHProducts(PortalId, productList, catalogNav.SearchText, catalogNav.SearchField);
                            productList = TruncateList(productList, int.Parse(moduleSettings.MYSEARCHProducts.RowCount) * int.Parse(moduleSettings.MYSEARCHProducts.ColumnCount));
                            return LoadProductList(productList, ProductListTypes.MySearchResult);
                        }
                    }
                    else
                    {
                        return null;
                    }



    case "POPULAR":
     if (bool.Parse(moduleSettings.General.ShowPopularProducts))
     {
      if(catalogNav.CategoryID != Null.NullInteger)
      {
                            GetPopularProducts(catalogNav.CategoryID, productList);
       productList = TruncateList(productList, int.Parse(moduleSettings.PopularProducts.RowCount) * int.Parse(moduleSettings.PopularProducts.ColumnCount));
       return LoadProductList(productList, ProductListTypes.Popular);
      }
      else
      {
                            GetPortalPopularProducts(PortalId, productList);
                            productList = TruncateList(productList, int.Parse(moduleSettings.PopularProducts.RowCount) * int.Parse(moduleSettings.PopularProducts.ColumnCount));
       return LoadProductList(productList, ProductListTypes.Popular);
      }
     }
     else
     {
      return null;
     }

    case "CATEGORY":
     if (bool.Parse(moduleSettings.General.ShowCategoryProducts))
     {
      if(catalogNav.CategoryID != Null.NullInteger && catalogNav.ProductID == Null.NullInteger)
      {
                            GetCategoryProducts(catalogNav.CategoryID, productList);
       return LoadProductList(productList, ProductListTypes.Category);
      }
      else
      {
       return null;
      }
     }
     else
     {
      return null;
     }

    case "DETAIL":
     if(bool.Parse(moduleSettings.General.ShowProductDetail) && catalogNav.ProductID != Null.NullInteger)
     {
      return LoadProductDetail();
     }
     else
     {
      return null;
     }

    default:
     LiteralControl litText = new LiteralControl(tokenName);
     return litText;
   }
  }

        private void GetNewProducts(int categoryID, ArrayList products)
        {
            CategoryController categoryController = new CategoryController();
            ProductController productController = new ProductController();

            CategoryInfo category = categoryController.GetCategory(categoryID);

            foreach (ProductInfo product in productController.GetNewProducts(categoryID, false))
            {
                if (storeInfo.ProductsBehavior == (int)Behavior.HideProduct && product.StockQuantity < 1)
                {
                    // Do nothing, in this case the product is hidden
                }
                else
                    products.Add(product);
            }

            foreach (CategoryInfo childCategory in categoryController.GetCategories(PortalId, false, categoryID))
            {
                if (childCategory.CategoryID != Null.NullInteger)
                {
                    GetNewProducts(childCategory.CategoryID, products);
                }
            }
        }

        private void GetPortalNewProducts(int portalID, ArrayList products)
        {
            ProductController productController = new ProductController();

            foreach (ProductInfo product in productController.GetPortalNewProducts(portalID, false))
            {
                if (storeInfo.ProductsBehavior == (int)Behavior.HideProduct && product.StockQuantity < 1)
                {
                    // Do nothing, in this case the product is hidden
                }
                else
                    products.Add(product);
            }
        }

        private void GetFeaturedProducts(int categoryID, ArrayList products)
        {
            CategoryController categoryController = new CategoryController();
            ProductController productController = new ProductController();

            CategoryInfo category = categoryController.GetCategory(categoryID);

            foreach (ProductInfo product in productController.GetFeaturedProducts(categoryID, false))
            {
                if (storeInfo.ProductsBehavior == (int)Behavior.HideProduct && product.StockQuantity < 1)
                {
                    // Do nothing, in this case the product is hidden
                }
                else
                    products.Add(product);
            }

            foreach (CategoryInfo childCategory in categoryController.GetCategories(PortalId, false, categoryID))
            {
                if (childCategory.CategoryID != Null.NullInteger)
                {
                    GetFeaturedProducts(childCategory.CategoryID, products);
                }
            }
        }

        private void GetPortalFeaturedProducts(int portalID, ArrayList products)
        {
            ProductController productController = new ProductController();

            foreach (ProductInfo product in productController.GetPortalFeaturedProducts(portalID, false))
            {
                if (storeInfo.ProductsBehavior == (int)Behavior.HideProduct && product.StockQuantity < 1)
                {
                    // Do nothing, in this case the product is hidden
                }
                else
                    products.Add(product);
            }
        }


        private void GetMYSEARCHProducts(int categoryID, ArrayList products, string SearchText, string SearchField)
        {
            CategoryController categoryController = new CategoryController();
            ProductController productController = new ProductController();

            CategoryInfo category = categoryController.GetCategory(categoryID);

            foreach (ProductInfo product in productController.GetMYSEARCHProducts(categoryID, false,SearchText,SearchField))
            {
                if (storeInfo.ProductsBehavior == (int)Behavior.HideProduct && product.StockQuantity < 1)
                {
                    // Do nothing, in this case the product is hidden
                }
                else
                    products.Add(product);
            }

            foreach (CategoryInfo childCategory in categoryController.GetCategories(PortalId, false, categoryID))
            {
                if (childCategory.CategoryID != Null.NullInteger)
                {
                    GetMYSEARCHProducts(childCategory.CategoryID, products,SearchText,SearchField);
                }
            }
        }

        private void GetPortalMYSEARCHProducts(int portalID, ArrayList products, string SearchText, string SearchField)
        {
            ProductController productController = new ProductController();

            foreach (ProductInfo product in productController.GetPortalMYSEARCHProducts(portalID, false,SearchText,SearchField))
            {
                if (storeInfo.ProductsBehavior == (int)Behavior.HideProduct && product.StockQuantity < 1)
                {
                    // Do nothing, in this case the product is hidden
                }
                else
                    products.Add(product);
            }
        }


        private void GetPopularProducts(int categoryID, ArrayList products)
        {
            CategoryController categoryController = new CategoryController();
            ProductController productController = new ProductController();

            CategoryInfo category = categoryController.GetCategory(categoryID);

            foreach (ProductInfo product in productController.GetPopularProducts(PortalId, categoryID, false))
            {
                if (storeInfo.ProductsBehavior == (int)Behavior.HideProduct && product.StockQuantity < 1)
                {
                    // Do nothing, in this case the product is hidden
                }
                else
                    products.Add(product);
            }

            foreach (CategoryInfo childCategory in categoryController.GetCategories(PortalId, false, categoryID))
            {
                if (childCategory.CategoryID != Null.NullInteger)
                {
                    GetPopularProducts(childCategory.CategoryID, products);
                }
            }
        }

        private void GetPortalPopularProducts(int portalID, ArrayList products)
        {
            ProductController productController = new ProductController();

            foreach (ProductInfo product in productController.GetPortalPopularProducts(portalID, false))
            {
                if (storeInfo.ProductsBehavior == (int)Behavior.HideProduct && product.StockQuantity < 1)
                {
                    // Do nothing, in this case the product is hidden
                }
                else
                    products.Add(product);
            }
        }

        private void GetCategoryProducts(int categoryID, ArrayList products)
        {
            CategoryController categoryController = new CategoryController();
            ProductController productController = new ProductController();

            CategoryInfo category = categoryController.GetCategory(categoryID);

            int sortID;
            if (catalogNav.SortID != Null.NullInteger)
            {
                // Currently selected sort column
                sortID = catalogNav.SortID;
            }
            else
            {
                // Default sort column
                sortID = int.Parse(moduleSettings.CategoryProducts.SortBy);
            }
            string sortDir;
            if (catalogNav.SortDir != Null.NullString)
            {
                // Currently selected sort direction
                sortDir = catalogNav.SortDir;
            }
            else
            {
                // Default sort direction
                sortDir = moduleSettings.CategoryProducts.SortDir;
            }

            foreach (ProductInfo product in productController.GetCategoryProducts(categoryID, false, sortID, sortDir))
            {
                if (storeInfo.ProductsBehavior == (int)Behavior.HideProduct && product.StockQuantity < 1)
                {
                    // Do nothing, in this case the product is hidden
                }
                else
                    products.Add(product);
            }

            if (bool.Parse(moduleSettings.CategoryProducts.SubCategories))
            {
                foreach (CategoryInfo childCategory in categoryController.GetCategories(PortalId, false, categoryID))
                {
                    if (childCategory.CategoryID != Null.NullInteger)
                    {
                        GetCategoryProducts(childCategory.CategoryID, products);
                    }
                }
            }
        }

  private Control LoadProductList(ArrayList products, ProductListTypes listType)
  {
   if (products != null && products.Count > 0)
   {
    ProductList productList = (ProductList)LoadControl(ModulePath + "ProductList.ascx");
    productList.ParentControl = this as PortalModuleBase;
    productList.CategoryID = catalogNav.CategoryID;
                productList.ModuleConfiguration = this.ModuleConfiguration;

    switch (listType)
    {
                    case ProductListTypes.New:
                        productList.ListType = listType;
                        productList.Title = npTitle;
                        productList.ContainerTemplate = moduleSettings.NewProducts.ContainerTemplate;
                        productList.ContainerCssClass = "StoreNewProductList";
                        productList.Template = moduleSettings.NewProducts.Template;
                        productList.ItemCssClass = "StoreNewProductItem";
                        productList.AlternatingItemCssClass = "StoreNewProductAlternatingItem";
                        productList.RowCount = int.Parse(moduleSettings.NewProducts.RowCount);
                        productList.ColumnCount = int.Parse(moduleSettings.NewProducts.ColumnCount);
                        productList.ColumnWidth = int.Parse(moduleSettings.NewProducts.ColumnWidth);
                        productList.Direction = moduleSettings.NewProducts.RepeatDirection;
                        productList.ShowThumbnail = bool.Parse(moduleSettings.NewProducts.ShowThumbnail);
                        productList.ThumbnailWidth = int.Parse(moduleSettings.NewProducts.ThumbnailWidth);
                        productList.ShowDetail = bool.Parse(moduleSettings.General.ShowProductDetail);
                        productList.DetailPage = int.Parse(moduleSettings.NewProducts.DetailPage);
                        break;

     case ProductListTypes.Featured:
                        productList.ListType = listType;
                        productList.Title = fpTitle;
                        productList.ContainerTemplate = moduleSettings.FeaturedProducts.ContainerTemplate;
                        productList.ContainerCssClass = "StoreFeaturedProductList";
      productList.Template = moduleSettings.FeaturedProducts.Template;
                        productList.ItemCssClass = "StoreFeaturedProductItem";
                        productList.AlternatingItemCssClass = "StoreFeaturedProductAlternatingItem";
      productList.RowCount = int.Parse(moduleSettings.FeaturedProducts.RowCount);
      productList.ColumnCount = int.Parse(moduleSettings.FeaturedProducts.ColumnCount);
      productList.ColumnWidth = int.Parse(moduleSettings.FeaturedProducts.ColumnWidth);
                        productList.Direction = moduleSettings.FeaturedProducts.RepeatDirection;
      productList.ShowThumbnail = bool.Parse(moduleSettings.FeaturedProducts.ShowThumbnail);
      productList.ThumbnailWidth = int.Parse(moduleSettings.FeaturedProducts.ThumbnailWidth);
                        productList.ShowDetail = bool.Parse(moduleSettings.General.ShowProductDetail);
      productList.DetailPage = int.Parse(moduleSettings.FeaturedProducts.DetailPage);
      break;

                    case ProductListTypes.MySearchResult:
                        productList.ListType = listType;
                        productList.Title = MSTitle;
                        productList.ContainerTemplate = moduleSettings.MYSEARCHProducts.ContainerTemplate;
                        productList.ContainerCssClass = "StoreFeaturedProductList";
                        productList.Template = moduleSettings.MYSEARCHProducts.Template;
                        productList.ItemCssClass = "StoreFeaturedProductItem";
                        productList.AlternatingItemCssClass = "StoreFeaturedProductAlternatingItem";
                        productList.RowCount = int.Parse(moduleSettings.MYSEARCHProducts.RowCount);
                        productList.ColumnCount = int.Parse(moduleSettings.MYSEARCHProducts.ColumnCount);
                        productList.ColumnWidth = int.Parse(moduleSettings.MYSEARCHProducts.ColumnWidth);
                        productList.Direction = moduleSettings.MYSEARCHProducts.RepeatDirection;
                        productList.ShowThumbnail = bool.Parse(moduleSettings.MYSEARCHProducts.ShowThumbnail);
                        productList.ThumbnailWidth = int.Parse(moduleSettings.MYSEARCHProducts.ThumbnailWidth);
                        productList.ShowDetail = bool.Parse(moduleSettings.General.ShowProductDetail);
                        productList.DetailPage = int.Parse(moduleSettings.MYSEARCHProducts.DetailPage);
                        break;

     case ProductListTypes.Popular:
                        productList.ListType = listType;
                        productList.Title = ppTitle;
                        productList.ContainerTemplate = moduleSettings.PopularProducts.ContainerTemplate;
                        productList.ContainerCssClass = "StorePopularProductList";
      productList.Template = moduleSettings.PopularProducts.Template;
                        productList.ItemCssClass = "StorePopularProductItem";
                        productList.AlternatingItemCssClass = "StorePopularProductAlternatingItem";
      productList.RowCount = int.Parse(moduleSettings.PopularProducts.RowCount);
      productList.ColumnCount = int.Parse(moduleSettings.PopularProducts.ColumnCount);
      productList.ColumnWidth = int.Parse(moduleSettings.PopularProducts.ColumnWidth);
                        productList.Direction = moduleSettings.PopularProducts.RepeatDirection;
      productList.ShowThumbnail = bool.Parse(moduleSettings.PopularProducts.ShowThumbnail);
      productList.ThumbnailWidth = int.Parse(moduleSettings.PopularProducts.ThumbnailWidth);
                        productList.ShowDetail = bool.Parse(moduleSettings.General.ShowProductDetail);
      productList.DetailPage = int.Parse(moduleSettings.PopularProducts.DetailPage);
      break;

     case ProductListTypes.Category:
                        productList.ListType = listType;
                        productList.Title = cpTitle;
                        productList.ContainerTemplate = moduleSettings.CategoryProducts.ContainerTemplate;
                        productList.ContainerCssClass = "StoreCategoryProductList";
      productList.Template = moduleSettings.CategoryProducts.Template;
                        productList.ItemCssClass = "StoreCategoryProductItem";
                        productList.AlternatingItemCssClass = "StoreCategoryProductAlternatingItem";
      productList.RowCount = int.Parse(moduleSettings.CategoryProducts.RowCount);
      productList.ColumnCount = int.Parse(moduleSettings.CategoryProducts.ColumnCount);
      productList.ColumnWidth = int.Parse(moduleSettings.CategoryProducts.ColumnWidth);
                        productList.Direction = moduleSettings.CategoryProducts.RepeatDirection;
      productList.ShowThumbnail = bool.Parse(moduleSettings.CategoryProducts.ShowThumbnail);
      productList.ThumbnailWidth = int.Parse(moduleSettings.CategoryProducts.ThumbnailWidth);
                        productList.ShowDetail = bool.Parse(moduleSettings.General.ShowProductDetail);
      productList.DetailPage = int.Parse(moduleSettings.CategoryProducts.DetailPage);
      break;
    }

    productList.DataSource = products;
    
    return productList;
   }
   else
   {
    return null;
   }
  }

  private Control LoadProductDetail()
  {
   ProductDetail productDetail = (ProductDetail)LoadControl(ModulePath + "ProductDetail.ascx");

   productDetail.ParentControl = this as PortalModuleBase;
            productDetail.ModuleConfiguration = this.ModuleConfiguration;
   productDetail.CategoryID = productInfo.CategoryID;
   productDetail.ShowThumbnail = bool.Parse(moduleSettings.ProductDetail.ShowThumbnail);
   productDetail.ThumbnailWidth = int.Parse(moduleSettings.ProductDetail.ThumbnailWidth);
   productDetail.ShowReviews = bool.Parse(moduleSettings.ProductDetail.ShowReviews);
   productDetail.DataSource = productInfo;

   return productDetail;
  }

  private ArrayList TruncateList(ArrayList list, int maxCount)
  {
   if (list.Count > maxCount)
   {
    list.RemoveRange(maxCount, list.Count - maxCount);
   }
   return list;
  }

        private string SEO(string seoResource, MetaTags metaType)
        {
            string tempResource = seoResource;
            string tempValue = "";
            MatchCollection matchCol = regTokens.Matches(tempResource);

            if (matchCol.Count > 0)
            {
                foreach (Match match in matchCol)
                {
                    switch (metaType)
                    {
                        case MetaTags.Title:
                            switch (match.Value.ToUpper())
                            {
                                case "[PAGETITLE]":
                                    tempValue = BasePage.Title;
                                    break;
                                case "[STORETITLE]":
                                    tempValue = storeInfo.Name;
                                    break;
                                case "[CATEGORYNAME]":
                                    if (catalogNav.CategoryID != Null.NullInteger)
                                    {
                                        tempValue = categoryInfo.CategoryName;
                                    }
                                    else
                                    {
                                        tempValue = "";
                                    }
                                    break;
                                default:
                                    tempValue = match.Value;
                                    break;
                            }
                            break;
                        case MetaTags.Keywords:
                            switch (match.Value.ToUpper())
                            {
                                case "[PAGEKEYWORDS]":
                                    tempValue = BasePage.KeyWords;
                                    break;
                                case "[STOREKEYWORDS]":
                                    tempValue = storeInfo.Keywords;
                                    break;
                                case "[CATEGORYKEYWORDS]":
                                    if (catalogNav.CategoryID != Null.NullInteger)
                                    {
                                        tempValue = categoryInfo.CategoryKeywords;
                                    }
                                    else
                                    {
                                        tempValue = "";
                                    }
                                    break;
                                default:
                                    tempValue = match.Value;
                                    break;
                            }
                            break;
                        case MetaTags.Description:
                            switch (match.Value.ToUpper())
                            {
                                case "[PAGEDESCRIPTION]":
                                    tempValue = BasePage.Description;
                                    break;
                                case "[STOREDESCRIPTION]":
                                    tempValue = storeInfo.Description;
                                    break;
                                case "[CATEGORYDESCRIPTION]":
                                    if (catalogNav.CategoryID != Null.NullInteger)
                                    {
                                        tempValue = categoryInfo.CategoryDescription;
                                    }
                                    else
                                    {
                                        tempValue = "";
                                    }
                                    break;
                                default:
                                    tempValue = match.Value;
                                    break;
                            }
                            break;
                    }
                    tempResource = tempResource.Replace(match.Value, tempValue);
                }
            }
            return tempResource.Trim();
        }

        #endregion

  #region IActionable Members

  public DotNetNuke.Entities.Modules.Actions.ModuleActionCollection ModuleActions
  {
   get
   {
    ModuleActionCollection actions = new ModuleActionCollection();
                if (storeInfo != null)
                {
                    actions.Add(GetNextActionID(), Localization.GetString("AddNewProduct", this.LocalResourceFile), ModuleActionType.AddContent, "", "", EditUrl("EditID", "Product"), false, SecurityAccessLevel.Edit, true, false);
                }
    return actions; 
   }
  }

  #endregion
 }
}


Continue - Part 2

dotnetnuke store product search module - part 2

Posted on 2:12:00 PM In: ,

ProductList.ascx.cs

using System;
using System.Globalization;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Modules.Store.Admin;
using DotNetNuke.Modules.Store.Catalog;
using DotNetNuke.Modules.Store.Components;
//using DotNetNuke.Modules.Store.Providers.Tax;
using DotNetNuke.Services.Localization;

namespace DotNetNuke.Modules.Store.WebControls
{
 /// 
 /// Summary description for Media.
 /// 
 public partial class ProductList : StoreControlBase
 {
  #region Private Declarations

        private ModuleSettings moduleSettings;
        private CatalogNavigation moduleNav;
  private ProductInfo productInfo;
        private CategoryController categoryControler;
        private int categoryID = 0;
  private string templatesPath = "";
  private string imagesPath = "";
  private string title = "";
        private string containerTemplate = "";
        private string containerCssClass = "";
  private string template = "";
        private string itemCssClass = "";
        private string alternatingItemCssClass = "";
  private int rowCount = 10;
  private int columnCount = 2;
  private int columnWidth = 200;
        private string direction = "";
  private bool showThumbnail = true;
  private int thumbnailWidth = 90;
  private bool showDetail = true;
  private int detailPageID = 0;
        private ProductListTypes listType;
        private StoreInfo storeInfo;
        private NumberFormatInfo LocalFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
        private ArrayList labelsPageInfo = new ArrayList();
        private ArrayList labelsPageNav = new ArrayList();
        private ArrayList buttonsPrevious = new ArrayList();
        private ArrayList buttonsNext = new ArrayList();
        private ArrayList placeholdersPageList = new ArrayList();
        private DataList lstProducts;

        

        #endregion

  #region Public Properties

  public int CategoryID
  {
   get {return categoryID;}
   set {categoryID = value;}
  }

  public string Title
  {
   get {return title;}
   set {title = value;}
  }

        public string ContainerTemplate
  {
            get { return containerTemplate; }
            set { containerTemplate = value; }
  }

        public string ContainerCssClass
  {
            get { return containerCssClass; }
            set { containerCssClass = value; }
  }

  public string Template
  {
   get {return template;}
   set {template = value;}
  }

  public string ItemCssClass
  {
            get { return itemCssClass; }
            set { itemCssClass = value; }
  }

        public string AlternatingItemCssClass
  {
            get { return alternatingItemCssClass; }
            set { alternatingItemCssClass = value; }
  }

  public int RowCount
  {
   get {return rowCount;}
   set {rowCount = value;}
  }

  public int ColumnCount
  {
   get {return columnCount;}
   set {columnCount = value;}
  }

  public int ColumnWidth
  {
   get {return columnWidth;}
   set {columnWidth = value;}
  }

        public string Direction
  {
            get { return direction; }
            set { direction = value; }
  }

  public bool ShowThumbnail
  {
   get {return showThumbnail;}
   set {showThumbnail = value;}
  }
  
  public int ThumbnailWidth
  {
   get {return thumbnailWidth;}
   set {thumbnailWidth = value;}
  }

  public bool ShowDetail
  {
            get { return showDetail; }
            set { showDetail = value; }
  }

  public int DetailPage
  {
   get { return detailPageID; }
   set { detailPageID = value; }
  }

        public ProductListTypes ListType
        {
            get { return listType; }
            set { listType = value; }
        }

  #endregion

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// 
  ///  Required method for Designer support - do not modify
  ///  the contents of this method with the code editor.
  /// 
  private void InitializeComponent()
  {
  }
  #endregion

  #region Events

  protected void Page_Load(object sender, EventArgs e)
  {
            if (storeInfo == null)
            {
                StoreController storeController = new StoreController();
                storeInfo = storeController.GetStoreInfo(PortalId);
                if (storeInfo.PortalTemplates)
                {
                    templatesPath = PortalSettings.HomeDirectoryMapPath + "Store\\";
                    imagesPath = PortalSettings.HomeDirectory + "Store/Templates/Images/";
                }
                else
                {
                    templatesPath = MapPath(ModulePath);
                    imagesPath = parentControl.ModulePath + "Templates/Images/";
                }
            }

            if (storeInfo.CurrencySymbol != string.Empty)
            {
                LocalFormat.CurrencySymbol = storeInfo.CurrencySymbol;
            }

            moduleSettings = new ModuleSettings(this.ModuleId, this.TabId);

            moduleNav = new CatalogNavigation(Request.QueryString);

            //0 indicates that no detail page is being used, so use current tabid
   if (this.DetailPage == 0) 
   {
    this.DetailPage = this.TabId;
   }
   moduleNav.TabId = this.DetailPage;

   if (moduleNav.PageIndex == Null.NullInteger)
   {
    moduleNav.PageIndex = 1;
   }

            if (containerTemplate == string.Empty)
            {
                this.Controls.Add(TemplateController.ParseTemplate(templatesPath, "ListContainer.htm", new ProcessTokenDelegate(processToken)));
            }
            else
            {
                this.Controls.Add(TemplateController.ParseTemplate(templatesPath, containerTemplate, new ProcessTokenDelegate(processToken)));
            }
            if (lstProducts != null) BindData();
        }

  private void lstProducts_ItemDataBound(object sender, DataListItemEventArgs e)
  {
   productInfo = (ProductInfo)e.Item.DataItem;

            if (columnWidth > 0)
       e.Item.Width = columnWidth;
            switch (e.Item.ItemType)
            {
                case ListItemType.Item:
                    e.Item.CssClass = itemCssClass;
                    break;
                case ListItemType.AlternatingItem:
                    e.Item.CssClass = alternatingItemCssClass;
                    break;
            }

            ProductDetail productListItem = (ProductDetail)LoadControl(ModulePath + "ProductDetail.ascx");
            productListItem.Template = template;
            productListItem.ParentControl = this.ParentControl;
            productListItem.CategoryID = productInfo.CategoryID;
            productListItem.ShowThumbnail = ShowThumbnail;
            productListItem.ThumbnailWidth = ThumbnailWidth;
            productListItem.DataSource = productInfo;
            productListItem.ShowDetail = (showDetail == false) & (detailPageID == Null.NullInteger) ? false : true;
            productListItem.DetailID = detailPageID;
            productListItem.InList = true;

            e.Item.Controls.Add(productListItem);
  }

  #endregion

  #region Protected Functions

  protected void BindData()
  {
   PagedDataSource pagedData = null;

   // Get the product data
   ArrayList productArray = (dataSource as ArrayList);
   if ((productArray == null) || (productArray.Count == 0))
   {
                foreach (Label lblPageNav in labelsPageNav)
                {
                    lblPageNav.Visible = false;
                }
            }
   else
   {
    int itemCount  = productArray.Count;
    int pageSize  = rowCount * columnCount;
    int currentPage  = moduleNav.PageIndex - 1; // Convert to zero-based index

                foreach (Label lblPageNav in labelsPageNav)
                {
                    lblPageNav.Visible = true;
                }

    // Created paged data source
    pagedData = new PagedDataSource();
                if (ViewState["productArray"] != null && IsPostBack)
                {
                    pagedData.DataSource = (ArrayList)ViewState["productArray"];
                }
                else
                {
                    pagedData.DataSource = productArray;
                    ViewState["productArray"] = pagedData.DataSource;
                }
    pagedData.AllowPaging = true;
    pagedData.PageSize = pageSize;
    pagedData.CurrentPageIndex = currentPage;

    UpdatePagingControls(itemCount, pageSize, moduleNav.PageIndex);
   }

   // Databind with product list
            if (lstProducts != null)
            {
                lstProducts.DataSource = pagedData;
                lstProducts.DataBind();

                if (lstProducts.Items.Count == 0)
                {
                    this.Visible = false;
                }
            }
        }

  protected void UpdatePagingControls(int itemCount, int pageSize, int currentPage)
  {
   StringDictionary replaceParams = new StringDictionary();

   // Get total pages
   int rem;
   int totalPages = Math.DivRem(itemCount, pageSize, out rem);
   if (rem > 0)
   {
    totalPages++;
   }

   // Hide and return if only one page
   if (totalPages == 1)
   {
                foreach (Label lblPageNav in labelsPageNav)
                {
                    lblPageNav.Visible = false;
                }
                return;
   }

   ////////////////////////////
   // Previous/Next Buttons

   int prevIndex = currentPage - 1;
   if ((prevIndex < 1) || (prevIndex > totalPages))
   {
    prevIndex = 1;
   }

   replaceParams["PageIndex"] = prevIndex.ToString();
            foreach (HyperLink btnPrev in buttonsPrevious)
            {
                btnPrev.NavigateUrl = moduleNav.GetNavigationUrl(replaceParams, storeInfo.StorePageID);
            }

   int nextIndex = currentPage + 1;
   if (nextIndex >= totalPages)
   {
    nextIndex = totalPages;
   }

   replaceParams["PageIndex"] = nextIndex.ToString();
            foreach (HyperLink btnNext in buttonsNext)
            {
                btnNext.NavigateUrl = moduleNav.GetNavigationUrl(replaceParams, storeInfo.StorePageID);
            }

   ////////////////////////////
   // Page Index List

   // Determine page range to display
   int rangeMin = currentPage - 10;
   int rangeMax = currentPage + 10;

   if (rangeMin < 1)
   {
    rangeMax = rangeMax + Math.Abs(rangeMin) + 1;
    rangeMin = 1;
   }

   if (rangeMax >= totalPages)
   {
    rangeMin = rangeMin - (rangeMax - totalPages);
    if (rangeMin <= 1)
    {
     rangeMin = 1;
    }

    rangeMax = totalPages;
   }

            foreach (PlaceHolder phPageList in placeholdersPageList)
            {
                // Create link for each page
                for (int i = rangeMin; i <= rangeMax; i++)
                {
                    replaceParams["PageIndex"] = i.ToString();

                    if (i == currentPage)
                    {
                        Label pageLabel = new Label();
                        pageLabel.Text = i.ToString();
                        pageLabel.CssClass = "StoreCurrentPageNumber";
                        phPageList.Controls.Add(pageLabel);
                        phPageList.Controls.Add(new LiteralControl("  "));
                    }
                    else
                    {
                        HyperLink pageLink = new HyperLink();
                        pageLink.Text = i.ToString();
                        pageLink.NavigateUrl = moduleNav.GetNavigationUrl(replaceParams, storeInfo.StorePageID);
                        pageLink.CssClass = "StorePageNumber";

                        phPageList.Controls.Add(pageLink);
                        phPageList.Controls.Add(new LiteralControl("  "));
                    }

                }
            }

            foreach (Label lblPageInfo in labelsPageInfo)
            {
                lblPageInfo.Text = string.Format(Localization.GetString("PageInfo.Text", this.LocalResourceFile), currentPage, totalPages);
            }
        }

        protected void ddlSortBy_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddlSortBy = (sender as DropDownList);
            if (ddlSortBy != null)
            {
                moduleNav.SortID = int.Parse(ddlSortBy.SelectedValue);
                moduleNav.SortDir = "ASC";
                moduleNav.PageIndex = Null.NullInteger;
            }
            Response.Redirect(moduleNav.GetNavigationUrl());
        }

        private void btnSortDir_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton button = (sender as ImageButton);
            if (button != null)
            {
                moduleNav.PageIndex = Null.NullInteger;
                if (button.CommandArgument.ToUpper() == "ASC")
                {
                    moduleNav.SortDir = "DESC";
                }
                else
                {
                    moduleNav.SortDir = "ASC";
                }
                Response.Redirect(moduleNav.GetNavigationUrl());
            }
        }

        private void btnMYSEARCH_Click(object sender, ImageClickEventArgs e)
        {
            //ImageButton button_Myserch = (sender as ImageButton);
            ImageButton button_Myserch = sender as ImageButton;
            if (button_Myserch != null)
            {
                moduleNav.PageIndex = Null.NullInteger;

                    moduleNav.SortDir = "DESC";

                    DropDownList ddlMYSEARCH = (DropDownList)this.FindControl("ddMYSEARCH");
                    TextBox txtMYSEARCH = (TextBox)this.FindControl("txtMYSEARCH");

                    if (ddlMYSEARCH != null && txtMYSEARCH != null)
                    //&& ddlMYSEARCH.SelectedValue.ToString() != null && txtMYSEARCH.Text.ToString() != null
                    {
                        moduleNav.SearchField = ddlMYSEARCH.SelectedValue.ToString();
                        moduleNav.SearchText = txtMYSEARCH.Text.ToString();
                    }
                    else
                    {
                        moduleNav.SearchField = "Manufacturer";
                        moduleNav.SearchText = "JK";

                    }

                Response.Redirect(moduleNav.GetNavigationUrl());
            }
        }



  #endregion

  #region Private Functions

  private Control processToken(string tokenName)
  {
   switch (tokenName.ToUpper())
   {
                case "LISTTITLE":
                    Label lblTitle = new Label();
                    lblTitle.CssClass = "StoreListTitle";
                    lblTitle.Text = title;
                    return lblTitle;

                case "PAGENAV":
                    if (ListType == ProductListTypes.Category || 
                        ListType == ProductListTypes.MySearchResult)
                    {
                        HyperLink btnPrevious = new HyperLink();
                        btnPrevious.Text = Localization.GetString("Previous.Text", this.LocalResourceFile);
                        btnPrevious.CssClass = "StorePagePrevious";
                        buttonsPrevious.Add(btnPrevious);

                        Literal lblSpace = new Literal();
                        lblSpace.Text = "  ";

                        HyperLink btnNext = new HyperLink();
                        btnNext.Text = Localization.GetString("Next.Text", this.LocalResourceFile);
                        btnNext.CssClass = "StorePageNext";
                        buttonsNext.Add(btnNext);

                        PlaceHolder phPageList = new PlaceHolder();
                        placeholdersPageList.Add(phPageList);

                        Label lblPageNav = new Label();
                        lblPageNav.Controls.Add(btnPrevious);
                        lblPageNav.Controls.Add(lblSpace);
                        lblPageNav.Controls.Add(phPageList);
                        lblPageNav.Controls.Add(btnNext);
                        lblPageNav.CssClass = "StorePageNav";
                        labelsPageNav.Add(lblPageNav);
                        return lblPageNav;
                    }
                    else
                        return null;

                case "PAGEINFO":
                    Label lblPageInfo = new Label();
                    lblPageInfo.CssClass = "StorePageInfo";
                    lblPageInfo.Text = string.Format(Localization.GetString("PageInfo.Text", this.LocalResourceFile), 1, 1);
                    labelsPageInfo.Add(lblPageInfo);
                    return lblPageInfo;

                case "PRODUCTS":
                    lstProducts = new DataList();
                    lstProducts.CssClass = containerCssClass;
                    lstProducts.RepeatLayout = RepeatLayout.Table;
                    switch (direction)
                    {
                        case "V":
                            lstProducts.RepeatDirection = RepeatDirection.Vertical;
                            break;
                        case "H":
                        default:
                            lstProducts.RepeatDirection = RepeatDirection.Horizontal;
                            break;
                    }
                    lstProducts.RepeatColumns = columnCount;
                    lstProducts.ItemDataBound += new DataListItemEventHandler(lstProducts_ItemDataBound);
                    return lstProducts;

                case "ITEMSCOUNT":
                    if (dataSource != null)
                    {
                        Label lblItems = new Label();
                        lblItems.CssClass = "StoreItemsCount";
                        lblItems.Text = string.Format(Localization.GetString("ItemsCount.Text", this.LocalResourceFile), (dataSource as ArrayList).Count);
                        return lblItems;
                    }
                    else
                        return null;

                case "SELECTEDCATEGORY":
                    if (ListType == ProductListTypes.Category)
                    {
                        categoryControler = new CategoryController();
                        CategoryInfo categoryInfo = categoryControler.GetCategory(CategoryID);
                        if (categoryInfo != null)
                        {
                            Label lblProductCategory = new Label();
                            lblProductCategory.Text = string.Format(Localization.GetString("SelectedCategory.Text", this.LocalResourceFile), categoryInfo.CategoryName);
                            lblProductCategory.CssClass = "StoreSelectedCategory";
                            return lblProductCategory;
                        }
                        else
                            return null;
                    }
                    else
                        return null;

                case "CATEGORIESBREADCRUMB":
                    if (ListType == ProductListTypes.Category || ListType == ProductListTypes.MySearchResult)
                    {
                        categoryControler = new CategoryController();
                        CategoryInfo categoryInfo = categoryControler.GetCategory(CategoryID);
                        if (categoryInfo != null)
                        {
                            string categoryName = categoryInfo.CategoryName;
                            bool hasParent = categoryInfo.ParentCategoryID != Null.NullInteger;
                            // Create label to contains all other controls
                            Label lblCategoriesBreadcrumb = new Label();
                            lblCategoriesBreadcrumb.CssClass = "StoreCategoriesBreadcrumb";
                            // Create "before" label with locale resource
                            Label lblBeforeBreadcrumb = new Label();
                            lblBeforeBreadcrumb.Text = Localization.GetString("BeforeCategoriesBreadcrumb", this.LocalResourceFile);
                            lblBeforeBreadcrumb.CssClass = "StoreBeforeBreadcrumb";
                            lblCategoriesBreadcrumb.Controls.Add(lblBeforeBreadcrumb);
                            // Create "between" label with locale resource
                            Literal litBetwenBreadcrumb = new Literal();
                            litBetwenBreadcrumb.Text = Localization.GetString("BetweenCategoriesBreadcrumb", this.LocalResourceFile);
                            // Create label to contains categories
                            Label lblBreadcrumb = new Label();
                            lblBreadcrumb.CssClass = "StoreBreadcrumb";
                            lblCategoriesBreadcrumb.Controls.Add(lblBreadcrumb);
                            int parentCategoryID = categoryInfo.ParentCategoryID;
                            // Create catalog navigation object to compute hyperlink URL
                            CatalogNavigation categogyNav = new CatalogNavigation();
                            categogyNav.TabId = this.TabId;
                            // Loop for parent categories
                            while (parentCategoryID != Null.NullInteger)
                            {
                                categoryInfo = categoryControler.GetCategory(categoryInfo.ParentCategoryID);
                                if (categoryInfo != null)
                                {
                                    parentCategoryID = categoryInfo.ParentCategoryID;
                                    if (parentCategoryID != Null.NullInteger)
                                    {
                                        lblBreadcrumb.Controls.Add(litBetwenBreadcrumb);
                                    }
                                    // Create hyperlink with the parent category
                                    HyperLink hlCategory = new HyperLink();
                                    hlCategory.Text = categoryInfo.CategoryName;
                                    categogyNav.CategoryID = categoryInfo.CategoryID;
                                    hlCategory.NavigateUrl = categogyNav.GetNavigationUrl();
                                    lblBreadcrumb.Controls.Add(hlCategory);
                                }
                                else
                                    parentCategoryID = Null.NullInteger;
                            }
                            // Insert separator if parent exist
                            if (hasParent)
                            {
                                lblBreadcrumb.Controls.Add(litBetwenBreadcrumb);
                            }
                            // Create literal with selected category name
                            Literal litSelectedCategory = new Literal();
                            litSelectedCategory.Text = categoryName;
                            lblBreadcrumb.Controls.Add(litSelectedCategory);
                            // Create "after" label with locale resource
                            Label lblAfterBreadcrumb = new Label();
                            lblAfterBreadcrumb.Text = Localization.GetString("AfterCategoriesBreadcrumb", this.LocalResourceFile);
                            lblAfterBreadcrumb.CssClass = "StoreAfterBreadcrumb";
                            lblCategoriesBreadcrumb.Controls.Add(lblAfterBreadcrumb);
                            return lblCategoriesBreadcrumb;
                        }
                        else
                            return null;
                    }
                    else
                        return null;

                case "SORTBY":
                    if (ListType == ProductListTypes.Category)
                    {
                        // Create label to contains all other controls
                        Label lblSortBy = new Label();
                        lblSortBy.CssClass = "StoreSortBy";
                        // Create literal text with locale resource
                        Literal litSortBy = new Literal();
                        litSortBy.Text = Localization.GetString("SortBy", this.LocalResourceFile);
                        lblSortBy.Controls.Add(litSortBy);
                        // Create DropDownList with column names
                        DropDownList ddlSortBy = new DropDownList();
                        ddlSortBy.AutoPostBack = true;
                        ddlSortBy.Items.Add(new ListItem(Localization.GetString("SortManufacturer", this.LocalResourceFile), "0"));
                        ddlSortBy.Items.Add(new ListItem(Localization.GetString("SortModelNumber", this.LocalResourceFile), "1"));
                        ddlSortBy.Items.Add(new ListItem(Localization.GetString("SortModelName", this.LocalResourceFile), "2"));
                        ddlSortBy.Items.Add(new ListItem(Localization.GetString("SortUnitPrice", this.LocalResourceFile), "3"));
                        if (moduleNav.SortID != Null.NullInteger)
                        {
                            // Currently selected sort column
                            ddlSortBy.SelectedIndex = moduleNav.SortID;
                        }
                        else
                        {
                            // Default sort column
                            ddlSortBy.SelectedValue = moduleSettings.CategoryProducts.SortBy;
                        }
                        ddlSortBy.SelectedIndexChanged += new EventHandler(ddlSortBy_SelectedIndexChanged);
                        lblSortBy.Controls.Add(ddlSortBy);

                        // Create Sort Order image button
                        ImageButton btnSortDir = new ImageButton();
                        string sortDir;
                        if (moduleNav.SortDir != Null.NullString)
                        {
                            // Currently selected sort direction
                            sortDir = moduleNav.SortDir;
                        }
                        else
                        {
                            // Default sort direction
                            sortDir = moduleSettings.CategoryProducts.SortDir;
                        }
                        string imageName;
                        string altText;
                        if (sortDir.ToUpper() == "ASC")
                        {
                            imageName = "arrow_up.png";
                            altText = Localization.GetString("SortAscending", this.LocalResourceFile);
                        }
                        else
                        {
                            imageName = "arrow_down.png";
                            altText = Localization.GetString("SortDescending", this.LocalResourceFile);
                        }
                        btnSortDir.CommandArgument = sortDir;
                        btnSortDir.AlternateText = altText;
                        if (storeInfo.PortalTemplates)
                        {
                            btnSortDir.ImageUrl = PortalSettings.HomeDirectory + "Store/Templates/Images/" + imageName;
                        }
                        else
                        {
                            btnSortDir.ImageUrl = this.TemplateSourceDirectory + "/Templates/Images/" + imageName;
                        }
                        btnSortDir.Click += new ImageClickEventHandler(btnSortDir_Click);
                        lblSortBy.Controls.Add(btnSortDir);
                        return lblSortBy;
                    }
                    else
                        return null;


                case "MYSEARCH":
                    if (ListType == ProductListTypes.Category)
                    {
                        // Create label to contains all other controls
                        Label lblMYSEARCH = new Label();
                        lblMYSEARCH.CssClass = "StoreSearchLable";
                        // Create literal text with locale resource
                        Literal litMYSEARCH = new Literal();
                        litMYSEARCH.Text = Localization.GetString("MYSEARCHBy", this.LocalResourceFile);
                        lblMYSEARCH.Controls.Add(litMYSEARCH);

                        // Create DropDownList with column names
                        DropDownList ddlMYSEARCH = new DropDownList();
                        ddlMYSEARCH.ID = "ddMYSEARCH";
                        ddlMYSEARCH.CssClass = "ddlMySearch";

                        ddlMYSEARCH.AutoPostBack = false;
                        ddlMYSEARCH.Items.Add(new ListItem(Localization.GetString("MYSEARCHManufacturer", this.LocalResourceFile), "Manufacturer"));
                        ddlMYSEARCH.Items.Add(new ListItem(Localization.GetString("MYSEARCHModelNumber", this.LocalResourceFile), "ModelNumber"));
                        ddlMYSEARCH.Items.Add(new ListItem(Localization.GetString("MYSEARCHModelName", this.LocalResourceFile), "ModelName"));

                        if (moduleNav.SearchField != Null.NullString)//Null.NullInteger
                        {
                            // Currently selected Search column
          ddlMYSEARCH.SelectedValue = moduleNav.SearchField.ToString();
                        }
                        else
                        {
                        }

                        

                        lblMYSEARCH.Controls.Add(ddlMYSEARCH);
                        
                        TextBox txtMYSEARCH = new TextBox();
                        txtMYSEARCH.ID = "txtMYSEARCH";
                        txtMYSEARCH.CssClass = "txtMySearch";

                        txtMYSEARCH.AutoPostBack = false;

                        if (moduleNav.SearchText != Null.NullString)
                        {
                            txtMYSEARCH.Text = moduleNav.SearchText;
                        }

                        // Create Searching image button
                        ImageButton btnMYSEARCH = new ImageButton();
                        
                        string imageName;
                        string altText;

                        string searching_field = ddlMYSEARCH.SelectedValue.ToString();
                        string searching_Text = txtMYSEARCH.Text.ToString();


                            imageName = "Search_button.png";
                            altText = Localization.GetString("SearchButtonAlt", this.LocalResourceFile);
                        
                        btnMYSEARCH.AlternateText = altText;
                        if (storeInfo.PortalTemplates)
                        {
                            btnMYSEARCH.ImageUrl = PortalSettings.HomeDirectory + "Store/Templates/Images/" + imageName;
                        }
                        else
                        {
                            btnMYSEARCH.ImageUrl = this.TemplateSourceDirectory + "/Templates/Images/" + imageName;
                        }

                        lblMYSEARCH.Controls.Add(txtMYSEARCH);
                        lblMYSEARCH.Controls.Add(btnMYSEARCH);
                        btnMYSEARCH.Click += new ImageClickEventHandler(btnMYSEARCH_Click);

                        return lblMYSEARCH;
                    }
                    else
                        return null;

    default:
     LiteralControl litText = new LiteralControl(tokenName);
     return litText;
   }
  }

  #endregion
 }
}



Continue - Part 3

dotnetnuke store product search module - part 3

Posted on 2:12:00 PM In: ,

CatalogSettings.ascx.cs

using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Modules.Store.Admin;
using DotNetNuke.Modules.Store.Catalog;
using DotNetNuke.Security;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;

namespace DotNetNuke.Modules.Store.WebControls
{
 /// 
 /// Summary description for Settings.
 /// 
    public partial class CatalogSettings : DotNetNuke.Entities.Modules.ModuleSettingsBase
 {
  protected ModuleSettings moduleSettings;
        private StoreInfo storeInfo;
        private string templatesPath = "";

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);

   moduleSettings = new ModuleSettings(this.ModuleId,  this.TabId);
  }
  
  /// 
  ///  Required method for Designer support - do not modify
  ///  the contents of this method with the code editor.
  /// 
  private void InitializeComponent()
  {

  }
  #endregion

  #region Events
  protected void Page_Load(object sender, System.EventArgs e)
  {
   try
   {
    if (!Page.IsPostBack)
    {
                    CategoryController categoryController = new CategoryController();
     ArrayList categoryList = categoryController.GetCategories(this.PortalId, false, -1);
     bool defaultExists = false;

                    lstDefaultCategory.Items.Add(new ListItem(Localization.GetString("SelectDefaultCategory", this.LocalResourceFile), "-1"));

     foreach (CategoryInfo categoryInfo in categoryList)
     {
      lstDefaultCategory.Items.Add(new ListItem(categoryInfo.CategoryName, categoryInfo.CategoryID.ToString()));

      if (categoryInfo.CategoryID.ToString() == moduleSettings.General.DefaultCategoryID)
      {
       defaultExists = true;
      }
     }

     if (lstDefaultCategory.Items.Count > 1 && Int32.Parse(moduleSettings.General.DefaultCategoryID) > 0 && defaultExists)
     {
      lstDefaultCategory.SelectedValue = moduleSettings.General.DefaultCategoryID;
     }
    }
   }
   catch(Exception ex)
   {
    Exceptions.ProcessModuleLoadException(this, ex);
   }
  }
  #endregion

  #region Base Method Implementations
  public override void LoadSettings()
  {
   try
   {
    if (!Page.IsPostBack)
    {
                    if (storeInfo == null)
                    {
                        StoreController storeController = new StoreController();
                        storeInfo = storeController.GetStoreInfo(PortalId);
                        if (storeInfo.PortalTemplates)
                        {
                            templatesPath = PortalSettings.HomeDirectoryMapPath + "Store\\";
                        }
                        else
                        {
                            templatesPath = MapPath(ModulePath) + "\\";
                        }
                    }

                    // Add tab name to combo boxes (Detail Page and Return Page) for each section
     TabController tabController = new TabController();
     ArrayList tabs = tabController.GetTabs(PortalId);

                    lstNPLDetailPage.Items.Add(new ListItem(Localization.GetString("NPLSamePage", this.LocalResourceFile), "0"));
                    lstFPLDetailPage.Items.Add(new ListItem(Localization.GetString("FPLSamePage", this.LocalResourceFile), "0"));
                    lstMSLDetailPage.Items.Add(new ListItem(Localization.GetString("MSLSamePage", this.LocalResourceFile), "0"));
                    lstPPLDetailPage.Items.Add(new ListItem(Localization.GetString("PPLSamePage", this.LocalResourceFile), "0"));
                    lstCPLDetailPage.Items.Add(new ListItem(Localization.GetString("CPLSamePage", this.LocalResourceFile), "0"));
                    lstPDSReturnPage.Items.Add(new ListItem(Localization.GetString("PDSSamePage", this.LocalResourceFile), "0"));

     foreach (TabInfo tabInfo in tabs)
     {
      if (!tabInfo.IsDeleted && !tabInfo.IsAdminTab && !tabInfo.IsSuperTab)
      {
                            lstNPLDetailPage.Items.Add(new ListItem(tabInfo.TabName, tabInfo.TabID.ToString()));
                            lstFPLDetailPage.Items.Add(new ListItem(tabInfo.TabName, tabInfo.TabID.ToString()));
                            lstMSLDetailPage.Items.Add(new ListItem(tabInfo.TabName, tabInfo.TabID.ToString()));
       lstPPLDetailPage.Items.Add(new ListItem(tabInfo.TabName, tabInfo.TabID.ToString()));
       lstCPLDetailPage.Items.Add(new ListItem(tabInfo.TabName, tabInfo.TabID.ToString()));
                            lstPDSReturnPage.Items.Add(new ListItem(tabInfo.TabName, tabInfo.TabID.ToString()));
      }
     }
     
     loadTemplates();

                    // Add directions to repeat combo boxes
                    String repeatDirection = Localization.GetString("RepeatDirectionHoriz", this.LocalResourceFile);
                    lstNPLRepeatDirection.Items.Add(new ListItem(repeatDirection, "H"));
                    lstFPLRepeatDirection.Items.Add(new ListItem(repeatDirection, "H"));
                    lstMSLRepeatDirection.Items.Add(new ListItem(repeatDirection, "H"));
                    lstPPLRepeatDirection.Items.Add(new ListItem(repeatDirection, "H"));
                    lstCPLRepeatDirection.Items.Add(new ListItem(repeatDirection, "H"));

                    repeatDirection = Localization.GetString("RepeatDirectionVert", this.LocalResourceFile);
                    lstNPLRepeatDirection.Items.Add(new ListItem(repeatDirection, "V"));
                    lstFPLRepeatDirection.Items.Add(new ListItem(repeatDirection, "V"));
                    lstMSLRepeatDirection.Items.Add(new ListItem(repeatDirection, "V"));
                    lstPPLRepeatDirection.Items.Add(new ListItem(repeatDirection, "V"));
                    lstCPLRepeatDirection.Items.Add(new ListItem(repeatDirection, "V"));

                    // Add column names to sort order combo boxes
                    String sortBy = "";
                    sortBy = Localization.GetString("SortManufacturer", this.LocalResourceFile);
                    lstCPLSortBy.Items.Add(new ListItem(sortBy, "0"));
                    sortBy = Localization.GetString("SortModelNumber", this.LocalResourceFile);
                    lstCPLSortBy.Items.Add(new ListItem(sortBy, "1"));
                    sortBy = Localization.GetString("SortModelName", this.LocalResourceFile);
                    lstCPLSortBy.Items.Add(new ListItem(sortBy, "2"));
                    sortBy = Localization.GetString("SortUnitPrice", this.LocalResourceFile);
                    lstCPLSortBy.Items.Add(new ListItem(sortBy, "3"));
                    String sortDir = "";
                    sortDir = Localization.GetString("SortAscending", this.LocalResourceFile);
                    lstCPLSortDir.Items.Add(new ListItem(sortDir, "ASC"));
                    sortDir = Localization.GetString("SortDescending", this.LocalResourceFile);
                    lstCPLSortDir.Items.Add(new ListItem(sortDir, "DESC"));

     // General Player Settings
                    chkEnableContentIndexing.Checked = bool.Parse(moduleSettings.General.EnableContentIndexing);
     chkUseDefaultCategory.Checked = bool.Parse(moduleSettings.General.UseDefaultCategory);
     chkShowMessage.Checked = bool.Parse(moduleSettings.General.ShowMessage);
                    chkShowNew.Checked = bool.Parse(moduleSettings.General.ShowNewProducts);
     chkShowFeatured.Checked = bool.Parse(moduleSettings.General.ShowFeaturedProducts);

                    chkShowMYSEARCH.Checked = bool.Parse(moduleSettings.General.ShowMYSEARCHProducts);

     chkShowPopular.Checked = bool.Parse(moduleSettings.General.ShowPopularProducts);
     chkShowCategory.Checked = bool.Parse(moduleSettings.General.ShowCategoryProducts);
     chkShowDetail.Checked = bool.Parse(moduleSettings.General.ShowProductDetail);
     lstDefaultCategory.SelectedValue = moduleSettings.General.DefaultCategoryID;
                    ListItem itemTemplate = lstTemplate.Items.FindByText(moduleSettings.General.Template);
                    if (itemTemplate != null)
                    {
                        itemTemplate.Selected = true;
                    }

                    // New list settings
                    ListItem itemNPLContainerTemplate = lstNPLContainerTemplate.Items.FindByText(moduleSettings.NewProducts.ContainerTemplate);
                    if (itemNPLContainerTemplate != null)
     {
                        itemNPLContainerTemplate.Selected = true;
     }
                    ListItem itemNPLTemplate = lstNPLTemplate.Items.FindByText(moduleSettings.NewProducts.Template);
                    if (itemNPLTemplate != null)
                    {
                        itemNPLTemplate.Selected = true;
                    }
                    txtNPLRowCount.Text = moduleSettings.NewProducts.RowCount;
                    txtNPLColumnCount.Text = moduleSettings.NewProducts.ColumnCount;
                    txtNPLColumnWidth.Text = moduleSettings.NewProducts.ColumnWidth;
                    ListItem itemNPLDirection = lstNPLRepeatDirection.Items.FindByValue(moduleSettings.NewProducts.RepeatDirection);
                    if (itemNPLDirection != null)
                    {
                        itemNPLDirection.Selected = true;
                    }
                    txtNPLThumbnailWidth.Text = moduleSettings.NewProducts.ThumbnailWidth;
                    chkNPLShowThumbnail.Checked = bool.Parse(moduleSettings.NewProducts.ShowThumbnail);
                    lstNPLDetailPage.SelectedValue = moduleSettings.NewProducts.DetailPage;

     // Featured list settings
                    ListItem itemFPLContainerTemplate = lstFPLContainerTemplate.Items.FindByText(moduleSettings.FeaturedProducts.ContainerTemplate);
                    if (itemFPLContainerTemplate != null)
     {
                        itemFPLContainerTemplate.Selected = true;
     }
     ListItem itemFPLTemplate = lstFPLTemplate.Items.FindByText(moduleSettings.FeaturedProducts.Template);
     if (itemFPLTemplate != null)
     {
      itemFPLTemplate.Selected = true;
     }
     txtFPLRowCount.Text = moduleSettings.FeaturedProducts.RowCount;
     txtFPLColumnCount.Text = moduleSettings.FeaturedProducts.ColumnCount;
     txtFPLColumnWidth.Text = moduleSettings.FeaturedProducts.ColumnWidth;
                    ListItem itemFPLDirection = lstFPLRepeatDirection.Items.FindByValue(moduleSettings.FeaturedProducts.RepeatDirection);
                    if (itemFPLDirection != null)
                    {
                        itemFPLDirection.Selected = true;
                    }
     txtFPLThumbnailWidth.Text = moduleSettings.FeaturedProducts.ThumbnailWidth;
     chkFPLShowThumbnail.Checked = bool.Parse(moduleSettings.FeaturedProducts.ShowThumbnail);
     lstFPLDetailPage.SelectedValue = moduleSettings.FeaturedProducts.DetailPage;


                    // MYSEARCH list settings
                    ListItem itemMSLContainerTemplate = lstMSLContainerTemplate.Items.FindByText(moduleSettings.MYSEARCHProducts.ContainerTemplate);
                    if (itemMSLContainerTemplate != null)
                    {
                        itemMSLContainerTemplate.Selected = true;
                    }
                    ListItem itemMSLTemplate = lstMSLTemplate.Items.FindByText(moduleSettings.MYSEARCHProducts.Template);
                    if (itemMSLTemplate != null)
                    {
                        itemMSLTemplate.Selected = true;
                    }
                    txtMSLRowCount.Text = moduleSettings.MYSEARCHProducts.RowCount;
                    txtMSLColumnCount.Text = moduleSettings.MYSEARCHProducts.ColumnCount;
                    txtMSLColumnWidth.Text = moduleSettings.MYSEARCHProducts.ColumnWidth;
                    ListItem itemMSLDirection = lstMSLRepeatDirection.Items.FindByValue(moduleSettings.MYSEARCHProducts.RepeatDirection);
                    if (itemMSLDirection != null)
                    {
                        itemMSLDirection.Selected = true;
                    }
                    txtMSLThumbnailWidth.Text = moduleSettings.MYSEARCHProducts.ThumbnailWidth;
                    chkMSLShowThumbnail.Checked = bool.Parse(moduleSettings.MYSEARCHProducts.ShowThumbnail);
                    lstMSLDetailPage.SelectedValue = moduleSettings.MYSEARCHProducts.DetailPage;


     // Popular list settings
                    ListItem itemPPLContainerTemplate = lstPPLContainerTemplate.Items.FindByText(moduleSettings.PopularProducts.ContainerTemplate);
                    if (itemPPLContainerTemplate != null)
     {
                        itemPPLContainerTemplate.Selected = true;
     }
     ListItem itemPPLTemplate = lstPPLTemplate.Items.FindByText(moduleSettings.PopularProducts.Template);
     if (itemPPLTemplate != null)
     {
      itemPPLTemplate.Selected = true;
     }
     txtPPLRowCount.Text = moduleSettings.PopularProducts.RowCount;
     txtPPLColumnCount.Text = moduleSettings.PopularProducts.ColumnCount;
     txtPPLColumnWidth.Text = moduleSettings.PopularProducts.ColumnWidth;
                    ListItem itemPPLDirection = lstPPLRepeatDirection.Items.FindByValue(moduleSettings.PopularProducts.RepeatDirection);
                    if (itemPPLDirection != null)
                    {
                        itemPPLDirection.Selected = true;
                    }
     txtPPLThumbnailWidth.Text = moduleSettings.PopularProducts.ThumbnailWidth;
     chkPPLShowThumbnail.Checked = bool.Parse(moduleSettings.PopularProducts.ShowThumbnail);
     lstPPLDetailPage.SelectedValue = moduleSettings.PopularProducts.DetailPage;

     // Category list settings
     ListItem itemCPLContainerTemplate = lstCPLContainerTemplate.Items.FindByText(moduleSettings.CategoryProducts.ContainerTemplate);
                    if (itemCPLContainerTemplate != null)
     {
                        itemCPLContainerTemplate.Selected = true;
     }
     ListItem itemCPLTemplate = lstCPLTemplate.Items.FindByText(moduleSettings.CategoryProducts.Template);
     if (itemCPLTemplate != null)
     {
      itemCPLTemplate.Selected = true;
     }
     txtCPLRowCount.Text = moduleSettings.CategoryProducts.RowCount;
     txtCPLColumnCount.Text = moduleSettings.CategoryProducts.ColumnCount;
     txtCPLColumnWidth.Text = moduleSettings.CategoryProducts.ColumnWidth;
                    ListItem itemCPLDirection = lstCPLRepeatDirection.Items.FindByValue(moduleSettings.CategoryProducts.RepeatDirection);
                    if (itemCPLDirection != null)
                    {
                        itemCPLDirection.Selected = true;
                    }
     txtCPLThumbnailWidth.Text = moduleSettings.CategoryProducts.ThumbnailWidth;
     chkCPLShowThumbnail.Checked = bool.Parse(moduleSettings.CategoryProducts.ShowThumbnail);
     lstCPLDetailPage.SelectedValue = moduleSettings.CategoryProducts.DetailPage;
                    lstCPLSortBy.SelectedValue = moduleSettings.CategoryProducts.SortBy;
                    lstCPLSortDir.SelectedValue = moduleSettings.CategoryProducts.SortDir;
                    chkCPLSubCategories.Checked = bool.Parse(moduleSettings.CategoryProducts.SubCategories);

     // Detail settings
     ListItem itemDetailTemplate = lstDetailTemplate.Items.FindByText(moduleSettings.ProductDetail.Template);
     if (itemDetailTemplate != null)
     {
      itemDetailTemplate.Selected = true;
     }
     chkDetailShowThumbnail.Checked = bool.Parse(moduleSettings.ProductDetail.ShowThumbnail);
     txtDetailThumbnailWidth.Text = moduleSettings.ProductDetail.ThumbnailWidth;
     chkDetailShowReviews.Checked = bool.Parse(moduleSettings.ProductDetail.ShowReviews);
                    lstPDSReturnPage.SelectedValue = moduleSettings.ProductDetail.ReturnPage;
    }
   }
   catch(Exception ex)
   {
    Exceptions.ProcessModuleLoadException(this, ex);
   }
  }

  public override void UpdateSettings()
  {
   try
   {
    PortalSecurity security = new PortalSecurity();

    // General Settings
                moduleSettings.General.EnableContentIndexing = chkEnableContentIndexing.Checked.ToString();
    moduleSettings.General.Template = lstTemplate.SelectedItem.Text;
    moduleSettings.General.UseDefaultCategory = chkUseDefaultCategory.Checked.ToString();
    moduleSettings.General.ShowMessage = chkShowMessage.Checked.ToString();
                moduleSettings.General.ShowNewProducts = chkShowNew.Checked.ToString();
                moduleSettings.General.ShowFeaturedProducts = chkShowFeatured.Checked.ToString();
    moduleSettings.General.ShowPopularProducts = chkShowPopular.Checked.ToString();
    moduleSettings.General.ShowCategoryProducts = chkShowCategory.Checked.ToString();
    moduleSettings.General.ShowProductDetail = chkShowDetail.Checked.ToString();
                moduleSettings.General.Template = lstTemplate.SelectedItem.Text;

    if (chkUseDefaultCategory.Checked)
    {
     moduleSettings.General.DefaultCategoryID = lstDefaultCategory.SelectedItem.Value;
    }

                // New list settings
                moduleSettings.NewProducts.ContainerTemplate = lstNPLContainerTemplate.SelectedItem.Text;
                moduleSettings.NewProducts.Template = lstNPLTemplate.SelectedItem.Text;
                moduleSettings.NewProducts.RowCount = security.InputFilter(txtNPLRowCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
                moduleSettings.NewProducts.ColumnCount = security.InputFilter(txtNPLColumnCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
                moduleSettings.NewProducts.ColumnWidth = security.InputFilter(txtNPLColumnWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
                moduleSettings.NewProducts.RepeatDirection = lstNPLRepeatDirection.SelectedItem.Value;
                moduleSettings.NewProducts.ThumbnailWidth = security.InputFilter(txtNPLThumbnailWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
                moduleSettings.NewProducts.ShowThumbnail = chkNPLShowThumbnail.Checked.ToString();
                moduleSettings.NewProducts.DetailPage = lstNPLDetailPage.SelectedItem.Value;

    // Featured list settings
                moduleSettings.FeaturedProducts.ContainerTemplate = lstFPLContainerTemplate.SelectedItem.Text;
    moduleSettings.FeaturedProducts.Template = lstFPLTemplate.SelectedItem.Text;
    moduleSettings.FeaturedProducts.RowCount = security.InputFilter(txtFPLRowCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
    moduleSettings.FeaturedProducts.ColumnCount = security.InputFilter(txtFPLColumnCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
    moduleSettings.FeaturedProducts.ColumnWidth = security.InputFilter(txtFPLColumnWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
                moduleSettings.FeaturedProducts.RepeatDirection = lstFPLRepeatDirection.SelectedItem.Value;
    moduleSettings.FeaturedProducts.ThumbnailWidth = security.InputFilter(txtFPLThumbnailWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
    moduleSettings.FeaturedProducts.ShowThumbnail = chkFPLShowThumbnail.Checked.ToString();
    moduleSettings.FeaturedProducts.DetailPage = lstFPLDetailPage.SelectedItem.Value;

                // MYSEARCH list settings
                moduleSettings.MYSEARCHProducts.ContainerTemplate = lstMSLContainerTemplate.SelectedItem.Text;
                moduleSettings.MYSEARCHProducts.Template = lstMSLTemplate.SelectedItem.Text;
                moduleSettings.MYSEARCHProducts.RowCount = security.InputFilter(txtMSLRowCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
                moduleSettings.MYSEARCHProducts.ColumnCount = security.InputFilter(txtMSLColumnCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
                moduleSettings.MYSEARCHProducts.ColumnWidth = security.InputFilter(txtMSLColumnWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
                moduleSettings.MYSEARCHProducts.RepeatDirection = lstMSLRepeatDirection.SelectedItem.Value;
                moduleSettings.MYSEARCHProducts.ThumbnailWidth = security.InputFilter(txtMSLThumbnailWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
                moduleSettings.MYSEARCHProducts.ShowThumbnail = chkMSLShowThumbnail.Checked.ToString();
                moduleSettings.MYSEARCHProducts.DetailPage = lstMSLDetailPage.SelectedItem.Value;

    // Popular list settings
                moduleSettings.PopularProducts.ContainerTemplate = lstPPLContainerTemplate.SelectedItem.Text;
    moduleSettings.PopularProducts.Template = lstPPLTemplate.SelectedItem.Text;
    moduleSettings.PopularProducts.RowCount = security.InputFilter(txtPPLRowCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
    moduleSettings.PopularProducts.ColumnCount = security.InputFilter(txtPPLColumnCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
    moduleSettings.PopularProducts.ColumnWidth = security.InputFilter(txtPPLColumnWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
                moduleSettings.PopularProducts.RepeatDirection = lstPPLRepeatDirection.SelectedItem.Value;
    moduleSettings.PopularProducts.ThumbnailWidth = security.InputFilter(txtPPLThumbnailWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
    moduleSettings.PopularProducts.ShowThumbnail = chkPPLShowThumbnail.Checked.ToString();
    moduleSettings.PopularProducts.DetailPage = lstPPLDetailPage.SelectedItem.Value;

    // Category list settings
                moduleSettings.CategoryProducts.ContainerTemplate = lstCPLContainerTemplate.SelectedItem.Text;
    moduleSettings.CategoryProducts.Template = lstCPLTemplate.SelectedItem.Text;
    moduleSettings.CategoryProducts.RowCount = security.InputFilter(txtCPLRowCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
    moduleSettings.CategoryProducts.ColumnCount = security.InputFilter(txtCPLColumnCount.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
    moduleSettings.CategoryProducts.ColumnWidth = security.InputFilter(txtCPLColumnWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
                moduleSettings.CategoryProducts.RepeatDirection = lstCPLRepeatDirection.SelectedItem.Value;
    moduleSettings.CategoryProducts.ThumbnailWidth = security.InputFilter(txtCPLThumbnailWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
    moduleSettings.CategoryProducts.ShowThumbnail = chkCPLShowThumbnail.Checked.ToString();
    moduleSettings.CategoryProducts.DetailPage = lstCPLDetailPage.SelectedItem.Value;
                moduleSettings.CategoryProducts.SortBy = lstCPLSortBy.SelectedItem.Value;
                moduleSettings.CategoryProducts.SortDir = lstCPLSortDir.SelectedItem.Value;
                moduleSettings.CategoryProducts.SubCategories = chkCPLSubCategories.Checked.ToString();

    // Detail settings
    moduleSettings.ProductDetail.Template = lstDetailTemplate.SelectedItem.Text;
    moduleSettings.ProductDetail.ShowThumbnail = chkDetailShowThumbnail.Checked.ToString();
    moduleSettings.ProductDetail.ThumbnailWidth = security.InputFilter(txtDetailThumbnailWidth.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting );
                moduleSettings.ProductDetail.ShowReviews = chkDetailShowReviews.Checked.ToString();
                moduleSettings.ProductDetail.ReturnPage = lstPDSReturnPage.SelectedItem.Value;
   }
   catch(Exception ex)
   {
    Exceptions.ProcessModuleLoadException(this, ex);
   }
  }

  #endregion

  #region Private Functions
  private void loadTemplates()
  {
            ArrayList templates = TemplateController.GetTemplates(templatesPath);

   foreach (TemplateInfo templateInfo in templates)
   {
    lstTemplate.Items.Add(new ListItem(templateInfo.Name,  templateInfo.Path));
                lstNPLContainerTemplate.Items.Add(new ListItem(templateInfo.Name, templateInfo.Path));
                lstNPLTemplate.Items.Add(new ListItem(templateInfo.Name, templateInfo.Path));
                lstFPLContainerTemplate.Items.Add(new ListItem(templateInfo.Name, templateInfo.Path));
    lstFPLTemplate.Items.Add(new ListItem(templateInfo.Name,  templateInfo.Path));

                lstMSLContainerTemplate.Items.Add(new ListItem(templateInfo.Name, templateInfo.Path)); //Prasad
                lstMSLTemplate.Items.Add(new ListItem(templateInfo.Name, templateInfo.Path)); //Prasad

                lstPPLContainerTemplate.Items.Add(new ListItem(templateInfo.Name, templateInfo.Path));
    lstPPLTemplate.Items.Add(new ListItem(templateInfo.Name,  templateInfo.Path));
                lstCPLContainerTemplate.Items.Add(new ListItem(templateInfo.Name, templateInfo.Path));
    lstCPLTemplate.Items.Add(new ListItem(templateInfo.Name,  templateInfo.Path));
    lstDetailTemplate.Items.Add(new ListItem(templateInfo.Name,  templateInfo.Path));
   }
  }
  #endregion
 }
}

 

Continue - Part 4

dotnetnuke store product search module - part 4

Posted on 2:12:00 PM In: ,

DesktopModules\Store\Catalog\Providers\DataProviders\SqlDataProvider\SqlDataProvider.cs
Add these methods

public override IDataReader GetPortalMYSEARCHProducts(int PortalID, bool Archived, string SearchText, string SearchField)
        {
            return SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "Store_Products_GetPortalMYSEARCHProducts", PortalID, Archived,SearchText,SearchField);
        }

public override IDataReader GetMYSEARCHProducts(int CategoryID, bool Archived, string SearchText, string SearchField)
        {
            return SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "Store_Products_GetMYSEARCHProducts", CategoryID, Archived,SearchText,SearchField);
        }




DesktopModules\Store\Catalog\ModuleSettings.cs

Change Public methods Like this.
public class ModuleSettings
 {
  public GeneralSettings General;
        public NewProductsSettings NewProducts;
        public FeaturedProductsSettings FeaturedProducts;
        public MYSEARCHProductsSettings MYSEARCHProducts; 
  public PopularProductsSettings PopularProducts;
  public CategoryProductsSettings CategoryProducts;
  public ProductDetailSettings ProductDetail;
  public CategoryMenuSettings CategoryMenu;

  public ModuleSettings(int moduleId, int tabId)
  {
   General = new GeneralSettings(moduleId, tabId);
            NewProducts = new NewProductsSettings(moduleId, tabId);
            FeaturedProducts = new FeaturedProductsSettings(moduleId, tabId);
            MYSEARCHProducts = new MYSEARCHProductsSettings(moduleId, tabId);
   PopularProducts = new PopularProductsSettings(moduleId, tabId);
   CategoryProducts = new CategoryProductsSettings(moduleId, tabId);
   ProductDetail = new ProductDetailSettings(moduleId, tabId);
   CategoryMenu = new CategoryMenuSettings(moduleId, tabId);
  }
 }



Add this Region with other settings. (ModuleSettings.cs)

#region MYSEARCH Product Settings
    public class MYSEARCHProductsSettings : SettingsWrapper
    {
        [ModuleSetting("mslcontainertemplate", "ListContainer.htm")]
        public string ContainerTemplate
        {
            [MethodImpl(MethodImplOptions.NoInlining)]
            get
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                return getSetting(m);
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            set
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                setSetting(m, value);
            }
        }

        [ModuleSetting("msltemplate", "MYSEARCHProduct.htm")]
        public string Template
        {
            [MethodImpl(MethodImplOptions.NoInlining)]
            get
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                return getSetting(m);
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            set
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                setSetting(m, value);
            }
        }

        [ModuleSetting("mslrowcount", "10")]
        public string RowCount
        {
            [MethodImpl(MethodImplOptions.NoInlining)]
            get
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                return getSetting(m);
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            set
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                setSetting(m, value);
            }
        }

        [ModuleSetting("mslcolumncount", "2")]
        public string ColumnCount
        {
            [MethodImpl(MethodImplOptions.NoInlining)]
            get
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                return getSetting(m);
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            set
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                setSetting(m, value);
            }
        }

        [ModuleSetting("mslcolumnwidth", "200")]
        public string ColumnWidth
        {
            [MethodImpl(MethodImplOptions.NoInlining)]
            get
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                return getSetting(m);
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            set
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                setSetting(m, value);
            }
        }

        [ModuleSetting("mslrepeatdirection", "H")]
        public string RepeatDirection
        {
            [MethodImpl(MethodImplOptions.NoInlining)]
            get
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                return getSetting(m);
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            set
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                setSetting(m, value);
            }
        }

        [ModuleSetting("mslshowthumbnail", "true")]
        public string ShowThumbnail
        {
            [MethodImpl(MethodImplOptions.NoInlining)]
            get
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                return getSetting(m);
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            set
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                setSetting(m, value);
            }
        }

        [ModuleSetting("mslthumbnailwidth", "90")]
        public string ThumbnailWidth
        {
            [MethodImpl(MethodImplOptions.NoInlining)]
            get
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                return getSetting(m);
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            set
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                setSetting(m, value);
            }
        }

        [ModuleSetting("msldetailtabid", "0")]
        public string DetailPage
        {
            [MethodImpl(MethodImplOptions.NoInlining)]
            get
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                return getSetting(m);
            }
            [MethodImpl(MethodImplOptions.NoInlining)]
            set
            {
                MethodBase m = MethodBase.GetCurrentMethod();
                setSetting(m, value);
            }
        }

        public MYSEARCHProductsSettings(int moduleId, int tabId): base(moduleId, tabId)
        {
        }
    }
    #endregion



ProductController.cs
Add these methods

public ArrayList GetPortalMYSEARCHProducts(int portalID, bool archived, string SearchText, string SearchField)
        {
            return CBO.FillCollection(DataProvider.Instance().GetPortalMYSEARCHProducts(portalID, archived,SearchText,SearchField), typeof(ProductInfo));
        }

public ArrayList GetMYSEARCHProducts(int categoryID, bool archived, string SearchText, string SearchField)
        {
            return CBO.FillCollection(DataProvider.Instance().GetMYSEARCHProducts(categoryID, archived,SearchText,SearchField), typeof(ProductInfo));
        }

Continue - Part 5

Visitors

free counters

Translate this page

AddThis

Share |

Random Post

Tags

Current Status

The On Demand Global Workforce - oDesk


Chat with me

My status