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 zslist : System.Web.UI.Page
    {
        public string strPID="-1";
        public string strPBewrite = "";//产品简介
        public string shichang = "";
        public string xiaoyi = "";
        public string strPUseMode = "";//使用说明
        public string strPValidity = "";//有效期

        public string strBuy = "";//打印留言询价 或 没有存货
        public static string imgname;
        public string company;
        public string word;
        public string sitename;
        public string name;        
    
		protected void Page_Load(object sender, System.EventArgs e)
		{
            if( !IsPostBack )
            {
                if(Request.QueryString["id"]!=null)
                {
                    string strID = Request.QueryString["id"].ToString();
                    strID = CleanString.htmlInputText( strID );
                    
                    DBConn myDB = new DBConn();
                    string sql = "select * from zhaoshang where ID=" + strID;
                    SqlDataReader dr;
                    try
                    {
                        dr = myDB.getDataReader( sql );
                    }
                    catch
                    {
                        Response.Write("<script>");
                        Response.Write("alert('没有这个产品!!!');");
                        Response.Write("</script>");
                        Response.Redirect("Default.aspx");
                        return;
                    }

                    if( dr.Read() )
                    {
                        ViewState["zspfl"] = dr["zspfl"].ToString();
                    }
                    else
                    {
                        Response.Write("<script>");
                        Response.Write("alert('没有这个产品!!!');");
                        Response.Write("</script>");
                        dr.Close();
                        myDB.Close();
                        Response.Redirect("Default.aspx");
                        return;
                    }
                    dr.Close();
                    myDB.Close();

                    ViewState["ID"] = strID;
                }
               
                HData();
                newData();
                DHData();
                PData();
                comp();
                getNewDataList();//最新上架
                qqDataList();//求购
                zsDataList();
                upphb();
               
            }
		}

        private void upphb()
        {
            string strID = ViewState["ID"].ToString();
            DBConn mydb = new DBConn();
            string sql = "update zhaoshang set phb=(select phb from zhaoshang where id=" + strID + ") +1 where id=" + strID;
            mydb.Update(sql);
            mydb.Close();
        }
        private void zsDataList()//创业
        {
            DBConn mydb = new DBConn();
            string sql = "select id,zname,zimg from zhaoshang where hyname='" + Label5.Text + "' order by id desc";
            DataList2.DataSource = mydb.getDataReader(sql);
            DataList2.DataBind();
            mydb.Close();
        }
        private void PData()//显示相应产品信息
        {
            string strID = ViewState["ID"].ToString();

            DBConn myDB = new DBConn();
            string sql = "select * from zhaoshang where ID=" + strID;
            SqlDataReader dr = myDB.getDataReader( sql );
            if( dr.Read() )
            {
                lblPName.Text = dr["zname"].ToString();
                sitename = dr["zname"].ToString();
                lblPNPrice.Text =dr["zztze"].ToString();
                strPBewrite = dr["zgaikuang"].ToString();
                shichang=dr["zscfx"].ToString();
                xiaoyi=dr["zjjxy"].ToString();
                Label1.Text = dr["zhezuo"].ToString();
                Label2.Text = dr["zjzrg"].ToString();
                imgname = dr["zimg"].ToString();
                Label5.Text = dr["hyname"].ToString();
                name = dr["hyname"].ToString();
                word = dr["id"].ToString();
            }
            dr.Close();
            myDB.Close();
        }
        private void comp()//显示相应产品信息
        {
             DBConn myDB = new DBConn();
             string sql = "select gsname,zsname,gsleixing,gsdiqu from Muser where hyname='"+Label5.Text+"'";
            SqlDataReader dr = myDB.getDataReader(sql);
            if (dr.Read())
            {
                company = dr["gsname"].ToString();
                Label3.Text = dr["gsdiqu"].ToString();
                Label4.Text = dr["zsname"].ToString();
                Label6.Text = dr["gsleixing"].ToString();
            }
            dr.Close();
            myDB.Close();
        }
        private void getNewDataList()//最新上架
        {
            DBConn myDB = new DBConn();
            string sql = "select * from Products where uname='"+Label5.Text+"' order by PID desc";
            NDataList.DataSource = myDB.getDataReader(sql);
            NDataList.DataBind();
            myDB.Close();
        }
        private void qqDataList()//求购
        {
            DBConn mydb = new DBConn();
            string sql = "select qid,qname from qqproduct where uname='" + Label5.Text + "' order by qID desc";
            DataList1.DataSource = mydb.getDataReader(sql);
            DataList1.DataBind();
            mydb.Close();
        }

        private void DHData()//导航条设置
        {
            string strCID = ViewState["zspfl"].ToString();

            if( ViewState["zspfl"] == null || ViewState["zspfl"].ToString() == String.Empty )
            {
                lblDaohang.Text = "所有产品";
            }
            else
            {
                DBConn myDB = new DBConn();
                string sql = "select * from Category where CID=" + strCID;
                SqlDataReader dr = myDB.getDataReader( sql );
                if( dr.Read() )
                {
                    lblDaohang.Text = dr["CName"].ToString();
                }
                dr.Close();
                myDB.Close();
            }          
        }

        private void HData()//推荐列表绑定
        {
           DBConn myDB = new DBConn();
           string sql = "select top 10 * from zhaoshang where zsftg=1 ";
           HotRepeater.DataSource = myDB.getDataReader(sql);
           HotRepeater.DataBind();
           myDB.Close();

        }
        private void newData()//最新列表绑定
        {
            DBConn myDB = new DBConn();
            string sql = "select top 10 * from zhaoshang order by id desc";
            Repeater1.DataSource = myDB.getDataReader(sql);
            Repeater1.DataBind();
            myDB.Close();
            

        }
            
        }
	}
