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.ArticleModule;
public partial class CIlgharCMS : IlgharCMS.Lib.AdminPageBase
{
public CIlgharCMS()
: base("IlgharCMS.ArticleModule/article/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(t11519);
                                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.Article.IsDeleted + "=false");
	else if (isRecycled != String.Empty)
		condition.Append(Alias.Article.IsDeleted + "=" + isRecycled);
	#endregion

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

	#region 是否审核
	string isChecked = Request.QueryString["IsChecked"];
	if (isChecked == null)
		condition.Append(and + Alias.Article.IsChecked + "=true");
	else if (isChecked != String.Empty)
		condition.Append(and + Alias.Article.IsChecked + "=" + isChecked);
	#endregion

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

	#region 是否推荐
	string isRecommended = Request.QueryString["IsRecommended"];
	if (!String.IsNullOrEmpty(isRecommended))
		condition.Append(and + Alias.Article.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.Article.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.Article.IncludeSubCategory + "=" + categoryID);
		}
		else
		{
			if (categoryID == "0")
				condition.Append(and + Alias.Article.CategoryID + " IS NULL");
			else
				condition.Append(and + Alias.Article.CategoryID + "=" + categoryID);
		}
	}
	#endregion

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

	#region 类型
	string type = Request.QueryString["Type"];
	if (!String.IsNullOrEmpty(type))
		condition.Append(and + Alias.Article.Type + "='" + type + "'");
	#endregion

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

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

protected string Sort()
{
	string sort = String.Empty;
	switch (Request.QueryString["Sort"])
	{
		case "1":
			sort = Alias.Article.UpdateTime + " DESC";
			break;
		case "2":
			sort = Alias.Article.UpdateTime + " ASC";
			break;
		case "3":
			sort = Alias.Article.HitCount + " DESC";
			break;
		case "4":
			sort = Alias.Article.HitCount + " ASC";
			break;
		case "5":
			sort = Alias.Article.Recommend + " DESC";
			break;
		case "6":
			sort = Alias.Article.Recommend + " ASC";
			break;
		case "7":
			sort = Alias.Article.Hold + " DESC";
			break;
		case "8":
			sort = Alias.Article.Hold + " ASC";
			break;
		case "9":
			sort = Alias.Article.InnerID + " DESC";
			break;
		case "10":
			sort = Alias.Article.InnerID + " ASC";
			break;
		case "11":
			sort = Alias.Article.Up + " DESC";
			break;
		case "12":
			sort = Alias.Article.Up + " ASC";
			break;
		case "13":
			sort = Alias.Article.Down + " DESC";
			break;
		case "14":
			sort = Alias.Article.Down + " ASC";
			break;
		default:
			sort = Alias.Article.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 int t7905IDRecordCount
                        {
                            get
                            {
                                int instanceID;
instanceID = InstanceID;
                                using (IlgharCMS.ArticleModule.IArticleCategory bll = (IlgharCMS.ArticleModule.IArticleCategory)Manager.CreateObject("ArticleCategory", instanceID, ContentLang, false))
                                {
                                    string condition = null;


                                    return bll.GetRecordCount(condition);
                                }
                            }
                        }
                        
                            protected int t7905IDCounter = 0;
                            protected object t7905IDRecord = null;
                        
                            private DataTable t7905ID;
                            private DataTable t7905ID_
                            {
                                get
                                {
                                    string condition = null;


                                    string sort = null;

                                    int instanceID;
instanceID = InstanceID;

                                    using (IlgharCMS.ArticleModule.IArticleCategory bll = (IlgharCMS.ArticleModule.IArticleCategory)Manager.CreateObject("ArticleCategory", instanceID, ContentLang, false))
                                    {
                                        t7905ID = bll.List(-1, -1, condition, sort);
                                    }

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

                                                                            return t8345;
                                                                        }
                                                                        );
                                                replacementPair["{#Control#}"] = null;replacementPair["{#ChildRecords#}"] = null;replacementPair["{#ID#}"] = IlgharCMS.ArticleModule.Alias.ArticleCategory.ID;replacementPair["{#Name#}"] = IlgharCMS.ArticleModule.Alias.ArticleCategory.Name;
                                    StringBuilder all = Manager.BuildTree(node, t7905ID_, replacementPair, IlgharCMS.ArticleModule.Alias.ArticleCategory.ParentID, IlgharCMS.ArticleModule.Alias.ArticleCategory.ID, ref t7905IDRecord, ref t7905IDCounter);
                                    
                                    
                                    
                                    return all.ToString();
                                }
                            }
                          
                        protected int ListRecordCount
                        {
                            get
                            {
                                int instanceID;
instanceID = InstanceID;
                                using (IlgharCMS.ArticleModule.IArticle bll = (IlgharCMS.ArticleModule.IArticle)Manager.CreateObject("Article", 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.ArticleModule.IArticle bll = (IlgharCMS.ArticleModule.IArticle)Manager.CreateObject("Article", instanceID, ContentLang, false))
                                        {
                                            ListData = bll.List(Convert.ToInt32(PageNumber), 20, condition, sort);
                                        }

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

                                                                            return t11030;
                                                                        }
                                                                        );
                                                
                                        replacementPair[@"{#ContentLang#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {
                                                                            object t11185 = ContentLang;
                                                                            if (t11185 != null)
                                                                                return t11185.ToString();
                                                                            else
                                                                                return String.Empty;
                                                                        }
                                                                        );
                                                replacementPair["{#InnerID#}"] = IlgharCMS.ArticleModule.Alias.Article.InnerID;replacementPair["{#Title#}"] = IlgharCMS.ArticleModule.Alias.Article.Title;replacementPair["{#Creator#}"] = IlgharCMS.ArticleModule.Alias.Article.Creator;replacementPair["{#UpdateTime#}"] = IlgharCMS.ArticleModule.Alias.Article.UpdateTime;replacementPair["{#HitCount#}"] = IlgharCMS.ArticleModule.Alias.Article.HitCount;replacementPair["{#Up#}"] = IlgharCMS.ArticleModule.Alias.Article.Up;replacementPair["{#Down#}"] = IlgharCMS.ArticleModule.Alias.Article.Down;
                                    StringBuilder all = Manager.Build(node, List_, replacementPair, ref ListRecord, ref ListCounter);
                                    
                                    
                                    
                                    return all.ToString();
                                }
                            }
                          
                            
                        private string t11519URL_ = null;
                        private string t11519URL
                        {
                            get
                            {
                                if (t11519URL_ != null)
                                    return t11519URL_;

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

                                t11519URL_ = result.ToString();
                                return t11519URL_;
                            }
                        }
                        
                            private int t11519Page;
                            private int t11519PageCount;
                            private int t11519RecordCount;
                            private int t11519PageSize;
                            private int t11519Index;
                            protected string t11519
                            {
                                get
                                {
                                    t11519Page = Convert.ToInt32(PageNumber);
                                    if (t11519Page <= 0)
                                        t11519Page = 1;
                                    t11519PageSize = 20;
                                    t11519RecordCount = Convert.ToInt32(ListRecordCount);

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

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

                                    t11519PageCount = t11519RecordCount / t11519PageSize;
                                    if (t11519RecordCount % t11519PageSize > 0)
                                        t11519PageCount += 1;

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

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

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

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

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

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

                                        bool isAll = false;
                                        int pageEnd = 0;
                                        if (isAll)
                                        {
                                            t11519Index = 1;
                                            pageEnd = t11519PageCount;
                                        }
                                        else
                                        {
                                            t11519Index = t11519Page - 5;
                                            if (t11519Index <= 0)
                                                t11519Index = 1;

                                            pageEnd = t11519Page + 5;
                                            if (pageEnd > t11519PageCount)
                                                pageEnd = t11519PageCount;
                                        }

                                        while (t11519Index <= pageEnd)
                                        {
                                            if (t11519Index == t11519Page)
                                            {
                                                currentPage.Append(currentPageYesTpl);
                                                object t12344 = t11519Index;
currentPage.Replace("{#t12344#}", t12344 == null ? "" : t12344.ToString());

                                            }
                                            else
                                            {
                                                currentPage.Append(currentPageNoTpl);
                                                object t12439 = t11519Index;
currentPage.Replace("{#t12439#}", t12439 == null ? "" : t12439.ToString());
object t12453 = t11519Index;
currentPage.Replace("{#t12453#}", t12453 == null ? "" : t12453.ToString());

                                            }
                                            t11519Index++;
                                        }
                                    }
                                    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 (t11519Page < t11519PageCount)
                                    {
                                        lastPage.Append(lastPageNoTpl);
                                        object t12760 = PageNumber;
lastPage.Replace("{#t12760#}", t12760 == null ? "" : t12760.ToString());
object t12806 = ImagePath;
lastPage.Replace("{#t12806#}", t12806 == null ? "" : t12806.ToString());
object t12886 = t11519PageCount;
lastPage.Replace("{#t12886#}", t12886 == null ? "" : t12886.ToString());
object t12913 = ImagePath;
lastPage.Replace("{#t12913#}", t12913 == null ? "" : t12913.ToString());

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

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

                                    object t11657 = t11519RecordCount;
all.Replace("{#t11657#}", t11657 == null ? "" : t11657.ToString());
object t11682 = PageNumber;
all.Replace("{#t11682#}", t11682 == null ? "" : t11682.ToString());
object t11702 = (t11519Page - 1) * t11519PageSize + 1;
all.Replace("{#t11702#}", t11702 == null ? "" : t11702.ToString());
object t11718 = t11519RecordCount < t11519Page * t11519PageSize ? t11519RecordCount : t11519Page * t11519PageSize;
all.Replace("{#t11718#}", t11718 == null ? "" : t11718.ToString());


                                    return all.ToString();
                                }
                            }
                          }
