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_buju_top : System.Web.UI.UserControl
{
    SqlConnection conn;
    protected void Page_Load(object sender, EventArgs e)
    {
        conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select * from SystemBasicInformation", conn);
        SqlDataReader sdr = smd.ExecuteReader();
        sdr.Read();
        Parent.Page.Title = sdr.GetString(3);
        if (sdr.GetString(1) != "y")
        {
            Response.Write("<script>alert('友情提示：很抱歉，因数据升级，网站暂关闭！');window.location.href='china/error2.aspx?err=网站关闭中。。。 WEB CLOSE'</script>");
        }
        if (Session["userid"] == null)
        {
            Session["userid"] = DateTime.Now.ToString("hmmssffff");
            Session["ad"] = "1";
            Session["vote"] = "1";
        }
        this.logo.ImageUrl="~/images/"+sdr.GetString(15);
        sdr.Close();

        SqlDataAdapter smdbig = new SqlDataAdapter("select top 6 id,BigCategory from BigProductCategory where id<>10000034 and id<>10000043 order by sort",conn);
        DataSet dsbig = new DataSet();
        smdbig.Fill(dsbig,"t1");


        this.sclink2.Text = dsbig.Tables["t1"].Rows[0][1].ToString();
        this.sclink2.NavigateUrl = "~/china/productPP.aspx?BigID=" + dsbig.Tables["t1"].Rows[0][0].ToString();
        this.sclink2.ToolTip = dsbig.Tables["t1"].Rows[0][1].ToString();

        this.sclink3.Text = dsbig.Tables["t1"].Rows[1][1].ToString();
        this.sclink3.NavigateUrl = "~/china/productPP.aspx?BigID=" + dsbig.Tables["t1"].Rows[1][0].ToString();
        this.sclink3.ToolTip = dsbig.Tables["t1"].Rows[1][1].ToString();

        this.sclink4.Text = dsbig.Tables["t1"].Rows[2][1].ToString();
        this.sclink4.NavigateUrl = "~/china/productPP.aspx?BigID=" + dsbig.Tables["t1"].Rows[2][0].ToString();
        this.sclink4.ToolTip = dsbig.Tables["t1"].Rows[2][1].ToString();

        this.sclink5.Text = dsbig.Tables["t1"].Rows[3][1].ToString();
        this.sclink5.NavigateUrl = "~/china/productPP.aspx?BigID=" + dsbig.Tables["t1"].Rows[3][0].ToString();
        this.sclink5.ToolTip = dsbig.Tables["t1"].Rows[3][1].ToString();

        this.sclink6.Text = dsbig.Tables["t1"].Rows[4][1].ToString();
        this.sclink6.NavigateUrl = "~/china/productPP.aspx?BigID=" + dsbig.Tables["t1"].Rows[4][0].ToString();
        this.sclink6.ToolTip = dsbig.Tables["t1"].Rows[4][1].ToString();

        this.sclink7.Text = dsbig.Tables["t1"].Rows[5][1].ToString();
        this.sclink7.NavigateUrl = "~/china/productPP.aspx?BigID=" + dsbig.Tables["t1"].Rows[5][0].ToString();
        this.sclink7.ToolTip = dsbig.Tables["t1"].Rows[5][1].ToString();

        SqlCommand titsmd;
        SqlDataReader titsdr;
        TableRow tr;
        TableCell tc;
        HyperLink h1;
        titsmd = new SqlCommand("select top 19 *  from SmallProductCategory where BigCategoryId=" + dsbig.Tables["t1"].Rows[0][0].ToString() + " order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        while (titsdr.Read())
        {
            tc = new TableCell();
            h1 = new HyperLink();
            h1.Text = titsdr["SmallCategory"].ToString();
            h1.NavigateUrl = "~/china/product.aspx?SmallId="+titsdr["id"].ToString();
            tc.Controls.Add(h1);
            tr.Controls.Add(tc);
        }
        TB1.Controls.Add(tr);
        titsdr.Close();
        titsmd = new SqlCommand("select top 19 *  from SmallProductCategory where BigCategoryId=" + dsbig.Tables["t1"].Rows[0][0].ToString() + " order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        while (titsdr.Read())
        {
            tc = new TableCell();
            h1 = new HyperLink();
            h1.Text = titsdr["SmallCategory"].ToString();
            h1.NavigateUrl = "~/china/product.aspx?SmallId=" + titsdr["id"].ToString();
            tc.Controls.Add(h1);
            tr.Controls.Add(tc);
        }
        TB2.Controls.Add(tr);
        titsdr.Close();
        titsmd = new SqlCommand("select top 18 *  from SmallProductCategory where BigCategoryId=" + dsbig.Tables["t1"].Rows[1][0].ToString() + " order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        while (titsdr.Read())
        {
            tc = new TableCell();
            h1 = new HyperLink();
            h1.Text = titsdr["SmallCategory"].ToString();
            h1.NavigateUrl = "~/china/product.aspx?SmallId=" + titsdr["id"].ToString();
            tc.Controls.Add(h1);
            tr.Controls.Add(tc);
        }
        TB3.Controls.Add(tr);
        titsdr.Close();
        titsmd = new SqlCommand("select top 18 *  from SmallProductCategory where BigCategoryId=" + dsbig.Tables["t1"].Rows[2][0].ToString() + " order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        while (titsdr.Read())
        {
            tc = new TableCell();
            h1 = new HyperLink();
            h1.Text = titsdr["SmallCategory"].ToString();
            h1.NavigateUrl = "~/china/product.aspx?SmallId=" + titsdr["id"].ToString();
            tc.Controls.Add(h1);
            tr.Controls.Add(tc);
        }
        TB4.Controls.Add(tr);
        titsdr.Close();
        titsmd = new SqlCommand("select top 18 *  from SmallProductCategory where BigCategoryId=" + dsbig.Tables["t1"].Rows[3][0].ToString() + " order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        while (titsdr.Read())
        {
            tc = new TableCell();
            h1 = new HyperLink();
            h1.Text = titsdr["SmallCategory"].ToString();
            h1.NavigateUrl = "~/china/product.aspx?SmallId=" + titsdr["id"].ToString();
            tc.Controls.Add(h1);
            tr.Controls.Add(tc);
        }
        TB5.Controls.Add(tr);
        titsdr.Close();
        titsmd = new SqlCommand("select top 18 *  from SmallProductCategory where BigCategoryId=" + dsbig.Tables["t1"].Rows[4][0].ToString() + " order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        while (titsdr.Read())
        {
            tc = new TableCell();
            h1 = new HyperLink();
            h1.Text = titsdr["SmallCategory"].ToString();
            h1.NavigateUrl = "~/china/product.aspx?SmallId=" + titsdr["id"].ToString();
            tc.Controls.Add(h1);
            tr.Controls.Add(tc);
        }
        TB6.Controls.Add(tr);
        titsdr.Close();

        titsmd = new SqlCommand("select top 18 *  from SmallProductCategory where BigCategoryId=" + dsbig.Tables["t1"].Rows[5][0].ToString() + " order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        while (titsdr.Read())
        {
            tc = new TableCell();
            h1 = new HyperLink();
            h1.Text = titsdr["SmallCategory"].ToString();
            h1.NavigateUrl = "~/china/product.aspx?SmallId=" + titsdr["id"].ToString();
            tc.Controls.Add(h1);
            tr.Controls.Add(tc);
        }
        TB7.Controls.Add(tr);
        titsdr.Close();

        titsmd = new SqlCommand("select top 15 *  from PackageCategory order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        while (titsdr.Read())
        {
            tc = new TableCell();
            h1 = new HyperLink();
            h1.Text = titsdr["BigCategory"].ToString();
            h1.NavigateUrl = "~/china/producttcall.aspx?lbId=" + titsdr["id"].ToString();
            tc.Controls.Add(h1);
            tr.Controls.Add(tc);
        }
        TB9.Controls.Add(tr);
        titsdr.Close();

        titsmd = new SqlCommand("select top 11 *  from newsSole where id<>10036 and id<>10035 and id<>10039 order by times", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        while (titsdr.Read())
        {
            tc = new TableCell();
            h1 = new HyperLink();
            h1.Text = titsdr["title"].ToString();
            h1.NavigateUrl = "~/china/helpFAQ.aspx?Id=" + titsdr["id"].ToString();
            tc.Controls.Add(h1);
            tr.Controls.Add(tc);
        }
        TB8.Controls.Add(tr);
        titsdr.Close();
        //
        //此处可插入商品分类效果；

       // lb();//可以调用AJAX特效

        //
        titsmd = new SqlCommand("select sysgg from SystemBasicInformation ", conn);
        this.gg.Text =Convert.ToString(titsmd.ExecuteScalar());

        SqlCommand cmdtb = new SqlCommand("select amount,price,userid from cart where userid=" + Session["userid"], conn);
        SqlDataReader sdrtb = cmdtb.ExecuteReader();
        int amo = 0, pri = 0;
        while (sdrtb.Read())
        {
            amo++;
            pri += sdrtb.GetInt32(0) * Convert.ToInt32(sdrtb.GetDecimal(1));
        }
        Label1.Text = "购物车中有<font color=red><b> " + amo + " </b></font>款产品|总共价格：<font color=red><b>￥" + pri + "</b></font> RMB";
        sdrtb.Close();
        if (!IsPostBack)
        {
            SqlCommand smdlb;
            SqlDataAdapter sdalb;
            DataSet dslb;
            DataTable tb;
            DataRow dr;
            SqlDataReader sdrlb;
            tb = new DataTable();
            tb.Columns.Add("id", typeof(int));
            tb.Columns.Add("BigCategory", typeof(string));
            tb.Columns.Add("sort", typeof(int));
            smdlb = new SqlCommand("select * from BigProductCategory order by Sort", conn);
            dr = tb.NewRow();
            dr["id"] = 0;
            dr["BigCategory"] = "请选择大类产品";
            dr["sort"] = 0;
            tb.Rows.Add(dr);
            sdrlb = smdlb.ExecuteReader();
            while (sdrlb.Read())
            {
                dr = tb.NewRow();
                dr["id"] = sdrlb["id"].ToString();
                dr["BigCategory"] = sdrlb["BigCategory"].ToString();
                dr["sort"] = sdrlb["sort"].ToString();
                tb.Rows.Add(dr);
            }
            sdrlb.Close();
            Doadmin.ddldatabind2(biglb, tb, "BigCategory", "id");
            if (biglb.SelectedValue.ToString() == "0")
            {
                tb = new DataTable();
                tb.Columns.Add("id", typeof(int));
                tb.Columns.Add("SmallCategory", typeof(string));
                tb.Columns.Add("sort", typeof(string));
                dr = tb.NewRow();
                dr["id"] = 0;
                dr["SmallCategory"] = "请选择小类产品";
                dr["sort"] = 0;
                tb.Rows.Add(dr);
                Doadmin.ddldatabind2(smalllb, tb, "SmallCategory", "id");
            }
        }
        conn.Close();
    }
    //#region 类别调用
    //public void lb()
    //{
    //    SqlCommand smd8 = new SqlCommand("select * from BigProductCategory", conn);
    //    SqlDataReader sdr8 = smd8.ExecuteReader();
    //    string strall = "";
    //    string strbll = "";
    //    string[] str;
    //    string[] str2;
    //    int ii = 0;
    //    if (sdr8.HasRows)
    //    {
    //        while (sdr8.Read())
    //        {
    //            strall += Convert.ToString(sdr8.GetInt32(0)) + ":" + sdr8.GetString(1).ToString().Trim() + "|";
    //        }

    //    }
    //    else
    //    {
    //        strbll = "暂无产品!";
    //    }
    //    sdr8.Close();

    //    if (strall != "")
    //    {
    //        strbll = "<table width=98% height=73 border=0 align=center cellpadding=0 cellspacing=5>";
    //        str = strall.Split('|');
    //        int g = str.Length;
    //        for (int i = 0; i < g - 1; i++)
    //        {

    //            str2 = str[i].Split(':');

    //            strbll += "<tr ><td  class=fonttb4><a href=/china/productPP.aspx?BigID=" + str2[0] + ">" + str2[1].ToString() + "</a></td></tr>";
    //            SqlCommand smd2 = new SqlCommand("select * from SmallProductCategory where BigCategoryId=" + str2[0], conn);
    //            SqlDataReader sdr2 = smd2.ExecuteReader();
    //            strbll += "<tr><td>";
    //            while (sdr2.Read())
    //            {
    //                ii++;
    //                strbll += "<a href=/china/product.aspx?SmallId=" + sdr2.GetInt32(0) + " class=fonttb3>" + sdr2.GetString(2) + "</a>";
    //                if (ii % 5 == 0)
    //                {
    //                    strbll += "<br>";
    //                }
    //            }
    //            ii = 0;
    //            strbll += "</td></tr>";
    //            sdr2.Close();
    //        }
    //        strbll += "</table>";
    //    }
    //    this.HyperLink2.Attributes.Add("onMouseOver", "over('two','" + strbll + "')");
    //    this.HyperLink2.Attributes.Add("onmouseout", "out(two)");
    //}
    //#endregion
    protected void biglb_SelectedIndexChanged(object sender, EventArgs e)
    {
        conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smdlb;
        SqlDataAdapter sdalb;
        DataSet dslb;
        DataTable tb;
        DataRow dr;
        SqlDataReader sdrlb;
        if (this.biglb.SelectedValue.ToString() != "0")
        {
            tb = new DataTable();
            tb.Columns.Add("id", typeof(int));
            tb.Columns.Add("SmallCategory", typeof(string));
            tb.Columns.Add("sort", typeof(int));
            smdlb = new SqlCommand("select * from SmallProductCategory where BigCategoryId=" + this.biglb.SelectedValue + " order by Sort", conn);
            sdrlb = smdlb.ExecuteReader();
            while (sdrlb.Read())
            {
                dr = tb.NewRow();
                dr["id"] = sdrlb["id"].ToString();
                dr["SmallCategory"] = sdrlb["SmallCategory"].ToString();
                dr["sort"] = sdrlb["sort"].ToString();
                tb.Rows.Add(dr);
            }
            sdrlb.Close();
            Doadmin.ddldatabind2(smalllb, tb, "SmallCategory", "id");
        }
        else
        {
            tb = new DataTable();
            tb.Columns.Add("id", typeof(int));
            tb.Columns.Add("SmallCategory", typeof(string));
            tb.Columns.Add("sort", typeof(int));
            dr = tb.NewRow();
            dr["id"] = 0;
            dr["SmallCategory"] = "请选择小类产品";
            dr["sort"] = 0;
            tb.Rows.Add(dr);
            Doadmin.ddldatabind2(smalllb, tb, "SmallCategory", "id");
        }

    }
    protected void imgbtn_Click(object sender, ImageClickEventArgs e)
    {
        string txt = keywords.Text;
        Response.Redirect("~/china/searchresult.aspx?pcount=20&bigid=" + biglb.SelectedValue.ToString() + "&smallid=" + smalllb.SelectedValue.ToString() + "&keywords=" + Server.UrlEncode(txt) + "&");
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session["skin"] = "1";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Session["skin"] = "2";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        Session["skin"] = "3";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        Session["skin"] = "4";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton5_Click(object sender, EventArgs e)
    {
        Session["skin"] = "5";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton6_Click(object sender, EventArgs e)
    {
        Session["skin"] = "6";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton7_Click(object sender, EventArgs e)
    {
        Session["skin"] = "7";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton8_Click(object sender, EventArgs e)
    {
        Session["skin"] = "8";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton9_Click(object sender, EventArgs e)
    {
        Session["skin"] = "9";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton10_Click(object sender, EventArgs e)
    {
        Session["skin"] = "10";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void LinkButton11_Click(object sender, EventArgs e)
    {
        Session["skin"] = "11";
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
}
