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;

public partial class Includes_right : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    protected void Bind()
    {
        BLL.Type_1 t_1 = new BLL.Type_1();
        BLL.Type_2 t_2 = new BLL.Type_2();
        DataTable dt1 = t_1.type_1list("");

        TreeView tv = new TreeView();
        TreeNode RootNode = new TreeNode();
        RootNode.Expanded = false;
        RootNode.Text = "目录查询请点击展开";
        RootNode.Value = "1";
        RootNode.NavigateUrl = "Product_Search.aspx?id=" + RootNode.Value;//有误.
        RootNode.ImageUrl = "images/treeview/menu.gif";
        
        tv.Nodes.Add(RootNode);

        foreach (DataRow dr in dt1.Rows)
        {
            TreeNode node = new TreeNode();
            node.Expanded = false;
            node.Text = dr["TypeName"].ToString();
            node.Value = dr["TypeID_1"].ToString();
            node.NavigateUrl = @"~/Product_Search.aspx?type_1=" + node.Value;//链接
            this.TV_pro.Nodes.Add(node);
        }

        int k = this.TV_pro.Nodes.Count;
        for (int i = 0; i < k; i++)
        {
            int id = Convert.ToInt32(this.TV_pro.Nodes[i].Value.ToString().Trim());
            DataTable dt2 = t_2.type_2list(id, "");

            foreach (DataRow dr in dt2.Rows)
            {
                TreeNode node = new TreeNode();
                node.Expanded = false;
                node.Text = dr["type_2name"].ToString();
                node.Value = dr["TypeID2"].ToString();
                node.NavigateUrl = @"~/Product_Search.aspx?type_1=" + this.TV_pro.Nodes[i].Value.ToString() + @"&&type_2=" + node.Value;//链接
                this.TV_pro.Nodes[i].ChildNodes.Add(node);
            }
        }

        //绑定新闻
        BLL.Class_1 c_1 = new BLL.Class_1();
        BLL.Class_2 c_2 = new BLL.Class_2();
        DataTable dt_c1 = c_1.Class_1list("");

        TreeView tvc = new TreeView();
        TreeNode cRootNode = new TreeNode();
        cRootNode.Expanded = false;
        cRootNode.Text = "目录查询请点击展开";
        cRootNode.Value = "1";
        cRootNode.NavigateUrl = "New_Search.aspx?id=" + cRootNode.Value;//有误
        cRootNode.ImageUrl = "images/treeview/menu.gif";

        tvc.Nodes.Add(cRootNode);

        foreach (DataRow dr in dt_c1.Rows)
        {
            TreeNode node = new TreeNode();
            node.Expanded = false;
            node.Text = dr["ClassName"].ToString();
            node.Value = dr["ClassID_1"].ToString();
            node.NavigateUrl = @"~/New_Search.aspx?Class_1=" + node.Value;//链接
            this.TV_new.Nodes.Add(node);
        }

        int c = this.TV_new.Nodes.Count;
        for (int i = 0; i < c; i++)
        {
            int id = Convert.ToInt32(this.TV_new.Nodes[i].Value.ToString().Trim());
            DataTable dt_c2 = c_2.Class_2list(id, "");

            foreach (DataRow dr in dt_c2.Rows)
            {
                TreeNode node = new TreeNode();
                node.Expanded = false;
                node.Text = dr["Class_2name"].ToString();
                node.Value = dr["ClassID_2"].ToString();
                node.NavigateUrl = @"~/New_Search.aspx?Class_1=" + this.TV_new.Nodes[i].Value.ToString() + @"&&Class_2=" + node.Value;//链接
                this.TV_new.Nodes[i].ChildNodes.Add(node);
            }
        }
    }
}
