📄 bills.aspx
字号:
<%@ Page language="Vb" %>
<%@ Register TagPrefix="ASPNETBank" TagName="Header" src="header.ascx" %>
<%@ Register TagPrefix="ASPNETBank" TagName="Menu" src="nav.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
'*******************************************************
'
' Bills.aspx: Allows user to pay bills online
'
'*******************************************************
'declare connection object
dim Conn as new OleDbConnection("Provider=" & _
"Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\ASPNET\data\banking.mdb")
'*******************************************************
' Event hander for submit button. Determines if amount
' is valid, and if so, calls necessary functions to
' update balance and add transaction
'*******************************************************
sub PayBill(obj as object, e as eventargs)
dim decBalance as Decimal = GetBalance
dim decAmount as Decimal = tbAmount.Text
if decAmount < 0 then
lblMessage.Text = "<font color=red>The " & _
"transaction amount cannot be negative!" & _
"</font>"
exit sub
end if
if decAmount <= decBalance then
UpdateBalance(decBalance - decAmount)
AddTransaction(tbPayee.Text, decAmount)
lblMessage.Text = "<font color=red>Transaction " & _
"added.</font>"
tbAmount.Text = ""
tbPayee.Text = ""
else
lblMessage.Text = "<font color=red>You do not " & _
"have enough funds to complete this " & _
"transaction!</font>"
end if
end sub
'*******************************************************
' This function returns the balance of the account with
' the specified user ID (stored in the cookie created
' by forms authentication)
'*******************************************************
function GetBalance as Decimal
dim decBalance as decimal
dim objCmd as OleDbCommand = new OleDbCommand _
("spRetrieveBalance", Conn)
objCmd.CommandType = CommandType.StoredProcedure
dim objReader as OleDbDataReader
'set parameters for stored procedure
dim objParam as OleDbParameter
objParam = objCmd.Parameters.Add("@UserID", _
OleDbType.BSTR)
objParam.Direction = ParameterDirection.Input
objParam.Value = Request.Cookies("Account").Value
try
objCmd.Connection.Open()
decBalance = CType(objCmd.ExecuteScalar, Decimal)
objCmd.Connection.Close()
catch ex as OleDbException
lblMessage.Text = ex.Message
end try
return decBalance
end function
'*******************************************************
' Adds a transaction into the database, calling
' spInsertTransaction and specifying amount, payee, and
' user id
'*******************************************************
sub AddTransaction(strPayee as string, decAmount _
as Decimal)
dim objCmd as OleDbCommand = new OleDbCommand _
("spInsertTransaction", Conn)
objCmd.CommandType = CommandType.StoredProcedure
'set parameters for stored procedure
dim objParam as OleDbParameter
objParam = objCmd.Parameters.Add("@Date", _
OleDbType.Date)
objParam.Direction = ParameterDirection.Input
objParam.Value = Datetime.Now
objParam = objCmd.Parameters.Add("@Amount", _
OleDbType.Decimal)
objParam.Direction = ParameterDirection.Input
objParam.Value = decAmount
objParam = objCmd.Parameters.Add("@Payee", _
OleDbType.BSTR)
objParam.Direction = ParameterDirection.Input
objParam.Value = strPayee
objParam = objCmd.Parameters.Add("@UserID", _
OleDbType.BSTR)
objParam.Direction = ParameterDirection.Input
objParam.Value = Request.Cookies("Account").Value
try
objCmd.Connection.Open()
objCmd.ExecuteNonQuery
catch ex as OleDbException
lblMessage.Text = ex.Message
finally
objCmd.Connection.Close()
end try
end sub
'*******************************************************
' Updates the account balance
' calls spUpdateBalance
'*******************************************************
sub UpdateBalance(decNewAmount as Decimal)
dim objCmd as OleDbCommand = new OleDbCommand _
("spUpdateBalance", Conn)
objCmd.CommandType = CommandType.StoredProcedure
'set parameters for stored procedure
dim objParam as OleDbParameter
objParam = objCmd.Parameters.Add("@NewBalance", _
OleDbType.Decimal)
objParam.Direction = ParameterDirection.Input
objParam.Value = decNewAmount
objParam = objCmd.Parameters.Add("@UserID", _
OleDbType.BSTR)
objParam.Direction = ParameterDirection.Input
objParam.Value = Request.Cookies("Account").Value
try
objCmd.Connection.Open()
objCmd.ExecuteNonQuery
catch ex as OleDbException
lblMessage.Text = ex.Message
finally
objCmd.Connection.Close()
end try
end sub
</script>
<html><body>
<ASPNETBank:Header runat="server" />
<table>
<tr>
<td valign="top" width="150">
<ASPNETBank:Menu runat="server" />
</td>
<td width="550" valign="top">
<font face="arial">
<asp:Label id="lblMessage" runat="server"/>
<form runat="server">
<table>
<tr>
<td width="10">
</td>
<td width="100%">
<font face="arial">
<p>
Welcome to the bill paying service!
Please fill out the information below
and hit "Pay that Bill!" to automatically
transfer available funds.<p>
<table>
<tr>
<td width="150" valign="top">
<font face="arial">
Payee:
</td>
<td width="100" valign="top">
<font face="arial">
<asp:textbox id="tbPayee" runat="server"/>
</td>
</tr>
<tr>
<td valign="top">
<font face="arial">
Amount:
</td>
<td valign="top">
<font face="arial">
<asp:textbox id="tbAmount" runat="server"/>
</td>
</tr>
<tr>
<td valign="top" colspan="2" align="right">
<font face="arial">
<asp:button id="btSubmit" runat="server"
text="Pay That Bill!"
OnClick="PayBill" />
</td>
</tr>
</table>
</font>
</td>
</tr>
</table>
</form>
</font>
</td>
</tr>
</table>
</font>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -