Imports System.Data
Imports System.Data.OleDb
Public Class prod
Inherits System.Web.UI.Page
Dim dbPath As String = Server.MapPath("/kmwperformance/db/kmwperfdata.mdb")
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents rpProducts As System.Web.UI.WebControls.Repeater
Protected WithEvents lblError As System.Web.UI.WebControls.Label
Protected WithEvents rpHeader As System.Web.UI.WebControls.Repeater
Protected WithEvents frmproduct As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents rpTest As System.Web.UI.WebControls.Repeater
Protected WithEvents lblTitle As System.Web.UI.WebControls.Label
Protected WithEvents lbAddToCart As System.Web.UI.WebControls.ImageButton
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Get the values passed from another page
Dim strSQL, strCat, strMake, strModel, strYear As String
strCat = Request.QueryString("c") 'Category
strMake = Request.QueryString("m") 'Make
strModel = Request.QueryString("l") 'Model
strYear = Request.QueryString("y") 'Year
If strCat <> "" Then 'Check to see if there is a category
If strCat <> "1" Then
Call GetProducts(strCat, strMake, strModel, strYear)
Else
Call GetProductsBrackets(strCat, strMake, strModel, strYear)
End If
Else
lblError.Text = "Sorry, there was a problem processing this page. Please click on a menu item on the left to get a product listing."
End If
End Sub
Sub GetProductsBrackets(ByVal strCat As String, ByVal strMake As String, ByVal strModel As String, ByVal strYear As String)
Dim strSQL As String = "SELECT * FROM tblProduct WHERE fldSubCategory = " + strCat
Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + dbPath
Dim ojbConnection As New OleDbConnection(strConnection)
Dim ojbCommand As New OleDbCommand(strSQL, ojbConnection)
Dim ojbDataAdapter As New OleDbDataAdapter
Dim dtProduct As New DataTable
Dim drProduct As DataRow
Dim iProductRow As Integer
ojbDataAdapter.SelectCommand = ojbCommand
ojbDataAdapter.Fill(dtProduct)
iProductRow = dtProduct.Rows.Count
Dim strSQL1 As String = "SELECT * FROM tblProduct WHERE (fldSubCategory = 2) AND (fldMake='" + strMake + "') AND (fldModel='" + strModel + "') AND (fldMinYr <=" + strYear + ") AND (fldMaxYr >=" + strYear + ")"
Dim strConnection1 As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + dbPath
Dim ojbConnection1 As New OleDbConnection(strConnection1)
Dim ojbCommand1 As New OleDbCommand(strSQL1, ojbConnection)
Dim ojbDataAdapter1 As New OleDbDataAdapter
Dim dtBrackets As New DataTable
Dim drBrackets As DataRow
Dim iBracketRow As Integer
ojbDataAdapter1.SelectCommand = ojbCommand1
ojbDataAdapter1.Fill(dtBrackets)
iBracketRow = dtBrackets.Rows.Count
If iProductRow = 0 Or iBracketRow <= 1 Then
lblError.Text = "Sorry we don't show anything for your vehicle at this time"
Else
Dim strBracketTitle(2), strBracketDesc(2), strBracketPrice(2) As String
Dim strTempTitle, strTempPrice, strTempDesc As String
Dim iBracketPriceTotal
Dim iCount As Integer = 1
For iCount = 1 To 2
drBrackets = dtBrackets.Rows.Item(iCount - 1)
strBracketTitle(iCount) = drBrackets.Item("fldTitle")
strBracketDesc(iCount) = drBrackets.Item("fldDescription")
strBracketPrice(iCount) = drBrackets.Item("fldPrice")
Next
iBracketPriceTotal = Val(strBracketPrice(1)) + Val(strBracketPrice(2))
iCount = 0
For iCount = 0 To iProductRow - 1
drProduct = dtProduct.Rows.Item(iCount)
drProduct.Item("fldTitle") += " for a " + strYear + " " + strMake + " " + strModel
drProduct.Item("fldPrice") += iBracketPriceTotal
drProduct.Item("fldDescription") += "<br /><br />" + strBracketTitle(1) + "<br />" + strBracketDesc(1) + "<br /><br />" + strBracketTitle(2) + "<br />" + strBracketDesc(2)
Next
rpProducts.DataSource = dtProduct
rpProducts.DataBind()
Call GetCategory(strCat)
End If
End Sub
Sub GetCategory(ByVal strCat)
Dim strSQL As String = "SELECT * FROM tblSubCategory WHERE fldSubCatID = " + strCat
Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + dbPath
Dim ojbConnection As New OleDbConnection(strConnection)
Dim ojbCommand As New OleDbCommand(strSQL, ojbConnection)
ojbConnection.Open()
rpHeader.DataSource = ojbCommand.ExecuteReader()
rpHeader.DataBind()
ojbConnection.Close()
End Sub
Sub GetProducts(ByVal strCat As String, ByVal strMake As String, ByVal strModel As String, ByVal strYear As String)
Dim strSQL As String
If strMake = "" Then
strSQL = "SELECT * FROM tblProduct WHERE fldSubCategory = " + strCat
Else
strSQL = "SELECT * FROM tblProduct WHERE (fldSubCategory = " + strCat + ") AND (fldMake='" + strMake + "') AND (fldModel='" + strModel + "') AND (fldMinYr <=" + strYear + ") AND (fldMaxYr >=" + strYear + ")"
End If
Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + dbPath
Dim ojbConnection As New OleDbConnection(strConnection)
Dim ojbCommand As New OleDbCommand(strSQL, ojbConnection)
Dim ojbDataAdapter As New OleDbDataAdapter
Dim dtProduct As New DataTable
ojbDataAdapter.SelectCommand = ojbCommand
ojbDataAdapter.Fill(dtProduct)
rpProducts.DataSource = dtProduct
rpProducts.DataBind()
Call GetCategory(strCat)
End Sub
Sub rpProducts_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs)
'Add to cart data
End Sub
End Class