<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@ Page Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Register TagPrefix="Edit" Namespace="DataCon_vb" Assembly="Edit_vb" %>
<html>
<head>
	<script language="vb" runat="server">
	sub Page_load(sender as object, e as EventArgs)
		if IsPostBack=false then
			bindNew(true)
			NowEdit.NowRecord=0'设定目前条数
			Page.DataBind()
		end if
	end sub
	sub bindNew(tag as Boolean)
		if tag=true then'以下均是自定义控件的属性
			NowEdit.SQLString="Select * from Customers"
			NowEdit.ServerName="Localhost"'服务器名称
			NowEdit.Uid="sa"'登录id
			NowEdit.Pass=""'密码
			NowEdit.DataKeyField="CusID"
			NowEdit.DBName="stockSQL"
			NowEdit.TBName="customers"
			NowEdit.NowMode="View"
			Page.DataBind()
		end if
	end sub
	sub SaveClick(sender as object, e as EventArgs)
		Dim x as Boolean=NowEdit.Save()
		if x<>true then
			ErrorSave.Text = "保存错误"
		else
			ErrorSave.Text = ""
			Save.Visible=false
			Del.Visible=true
			EditOrView.Text="编辑"
			NowEdit.NowMode="View"
		end if
	end sub
	sub DelClick(sender as object, e as EventArgs)
		dim d as string="Delete " & NowEdit.TBName & " Where " & NowEdit.DataKeyField & " ='" & NowEdit.DataKeyValue & "'"
		NowEdit.Delete(d)'删除
		bindNew(true)
	end sub
	sub EditClick(sender as object, e as EventArgs)
		ErrorSave.Text = ""
		if EditOrView.Text="编辑" then'编辑
			NowEdit.NowMode="Edit"
			EditOrView.Text="取消"
			Save.Visible=true
			Del.Visible=false
		else'检视
			NowEdit.NowMode="View"
			EditOrView.Text="编辑"
			Save.Visible=false
			Del.Visible=true
		end if
	end sub
	sub ChangeRecord(sender as object, e as CommandEventArgs)
		if e.CommandArgument = "Next" then'下条
			if NowEdit.NowRecord+1<NowEdit.AllRecords then
				NowEdit.NowRecord+=1
			end if
		elseif e.CommandArgument = "First" then'首条
			NowEdit.NowRecord=0
		elseif e.CommandArgument = "Last" then'末条
			NowEdit.NowRecord=NowEdit.AllRecords-1
		elseif e.CommandArgument = "Prev" then'上条
			if NowEdit.NowRecord > 0 then
				NowEdit.NowRecord-=1
			else
				NowEdit.NowRecord = 0
			end if
		end if
		Page.DataBind()
	end sub
	sub GotoRecord(sender as object,e as EventArgs)
		if Convert.ToInt32(ToRecord.Text)<NowEdit.AllRecords then
			NowEdit.NowRecord=Convert.ToInt32(ToRecord.Text)-1
		elseif(Convert.ToInt32(ToRecord.Text)<0) then
			NowEdit.NowRecord=0
		end if
		Page.DataBind()
	end sub
	</script>
</head>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
<form runat="server">
查看 <asp:hyperlink id="h1" NavigateUrl="/aspnetdata/shows.aspx?cate=c&file=ch12/12-3/vb/Edit.vb" Text="Edit.cs" runat="server" target="_blank"/><br>
<asp:LinkButton ID="First" Tooltip="First" OnCommand="ChangeRecord" Runat="server" Text="首条" CommandArgument="First" cssclass="Tab_08" />
<asp:LinkButton ID="Prev" Tooltip="Prev" OnCommand="ChangeRecord" Runat="server" Text="上条" CommandArgument="Prev"  cssclass="Tab_08"/>
<asp:LinkButton ID="Next" Tooltip="Next" OnCommand="ChangeRecord" Runat="server" Text="下条" CommandArgument="Next"  cssclass="Tab_08"/>
<asp:LinkButton ID="Last" Tooltip="Last" OnCommand="ChangeRecord" Runat="server" Text="末条" CommandArgument="Last"  cssclass="Tab_08"/>
至第<asp:TextBox Columns="3" AutoPostBack="true" ID="ToRecord" OnTextChanged="GotoRecord" Runat="server" />条
<p>第<asp:Label ID="CurrentRecord" Text='<%# NowEdit.NowRecord+1 %>' Tooltip="CurrentRecord" Runat="server" />条，共<asp:Label ID="AllRecords" Text='<%# NowEdit.AllRecords %>' Tooltip="AllRecords" Runat="server" />条
<asp:linkButton ID="EditOrView" Text="编辑" Runat="server" Onclick="EditClick" />  
<asp:linkButton ID="Save" Text="保存" Visible="false" Runat="server" Onclick="SaveClick" />  
<asp:linkButton ID="Del" Text="删除" Runat="server" Onclick="DelClick" />
<asp:label id="ErrorSave" runat="server" />
<hr>
<Edit:SqlData_vb ID="NowEdit" Runat="server" />
</form>
</body>