using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
//该源码首发自www.51aspx.com(５１ａｓpｘ．ｃｏｍ)

namespace norke
{
	/// <summary>
	/// productsList 的摘要说明。
	/// </summary>
	public partial class productsList : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if( !IsPostBack )
			{
                ViewState["CID"] = null;

                if(Request.QueryString["cid"] != null)
                {
                    string strCID = Request.QueryString["cid"].ToString();
                    ViewState["CID"] = CleanString.htmlInputText( strCID );
                }				
                PData();
                HData();
                newdata();               
			}
		}
        private void PData()//产品列表绑定
        {
            if( ViewState["CID"] == null )
            {/*
                DBConn myDB = new DBConn();
                string sql="select * from Products order by PID desc";
                PDataList.DataSource = myDB.getDataReader( sql );
                PDataList.DataBind();
                myDB.Close();
              */
              
                //分页
                mySqlPager.setAttribute( SqlPager1, "PDataList", "select * from Products order by PID desc", "1000000-PID", 20);
                
                lblDaohang.Text = "产品供应";
            }
            else
            {
                string strCID = ViewState["CID"].ToString();
                DBConn myDB = new DBConn();
                string sql="select * from Products where CID=" + strCID + " order by PID desc";
                try
                {
                    /*
                    PDataList.DataSource = myDB.getDataReader( sql );
                    PDataList.DataBind();
                    */
                    //分页
                    mySqlPager.setAttribute( SqlPager1, "PDataList", sql, "1000000-PID", 20);
                }
                catch
                {
                    Response.Write("<script>");
                    Response.Write("alert('没有记录!!!');");
                    Response.Write("</script>");
                    myDB.Close();
                    Response.Redirect("Default.aspx");
                    return;
                }
                myDB.Close();

                DBConn DB = new DBConn();
                string mySql = "select * from Category where CID=" + strCID;
                SqlDataReader dr = DB.getDataReader( mySql );
                if( dr.Read() )
                {
                    lblDaohang.Text = dr["CName"].ToString();
                }
                else
                {
                    Response.Write("<script>");
                    Response.Write("alert('没有这个类别!!!');");
                    Response.Write("</script>");
                    dr.Close();
                    DB.Close();
                    Response.Redirect("Default.aspx");
                    return;
                }
                dr.Close();
                DB.Close();
            }
        }
        private void newdata()
        {
            DBConn myDB = new DBConn();
            string sql = "select top 10 * from Products order by pid desc";
            Repeater1.DataSource = myDB.getDataReader(sql);
            Repeater1.DataBind();
            myDB.Close(); 
            
 
        }
        private void HData()//推荐产品列表绑定
        {           
                DBConn myDB = new DBConn();
                string sql = "select top 10 * from Products  where PCommend=1 order by pid desc";
                HotRepeater.DataSource = myDB.getDataReader( sql );
                HotRepeater.DataBind();
                myDB.Close();
        }

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

        }
		#endregion

       
	}
}
