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 _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smdkg = new SqlCommand("select IsOpen from UserAdmin",conn);
        if (Convert.ToString(smdkg.ExecuteScalar()) == "close")
        {
            Response.Redirect("~/china/error2.aspx?err=网站未开通!");
            Response.End();
        }
        SqlCommand smd = new SqlCommand("select count(*) from Advertisement where Type='1' and Condition='y'", conn);
        int count = Convert.ToInt32(smd.ExecuteScalar());
        if (count != 0)
        {
                RegisterStartupScript(" ", " <script language=\"javascript\" src=\"js/ad.js\"></script> ");
        }

        if (Session["userid"] == null)
        {
            Session["userid"] = DateTime.Now.ToString("hmmssffff");
            Session["ad"] = "1";
            Session["vote"] = "1";
        }



        SqlCommand titsmd;
        SqlDataReader titsdr;
        TableRow tr;
        TableCell tc;
        HyperLink h1;

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

        titsmd = new SqlCommand("select top 10 *  from SmallProductCategory where BigCategoryId="+dsbigflow.Tables["t1"].Rows[0][0]+" order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        this.flow2.Text = dsbigflow.Tables["t1"].Rows[0][1].ToString();
        this.PID2.PSid = dsbigflow.Tables["t1"].Rows[0][0].ToString();
        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);
            tc.VerticalAlign = VerticalAlign.Bottom;
            tr.Controls.Add(tc);
        }
        zx.Controls.Add(tr);
        titsdr.Close();
        titsmd = new SqlCommand("select top 10 *  from SmallProductCategory where BigCategoryId=" + dsbigflow.Tables["t1"].Rows[1][0] + "  order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        this.flow3.Text = dsbigflow.Tables["t1"].Rows[1][1].ToString();
        this.PID3.PSid = dsbigflow.Tables["t1"].Rows[1][0].ToString().Trim();
        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);
            tc.VerticalAlign = VerticalAlign.Bottom;
            tr.Controls.Add(tc);
        }
        zx3.Controls.Add(tr);
        titsdr.Close();

        titsmd = new SqlCommand("select top 10 *  from SmallProductCategory where BigCategoryId=" + dsbigflow.Tables["t1"].Rows[2][0] + "  order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        this.flow4.Text = dsbigflow.Tables["t1"].Rows[2][1].ToString();
        this.PID4.PSid = dsbigflow.Tables["t1"].Rows[2][0].ToString().Trim();
        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);
            tc.VerticalAlign = VerticalAlign.Bottom;
            tr.Controls.Add(tc);
        }
        zx4.Controls.Add(tr);
        titsdr.Close();

        titsmd = new SqlCommand("select top 10 *  from SmallProductCategory where BigCategoryId=" + dsbigflow.Tables["t1"].Rows[3][0] + "  order by sort", conn);
        titsdr = titsmd.ExecuteReader();
        tr = new TableRow();
        this.flow5.Text = dsbigflow.Tables["t1"].Rows[3][1].ToString();
        this.PID5.PSid = dsbigflow.Tables["t1"].Rows[3][0].ToString().Trim();
        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);
            tc.VerticalAlign = VerticalAlign.Bottom;
            tr.Controls.Add(tc);
        }
        zx5.Controls.Add(tr);
        titsdr.Close();

        titsmd = new SqlCommand("select top 10 *  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);
            tc.VerticalAlign = VerticalAlign.Bottom;
            tr.Controls.Add(tc);
        }
        zx1.Controls.Add(tr);
        titsdr.Close();
        
        conn.Close();

    }



    protected void Page_PreInit(object sender, EventArgs e)
    {
        SqlConnection connsk = CDatabase.wtoconn();
        connsk.Open();
        if (Session["skin"] == null)
        {
            SqlCommand smdskin = new SqlCommand("select skinid from SystemBasicInformation", connsk);
            Session["skin"] = Convert.ToString(smdskin.ExecuteScalar());
        }
        this.Page.Theme = Session["skin"].ToString();
        connsk.Close();
    }



    protected void MemberLogin1_Load(object sender, EventArgs e)
    {
    }
}
