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 System.Data.SqlClient;

public partial class WebMain_Product_Mainprodecttree : System.Web.UI.UserControl
{
    Label l1;
    Image img;
    ImageButton ibn;
    SqlDataReader sdr;
    SqlCommand smd;
    
    string[] str;
    string[] str2;
    string strall = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        smd = new SqlCommand("select * from BigProductCategory", conn);
        sdr = smd.ExecuteReader();
        if (sdr.HasRows)
        {
            while (sdr.Read())
            {
                strall += Convert.ToString(sdr.GetInt32(0)) + ":" + sdr.GetString(1).ToString().Trim()+"|";
            }
            

        }
        else
        {
            Response.Write("暂无产品!");
        }
        sdr.Close();
        TableRow tr;
        TableCell tc;
        Label l2;

        if (strall != "")
        {
            str = strall.Split('|');
            int g = str.Length;
            for (int i = 0; i < g-1; i++)
            {
                HyperLink lbt;
                str2 = str[i].Split(':');
                tr = new TableRow();
                tc = new TableCell();

                lbt = new HyperLink();
                lbt.Target = "_blank";
                lbt.Text = str2[1].ToString();
                lbt.NavigateUrl = "~/china/productPP.aspx?BigID=" + str2[0];
                tc.Controls.Add(lbt);
                tc.Width = 70;
                tr.Controls.Add(tc);
                TB.Controls.Add(tr);
                SqlCommand smd2 = new SqlCommand("select * from SmallProductCategory where BigCategoryId="+str2[0], conn);
                SqlDataReader sdr2 = smd2.ExecuteReader();
              
                tc = new TableCell();
                while (sdr2.Read())
               {
                   lbt = new HyperLink();
                   lbt.Target = "_blank";
                  lbt.Text = sdr2.GetString(2);
                  lbt.NavigateUrl = "~/china/product.aspx?SmallId="+Convert.ToString(sdr2.GetInt32(0)).Trim();
                  l2 = new Label();
                  l2.Text = " / ";
                  tc.Controls.Add(lbt);
                  tc.Controls.Add(l2);
                  tr.Controls.Add(tc); 
               }
                 
                TB.Controls.Add(tr);
                sdr2.Close();
            }
        }
        conn.Close();

    }
   
}
