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.GuestBookModule;
public partial class CIlgharCMS : IlgharCMS.Lib.AdminPageBase
{
public CIlgharCMS()
: base("IlgharCMS.GuestBookModule/guest_book/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(t7424);
                                Response.End();
                            }
                        
}

                            protected System.Collections.Generic.Dictionary<System.String,System.String> Config
                            {
                                get
                                {
                                    object id = null;
                                    
                                    if (_ConfigID != null && _ConfigID == id)
                                        return _Config;

                                    int instanceID;
instanceID = InstanceID;

                                    using (IlgharCMS.GuestBookModule.IInstanceConfig bll = (IlgharCMS.GuestBookModule.IInstanceConfig)Manager.CreateObject("InstanceConfig", instanceID, ContentLang, false))
                                    {
                                        _ConfigID = id;
                                        _Config = bll.GetBasicSettings();
                                    }

                                    return _Config;
                                }
                            }
                            private System.Collections.Generic.Dictionary<System.String,System.String> _Config;
                            private object _ConfigID;
                            
protected string Condition()
{
	StringBuilder condition = new StringBuilder();
	string and = String.Empty;

	#region 是否审核
	string isChecked = Request.QueryString["IsChecked"];
	if (isChecked == null && Request.Cookies["IsChecked"] != null)
		isChecked = Request.Cookies["IsChecked"].Value;

	if (isChecked == null)
		condition.Append(and + Alias.GuestBook.IsChecked + "=true");
	else if (isChecked != String.Empty && isChecked != "*")
		condition.Append(and + Alias.GuestBook.IsChecked + "=" + isChecked);
	#endregion

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

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

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

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

protected string Sort()
{
	string sort = String.Empty;
	switch (Request.QueryString["Sort"])
	{
		case "1":
			sort = Alias.GuestBook.CreateTime + " DESC";
			break;
		case "2":
			sort = Alias.GuestBook.CreateTime + " ASC";
			break;
		default:
			sort = Alias.GuestBook.CreateTime + " DESC";
			break;
	}
	
	return sort;
}

                        protected int t4449IDRecordCount
                        {
                            get
                            {
                                int instanceID;
instanceID = InstanceID;
                                using (IlgharCMS.GuestBookModule.ICategory bll = (IlgharCMS.GuestBookModule.ICategory)Manager.CreateObject("Category", instanceID, ContentLang, false))
                                {
                                    string condition = null;


                                    return bll.GetRecordCount(condition);
                                }
                            }
                        }
                        
                            protected int t4449IDCounter = 0;
                            protected object t4449IDRecord = null;
                        
                            private DataTable t4449ID;
                            private DataTable t4449ID_
                            {
                                get
                                {
                                    string condition = null;


                                    string sort = null;

                                    int instanceID;
instanceID = InstanceID;

                                    using (IlgharCMS.GuestBookModule.ICategory bll = (IlgharCMS.GuestBookModule.ICategory)Manager.CreateObject("Category", instanceID, ContentLang, false))
                                    {
                                        t4449ID = bll.List(-1, -1, condition, sort);
                                    }

                                    return t4449ID;
                                }
                            }
                        
                            protected string t4449
                            {
                                get
                                {
                                    XmlNode node = _xmlTemplate.SelectSingleNode("//t4449");
                                    Dictionary<string, object> replacementPair = new Dictionary<string, object>();
                                    replacementPair["{#Control#}"] = null;replacementPair["{#ChildRecords#}"] = null;replacementPair["{#ID#}"] = IlgharCMS.GuestBookModule.Alias.Category.ID;replacementPair["{#Name#}"] = IlgharCMS.GuestBookModule.Alias.Category.Name;
                                    StringBuilder all = Manager.BuildTree(node, t4449ID_, replacementPair, IlgharCMS.GuestBookModule.Alias.Category.ParentID, IlgharCMS.GuestBookModule.Alias.Category.ID, ref t4449IDRecord, ref t4449IDCounter);
                                    
                                    
                                    
                                    return all.ToString();
                                }
                            }
                          
                        protected int ListRecordCount
                        {
                            get
                            {
                                int instanceID;
instanceID = InstanceID;
                                using (IlgharCMS.GuestBookModule.IGuestBook bll = (IlgharCMS.GuestBookModule.IGuestBook)Manager.CreateObject("GuestBook", instanceID, ContentLang, true))
                                {
                                    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.GuestBookModule.IGuestBook bll = (IlgharCMS.GuestBookModule.IGuestBook)Manager.CreateObject("GuestBook", instanceID, ContentLang, true))
                                        {
                                            ListData = bll.List(Convert.ToInt32(PageNumber), 5, condition, sort);
                                        }

                                        return ListData;
                                    }
                                }
                            
                            protected string t5700
                            {
                                get
                                {
                                    XmlNode node = _xmlTemplate.SelectSingleNode("//t5700");
                                    Dictionary<string, object> replacementPair = new Dictionary<string, object>();
                                    
                                        replacementPair["{#t6577#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {string t6577 = String.Empty;
if (Convert.ToBoolean(List.Rows[ListCounter][IlgharCMS.GuestBookModule.Alias.GuestBook.Private]))
{t6577 = _xmlTemplate.SelectSingleNode("/" + "/t6577/If").InnerText;}
else
{t6577 = _xmlTemplate.SelectSingleNode("/" + "/t6577/Else").InnerText;}

                                                                            return t6577;
                                                                        }
                                                                        );
                                                
                                        replacementPair["{#t7061#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {string t7061 = String.Empty;
if (Convert.ToBoolean((Config==null?null:Config[IlgharCMS.GuestBookModule.Alias.InstanceConfig.EnableHtmlEditor])))
{t7061 = _xmlTemplate.SelectSingleNode("/" + "/t7061/If").InnerText;}
else
{t7061 = _xmlTemplate.SelectSingleNode("/" + "/t7061/Else").InnerText;object t7160 = HttpUtility.HtmlEncode(Convert.ToString(List.Rows[ListCounter][IlgharCMS.GuestBookModule.Alias.GuestBook.Content]));
t7061 = t7061.Replace("{#t7160#}",t7160 == null ? "" : t7160.ToString());
}

                                                                            return t7061;
                                                                        }
                                                                        );
                                                
                                        replacementPair[@"{#ContentLang#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {
                                                                            object t5983 = ContentLang;
                                                                            if (t5983 != null)
                                                                                return t5983.ToString();
                                                                            else
                                                                                return String.Empty;
                                                                        }
                                                                        );
                                                
                                        replacementPair[@"{#HttpUtility.HtmlEncode(Convert.ToString(Subject))#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {
                                                                            object t6856 = HttpUtility.HtmlEncode(Convert.ToString(List.Rows[ListCounter][IlgharCMS.GuestBookModule.Alias.GuestBook.Subject]));
                                                                            if (t6856 != null)
                                                                                return t6856.ToString();
                                                                            else
                                                                                return String.Empty;
                                                                        }
                                                                        );
                                                replacementPair["{#InnerID#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.InnerID;replacementPair["{#Head#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.Head;replacementPair["{#Name#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.Name;replacementPair["{#QQ#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.QQ;replacementPair["{#Email#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.Email;replacementPair["{#HomePage#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.HomePage;replacementPair["{#IP#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.IP;replacementPair["{#CreateTime#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.CreateTime;replacementPair["{#Content#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.Content;replacementPair["{#Reply#}"] = IlgharCMS.GuestBookModule.Alias.GuestBook.Reply;
                                    StringBuilder all = Manager.Build(node, List_, replacementPair, ref ListRecord, ref ListCounter);
                                    
                                    
                                    
                                    return all.ToString();
                                }
                            }
                          
                            
                        private string t7424URL_ = null;
                        private string t7424URL
                        {
                            get
                            {
                                if (t7424URL_ != null)
                                    return t7424URL_;

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

                                t7424URL_ = result.ToString();
                                return t7424URL_;
                            }
                        }
                        
                            private int t7424Page;
                            private int t7424PageCount;
                            private int t7424RecordCount;
                            private int t7424PageSize;
                            private int t7424Index;
                            protected string t7424
                            {
                                get
                                {
                                    t7424Page = Convert.ToInt32(PageNumber);
                                    if (t7424Page <= 0)
                                        t7424Page = 1;
                                    t7424PageSize = 5;
                                    t7424RecordCount = Convert.ToInt32(ListRecordCount);

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

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

                                    t7424PageCount = t7424RecordCount / t7424PageSize;
                                    if (t7424RecordCount % t7424PageSize > 0)
                                        t7424PageCount += 1;

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

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

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

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

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

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

                                        bool isAll = false;
                                        int pageEnd = 0;
                                        if (isAll)
                                        {
                                            t7424Index = 1;
                                            pageEnd = t7424PageCount;
                                        }
                                        else
                                        {
                                            t7424Index = t7424Page - 5;
                                            if (t7424Index <= 0)
                                                t7424Index = 1;

                                            pageEnd = t7424Page + 5;
                                            if (pageEnd > t7424PageCount)
                                                pageEnd = t7424PageCount;
                                        }

                                        while (t7424Index <= pageEnd)
                                        {
                                            if (t7424Index == t7424Page)
                                            {
                                                currentPage.Append(currentPageYesTpl);
                                                object t8232 = t7424Index;
currentPage.Replace("{#t8232#}", t8232 == null ? "" : t8232.ToString());

                                            }
                                            else
                                            {
                                                currentPage.Append(currentPageNoTpl);
                                                object t8324 = t7424Index;
currentPage.Replace("{#t8324#}", t8324 == null ? "" : t8324.ToString());
object t8338 = t7424Index;
currentPage.Replace("{#t8338#}", t8338 == null ? "" : t8338.ToString());

                                            }
                                            t7424Index++;
                                        }
                                    }
                                    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 (t7424Page < t7424PageCount)
                                    {
                                        lastPage.Append(lastPageNoTpl);
                                        object t8636 = PageNumber;
lastPage.Replace("{#t8636#}", t8636 == null ? "" : t8636.ToString());
object t8682 = ImagePath;
lastPage.Replace("{#t8682#}", t8682 == null ? "" : t8682.ToString());
object t8761 = t7424PageCount;
lastPage.Replace("{#t8761#}", t8761 == null ? "" : t8761.ToString());
object t8788 = ImagePath;
lastPage.Replace("{#t8788#}", t8788 == null ? "" : t8788.ToString());

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

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

                                    object t7559 = t7424RecordCount;
all.Replace("{#t7559#}", t7559 == null ? "" : t7559.ToString());
object t7584 = PageNumber;
all.Replace("{#t7584#}", t7584 == null ? "" : t7584.ToString());
object t7604 = (t7424Page - 1) * t7424PageSize + 1;
all.Replace("{#t7604#}", t7604 == null ? "" : t7604.ToString());
object t7620 = t7424RecordCount < t7424Page * t7424PageSize ? t7424RecordCount : t7424Page * t7424PageSize;
all.Replace("{#t7620#}", t7620 == null ? "" : t7620.ToString());


                                    return all.ToString();
                                }
                            }
                          }
