using System;
using System.Data;
using System.Xml;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Web;
using IlgharCMS;
using IlgharCMS.ShopModule;
public partial class CIlgharCMS : IlgharCMS.Lib.AdminPageBase
{
public CIlgharCMS()
: base("IlgharCMS.ShopModule/goods/list.dwt.aspx")
{}
protected XmlDocument _xmlTemplate;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_xmlTemplate = XmlData.GetXmlDocument();
if (!String.IsNullOrEmpty(Request.QueryString["GetPageCount"]))
                            {
                                Response.Write(t11077);
                                Response.End();
                            }
                        
}

protected string Condition()
{
	StringBuilder condition = new StringBuilder();
	string and = String.Empty;

	#region 是否回收
	string isRecycled = Request.QueryString["IsRecycled"];
	if (isRecycled == null)
		condition.Append(Alias.Goods.IsDeleted + "=false");
	else if (isRecycled != String.Empty)
		condition.Append(Alias.Goods.IsDeleted + "=" + isRecycled);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 是否发布
	string isReleased = Request.QueryString["IsReleased"];
	if (isReleased == null)
		condition.Append(and + Alias.Goods.IsReleased + "=true");
	else if (isReleased != String.Empty)
		condition.Append(and + Alias.Goods.IsReleased + "=" + isReleased);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 是否推荐
	string isRecommended = Request.QueryString["IsRecommended"];
	if (!String.IsNullOrEmpty(isRecommended))
		condition.Append(and + Alias.Goods.IsRecommended + "=" + isRecommended);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 是否置顶
	string isHeld = Request.QueryString["IsHeld"];
	if (!String.IsNullOrEmpty(isHeld))
		condition.Append(and + Alias.Goods.IsHeld + "=" + isHeld);
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 类别
	string categoryID = Request.QueryString["CategoryID"];
	if (!String.IsNullOrEmpty(categoryID))
	{
		if (Convert.ToBoolean(Request.QueryString["IncludeSubCategory"]))
		{
			condition.Append(and + Alias.Goods.IncludeSubCategory + "=" + categoryID);
		}
		else
		{
			if (categoryID == "0")
				condition.Append(and + Alias.Goods.CategoryID + " IS NULL");
			else
				condition.Append(and + Alias.Goods.CategoryID + "=" + categoryID);
		}
	}
	#endregion

	if (and == String.Empty && condition.Length != 0)
		and = " AND ";

	#region 关键词
	string keyword = Request.QueryString["Keyword"];
	if (!String.IsNullOrEmpty(keyword))
	{
		if (Request.QueryString["KeywordType"] == "Name")
			condition.Append(and + Alias.Goods.Name + " LIKE '%" + keyword + "%'");
	}
	#endregion
	
	return condition.ToString();
}

protected string Sort()
{
	string sort = String.Empty;
	switch (Request.QueryString["Sort"])
	{
		case "1":
			sort = Alias.Goods.UpdateTime + " DESC";
			break;
		case "2":
			sort = Alias.Goods.UpdateTime + " ASC";
			break;
		case "3":
			sort = Alias.Goods.HitCount + " DESC";
			break;
		case "4":
			sort = Alias.Goods.HitCount + " ASC";
			break;
		case "5":
			sort = Alias.Goods.Recommend + " DESC";
			break;
		case "6":
			sort = Alias.Goods.Recommend + " ASC";
			break;
		case "7":
			sort = Alias.Goods.Hold + " DESC";
			break;
		case "8":
			sort = Alias.Goods.Hold + " ASC";
			break;
		case "9":
			sort = Alias.Goods.InnerID + " DESC";
			break;
		case "10":
			sort = Alias.Goods.InnerID + " ASC";
			break;
		case "11":
			sort = Alias.Goods.Up + " DESC";
			break;
		case "12":
			sort = Alias.Goods.Up + " ASC";
			break;
		case "13":
			sort = Alias.Goods.Down + " DESC";
			break;
		case "14":
			sort = Alias.Goods.Down + " ASC";
			break;
		default:
			sort = Alias.Goods.UpdateTime + " DESC";
			break;
	}
	
	return sort;
}

protected bool Move
{
	get
	{
		if (Request.QueryString["Sort"] == "5" || Request.QueryString["Sort"] == "6")
			return Request.QueryString["IsRecommended"] == "true";
		else if (Request.QueryString["Sort"] == "7" || Request.QueryString["Sort"] == "8")
			return Request.QueryString["IsHeld"] == "true";
		else
			return false;
	}
}

protected bool ListByPicture
{
	get
	{
		if (Request.QueryString["ListByPicture"] != null)
			return Convert.ToBoolean(Request.QueryString["ListByPicture"]);
		else if (Request.Cookies["ListByPicture"] != null)
			return Convert.ToBoolean(Request.Cookies["ListByPicture"].Value);
		else
			return false;
	}
}

                        protected int t7302IDRecordCount
                        {
                            get
                            {
                                int instanceID;
instanceID = InstanceID;
                                using (IlgharCMS.ShopModule.IGoodsCategory bll = (IlgharCMS.ShopModule.IGoodsCategory)Manager.CreateObject("GoodsCategory", instanceID, ContentLang, false))
                                {
                                    string condition = null;


                                    return bll.GetRecordCount(condition);
                                }
                            }
                        }
                        
                            protected int t7302IDCounter = 0;
                            protected object t7302IDRecord = null;
                        
                            private DataTable t7302ID;
                            private DataTable t7302ID_
                            {
                                get
                                {
                                    string condition = null;


                                    string sort = null;

                                    int instanceID;
instanceID = InstanceID;

                                    using (IlgharCMS.ShopModule.IGoodsCategory bll = (IlgharCMS.ShopModule.IGoodsCategory)Manager.CreateObject("GoodsCategory", instanceID, ContentLang, false))
                                    {
                                        t7302ID = bll.List(-1, -1, condition, sort);
                                    }

                                    return t7302ID;
                                }
                            }
                        
                            protected string t7302
                            {
                                get
                                {
                                    XmlNode node = _xmlTemplate.SelectSingleNode("//t7302");
                                    Dictionary<string, object> replacementPair = new Dictionary<string, object>();
                                    
                                        replacementPair["{#t7740#}"] = new CustomBuildTree(
                                                                        delegate(TreeNode record, int index)
                                                                        {string t7740 = String.Empty;
if ((Convert.ToString((t7302IDRecord as TreeNode).Row[IlgharCMS.ShopModule.Alias.GoodsCategory.ID])==Request.QueryString["CategoryID"]))
{t7740 = _xmlTemplate.SelectSingleNode("/" + "/t7740/If").InnerText;}
else
{t7740 = _xmlTemplate.SelectSingleNode("/" + "/t7740/Else").InnerText;}

                                                                            return t7740;
                                                                        }
                                                                        );
                                                replacementPair["{#Control#}"] = null;replacementPair["{#ChildRecords#}"] = null;replacementPair["{#ID#}"] = IlgharCMS.ShopModule.Alias.GoodsCategory.ID;replacementPair["{#Name#}"] = IlgharCMS.ShopModule.Alias.GoodsCategory.Name;
                                    StringBuilder all = Manager.BuildTree(node, t7302ID_, replacementPair, IlgharCMS.ShopModule.Alias.GoodsCategory.ParentID, IlgharCMS.ShopModule.Alias.GoodsCategory.ID, ref t7302IDRecord, ref t7302IDCounter);
                                    
                                    
                                    
                                    return all.ToString();
                                }
                            }
                          
                        protected int ListRecordCount
                        {
                            get
                            {
                                int instanceID;
instanceID = InstanceID;
                                using (IlgharCMS.ShopModule.IGoods bll = (IlgharCMS.ShopModule.IGoods)Manager.CreateObject("Goods", instanceID, ContentLang, false))
                                {
                                    string condition = null;
condition += Condition();


                                    return bll.GetRecordCount(condition);
                                }
                            }
                        }
                        
                            protected int ListCounter = 0;
                            protected object ListRecord = null;
                            private DataTable ListData;
                            protected DataTable List
                            {
                                get
                                {
                                    if (ListData != null)
                                        return ListData;

                                    ListData = List_;
                                    return ListData;
                                }
                            }
                        
                                private DataTable List_
                                {
                                    get
                                    {
                                        string condition = null;
condition += Condition();


                                        string sort = null;sort = Sort();

                                        int instanceID;
instanceID = InstanceID;

                                        using (IlgharCMS.ShopModule.IGoods bll = (IlgharCMS.ShopModule.IGoods)Manager.CreateObject("Goods", instanceID, ContentLang, false))
                                        {
                                            ListData = bll.List(Convert.ToInt32(PageNumber), 20, condition, sort);
                                        }

                                        return ListData;
                                    }
                                }
                            
                            protected string t9210
                            {
                                get
                                {
                                    ListData = List_;

                                    XmlNode node = _xmlTemplate.SelectSingleNode("//t9210");
                                    StringBuilder all = new StringBuilder();
                                    all.Replace("{#Row#}", "");
                                    

                                    return all.ToString();
                                }
                            }
                                
                            protected int t9349IDCounter = 0;
                            protected object t9349IDRecord = null;
                            private DataTable t9349IDData;
                            protected DataTable t9349ID
                            {
                                get
                                {
                                    if (t9349IDData != null)
                                        return t9349IDData;

                                    t9349IDData = t9349ID_;
                                    return t9349IDData;
                                }
                            }
                        
                        protected DataTable t9349ID_
                        {
                            get
                            {
                                t9349IDData = List;
                                return t9349IDData;
                            }
                        }
                        protected string t9349
                        {
                            get
                            {
                                XmlNode node = _xmlTemplate.SelectSingleNode("//t9349");
                                Dictionary<string, object> replacementPair = new Dictionary<string, object>();
                                
                                        replacementPair[@"{#ContentLang#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {
                                                                            object t9538 = ContentLang;
                                                                            if (t9538 != null)
                                                                                return t9538.ToString();
                                                                            else
                                                                                return String.Empty;
                                                                        }
                                                                        );
                                                replacementPair["{#InnerID#}"] = IlgharCMS.ShopModule.Alias.Goods.InnerID;replacementPair["{#Thumbnail#}"] = IlgharCMS.ShopModule.Alias.Goods.Thumbnail;replacementPair["{#Name#}"] = IlgharCMS.ShopModule.Alias.Goods.Name;
                                StringBuilder all = Manager.Build(node, t9349ID_, replacementPair, ref t9349IDRecord, ref t9349IDCounter);
                                
                                
                                
                                return all.ToString();
                            }
                        }
                      
                            protected int t10431IDCounter = 0;
                            protected object t10431IDRecord = null;
                            private DataTable t10431IDData;
                            protected DataTable t10431ID
                            {
                                get
                                {
                                    if (t10431IDData != null)
                                        return t10431IDData;

                                    t10431IDData = t10431ID_;
                                    return t10431IDData;
                                }
                            }
                        
                        protected DataTable t10431ID_
                        {
                            get
                            {
                                t10431IDData = List;
                                return t10431IDData;
                            }
                        }
                        protected string t10431
                        {
                            get
                            {
                                XmlNode node = _xmlTemplate.SelectSingleNode("//t10431");
                                Dictionary<string, object> replacementPair = new Dictionary<string, object>();
                                
                                        replacementPair["{#t10595#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {string t10595 = String.Empty;
if (Move)
{t10595 = _xmlTemplate.SelectSingleNode("/" + "/t10595/If").InnerText;object t10681 = ImagePath;
t10595 = t10595.Replace("{#t10681#}",t10681 == null ? "" : t10681.ToString());
}

                                                                            return t10595;
                                                                        }
                                                                        );
                                                
                                        replacementPair[@"{#ContentLang#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {
                                                                            object t10752 = ContentLang;
                                                                            if (t10752 != null)
                                                                                return t10752.ToString();
                                                                            else
                                                                                return String.Empty;
                                                                        }
                                                                        );
                                                replacementPair["{#InnerID#}"] = IlgharCMS.ShopModule.Alias.Goods.InnerID;replacementPair["{#Name#}"] = IlgharCMS.ShopModule.Alias.Goods.Name;replacementPair["{#CreateTime#}"] = IlgharCMS.ShopModule.Alias.Goods.CreateTime;replacementPair["{#HitCount#}"] = IlgharCMS.ShopModule.Alias.Goods.HitCount;replacementPair["{#Up#}"] = IlgharCMS.ShopModule.Alias.Goods.Up;replacementPair["{#Down#}"] = IlgharCMS.ShopModule.Alias.Goods.Down;
                                StringBuilder all = Manager.Build(node, t10431ID_, replacementPair, ref t10431IDRecord, ref t10431IDCounter);
                                
                                
                                
                                return all.ToString();
                            }
                        }
                      
                            
                        private string t11077URL_ = null;
                        private string t11077URL
                        {
                            get
                            {
                                if (t11077URL_ != null)
                                    return t11077URL_;

                                StringBuilder result = new StringBuilder("?Page={Page}");
                                for (int i = 0; i < Request.QueryString.Count; i++)
                                {
                                    if (Request.QueryString.GetKey(i).ToLower() == "page")
                                        continue;

                                    result.Append("&amp;" + Request.QueryString.GetKey(i) + "=" + Server.UrlEncode(Request.QueryString[i]));
                                }

                                t11077URL_ = result.ToString();
                                return t11077URL_;
                            }
                        }
                        
                            private int t11077Page;
                            private int t11077PageCount;
                            private int t11077RecordCount;
                            private int t11077PageSize;
                            private int t11077Index;
                            protected string t11077
                            {
                                get
                                {
                                    t11077Page = Convert.ToInt32(PageNumber);
                                    if (t11077Page <= 0)
                                        t11077Page = 1;
                                    t11077PageSize = 20;
                                    t11077RecordCount = Convert.ToInt32(ListRecordCount);

                                    XmlNode node = _xmlTemplate.SelectSingleNode("//t11077");

                                    StringBuilder all = new StringBuilder(node.SelectSingleNode("All").InnerText);

                                    t11077PageCount = t11077RecordCount / t11077PageSize;
                                    if (t11077RecordCount % t11077PageSize > 0)
                                        t11077PageCount += 1;

                                    if (!String.IsNullOrEmpty(Request.QueryString["GetPageCount"]))
                                        return t11077PageCount.ToString();

                                    //--------------------------------------
                                    //Start : FirstPage
                                    StringBuilder firstPage = new StringBuilder();
                                    string firstPageYesTpl = node.SelectSingleNode("FirstPage/Yes").InnerText;
                                    string firstPageNoTpl = node.SelectSingleNode("FirstPage/No").InnerText;
                                    if (t11077Page > 1)
                                    {
                                        firstPage.Append(firstPageNoTpl);
                                        object t11589 = ImagePath;
firstPage.Replace("{#t11589#}", t11589 == null ? "" : t11589.ToString());
object t11670 = PageNumber;
firstPage.Replace("{#t11670#}", t11670 == null ? "" : t11670.ToString());
object t11716 = ImagePath;
firstPage.Replace("{#t11716#}", t11716 == null ? "" : t11716.ToString());

                                    }
                                    else
                                    {
                                        firstPage.Append(firstPageYesTpl);
                                        object t11389 = ImagePath;
firstPage.Replace("{#t11389#}", t11389 == null ? "" : t11389.ToString());
object t11454 = ImagePath;
firstPage.Replace("{#t11454#}", t11454 == null ? "" : t11454.ToString());

                                    }
                                    all.Replace("{#FirstPage#}", firstPage.ToString());
                                    //End : FirstPage
                                    //--------------------------------------

                                    //--------------------------------------
                                    //Start : CurrentPage
                                    StringBuilder currentPage = new StringBuilder();

                                    if (t11077PageCount > 1)
                                    {
                                        string currentPageYesTpl = node.SelectSingleNode("CurrentPage/Yes").InnerText;
                                        string currentPageNoTpl = node.SelectSingleNode("CurrentPage/No").InnerText;

                                        bool isAll = false;
                                        int pageEnd = 0;
                                        if (isAll)
                                        {
                                            t11077Index = 1;
                                            pageEnd = t11077PageCount;
                                        }
                                        else
                                        {
                                            t11077Index = t11077Page - 5;
                                            if (t11077Index <= 0)
                                                t11077Index = 1;

                                            pageEnd = t11077Page + 5;
                                            if (pageEnd > t11077PageCount)
                                                pageEnd = t11077PageCount;
                                        }

                                        while (t11077Index <= pageEnd)
                                        {
                                            if (t11077Index == t11077Page)
                                            {
                                                currentPage.Append(currentPageYesTpl);
                                                object t11902 = t11077Index;
currentPage.Replace("{#t11902#}", t11902 == null ? "" : t11902.ToString());

                                            }
                                            else
                                            {
                                                currentPage.Append(currentPageNoTpl);
                                                object t11997 = t11077Index;
currentPage.Replace("{#t11997#}", t11997 == null ? "" : t11997.ToString());
object t12011 = t11077Index;
currentPage.Replace("{#t12011#}", t12011 == null ? "" : t12011.ToString());

                                            }
                                            t11077Index++;
                                        }
                                    }
                                    all.Replace("{#CurrentPage#}", currentPage.ToString());
                                    //End : CurrentPage
                                    //--------------------------------------

                                    //--------------------------------------
                                    //Start : LastPage
                                    StringBuilder lastPage = new StringBuilder();

                                    string lastPageYesTpl = node.SelectSingleNode("LastPage/Yes").InnerText;
                                    string lastPageNoTpl = node.SelectSingleNode("LastPage/No").InnerText;

                                    if (t11077Page < t11077PageCount)
                                    {
                                        lastPage.Append(lastPageNoTpl);
                                        object t12318 = PageNumber;
lastPage.Replace("{#t12318#}", t12318 == null ? "" : t12318.ToString());
object t12364 = ImagePath;
lastPage.Replace("{#t12364#}", t12364 == null ? "" : t12364.ToString());
object t12444 = t11077PageCount;
lastPage.Replace("{#t12444#}", t12444 == null ? "" : t12444.ToString());
object t12471 = ImagePath;
lastPage.Replace("{#t12471#}", t12471 == null ? "" : t12471.ToString());

                                    }
                                    else
                                    {
                                        lastPage.Append(lastPageYesTpl);
                                        object t12137 = ImagePath;
lastPage.Replace("{#t12137#}", t12137 == null ? "" : t12137.ToString());
object t12201 = ImagePath;
lastPage.Replace("{#t12201#}", t12201 == null ? "" : t12201.ToString());

                                    }
                                    all.Replace("{#LastPage#}", lastPage.ToString());
                                    //End : LastPage
                                    //--------------------------------------

                                    object t11215 = t11077RecordCount;
all.Replace("{#t11215#}", t11215 == null ? "" : t11215.ToString());
object t11240 = PageNumber;
all.Replace("{#t11240#}", t11240 == null ? "" : t11240.ToString());
object t11260 = (t11077Page - 1) * t11077PageSize + 1;
all.Replace("{#t11260#}", t11260 == null ? "" : t11260.ToString());
object t11276 = t11077RecordCount < t11077Page * t11077PageSize ? t11077RecordCount : t11077Page * t11077PageSize;
all.Replace("{#t11276#}", t11276 == null ? "" : t11276.ToString());


                                    return all.ToString();
                                }
                            }
                          }
