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;
using AjaxControlToolkit;
public partial class WebMain_Product_leftprodecttree : 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  order by sort", conn);
        sdr = smd.ExecuteReader();
        if (sdr.HasRows)
        {
            while (sdr.Read())
            {
                strall += Convert.ToString(sdr.GetInt32(0)) + ":" + sdr.GetString(1).ToString().Trim()+"|";
            }
            
        }
        else
        {
            TableRow tr2 = new TableRow();
            TableCell tc2 = new TableCell();
            l1=new Label();
            l1.Text = "产品暂无分类";
            tc2.Controls.Add(l1);
            tr2.Controls.Add(tc2);
            TB.Controls.Add(tr2);
        }
        sdr.Close();
        TableRow tr;
        TableCell tc;

        if (strall != "")
        {
            str = strall.Split('|');
            int g = str.Length;
            for (int i = 0; i < g-1; i++)
            {
                int ii = 0;
                int zh =4;
                int gd;
                HyperLink lbt;
                Panel p1;
                Table tbp;
                HoverMenuExtender hme;
                str2 = str[i].Split(':');
                tr = new TableRow();

                tc = new TableCell();
                tc.CssClass = "fobb";
                tc.ColumnSpan = zh;
                tc.HorizontalAlign = HorizontalAlign.Left;
                lbt = new HyperLink();
                SqlCommand smdcount = new SqlCommand("select count(*) from SmallProductCategory where BigCategoryId="+str2[0], conn);
                lbt.Text = str2[1].ToString()+"("+Convert.ToString(smdcount.ExecuteScalar())+")";
                //lbt.NavigateUrl = "javascript:void(0)";
                //if (str2[0]== "10000043")
                //{
                //    lbt.NavigateUrl = "~/china/productpm.aspx?BigID=" + str2[0];
                //}
                //else if (str2[0] == "10000034")
                //{
                //    lbt.NavigateUrl = "~/china/intproduct.aspx?BigID=" + str2[0];
                //}
                //else
                //{ 
                //   lbt.NavigateUrl = "~/china/productPP.aspx?BigID=" + str2[0];
                //}

                tc.Controls.Add(lbt);
                tr.Controls.Add(tc);
                TB.Controls.Add(tr);



                SqlCommand smd2 = new SqlCommand("select * from SmallProductCategory where BigCategoryId="+str2[0]+" order by sort", conn);
                SqlDataReader sdr2 = smd2.ExecuteReader();
                tr = new TableRow();
                string strtxt = "";
               while (sdr2.Read())
               {
                   strtxt += Convert.ToString(sdr2.GetInt32(0)) + "|" + sdr2.GetString(2)+"$";
               }
               string[] txt = strtxt.Split('$');
               string[] txt2;  
                p1 = new Panel();
                p1.CssClass = "pah";
                for (int j=0;j<txt.Length-1;j++)
                {
                    ii++;
                    txt2 = txt[j].Split('|');
                    if (j <= 2)
                    {
                            tc = new TableCell();
                            lbt = new HyperLink();
                            lbt.Text = txt2[1].ToString();
                            if (str2[0]== "10000043")
                            {
                               lbt.NavigateUrl = "~/china/productpms.aspx?SmallId=" + txt2[0]; 
                            }
                            else if (str2[0] == "10000034")
                            {
                                lbt.NavigateUrl = "~/china/intproductsmall.aspx?SmallId=" + txt2[0];
                            }
                            else
                            { 
                                lbt.NavigateUrl = "~/china/product.aspx?SmallId=" + txt2[0];
                            }
                            tc.Controls.Add(lbt);
                            tr.Controls.Add(tc);
                    }
                    else
                    {
                            if (j == 3)
                            {                
                                tc = new TableCell();
                                lbt = new HyperLink();
                                lbt.Text = "更多";


                                if (str2[0] == "10000043")
                                {
                                    lbt.NavigateUrl = "~/china/productpms.aspx?SmallId=" + txt2[0];
                                }
                                else if (str2[0] == "10000034")
                                {
                                    lbt.NavigateUrl = "~/china/intproductsmall.aspx?SmallId=" + txt2[0];
                                }
                                else
                                {
                                    lbt.NavigateUrl = "~/china/product.aspx?SmallId=" + txt2[0];
                                }

                                lbt.ID = "lbd" + Convert.ToString(3) + Convert.ToString(i);
                                tc.Controls.Add(lbt);
                                tr.Controls.Add(tc);
                            }
                            if (j >=3)
                            {
                                p1.ID = "p" + Convert.ToString(3) + Convert.ToString(i);
                                lbt = new HyperLink();
                                lbt.Text = "·"+txt2[1].ToString();
                                if (str2[0] == "10000043")
                                {
                                    lbt.NavigateUrl = "~/china/productpms.aspx?SmallId=" + txt2[0];
                                }
                                else if (str2[0] == "10000034")
                                {
                                    lbt.NavigateUrl = "~/china/intproductsmall.aspx?SmallId=" + txt2[0];
                                }
                                else
                                {
                                    lbt.NavigateUrl = "~/china/product.aspx?SmallId=" + txt2[0];
                                }

                                p1.Controls.Add(lbt);
                                l1 = new Label();
                                l1.Text = "&nbsp;&nbsp;&nbsp;";
                                p1.Controls.Add(l1);
                                if (j % 2 == 0)
                                {
                                    l1 = new Label();
                                    l1.Text = "<br>";
                                    p1.Controls.Add(l1);
                                }


                                p1.BackColor = System.Drawing.Color.White;
                                Panel1.Controls.Add(p1);
                                if (ii == txt.Length - 1)
                                {
                                    tc = new TableCell();
                                    hme = new HoverMenuExtender();
                                    hme.TargetControlID = "lbd" + Convert.ToString(3) + Convert.ToString(i);
                                    hme.PopupControlID = "p" + Convert.ToString(3) + Convert.ToString(i);
                                    hme.PopupPosition = HoverMenuPopupPosition.Right;
                                    tc.Controls.Add(hme);
                                    tr.Controls.Add(tc);
                                }
                            }
                        
                    }

                }
                sdr2.Close();
                TB.Controls.Add(tr);
            }
        }
        TB.CellSpacing = 3;
        conn.Close();

    }
   
}
