<%@ Page Trace="true" TraceMode="SortByCategory" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<script language="C#" runat="server">
	DataSet DS;
	DataRow[] NRows;
	SqlConnection NowConn;
	SqlConnection Source;
	void OKClick(object sender,EventArgs e){
		if(SQLServer.Text!=""){
			string f="server=" + SQLServer.Text + ";uid=" + uid.Text + ";pwd=" + Password.Text + ";database=WuzchSQL";
			Source = new SqlConnection(f);
			Session["NowWuz"]=Source;
			gData.Visible=false;
			diss.Visible=true;
			SqlDataAdapter NCommx = 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();
//			if(Trace.IsEnabled==true){
//				Trace.Write("ok处理","完成");
//			}
		}
		else{
			err.Text="未输入SQL服务器名称";
//			Trace.Write("ok处理","未执行");
		}
	}
	void PDName_Click(object sender,CommandEventArgs e){
		string Par = e.CommandArgument.ToString();
		Response.Redirect("SelectP.aspx?NowID=" + Par);
	}
	void PFName_OnClick(object sender,CommandEventArgs e){
		string Par = e.CommandArgument.ToString();
		Response.Redirect("SelectP.aspx?NowID=" + Par);
	}
	void page_load(object sender, EventArgs e){
		if(IsPostBack==false){
			if(Session["NowWuz"]!=null){
				gData.Visible=false;
				diss.Visible=true;
				Source = (SqlConnection)Session["NowWuz"];
				SqlDataAdapter NCommx = 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{
				gData.Visible=true;
				diss.Visible=false;
			}
		}
		else{
			Source = (SqlConnection)Session["NowWuz"];
		}
	}
	void selectBrand_t1_onClick(object sender,ImageClickEventArgs e){
		selectBrandSub();
	}
	void selectBrand(object sender,EventArgs e){
		selectBrandSub();
	}
	void selectBrandSub(){
//		allPro.Visible=false;
		string qString = "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 + "'" + "))";
		SqlDataAdapter NComm = 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();
		DataTable t =(DataTable)Session["NowType"];
		if(t.Rows.Count >0){
			show(NRows[0]["ProductTypeID"].ToString());
		}
	}
	void Level1_Click(object sender,CommandEventArgs e){
		show(e.CommandArgument.ToString());
	}
	void show(string PTID){
		DataRow[] k;
		DataTable NowPro=(DataTable)Session["NowType"];
		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();
		SqlDataAdapter NComm = 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();
	}
</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>