using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using UUN;
using System.Data.SqlClient;

public partial class Admin_PageSystem_Select_Topic : System.Web.UI.Page
{
    private 访问 访问;
    protected String SQL;
    protected String 数量SQL;
    protected int 所属版块;
    protected String 返回类型;
    protected void Page_Load(object sender, EventArgs e)
    {
        访问 = new 访问(this.Context);
        访问.开始处理("选择贴子", "网站后台", "选择贴子", new 访问.回调委托(ZhiXing));
        访问.关闭连接();
    }

    private void ZhiXing()
    {
        访问.验证管理员();

        所属版块 = Convert.ToInt32(Request.QueryString["ID"]);
        返回类型 = Request.QueryString["type"];

        DataSet 数据 = (DataSet)Application["UUN_UUN3G_LunTanBanKuai"];

        生成版块(数据, 0, 1);
        BanKuai.Attributes["onchange"] = "location.href='Select_Topic.aspx?ID='+this.value";
        DataRow 版块 = 常用.获取版块(所属版块);

        if (版块 != null)
            Label1.Text = 版块["版块名称"].ToString();
        else
            Label1.Text = "无";

        SQL = "SELECT [ID],[标题],[所属版块] FROM [" + 程序.数据表前缀 + "社区_论坛_贴子]";
        数量SQL = "SELECT COUNT(ID) FROM [" + 程序.数据表前缀 + "社区_论坛_贴子]";
        if (版块 == null)
        {
            SQL += " WHERE [是否删除]='0' ORDER BY [ID] DESC";
            数量SQL += " WHERE [是否删除]='0'";
        }
        else
        {
            SQL += " WHERE [所属版块]=" + 所属版块 + " AND [是否删除]='0' ORDER BY [ID] DESC";
            数量SQL += " WHERE [所属版块]=" + 所属版块 + " AND [是否删除]='0'";
        }

        if (!this.IsPostBack)
            生成数据();
    }

    private void 生成版块(DataSet 数据, int 父版块, int 深度)
    {
        for (int i = 0; i < 数据.Tables[0].Rows.Count; i++)
        {
            DataRow 行 = 数据.Tables[0].Rows[i];
            if (Convert.ToInt32(行["所属版块"]) == 父版块)
            {
                ListItem 列表项 = new ListItem(生成空格(深度) + Convert.ToString(行["版块名称"]),
                    Convert.ToString(行["ID"]));
                BanKuai.Items.Add(列表项);
                生成版块(数据, Convert.ToInt32(行["ID"]), 深度 + 1);
            }
        }
    }

    private void 生成数据()
    {
        SqlCommand 语句 = new SqlCommand(数量SQL, 访问.连接);

        后台分页 分页 = new 后台分页(Convert.ToInt32(语句.ExecuteScalar()),
            Convert.ToInt32(Request.QueryString["page"]),
            10,
            "Select_Topic.aspx?ID=" + 所属版块 + "&type=" + Server.UrlEncode(返回类型));

        DataSet 数据 = new DataSet();
        语句 = new SqlCommand(SQL, 访问.连接);
        SqlDataAdapter 填充 = new SqlDataAdapter(语句);
        填充.Fill(数据, (分页.当前页 - 1) * 10, 10, "贴子");

        GridView1.DataSource = 数据;
        GridView1.DataBind();

        FenYeDaiMa.Text = 分页.生成代码();
    }

    private String 生成空格(int 数量)
    {
        String 返回值 = "";
        for (int i = 0; i < 数量; i++)
            返回值 += "　";
        return 返回值 + "|-";
    }
}
