<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<script language="vb" runat="server">
	Dim DS as DataSet
	Dim NRows() as DataRow
	Dim NowConn as SqlConnection
	Dim Source as SqlConnection
	sub OKClick(sender as object,e as EventArgs)
		if SQLServer.Text<>"" then
			dim f as string ="server=" & SQLServer.Text & ";uid=" & uid.Text & ";pwd=" & Password.Text & ";database=WuzchSQL"
			Source = new SqlConnection(f)
			Session("NowWuzvb")=Source
			gData.Visible=false
			diss.Visible=true
			Dim Ncommx as SqlDataAdapter = new SqlDataAdapter("SELECT Brands.*, Suppliers.CompanyName AS CompanyName, Suppliers.HomePage AS HomePage, Suppliers.WebName AS WebName FROM Brands INNER JOIN Suppliers ON Brands.SupplierID = Suppliers.SupplierID",Source)
			DS = new DataSet()
			NCommx.Fill(DS, "Brands")
			SelBrand.DataSource=DS.Tables("Brands").DefaultView
			SelBrand.DataTextField="BrandName"
			SelBrand.DataValueField="BrandID"
			SelBrand.DataBind()
			SelBrand.SelectedIndex=0
			selectBrandSub()
		else
			err.Text="未输入SQL服务器名称"
		end if
	end sub
	sub PDName_Click(sender as object,e as CommandEventArgs)
		dim Par as string = e.CommandArgument.ToString()
		Response.Redirect("SelectP.aspx?NowID=" & Par)
	end sub
	sub PFName_OnClick(sender as object,e as CommandEventArgs)
		Dim Par as string = e.CommandArgument.ToString()
		Response.Redirect("SelectP.aspx?NowID=" & Par)
	end sub
	sub page_load(sender as object, e as EventArgs)
		if IsPostBack=false then
			if Session("NowWuzvb") is nothing then
				gData.Visible=true
				diss.Visible=false
			else
				gData.Visible=false
				diss.Visible=true
				Source = Ctype(Session("NowWuzvb"),SqlConnection)
				Dim NCommx as SqlDataAdapter = new SqlDataAdapter("SELECT Brands.*, Suppliers.CompanyName AS CompanyName, Suppliers.HomePage AS HomePage, Suppliers.WebName AS WebName FROM Brands INNER JOIN Suppliers ON Brands.SupplierID = Suppliers.SupplierID",Source)
				DS = new DataSet()
				NCommx.Fill(DS, "Brands")
				SelBrand.DataSource=DS.Tables("Brands").DefaultView
				SelBrand.DataTextField="BrandName"
				SelBrand.DataValueField="BrandID"
				SelBrand.DataBind()
				SelBrand.SelectedIndex=0
				selectBrandSub()
			end if
		else
			Source = Ctype(Session("NowWuzvb"),SqlConnection)
		end if
	end sub
	sub selectBrand_t1_onClick(sender as object,e as ImageClickEventArgs)
		selectBrandSub()
	end sub
	sub selectBrand(sender as object,e as EventArgs)
		selectBrandSub()
	end sub
	sub selectBrandSub()
		Dim qstring as string= "SELECT ProductTypes.*, Brands.BrandID, ProductTypes.BrandID, Suppliers.CompanyName, Suppliers.ContactName, Suppliers.HomePage, Suppliers.WebName"
		qString += " FROM ((Suppliers INNER JOIN Brands ON Suppliers.SupplierID = Brands.SupplierID) INNER JOIN ProductTypes ON Brands.BrandID = ProductTypes.BrandID)"
		qString += " WHERE (((ProductTypes.BrandID) Like '" & SelBrand.SelectedItem.Value & "'" & "))"
		Dim NComm as SqlDataAdapter = new SqlDataAdapter(qString, Source)
		DS = new DataSet()
		NComm.Fill(DS, "ProductTypes")
	        Level1.DataSource=DS.Tables("ProductTypes").DefaultView
        	Level1.DataBind()
		Session("NowType")=DS.Tables("ProductTypes")
		NRows = DS.Tables("ProductTypes").Select()
		Dim t as DataTable  =Ctype(Session("NowType"),DataTable)
		if t.Rows.Count >0 then
			show(NRows(0)("ProductTypeID").ToString())
		end if
	end sub
	sub Level1_Click(sender as object,e as CommandEventArgs)
		show(e.CommandArgument.ToString())
	end sub
	sub show(PTID as string)
		dim k() as DataRow
		Dim NowPro as DataTable=Ctype(Session("NowType"),DataTable)
		k=NowPro.Select("ProductTypeID Like '" & PTID & "'")
		Model.Text=k(0)("Model").ToString()
		size.Text=k(0)("Size").ToString()
		cheight.Text=k(0)("CHeight").ToString()&"cm"
		DS = new DataSet()
		Dim NComm as SqlDataAdapter = new SqlDataAdapter("select * from Products where ProductTypeID like '" & PTID & "' ORDER BY ProductID asc",Source)
		NComm.Fill(DS, "Products")
	        Level2.DataSource=DS.Tables("Products").DefaultView
        	Level2.DataBind()
	end sub
</script>
</head>
<body background="../../../images/winback.gif">
<form runat="server">
<asp:panel id="gData" runat="server" >
SQL服务器名称：<ASP:TEXTBOX Text="Localhost" runat="server" id="SQLServer" /><br>
登录ID：<ASP:TEXTBOX Text="sa" runat="server" id="uid" /><br>
密码：<ASP:TEXTBOX Runat="server" TextMode="Password" id="Password" /><ASP:button Text="OK" Runat="server" onclick="OKClick" /><br>
<asp:Label id="err" runat="server" />
</asp:panel>
<asp:panel id="diss" visible="false" runat="server" >
<table border="1" cellpadding="2" cellspacing="0" width="100%" >
<tr><td align="center">
   </td>
</tr>
<tr>
<td align="left" valign=middle class="Tab_01" bgcolor="#999999">
	选择品牌：
	<asp:DropDownList id="SelBrand" AutoPostBack=True OnSelectedIndexChanged="selectBrand" runat="server" />&nbsp&nbsp
	<asp:LinkButton Text="确定" onclick="selectBrand" visible=False Runat="server" />
	

</td>
</tr>
</table>

<div id="type_02" STYLE="display:"> 
	<asp:Repeater id="Level1" runat="server">
<HeaderTemplate>
        <font class="t4">平面尺寸：</font> 
		</HeaderTemplate>
		<ItemTemplate>
			<asp:LinkButton CommandArgument=<%# DataBinder.Eval(Container.DataItem, "ProductTypeID") %> Text=<%# DataBinder.Eval(Container.DataItem, "ProductTypeName") %> oncommand="Level1_Click" Runat="server" />
		</ItemTemplate>
	</asp:Repeater>
	<br><font class="t4">配置方式：</font>                                   
	<table border="3" bordercolor="blue" align="center"  class="Tab_08">
		<tr>
			<td class="Tab_06">产品型号</td>
			<td colspan="2" ><asp:Label id="Model" runat="server" /></td>
		</tr>	
		<tr>				
			<td  class="Tab_06">平面尺寸</td>
			<td  ><asp:Label id="size" runat="server" /></td>
			<td></td>
		</tr>	
		<tr>				
			<td  class="Tab_06">天花高度</td>
			<td ><asp:Label id="cheight" runat="server" /></td>
		</tr>	
		<tr><td align="center"  class="Tab_06">配<P>置</P><P>方</P><P>式</P></td>					
			<td  colspan="2"  class="Tab_08">
				<asp:DataList id="Level2" runat="server"
					RepeatColumns="3"
					RepeatDirection="Horizontal"
					align="center"
					BorderColor="black"
					CellPadding="3"
					Font-Name="Verdana"
					Font-Size="8pt"
					HeaderStyle-BackColor="#aaaadd">
					<ItemTemplate>
						<table border="1"><tr><td Width="33%" class="Tab_07">                                       
						<asp:LinkButton CommandArgument=<%# DataBinder.Eval(Container.DataItem, "ProductID") %> Text=<%# DataBinder.Eval(Container.DataItem, "ProductName") %> id=PDName oncommand="PDName_Click" Runat="server" /><br>
						<asp:ImageButton CommandArgument=<%# DataBinder.Eval(Container.DataItem, "ProductID") %> ImageUrl=<%# DataBinder.Eval(Container.DataItem, "PicFileName") %> id=PFName BorderWidth="2px" oncommand="PFName_OnClick" runat="server" /> </td>
						</td></tr></table>
					</ItemTemplate>
				</asp:datalist>
			</td>
		</tr>
	</table>
	<ASP:LABEL ID="LABEL1" RUNAT="SERVER"/>
</div>
</asp:panel>
</form>
</html>