using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebXabara_ads_Default : System.Web.UI.Page
{
    XabaraCom xc = new XabaraCom();
    dbDataFunction db = new dbDataFunction();
    XabaraClass xClass = new XabaraClass();

    protected void Page_Load(object sender, EventArgs e)
    {
        xc.CheckAdminLogin(string.Empty);

        xClass.NewsTypeData("ads", adWhere);
        
        string strSql = string.Empty;
        string ifStr = string.Empty;

        if (!IsPostBack)
        {
            long cidTemp = xc.SafeNum(Request.QueryString["aid"]);
            if (cidTemp > 0)
            {
                string cidStr = xClass.getClassAllID("ads", cidTemp); //得到所有ID

                if (cidStr.IndexOf(",") > 0)
                {
                    string[] ids = cidStr.Split(new char[] { ',' });
                    for (int i = 0; i <= ids.GetUpperBound(0); i++)
                    {
                        ifStr += " select * from ads where classID=" + ids[i].ToString() + " union ";
                    }
                }
                else
                {
                    ifStr = " select * from ads where classID=" + cidTemp.ToString() + " union ";
                }

                this.adWhere.Items.FindByValue(cidTemp.ToString()).Selected = true;
            }
            else
            {
                ifStr = " select * from ads union ";
            }

            ifStr = "(" + ifStr.Substring(0, ifStr.Length - 6) + ") as news";
            strSql = "select * from " + ifStr + " order by aID DESC";
            //Response.Write(strSql);
            //Response.End();
            lblCurrentPage.Text = db.RepeaterDB(RepeaterList, strSql, "&aid=" + cidTemp.ToString(), 5, "page", "center", true);
        }
    }

    protected void adWhere_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx?aid=" + adWhere.Text, true);
    }

    public string getClass(Int64 cid)
    {
        return xClass.getClass(cid, string.Empty, string.Empty);
    }
}