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



_513.gif)


Friday, November 09, 2012 10:45:00 AM
Tremendous thingѕ here. I am very satisfied to peer youг poѕt.
Thanκ уοu а lot аnd І am lοoκing ahead
to touсh you. Wіll уou kindly droρ me a mail?
Look at my web site ... rulett taktikák