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;
namespace norke
{
    public partial class qgproducte : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["CID"] = null;

                if (Request.QueryString["cid"] != null)
                {
                    string strCID = Request.QueryString["cid"].ToString();
                    ViewState["CID"] = CleanString.htmlInputText(strCID);
                }
                PData();
                hotdata();
                newdata();
            }
        }
        private void PData()//产品列表绑定
        {
            if (ViewState["CID"] == null)
            {
                //分页
                mySqlPager.setAttribute(SqlPager1, "PDataList", "select * from qqproduct order by qID desc", "1000000-qID", 20);

                lblDaohang.Text = "产品求购";
            }
            else
            {
                string strCID = ViewState["CID"].ToString();
                DBConn myDB = new DBConn();
                string sql = "select * from qqproduct where qlb=" + strCID + " order by qID desc";
                try
                {
                    //分页
                    mySqlPager.setAttribute(SqlPager1, "PDataList", sql, "1000000-qID", 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 hotdata()//推荐求购
        {
            DBConn mydb = new DBConn();
            string sql = "select top 10 * from qqproduct where qtj=1 ";
            HotRepeater.DataSource = mydb.getDataReader(sql);
            HotRepeater.DataBind();
            mydb.Close();
        }
        private void newdata()//最新求购
        {
            DBConn mydb = new DBConn();
            string sql = "select top 10 * from qqproduct order by qid desc";
            Repeater1.DataSource = mydb.getDataReader(sql);
            Repeater1.DataBind();
            mydb.Close();
        }
}
}
