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_Link_list : System.Web.UI.Page
{
    admin a = new admin();
    classify c = new classify();
    sqlServer sql = new sqlServer();
    fileDocument f = new fileDocument();

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

        if (!IsPostBack)
        {
            string strSql = string.Empty;
            string ifStr = string.Empty;           

            long _cid = xabara.isNum(Request.QueryString["cid"]);

            c.bindingDropDownList("all",true, 0, "link", linkType);

            if (_cid > 0)
            {
                string idNums = c.ReadAllClassID("link", _cid);

                if (idNums.IndexOf(',') > 0)
                {
                    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.linkType.Items.FindByValue(_cid.ToString()).Selected = true;
            }

            strSql = "select * from linkXabara where 1=1 " + ifStr + " order by listID asc, lid asc";
            lblCurrentPage.Text = sql.RepeaterDB(RepeaterList, strSql, string.Empty, 20, "page", "center", true);
        }
    }

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

    public string getPre(string strImg)
    {
        return f.picDisplay(strImg);
    }

    protected void linkType_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("?cid=" + linkType.Text.Trim(), true);
    }
}
