<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<script language="vb" runat="server">
	Dim NRows() as DataRow
	Dim NRows1() as DataRow
	Dim NRows2() as DataRow
	Dim Source As SqlConnection
	Dim userData as DataSet
	sub Page_Load(sender as object,e as EventArgs)
		Join.Visible=false
		Source = Ctype(Session("NowWuzvb"),SqlConnection)
		if IsPostBack=false then
			Session("NowID")=Request.QueryString("NowID")
			Dim NComm1 as SqlDataAdapter = new SqlDataAdapter("select * from BuiltinCat", Source)
			Dim NComm2 as SqlDataAdapter = new SqlDataAdapter("select * from BuiltinParts where CombSubID like '" & Request.QueryString("NowID") & "%'", Source)
			Dim DS as DataSet = new DataSet()
			NComm1.Fill(DS, "BuiltinCat")
			NComm2.Fill(DS, "BuiltinParts")
			Level1.DataSource=DS.Tables("BuiltinCat").DefaultView
			Level1.DataBind()
		 	DIm newCol as DataColumn
			Dim DRow as DataRow 
			Dim UserDataTable as DataTable= new DataTable("UserTableS")
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "UserPartid"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "PartID"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "Photo"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "LocLeft"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "Color"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "Model"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.Double")
			newCol.ColumnName = "UpricePart"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "LocTop"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "LocZIndex"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "CatSubPartID"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "UserPartName"
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "CombSubID"
			newCol.Unique = true
			UserDataTable.Columns.Add(newCol)
			newCol = new DataColumn()
			newCol.DataType = System.Type.GetType("System.String")
			newCol.ColumnName = "PartName"
			UserDataTable.Columns.Add(newCol)
			userData = new DataSet()
			userData.Tables.Add(UserDataTable)
			Dim PrimaryKeyColumns(1) as DataColumn
			PrimaryKeyColumns(0) = userData.Tables(UserDataTable.TableName).Columns("CombSubID")
			userData.Tables(UserDataTable.TableName).PrimaryKey = PrimaryKeyColumns
			dim n as string =""
	n="<div  id=plan style=""position: relative ; z-index:1; display:  ""><img border=0 src=""images\CB\Lpic\Type\UB-TYPE01.jpg""  alt=底图>"
			NRows = DS.Tables("BuiltinParts").Select()
			dim i as integer =0 
			for i=0  to NRows.Length-1
				Dim NComm3 as SqlDataAdapter = new SqlDataAdapter("select * from Parts where PartID like '" & NRows(i)("PartID").ToString() & "'",Source)
				dim k as string=""
				k+= NRows(i)("Partid")
				NComm3.Fill(DS, "Parts")
				NRows1 = DS.Tables("Parts").Select()
		n=n & "<div id=" & nRows(i)("PartID").Tostring & " style=""position: absolute; left: " & nRows(i)("LocLeft").Tostring & "; top:" & nRows(i)("LocTop").Tostring & "; z-index:" & nRows(i)("LocZindex").Tostring & ";display:""><img border=0 src=""" & trim(nRows1(i)("CpathName").Tostring) & "\" & trim(nRows1(i)("CfileName").Tostring) & """></div>"
				if IsPostBack=false then
					DRow = UserDataTable.NewRow()
					DRow("CombSubID")=NRows(i)("CombSubID").ToString()
					DRow("PartName")=NRows(i)("PartName").ToString()
					DRow("PartID")=NRows(i)("PartID").ToString()
					DRow("LocLeft")=NRows(i)("LocLeft").ToString()
					DRow("LocTop")=NRows(i)("LocTop").ToString()
					DRow("Color")=NRows(i)("Color").ToString()
					DRow("CatSubPartID")=NRows(i)("CatSubPartID").ToString()
					DRow("Model")=NRows(i)("Model").ToString()
					DRow("UpricePart")=Convert.ToDouble(NRows1(i)("UpricePart").ToString())
					DRow("LocZindex")=NRows(i)("LocZindex")
					DRow("Photo")=NRows1(i)("CpathName") & "\" & NRows1(i)("CfileName")
					UserDataTable.Rows.Add(DRow)
				end if
			next
			Session("NowUserData")=userData.Tables("UserTableS")
			Level5.DataSource=userData.Tables("UserTableS").DefaultView
			n+= "</div>"
			s1.InnerHtml= n
			Session("NowDSA")=DS
		end if
		Dim t as DataTable =Ctype(Session("NowUserData"),DataTable)
		Level5.DataSource=t.DefaultView
		Level5.DataBind()
		UserLevel5.DataSource=t.DefaultView
		UserLevel5.DataBind()
	end sub
	sub OKClick(sender as object,e as EventArgs)
		Response.Redirect("Result.aspx")
	end sub
	sub Level1_Click(sender as object,e as CommandEventArgs)
		Dim DS as DataSet = Ctype(Session("NowDSA"),DataSet)
		dim i as integer =0 
		for i = 0  to DS.Tables.Count-1
			if DS.Tables(i).TableName="BuiltinCatSub" then
				DS.Tables("BuiltinCatSub").Rows.Clear()
				exit for
			end if
		next
		Dim NComm1 as SqlDataAdapter = new SqlDataAdapter("select * from BuiltinCatSub where CatPartID like '" & e.CommandArgument.ToString() & "'", Source)
		NComm1.Fill(DS, "BuiltinCatSub")
		Level2.DataSource=DS.Tables("BuiltinCatSub").DefaultView
		Level2.DataBind()
	end sub
	sub Level2_Click(sender as object ,e as CommandEventArgs)
		Dim DS as DataSet = Ctype(Session("NowDSA"),DataSet)
		dim i as integer =0
		for i = 0  to DS.Tables.Count-1
			if DS.Tables(i).TableName="AvailableParts" then
				DS.Tables("AvailableParts").Rows.Clear()
				exit for
			end if
		next
		dim j() as DataRow
		dim p as DataTable = Ctype(Session("NowUserData"),DataTable)
		j=p.Select("CatSubPartID like '" & e.CommandArgument.ToString() & "'")
		dim x as string =j(0)("CombSubID").ToString()
		dim k(1) as DataColumn
		dim Col as DataColumn
		dim d as string
	d="SELECT AvailableParts.PartID, Parts.lpathname, Parts.lFilename,Parts.Cpathname + '/' + Parts.CFilename as Combine,Parts.lFilename,Parts.lpathname + '/' + Parts.lFilename as Large,Parts.spathname, Parts.sFilename,Parts.spathname + '/' + Parts.sFilename as small,"
	d=d & "AvailableParts.AvailablePartID,AvailableParts.Material,AvailableParts.Specification, AvailableParts.PartName, "
	d=d & "AvailableParts.CombSubID, AvailableParts.CatSubPartID, AvailableParts.LocLeft, AvailableParts.LocTop, Parts.Color,Parts.UpricePart,Parts.Model,"
	d=d & "AvailableParts.LocZindex FROM Parts INNER JOIN AvailableParts ON Parts.PartID = AvailableParts.PartID"
	d=d & " where AvailableParts.CombSubID like '" & x & "'"
		dim NComm2 as SqlDataAdapter = new SqlDataAdapter(d, Source)
		NComm2.Fill(DS, "AvailableParts")
		Col = DS.Tables("AvailableParts").Columns("PartID")
		k(0) = Col
		DS.Tables("AvailableParts").PrimaryKey = k
		Session("NowBuiltSub")=e.CommandArgument.ToString()
		detail.Visible=false
		NRows2 = DS.Tables("AvailableParts").Select()
		Level3.DataSource=DS.Tables("AvailableParts").DefaultView
		Level3.DataBind()
		Session("AvailableParts")=DS.Tables("AvailableParts")
	end sub
	sub ShowDetail(sender as object,e as EventArgs)
		Join.Visible=true
		detail.Visible=true
		dim foundRow as DataRow 
		dim t as DataTable = Ctype(Session("AvailableParts"),DataTable)
		foundRow = t.Rows.Find(Level3.DataKeys(Level3.SelectedItem.ItemIndex))
		dim k as string
		k="材质：" & foundRow("Material").ToString() & "<br>" & "颜色：" & foundRow("color").ToString() & "<br>" & "型号：" & foundRow("model").ToString()
		detail.Text=k
		Session("NowBuiltSub")=foundRow("CombSubID").ToString()
		Session("NowPart")=Level3.DataKeys(Level3.SelectedItem.ItemIndex)
		Session("NowPartName")=foundRow("PartName").ToString()
		Session("NowPhoto")=foundRow("Combine").ToString()
		Session("LocLeft")=foundRow("LocLeft").ToString()
		Session("LocTop")=foundRow("LocTop").ToString()
		Session("Model")=foundRow("Model").ToString()
		Session("Color")=foundRow("Color").ToString()
		Session("UpricePart")=foundRow("UpricePart").ToString()
		Session("LocZindex")=foundRow("LocZindex").ToString()
	end sub
	sub Join_Click(sender as object,e as EventArgs)
		dim n as string
	n="<div  id=plan style=""position: relative ; z-index:1; display:  ""><img border=0 src=""images\CB\Lpic\Type\UB-TYPE01.jpg""  alt=底图>"
		dim foundRow as DataRow 
		dim t as DataTable = Ctype(Session("NowUserData"),DataTable)
		foundRow = t.Rows.Find(Session("NowBuiltSub").ToString())
		foundRow("UserPartID")=Session("NowPart").ToString()
		foundRow("UserPartName")=Session("NowPartName").ToString()
		foundRow("Photo")=Session("NowPhoto").ToString()
		foundRow("LocLeft")=Session("LocLeft").ToString()
		foundRow("LocTop")=Session("LocTop").ToString()
		foundRow("Model")=Session("Model").ToString()
		foundRow("Color")=Session("Color").ToString()
		foundRow("UpricePart")=Session("UpricePart").ToString()
		foundRow("LocZindex")=Session("LocZindex").ToString()
		Dim t1 as DataTable = Ctype(Session("NowUserData"),DataTable)
		Level5.DataSource=t1.DefaultView
		Level5.DataBind()
		UserLevel5.DataSource=t1.DefaultView
		UserLevel5.DataBind()
		Dim Row As DataRow
		for each Row in t.Rows
		n=n & "<div id=" & Row("PartID") & " style=""position: absolute; left: " & Row("LocLeft") & "; top:" & Row("LocTop") & "; z-index:" & Row("LocZindex") & ";display:""><img border=0 src=""" & Row("photo") & """></div>"	
		next
		n+= "</div>"
		s1.InnerHtml= n
	end sub
</script>
</head>

<body background="../../images/winback.gif">
<form runat="server">
<asp:hyperlink text="回首页" NavigateUrl="Default.aspx" runat="server" />
<center>   <table border="1" width="100%">
   <tr>
   <td class="Tab_02_1" align="center">主要项目：</td>
   <td class="Tab_02_2" width="80%" >
    <asp:DataList id="Level1" runat="server"
        RepeatColumns="4"
		RepeatDirection="Horizontal"
		BorderColor="black"
        CellPadding="3"
        Font-Name="Verdana"
        Font-Size="10pt"
        HeaderStyle-BackColor="#aaaadd"
        >
		<ItemTemplate>
			<asp:LinkButton CommandArgument=<%# DataBinder.Eval(Container.DataItem, "CatPartID") %> Text=<%# DataBinder.Eval(Container.DataItem, "CatPartName") %> onCommand="Level1_Click" Runat="server" />
		</ItemTemplate>
	</asp:datalist>
   </td></tr>
   <tr>
   <td class="Tab_02_1" align="center">内　　容：</td>
   <td class="Tab_02_2">
	
    <asp:DataList id="Level2" runat="server"
        RepeatColumns="10"
		RepeatDirection="Horizontal"
        BorderColor="black"
        CellPadding="3"
        Font-Name="Verdana"
        Font-Size="8pt"
        HeaderStyle-BackColor="#aaaadd"
        >
		<ItemTemplate>
			<asp:LinkButton CommandArgument=<%# DataBinder.Eval(Container.DataItem, "CatSubPartID") %> Text=<%# DataBinder.Eval(Container.DataItem, "CatSubPartName") %> onCommand="Level2_Click" Runat="server" />
		</ItemTemplate>
	</asp:datalist>
	</td>
	</tr>
	</table>
<table border="0"> <tr><td>
<table >
<tr>
<td>

<span ID="s1" RUNAT="SERVER"/>
</td>

<td>
</table>
</td>
<td valign="top" width="100%">
<table BORDER="1"><tr><td valign="middle" colspan="2" lign="center" class="Tab_02_1">细目内容
       </td>
       </tr>
       <tr><td valign="top">
       <asp:DataList id="Level3" runat="server"
            RepeatColumns="1"
			RepeatDirection="Horizontal"
			align="center"
			BorderColor="black"
            CellPadding="3"
            Font-Name="Verdana"
			SelectedItemStyle-bordercolor="Red"
			SelectedItemStyle-borderstyle="Solid"
			SelectedItemStyle-borderwidth="1"
            Font-Size="8pt"
			DataKeyField="PartID"
            HeaderStyle-BackColor="#aaaadd"
  			borderWidth="0"
			OnSelectedIndexChanged="ShowDetail"
            >
			<ItemTemplate> 
				<%# DataBinder.Eval(Container.DataItem, "PartName") %>
				<br>
				<asp:Hyperlink target="_blank" id="h1" NavigateUrl=<%# DataBinder.Eval(Container.DataItem,"Large") %> runat="server">
				<asp:Image id=Button1 ImageUrl=<%# DataBinder.Eval(Container.DataItem, "small") %> runat="server" />
				</asp:hyperlink>
				<asp:LinkButton id="Detail1" runat="server" Text="详细资料..." CommandArgument='<%# DataBinder.Eval(Container.DataItem, "CombSubID") %>' CommandName="select" />
			</ItemTemplate>
		</asp:datalist>
		</td>
		<td BORDER="1" valign="top">
			<asp:label id="detail" Font-Size="10pt" runat="server"/>
			<p><asp:linkButton text="选择" id="Join" onclick="Join_Click" runat="server" />
        </td>
        </tr>
</table>
</td></tr></table>

<asp:button id="ChoiceOK" onclick="OKClick" Text="选择确认"  Runat="server" />

<table border="1" width="100%">
<tr>
<td  class="Tab_02_1"  cellpadding="5"  cellspacing="0">
已选之内容：
</td>
</tr>
<tr>
<td>
<asp:Table id="Table1" Font-Name="Verdana" Font-Size="8pt" CellPadding=5 CellSpacing=0 BorderColor="black" BorderWidth="1" Gridlines="Both" runat="server"/>
<asp:label id="test" Visible=False runat="server"/>
    <ASP:DataGrid id="UserLevel5" runat="server"
		BorderColor="black"
        BorderWidth="1"
		columns="2"
	    GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="8pt"
        HeaderStyle-BackColor="#aaaadd"
AutoGenerateColumns="false"
		>
<Columns>
<asp:BoundColumn HeaderText="名称" DataField="PartName" ItemStyle-Wrap="false"/>
<asp:BoundColumn HeaderText="颜色" DataField="Color" ItemStyle-Wrap="false"/>
<asp:BoundColumn HeaderText="型号" DataField="Model" ItemStyle-Wrap="false"/>
<asp:BoundColumn HeaderText="价格" DataField="UpricePart" DataFormatString="{0:C0}"  ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="right" />
</Columns>
</asp:datagrid>

</td>
</tr>
<tr>
<td>
Dataset内容：
    <ASP:DataGrid id="Level5" runat="server"
		BorderColor="black"
        BorderWidth="1"
		columns="2"
	    GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="8pt"
        HeaderStyle-BackColor="#aaaadd"
        Visible="True"
		/>

</td>
</tr>
</table>
<asp:label id="nn" runat="server" />
</form>
</center>
</html>