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

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

    protected void Page_Load(object sender, EventArgs e)
    {
        a.check("|link|");

        if (!IsPostBack)
        {
            c.bindingDropDownList("all", true, 0, "link", linkType);

            string ifStr = string.Empty;
            long idTemp = xabara.isNum(Request["id"]);

            if (idTemp > 0)
            {
                ifStr = " classID=" + idTemp.ToString();
                this.linkType.Items.FindByValue(idTemp.ToString()).Selected = true;
            }
            else
            {
                ifStr = " classID = 0";
                editClassbottom.Visible = false;
            }

            string strSql = "select lid,listID,linkName,linkURL from linkXabara where " + ifStr + " order by listID ASC,lid ASC";
            DataTable dt = sql.getDataTable(strSql);

            if (dt.Rows.Count > 0)
            {
                treeCount.Value = dt.Rows.Count.ToString();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ListName.Text += "<tr><td class=\"tdTitle\" style='text-align:left;'><input name=\"tree" + i.ToString() + "\" type=\"text\" id=\"tree" + i.ToString() + "\" class=\"inputText\" value=\"" + dt.Rows[i]["ListID"].ToString().Trim() + "\" style=\"width:25px; text-align:center;\" />&nbsp;" + dt.Rows[i]["linkName"].ToString().Trim() + "<input type=\"hidden\" name=\"hid" + i.ToString() + "\" id=\"hid" + i.ToString() + "\" value=\"" + dt.Rows[i]["lid"].ToString().Trim() + "\" /></td></tr>";
                }

                errDiv.Visible = false;
            }
            else
            {
                editClassbottom.Enabled = false;
                editClassbottom.Visible = false;

                errInfo.Text = "请选择相关分类后再进行排序，当前分类没有友情链接用户！";
            }
            dt.Dispose();
        }
    }

    protected void editClassbottom_Click(object sender, EventArgs e)
    {
        string[] strValue = new string[1];
        for (int r = 0; r < xabara.isNum(treeCount.Value); r++)
        {
            strValue[0] = xabara.isNum(Request["tree" + r.ToString()]).ToString();
            sql.update("linkXabara", "@ListID", strValue, "lID=" + xabara.isNum(Request["hid" + r.ToString()]).ToString());
        }

        sql.log(a.uid, "admin", "友情链接排序");

        js.div(false, "", "text", "更新排序成功！", 350, 0, "", "");
    }

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