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/ajax_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(t5835);
                                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 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 t4080
                            {
                                get
                                {
                                    ListData = List_;

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

                                    return all.ToString();
                                }
                            }
                                
                            protected int t4215IDCounter = 0;
                            protected object t4215IDRecord = null;
                            private DataTable t4215IDData;
                            protected DataTable t4215ID
                            {
                                get
                                {
                                    if (t4215IDData != null)
                                        return t4215IDData;

                                    t4215IDData = t4215ID_;
                                    return t4215IDData;
                                }
                            }
                        
                        protected DataTable t4215ID_
                        {
                            get
                            {
                                t4215IDData = List;
                                return t4215IDData;
                            }
                        }
                        protected string t4215
                        {
                            get
                            {
                                XmlNode node = _xmlTemplate.SelectSingleNode("//t4215");
                                Dictionary<string, object> replacementPair = new Dictionary<string, object>();
                                
                                        replacementPair[@"{#ContentLang#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {
                                                                            object t4392 = ContentLang;
                                                                            if (t4392 != null)
                                                                                return t4392.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, t4215ID_, replacementPair, ref t4215IDRecord, ref t4215IDCounter);
                                
                                
                                
                                return all.ToString();
                            }
                        }
                      
                            protected int t5225IDCounter = 0;
                            protected object t5225IDRecord = null;
                            private DataTable t5225IDData;
                            protected DataTable t5225ID
                            {
                                get
                                {
                                    if (t5225IDData != null)
                                        return t5225IDData;

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

                                                                            return t5381;
                                                                        }
                                                                        );
                                                
                                        replacementPair[@"{#ContentLang#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {
                                                                            object t5532 = ContentLang;
                                                                            if (t5532 != null)
                                                                                return t5532.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, t5225ID_, replacementPair, ref t5225IDRecord, ref t5225IDCounter);
                                
                                
                                
                                return all.ToString();
                            }
                        }
                      
                            
                        private string t5835URL_ = null;
                        private string t5835URL
                        {
                            get
                            {
                                if (t5835URL_ != null)
                                    return t5835URL_;

                                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]));
                                }

                                t5835URL_ = result.ToString();
                                return t5835URL_;
                            }
                        }
                        
                            private int t5835Page;
                            private int t5835PageCount;
                            private int t5835RecordCount;
                            private int t5835PageSize;
                            private int t5835Index;
                            protected string t5835
                            {
                                get
                                {
                                    t5835Page = Convert.ToInt32(PageNumber);
                                    if (t5835Page <= 0)
                                        t5835Page = 1;
                                    t5835PageSize = 20;
                                    t5835RecordCount = Convert.ToInt32(ListRecordCount);

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

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

                                    t5835PageCount = t5835RecordCount / t5835PageSize;
                                    if (t5835RecordCount % t5835PageSize > 0)
                                        t5835PageCount += 1;

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

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

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

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

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

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

                                        bool isAll = false;
                                        int pageEnd = 0;
                                        if (isAll)
                                        {
                                            t5835Index = 1;
                                            pageEnd = t5835PageCount;
                                        }
                                        else
                                        {
                                            t5835Index = t5835Page - 5;
                                            if (t5835Index <= 0)
                                                t5835Index = 1;

                                            pageEnd = t5835Page + 5;
                                            if (pageEnd > t5835PageCount)
                                                pageEnd = t5835PageCount;
                                        }

                                        while (t5835Index <= pageEnd)
                                        {
                                            if (t5835Index == t5835Page)
                                            {
                                                currentPage.Append(currentPageYesTpl);
                                                object t6628 = t5835Index;
currentPage.Replace("{#t6628#}", t6628 == null ? "" : t6628.ToString());

                                            }
                                            else
                                            {
                                                currentPage.Append(currentPageNoTpl);
                                                object t6717 = t5835Index;
currentPage.Replace("{#t6717#}", t6717 == null ? "" : t6717.ToString());
object t6731 = t5835Index;
currentPage.Replace("{#t6731#}", t6731 == null ? "" : t6731.ToString());

                                            }
                                            t5835Index++;
                                        }
                                    }
                                    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 (t5835Page < t5835PageCount)
                                    {
                                        lastPage.Append(lastPageNoTpl);
                                        object t7020 = PageNumber;
lastPage.Replace("{#t7020#}", t7020 == null ? "" : t7020.ToString());
object t7066 = ImagePath;
lastPage.Replace("{#t7066#}", t7066 == null ? "" : t7066.ToString());
object t7144 = t5835PageCount;
lastPage.Replace("{#t7144#}", t7144 == null ? "" : t7144.ToString());
object t7171 = ImagePath;
lastPage.Replace("{#t7171#}", t7171 == null ? "" : t7171.ToString());

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

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

                                    object t5969 = t5835RecordCount;
all.Replace("{#t5969#}", t5969 == null ? "" : t5969.ToString());
object t5994 = PageNumber;
all.Replace("{#t5994#}", t5994 == null ? "" : t5994.ToString());
object t6014 = (t5835Page - 1) * t5835PageSize + 1;
all.Replace("{#t6014#}", t6014 == null ? "" : t6014.ToString());
object t6030 = t5835RecordCount < t5835Page * t5835PageSize ? t5835RecordCount : t5835Page * t5835PageSize;
all.Replace("{#t6030#}", t6030 == null ? "" : t6030.ToString());


                                    return all.ToString();
                                }
                            }
                          }
