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

public partial class WebXabara_ads_Default : System.Web.UI.Page
{
    admin a = new admin();
    classify c = new classify();
    sqlServer sql = new sqlServer();

    protected void Page_Load(object sender, EventArgs e)
    {
        a.check(string.Empty);

        c.bindingDropDownList("all", true, 0, "ads", classID);

        string strSql = string.Empty;
        string ifStr = string.Empty;

        if (!IsPostBack)
        {
            long _cid = xabara.isNum(Request.QueryString["cid"]);
            if (_cid > 0)
            {
                string idNums = c.ReadAllClassID("ads", _cid);

                if (!idNums.Equals(_cid.ToString()))
                {
                    string[] ids = idNums.Split(new char[] { ',' });
                    for (int i = 0; i <= ids.GetUpperBound(0); i++)
                    {
                        ifStr += "classID=" + ids[i].ToString().Trim() + " or ";
                    }
                    ifStr = " and (" + ifStr.Substring(0, ifStr.Length - 3) + ")";
                }
                else
                {
                    ifStr += " and classID=" + _cid.ToString().Trim();
                }
                this.classID.Items.FindByValue(_cid.ToString()).Selected = true;
            }

            strSql = "select * from ads where 1=1 " + ifStr + " order by stopDate DESC,aID desc";
            //Response.Write(strSql);
            lblCurrentPage.Text = sql.RepeaterDB(RepeaterList, strSql, "&aid=" + _cid, 5, "page", "center", true);
        }
    }

    protected void classID_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx?cid=" + classID.Text, true);
    }

    public string getClass(long cid)
    {
        return c.readClassName_Link(cid, string.Empty, string.Empty);
    }
}