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

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

	#region 是否审核
	string isAvailable = Request.QueryString["IsAvailable"];
	if (!String.IsNullOrEmpty(isAvailable))
		condition.Append(and + Alias.Position.IsAvailable + "=" + isAvailable);
	#endregion

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

	#region 类型
	string typeID = Request.QueryString["TypeID"];
	if (!String.IsNullOrEmpty(typeID))
	{
		condition.Append(and + Alias.Position.TypeID + "=" + typeID);
	}
	#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.Position.Name + " LIKE '%" + keyword + "%'");
		else if (Request.QueryString["KeywordType"] == "Guid")
			condition.Append(and + Alias.Position.ID + "=" + keyword);
	}
	#endregion
	
	return condition.ToString();
}

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

                        protected int t4563IDRecordCount
                        {
                            get
                            {
                                int instanceID;
instanceID = InstanceID;
                                using (IlgharCMS.AdModule.IType bll = (IlgharCMS.AdModule.IType)Manager.CreateObject("Type", instanceID, ContentLang, false))
                                {
                                    string condition = null;


                                    return bll.GetRecordCount(condition);
                                }
                            }
                        }
                        
                            protected int t4563IDCounter = 0;
                            protected object t4563IDRecord = null;
                            private DataTable t4563IDData;
                            protected DataTable t4563ID
                            {
                                get
                                {
                                    if (t4563IDData != null)
                                        return t4563IDData;

                                    t4563IDData = t4563ID_;
                                    return t4563IDData;
                                }
                            }
                        
                                private DataTable t4563ID_
                                {
                                    get
                                    {
                                        string condition = null;


                                        string sort = null;

                                        int instanceID;
instanceID = InstanceID;

                                        using (IlgharCMS.AdModule.IType bll = (IlgharCMS.AdModule.IType)Manager.CreateObject("Type", instanceID, ContentLang, false))
                                        {
                                            t4563IDData = bll.List(-1, -1, condition, sort);
                                        }

                                        return t4563IDData;
                                    }
                                }
                            
                            protected string t4563
                            {
                                get
                                {
                                    XmlNode node = _xmlTemplate.SelectSingleNode("//t4563");
                                    Dictionary<string, object> replacementPair = new Dictionary<string, object>();
                                    replacementPair["{#ID#}"] = IlgharCMS.AdModule.Alias.Type.ID;replacementPair["{#Name#}"] = IlgharCMS.AdModule.Alias.Type.Name;
                                    StringBuilder all = Manager.Build(node, t4563ID_, replacementPair, ref t4563IDRecord, ref t4563IDCounter);
                                    
                                    
                                    
                                    return all.ToString();
                                }
                            }
                          
                        protected int ListRecordCount
                        {
                            get
                            {
                                int instanceID;
instanceID = InstanceID;
                                using (IlgharCMS.AdModule.IPosition bll = (IlgharCMS.AdModule.IPosition)Manager.CreateObject("Position", 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.AdModule.IPosition bll = (IlgharCMS.AdModule.IPosition)Manager.CreateObject("Position", instanceID, ContentLang, true))
                                        {
                                            ListData = bll.List(Convert.ToInt32(PageNumber), 20, condition, sort);
                                        }

                                        return ListData;
                                    }
                                }
                            
                            protected string t5601
                            {
                                get
                                {
                                    XmlNode node = _xmlTemplate.SelectSingleNode("//t5601");
                                    Dictionary<string, object> replacementPair = new Dictionary<string, object>();
                                    
                                        replacementPair["{#t5911#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {string t5911 = String.Empty;
if ((!String.Equals(List.Rows[ListCounter][IlgharCMS.AdModule.Alias.Position.SketchMap],String.Empty)))
{t5911 = _xmlTemplate.SelectSingleNode("/" + "/t5911/If").InnerText;}

                                                                            return t5911;
                                                                        }
                                                                        );
                                                
                                        replacementPair[@"{#ContentLang#}"] = new CustomBuild(
                                                                        delegate(DataRow record, int index)
                                                                        {
                                                                            object t6112 = ContentLang;
                                                                            if (t6112 != null)
                                                                                return t6112.ToString();
                                                                            else
                                                                                return String.Empty;
                                                                        }
                                                                        );
                                                replacementPair["{#InnerID#}"] = IlgharCMS.AdModule.Alias.Position.InnerID;replacementPair["{#SketchMap#}"] = IlgharCMS.AdModule.Alias.Position.SketchMap;replacementPair["{#Name#}"] = IlgharCMS.AdModule.Alias.Position.Name;
                                    StringBuilder all = Manager.Build(node, List_, replacementPair, ref ListRecord, ref ListCounter);
                                    
                                    
                                    
                                    return all.ToString();
                                }
                            }
                          
                            
                        private string t6502URL_ = null;
                        private string t6502URL
                        {
                            get
                            {
                                if (t6502URL_ != null)
                                    return t6502URL_;

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

                                t6502URL_ = result.ToString();
                                return t6502URL_;
                            }
                        }
                        
                            private int t6502Page;
                            private int t6502PageCount;
                            private int t6502RecordCount;
                            private int t6502PageSize;
                            private int t6502Index;
                            protected string t6502
                            {
                                get
                                {
                                    t6502Page = Convert.ToInt32(PageNumber);
                                    if (t6502Page <= 0)
                                        t6502Page = 1;
                                    t6502PageSize = 20;
                                    t6502RecordCount = Convert.ToInt32(ListRecordCount);

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

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

                                    t6502PageCount = t6502RecordCount / t6502PageSize;
                                    if (t6502RecordCount % t6502PageSize > 0)
                                        t6502PageCount += 1;

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

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

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

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

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

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

                                        bool isAll = false;
                                        int pageEnd = 0;
                                        if (isAll)
                                        {
                                            t6502Index = 1;
                                            pageEnd = t6502PageCount;
                                        }
                                        else
                                        {
                                            t6502Index = t6502Page - 5;
                                            if (t6502Index <= 0)
                                                t6502Index = 1;

                                            pageEnd = t6502Page + 5;
                                            if (pageEnd > t6502PageCount)
                                                pageEnd = t6502PageCount;
                                        }

                                        while (t6502Index <= pageEnd)
                                        {
                                            if (t6502Index == t6502Page)
                                            {
                                                currentPage.Append(currentPageYesTpl);
                                                object t7327 = t6502Index;
currentPage.Replace("{#t7327#}", t7327 == null ? "" : t7327.ToString());

                                            }
                                            else
                                            {
                                                currentPage.Append(currentPageNoTpl);
                                                object t7422 = t6502Index;
currentPage.Replace("{#t7422#}", t7422 == null ? "" : t7422.ToString());
object t7436 = t6502Index;
currentPage.Replace("{#t7436#}", t7436 == null ? "" : t7436.ToString());

                                            }
                                            t6502Index++;
                                        }
                                    }
                                    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 (t6502Page < t6502PageCount)
                                    {
                                        lastPage.Append(lastPageNoTpl);
                                        object t7743 = PageNumber;
lastPage.Replace("{#t7743#}", t7743 == null ? "" : t7743.ToString());
object t7789 = ImagePath;
lastPage.Replace("{#t7789#}", t7789 == null ? "" : t7789.ToString());
object t7869 = t6502PageCount;
lastPage.Replace("{#t7869#}", t7869 == null ? "" : t7869.ToString());
object t7896 = ImagePath;
lastPage.Replace("{#t7896#}", t7896 == null ? "" : t7896.ToString());

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

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

                                    object t6640 = t6502RecordCount;
all.Replace("{#t6640#}", t6640 == null ? "" : t6640.ToString());
object t6665 = PageNumber;
all.Replace("{#t6665#}", t6665 == null ? "" : t6665.ToString());
object t6685 = (t6502Page - 1) * t6502PageSize + 1;
all.Replace("{#t6685#}", t6685 == null ? "" : t6685.ToString());
object t6701 = t6502RecordCount < t6502Page * t6502PageSize ? t6502RecordCount : t6502Page * t6502PageSize;
all.Replace("{#t6701#}", t6701 == null ? "" : t6701.ToString());


                                    return all.ToString();
                                }
                            }
                          }
