<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@ Register TagPrefix="Toolbar" TagName="Bar" Src="Toolbar.ascx" %>
<%@ Register TagPrefix="NewDropDownlist" TagName="Drop" Src="Drop.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>

<html>
<head>
	<script language="vb" runat="server">
	Dim Source as SqlConnection 
	Dim NowRecordP as integer'显示条数的全局变量
'	Dim GetNew as Boolean
	dim d as string = "SELECT * from Product"
	sub Page_load(sender as Object, e as EventArgs)
		Source = Ctype(Session("NowSTKSQL"),SqlConnection)
		if IsPostBack=false then
			NowRecordP = 1'取得第一条记录
			bindNew(true)
		end if
	end sub
	sub bindNew(tag as Boolean)
		if tag=true then
			Dim DS as DataSet = new DataSet()
			Dim NComm as SqlDataAdapter = new SqlDataAdapter(d, Source)
			Dim NComm1 as SqlDataAdapter = new SqlDataAdapter("SELECT * From Supplier order by SupID", Source)
			Dim NComm2 as SqlDataAdapter = new SqlDataAdapter("SELECT * From Category where CateType like '单位' order by CateID", Source)
			NComm.Fill(DS, "Product")
			NComm.Fill(DS, "ProductShow")
			DS.Tables("ProductShow").Rows.Clear()
			NowBar.NowRecord=NowRecordP
			NowBar.AllRecord=DS.Tables("Product").Rows.Count
			NowBar.NowSource=DS.Tables("Product")
			NowBar.NowUseSource=DS.Tables("ProductShow")
			NowBar.NowDataList="Product"
			NowBar.FirstUse=true
			NowBar.NowStatus="查看记录"
			NowBar.ShowRecord(NowRecordP)
			Session("NowDSPro")=DS
		else'由Session取得记录
			Dim NowDS as DataSet = Ctype(Session("NowDSE"),DataSet)
			Dim k as Integer = NowBar.NowRecord
			NowBar.ShowRecord(k)
		end if
	end sub
	sub Product_EditCommand(sender as Object,e as DataListCommandEventArgs)
		Product.EditItemIndex = e.Item.ItemIndex
        	bindNew(false)
		NowBar.NowStatus="编辑记录"
	end sub
	sub Product_DeleteCommand(sender as Object, e as DataListCommandEventArgs)
		Product.Items(0).FindControl("Sure").Visible=true
		Product.Items(0).FindControl("Button5").Visible=true
		Product.Items(0).FindControl("Button6").Visible=true
	end sub
	sub Product_CancelCommand(sender as Object,e as DataListCommandEventArgs)
		NowBar.NowStatus="查看记录"
		Product.EditItemIndex = -1
		bindNew(false)
	end sub
	sub Product_UpdateCommand(sender as Object, e as DataListCommandEventArgs)
		Dim NowDS as DataSet = Ctype(Session("NowDSPRo"),DataSet)
		Dim NowID as string = Ctype(Product.Items(0).FindControl("ProductID"),Label).Text
		Dim PDTCom as SqlDataAdapter = new SqlDataAdapter("Select * from Product where ProductID Like '" & NowID & "'", Source)
		PDTCom.Fill(NowDS,"NowProduct")
		NowDS.Tables("NowProduct").Rows(0)("PriceCus")=Ctype(Product.Items(0).FindControl("PriceCus"),TextBox).Text
		NowDS.Tables("NowProduct").Rows(0)("ProductName")=Ctype(Product.Items(0).FindControl("ProductName"),TextBox).Text
		Dim custCB as SqlCommandBuilder = new SqlCommandBuilder(PDTCom)
		PDTCom.Update(NowDS,"NowProduct")
		Product.EditItemIndex = -1
		NowRecordP=NowBar.NowRecord
		NowBar.NowStatus="查看记录"
		bindNew(true)
	end sub
	</script>
</head>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
<form enctype="multipart/form-data" runat="server">
查看 <asp:hyperlink id="h1" NavigateUrl="/aspnetdata/shows.aspx?cate=c&file=ch12/12-2/vb/Toolbar.ascx" Text="Toolbar.ascx" runat="server" target="_blank"/><br>
<hr><Toolbar:Bar ID="NowBar" Runat="server" />
        <asp:DataList id="Product" runat="server"
            BorderColor="black"
            BorderWidth="0"
            GridLines="Both"
            CellPadding="3"
            CellSpacing="0"
            Font-Name="Verdana"
            Font-Size="10pt"
            RepeatColumns="1"
            RepeatDirection="Horizontal"
RepeatLayout="Table"
            Width="350px"
           HeaderStyle-BackColor="#C0FFFF"
            SelectedItemStyle-BackColor="#FFFFC0"
            DataKeyField="ProductID"
            OnEditCommand="Product_EditCommand"
            OnUpdateCommand="Product_UpdateCommand"
            OnCancelCommand="Product_CancelCommand"
            >
              <HeaderTemplate>
                产品基本资料
              </HeaderTemplate>
              <ItemTemplate>
                <asp:LinkButton id="button1" runat="server" Text="Edit" CommandName="edit" />
		<table border="1"><tr><td width="160">
		<asp:image width="130" Height="170" ImageURL='<%# DataBinder.Eval(Container.DataItem,"Photo") %>' id="img" Runat="server"/><br></td><td width="150">
                产品编号：<asp:Label id="ProductID1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductID")  %>' /><br>
                书籍名称：<%# DataBinder.Eval(Container.DataItem,"ProductName")  %><br>
                建议售价：<%# DataBinder.Eval(Container.DataItem,"PriceCus")  %><br>
                安全库存：<%# DataBinder.Eval(Container.DataItem,"StockSafe")  %><br>
                目前存量：<%# DataBinder.Eval(Container.DataItem,"StockCurrent")  %><br>
      </ItemTemplate>
             <EditItemTemplate>
<asp:LinkButton id="button3" runat="server" Text="Save" CommandName="Update" />
<asp:LinkButton id="button4" runat="server" Text="Cancel" CommandName="Cancel" /><br>
<table border="1"><tr><td width="160">
		照片：<br><asp:image width="130" Height="170" ImageURL='<%# DataBinder.Eval(Container.DataItem,"Photo") %>' id="img1" Runat="server"/><br></td><td width="150"></td><td width="175" align="left">
                产品编号：
                <asp:Label id="ProductID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductID")  %>' /><br>
                产品名称：
                <asp:TextBox id="ProductName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductName")  %>' /><br>
		建议售价：
	 <asp:TextBox columns="6" id="PriceCus" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"PriceCus")  %>' /><br>
		安全库存：
	 <asp:TextBox columns="6" id="StockSafe" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"StockSafe")  %>' /><br>
		目前存量：
	 <asp:TextBox columns="6" id="StockCurrent" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"StockCurrent")  %>' /><br>
              </EditItemTemplate>
        </asp:DataList>
<asp:label id="nn" runat="server" />
</form>
</body>
