📄 bananamobile.vb
字号:
Imports System
Imports System.Data
Imports System.Data.OleDb
Namespace BananaMobile
Public Class BananaMobile
private objConn As New OleDbConnection("Provider=" & _
"Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\ASPNET\data\banana.mdb")
Public Sub Dispose()
objConn.Close
'GC.SuppressFinalize(Me)
End Sub
public Sub AddPart(UserID as Integer, PartID as Integer, Category as String)
dim strSPName as string
select case Category
case "BTS"
strSPName = "spAddBTS"
case "Carpet"
strSPName = "spAddCarpet"
case "Color"
strSPName = "spAddColor"
case "Engine"
strSPName = "spAddEngine"
case "Frame"
strSPName = "spAddFrame"
case "Wheels"
strSPName = "spAddWheels"
end select
Dim objCmd As New OleDbCommand(strSPName, objConn)
objCmd.CommandType = CommandType.StoredProcedure
Dim objParam As New OleDbParameter("@PartID", OleDbType.Integer)
objParam.Value = PartID
objCmd.Parameters.Add(objParam)
objParam = New OleDbParameter("@UserID", OleDbType.Integer)
objParam.Value = UserID
objCmd.Parameters.Add(objParam)
Try
objConn.Open
objCmd.ExecuteNonQuery
objConn.Close
Catch e As Exception
throw e
End Try
End Sub
public sub AddCart(UserID as Integer)
Dim objCmd As New OleDbCommand("spAddCart", objConn)
objCmd.CommandType = CommandType.StoredProcedure
Dim objParam As New OleDbParameter("@UserID", OleDbType.Integer)
objParam.Value = UserID
objCmd.Parameters.Add(objParam)
Try
objConn.Open
objCmd.ExecuteNonQuery
objConn.Close
Catch e As Exception
throw e
End Try
End sub
public function CartExists(UserID as Integer) as Boolean
Dim blnEmpty as Boolean = false
Dim objCmd As New OleDbCommand("spGetCart", objConn)
objCmd.CommandType = CommandType.StoredProcedure
Dim objParam As New OleDbParameter("@UserID", OleDbType.Integer)
objParam.Value = UserID
objCmd.Parameters.Add(objParam)
Try
objConn.Open
if not objCmd.ExecuteScalar is "" then
blnEmpty = True
end if
objConn.Close
Catch e As Exception
throw e
End Try
return blnEmpty
End function
public function GetSubTotal(UserID as Integer) as Double
Dim objSubTotal as Object
Dim objReader as OleDbDataReader
Dim objCmd As New OleDbCommand("spGetSubTotal", objConn)
objCmd.CommandType = CommandType.StoredProcedure
Dim objParam As New OleDbParameter("@UserID", OleDbType.Integer)
objParam.Value = UserID
objCmd.Parameters.Add(objParam)
Try
objConn.Open
'GetSubTotal = CType(objCmd.ExecuteScalar, Double)
objSubTotal = objCmd.ExecuteScalar
objConn.Close
Catch e As Exception
throw e
End Try
if objSubTotal.GetType is GetType(DBNull) then
return 0
end if
return CType(objSubTotal, Double)
End function
public function GetCategory(Category as String) as OleDbDataReader
Dim objReader as OleDbDataReader
Dim objCmd As New OleDbCommand("spGetCategory", objConn)
objCmd.CommandType = CommandType.StoredProcedure
Dim objParam As New OleDbParameter("@Category", OleDbType.Char)
objParam.Value = Category
objCmd.Parameters.Add(objParam)
Try
objConn.Open
objReader = objCmd.ExecuteReader
Catch e As Exception
throw e
End Try
return objReader
End function
public Function ViewMobile(UserID as Integer) as OleDbDataReader
Dim objReader as OleDbDataReader
Dim objCmd As New OleDbCommand("spViewMobile", objConn)
objCmd.CommandType = CommandType.StoredProcedure
Dim objParam As New OleDbParameter("@UserID", OleDbType.Integer)
objParam.Value = UserID
objCmd.Parameters.Add(objParam)
Try
objConn.Open
objReader = objCmd.ExecuteReader
Catch e As Exception
throw e
End Try
return objReader
End Function
public Sub Purchase(UserID as Integer)
Dim objReader as OleDbDataReader
Dim dblSubTotal as Double = 0
dblSubTotal = GetSubTotal(UserID)
Dim objCmdPurchase As New OleDbCommand("spPurchase", objConn)
objCmdPurchase.CommandType = CommandType.StoredProcedure
Dim objCmdRemove As New OleDbCommand("spRemoveCart", objConn)
objCmdRemove.CommandType = CommandType.StoredProcedure
Dim objParam As New OleDbParameter("@SubTotal", OleDbType.Double)
objParam.Value = dblSubTotal
objCmdPurchase.Parameters.Add(objParam)
objParam = New OleDbParameter("@UserID", OleDbType.Integer)
objParam.Value = UserID
objCmdPurchase.Parameters.Add(objParam)
objParam = New OleDbParameter("@UserID", OleDbType.Integer)
objParam.Value = UserID
objCmdRemove.Parameters.Add(objParam)
Try
objConn.Open
objCmdPurchase.ExecuteNonQuery
objCmdRemove.ExecuteNonQuery
objConn.Close
Catch e As Exception
throw e
End Try
End Sub
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -