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;

namespace norke
{
	/// <summary>
	/// Select 的摘要说明。
	/// </summary>
	public partial class Select : System.Web.UI.Page
	{
        public string url;
    
		protected void Page_Load(object sender, System.EventArgs e)
		{
			 if( !IsPostBack )
            {
                
                if(Request.QueryString["wd"] != null&& Request.QueryString["class"] != null && Request.QueryString["text"] != null )
                {
                    string strWd = Request.QueryString["wd"].ToString();
                    string strClass = Request.QueryString["class"].ToString();
                    string strText = Request.QueryString["text"].ToString();                    
                    strClass = CleanString.htmlInputText( strClass );
                    strText = CleanString.htmlInputText( Server.UrlDecode(strText) );                   
                    if (strWd == "1")
                    {
                        getSelectResult(strClass, strText);//供应
                        url = "productDisplay.aspx?id=";
                        return;
                    }
                    if (strWd == "2")
                    {
                        qgSelectResult(strClass, strText);//求购
                        url = "qglist.aspx?id=";
                        return;
                    }
                    if (strWd == "3")
                    {
                        busness(strClass, strText);//商业
                        url = "zslist.aspx?id=";
                        return;
                    }
                    if (strWd == "4")
                    {
                        company(strClass, strText);//单位
                        url = "Company/company.aspx?name=";
                        return;
                    }

                }    
            }
		}
        private void getSelectResult(string strClass, string strText)//供应查询
        {
            string mySql = "select pid as id,PName as name,PBewrite as content from Products order by PID desc";

            if( strClass.Equals("-1") )
            {
                mySql = "select pid as id,PName as name,PBewrite as content from Products where PName like '%" + strText + "%' order by PID desc";
            }
            else
            {
                mySql = "select pid as id,PName as name,PBewrite as content from Products where CID=" + strClass + " and PName like '%" + strText + "%' order by PID desc";
            }

            //分页
            mySqlPager.setAttribute( SqlPager1, "PDataList", mySql, "1000000-PID", 30);
        }
        private void qgSelectResult(string strClass, string strText)//求购查询
        {
            string mySql = "select qid as id,qname as name,qjs as content from qqproduct order by qID desc";

            if (strClass.Equals("-1"))
            {
                mySql = "select qid as id,qname as name,qjs as content from qqproduct where qname like '%" + strText + "%' order by qID desc";
            }
            else
            {
                mySql = "select qid as id,qname as name,qjs as content from qqproduct where qlb=" + strClass + " and qname like '%" + strText + "%' order by qID desc";
            }

            //分页
            mySqlPager.setAttribute(SqlPager1, "PDataList", mySql, "1000000-QID", 30);
        }
        private void busness(string strClass, string strText)//创业查询
        {
            string mySql = "select id,zname as name,zgaikuang as content from zhaoshang order by ID desc";

            if (strClass.Equals("-1"))
            {
                mySql = "select id,zname as name,zgaikuang as content from zhaoshang where zname like '%" + strText + "%' order by ID desc";
            }
            else
            {
                mySql = "select id,zname as name,zgaikuang as content from zhaoshang where zspfl=" + strClass + " and zname like '%" + strText + "%' order by ID desc";
            }

            //分页
            mySqlPager.setAttribute(SqlPager1, "PDataList", mySql, "1000000-ID", 30);
        }
        private void company(string strClass, string strText)//单位查询
        {
            string mySql = "select id,gsname as name,gsjs as content from Muser order by ID desc";

            if (strClass.Equals("-1"))
            {
                mySql = "select hyname as id,gsname as name,gsjs as content from Muser where gsname like '%" + strText + "%' order by ID desc";
            }
            else
            {
                mySql = "select hyname as id,gsname as name,gsjs as content from Muser where gshangye=" + strClass + " and gsname like '%" + strText + "%' order by ID desc";
            }

            //分页
            mySqlPager.setAttribute(SqlPager1, "PDataList", mySql, "1000000-ID", 30);
        }

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

        }
		#endregion

     
	}
}
