Dim dsSoftware As DataSet = New DataSet()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
dsSoftware = SoftwareDB.getEntries
Me.BindDataGrid()
Session("dsSoftware") = dsSoftware
Else
'dsSoftware = Session("dsSoftware") *** This is the line that would allow things to work, but causes too many search returns.
End If
End Sub
Private Sub BindDataGrid()
softwareGrid.DataSource = dsSoftware
softwareGrid.DataMember = "[SOFTWARE DATABASE]"
softwareGrid.DataKeyField = "Software #"
softwareGrid.DataBind()
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal E As System.EventArgs) Handles btnSearch.Click
Dim Connect As OleDbConnection = New OleDbConnection()
Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter()
Dim SelectStatement, ConnectString As String
Dim WhereClause As String
WhereClause = "Where "
If txtSoftwareNum.Text <> "" Then
WhereClause = WhereClause & "InStr([Software #],'" & _
txtSoftwareNum.Text & "')>0 AND "
End If
If txtSoftwareName.Text <> "" Then
WhereClause = WhereClause & "InStr([Software Name],'" & _
txtSoftwareName.Text & "')>0 AND "
End If
If txtVersion.Text <> "" Then
WhereClause = WhereClause & "InStr(Version,'" & _
txtVersion.Text & "')>0 AND "
End If
If txtLocation.Text <> "" Then
WhereClause = WhereClause & "InStr(Location,'" & _
txtLocation.Text & "')>0 AND "
End If
If txtSoftwareBrand.Text <> "" Then
WhereClause = WhereClause & "InStr([Soft Brand],'" & _
txtSoftwareBrand.Text & "')>0 AND "
End If
If txtDatePurchased.Text <> "" Then
WhereClause = WhereClause & "InStr(DatePurchased,'" & _
txtDatePurchased.Text & "')>0 AND "
End If
If txtFirstName.Text <> "" Then
WhereClause = WhereClause & "InStr(FirstName,'" & _
txtFirstName.Text & "')>0 AND "
End If
If txtLastName.Text <> "" Then
WhereClause = WhereClause & "InStr(LastName,'" & _
txtLastName.Text & "')>0 AND "
End If
If txtSerialNumber.Text <> "" Then
WhereClause = WhereClause & "InStr([Serial Number],'" & _
txtSerialNumber.Text & "')>0 AND "
End If
If txtModel.Text <> "" Then
WhereClause = WhereClause & "InStr(Model,'" & _
txtModel.Text & "')>0 AND "
End If
If Right(WhereClause, 4) = "AND " Then
WhereClause = Left(WhereClause, Len(WhereClause) - 4)
End If
SelectStatement = "Select * From [SOFTWARE DATABASE] " & WhereClause
' If they didnt enter anything in the textboxes:
If txtSoftwareNum.Text = "" And txtSoftwareName.Text = "" And _
txtVersion.Text = "" And txtLocation.Text = "" And _
txtSoftwareBrand.Text = "" And txtDatePurchased.Text = "" And _
txtFirstName.Text = "" And txtLastName.Text = "" And _
txtSerialNumber.Text = "" And txtModel.Text = "" Then
SelectStatement = "Select * From [SOFTWARE DATABASE]"
Else
End If
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Inetpub\wwwroot\ASPproject\WebApplication2\software\softwaredb.mdb"
Connect.ConnectionString = ConnectString
Adapter.SelectCommand = New OleDbCommand(SelectStatement, Connect)
Adapter.SelectCommand.Connection.Open()
Adapter.Fill(dsSoftware, "[SOFTWARE DATABASE]")
softwareGrid.DataSource = dsSoftware.Tables("[SOFTWARE DATABASE]")
Page.DataBind()
End Sub
Public Sub softwareGrid_EditCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
Handles softwareGrid.EditCommand
If Session("Add Mode") = True Then
Dim i As Integer = dsSoftware.Tables("[SOFTWARE DATABASE]").Rows.Count - 1
dsSoftware.Tables("[SOFTWARE DATABASE]").Rows(i).Delete()
Session("AddMode") = False
End If
softwareGrid.EditItemIndex = e.Item.ItemIndex
Me.BindDataGrid()
End Sub
Public Sub softwareGrid_CancelCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles softwareGrid.CancelCommand
If Session("AddMode") = True Then
Dim i As Integer = dsSoftware.Tables("[SOFTWARE DATABASE]").Rows.Count - 1
dsSoftware.Tables("[SOFTWARE DATABASE]").Rows(i).Delete()
Session("AddMode") = False
End If
softwareGrid.EditItemIndex = -1
Me.BindDataGrid()
End Sub
Public Sub softwareGrid_UpdateCommand(ByVal source As Object, ByVal E As DataGridCommandEventArgs) Handles softwareGrid.UpdateCommand
Dim tbSoftwareNum As String
tbSoftwareNum = E.Item.Cells(0).Text
Dim tbSoftwareName As String
tbSoftwareName = CType(E.Item.Cells(1).Controls(0), TextBox).Text
Dim tbVersion As String
tbVersion = CType(E.Item.Cells(2).Controls(0), TextBox).Text
Dim tbLocation As String
tbLocation = CType(E.Item.Cells(3).Controls(0), TextBox).Text
Dim tbSoftBrand As String
tbSoftBrand = CType(E.Item.Cells(4).Controls(0), TextBox).Text
Dim tbDatePurchased As String
tbDatePurchased = CType(E.Item.Cells(5).Controls(0), TextBox).Text
Dim tbFirstName As String
tbFirstName = CType(E.Item.Cells(6).Controls(0), TextBox).Text
Dim tbLastName As String
tbLastName = CType(E.Item.Cells(7).Controls(0), TextBox).Text
Dim tbSerialNumber As String
tbSerialNumber = CType(E.Item.Cells(8).Controls(0), TextBox).Text
Dim tbModel As String
tbModel = CType(E.Item.Cells(9).Controls(0), TextBox).Text
If ValidEntry(tbSoftwareNum, tbSoftwareName, tbLocation) Then
Debug.WriteLine("The row index is:")
Debug.WriteLine(E.Item.ItemIndex)
Debug.WriteLine("This is ds:")
Debug.WriteLine(dsSoftware.GetXml)
Dim dr As DataRow = dsSoftware.Tables("[SOFTWARE DATABASE]").Rows(E.Item.ItemIndex)
Try
dr("Software #") = tbSoftwareNum
dr("Software Name") = tbSoftwareName
dr("Version") = tbVersion
dr("Location") = tbLocation
dr("Soft Brand") = tbSoftBrand
dr("DatePurchased") = tbDatePurchased
dr("FirstName") = tbFirstName
dr("LastName") = tbLastName
dr("Serial Number") = tbSerialNumber
dr("Model") = tbModel
Me.UpdateDataBase()
softwareGrid.EditItemIndex = -1
Me.BindDataGrid()
Session("AddMode") = False
Catch eConstraint As ConstraintException
lblMessage.Text = "A category with that ID already exists."
End Try
End If
End Sub
Private Function ValidEntry(ByVal SoftwareNum As String, ByVal SoftwareName As String, _
ByVal Location As String) As Boolean
ValidEntry = True
If SoftwareNum = "" Then
ValidEntry = False
lblMessage.Text = "Software Number is required."
ElseIf Len(SoftwareNum) > 7 Then
ValidEntry = False
lblMessage.Text = "Software Number must be 7 characters or less."
ElseIf SoftwareName = "" Then
ValidEntry = False
lblMessage.Text = "Software Name is required."
ElseIf Location = "" Then
ValidEntry = False
lblMessage.Text = "A Location for where the software is stored must be specified."
End If
End Function
Private Sub UpdateDataBase()
Select Case SoftwareDB.UpdateEntries(dsSoftware)
Case SoftwareDB.UpdateResult.ConcurrencyError
lblMessage.Text = "Another user has updated that category. Please try again."
Case SoftwareDB.UpdateResult.ForeignKeyError
lblMessage.Text = "That entry is in use."
Case SoftwareDB.UpdateResult.PrimaryKeyError
lblMessage.Text = "Another user has added a category with that software number."
Case SoftwareDB.UpdateResult.OtherOleDbError
lblMessage.Text = "An unspecified OleDb Server error has occurred."
End Select
dsSoftware = SoftwareDB.getEntries
Session("dsSoftware") = dsSoftware
End Sub