Public
Class frmLookupAdd
Inherits
System.Windows.Forms.Form
Dim
donorDT As New DataTable
Dim
driveDT As New DataTable
Dim
donationDT As New DataTable
Dim
rowIndx As Integer
Dim
IdnoNameArray(2) As IdnoName
Structure IdnoName
Dim aIdno As String
Dim
aName As String
End Structure
Dim
chkIndx As Single
Private Sub frmLookupAdd_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim
wkIdno As String
Dim wkDriveNo
As String
Dim
wkContDate As Date
Dim
wkAmtCont As Double
Dim
aCmd As OleDb.OleDbCommand
wkIdno
= txtAddIdno.Text
wkDriveNo
= txtAddDrive.Text
dataAdapterDonor.Fill(donorDT)
dataAdapterDrive.Fill(driveDT)
dataAdapterDonation.SelectCommand
= New OleDb.OleDbCommand(sqlStrDonation, connDonor)
commandbuilderDonation
= New OleDb.OleDbCommandBuilder(dataAdapterDonation)
dataAdapterDonation.Fill(donationDT)
FillArray()
FillCombo()
FillTextBoxes()
End Sub
Sub
FillTextBoxes()
txtIdno.Text
= CStr(donorDT.Rows(rowIndx)("DIdno"))
txtName.Text
= CStr(donorDT.Rows(rowIndx)("DName"))
End Sub
Sub
FillArray()
'Note I never use the
IdnoNameArray().aName. My original
intention was to use a search.
'I left it because of the structure
definition that I wanted to include.
IdnoNameArray(0).aIdno
= "123"
IdnoNameArray(1).aIdno
= "124"
IdnoNameArray(2).aIdno
= "125"
IdnoNameArray(0).aName
= "Children's
Drive"
IdnoNameArray(1).aName
= "Lunch Drive"
IdnoNameArray(2).aName
= "Shelter Drive"
End Sub
Sub
FillCombo()
Dim i
As Integer
cboDrive.DisplayMember
= "DDriveName"
cboDrive.ValueMember
= "DDriveNo"
cboDrive.DataSource
= driveDT
'For i = 0 To 2
'cboDrive.Items.Add(driveDT.Rows(i))
'Next
'Note that I am also noting out the Add to
the combo box - again, I changed my mind.
'cboDrive.Items.Add("Children's
Drive")
'cboDrive.Items.Add("Lunch
Drive")
'cboDrive.Items.Add("Shelter
Drive")
End Sub
Private
Sub btnFirst_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
rowIndx
= 0
FillTextBoxes()
End Sub
Private
Sub btnNext_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If
rowIndx < donorDT.Rows.Count - 1 Then
rowIndx
= rowIndx + 1
FillTextBoxes()
Else
rowIndx
= 0
FillTextBoxes()
End If
End Sub
Private
Sub btnLast_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
rowIndx
= donorDT.Rows.Count - 1
FillTextBoxes()
End Sub
Private
Sub btnPrevious_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
If
rowIndx > 0 Then
rowIndx
= rowIndx - 1
FillTextBoxes()
Else
rowIndx
= 0
FillTextBoxes()
End If
End Sub
Private
Sub btnIdnoDrive_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnIdnoDrive.Click
txtAddIdno.Text
= txtIdno.Text
txtAddDrive.Text
= IdnoNameArray(cboDrive.SelectedIndex).aIdno
'txtAddDrive.Text = cboDrive.SelectedValue
End Sub
Private
Sub btnDonation_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnDonation.Click
Dim
newRecord As DataRow
newRecord
= donationDT.NewRow()
newRecord("DIdno") = txtAddIdno.Text
newRecord("DDriveNo") = txtAddDrive.Text
newRecord("DDateCont") = txtAddDate.Text
newRecord("DAmtCont") = CDbl(txtAddAmtCont.Text)
donationDT.Rows.Add(newRecord)
MsgBox(donationDT.Rows(donationDT.Rows.Count
- 1)("DAmtCont"))
Try
dataAdapterDonation.Update(donationDT)
Catch
ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Module
LoadMod
Public
currpath As String = System.Environment.CurrentDirectory
Public
connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =
" & currpath & "\donor.mdb"
Public
connDonor As New OleDb.OleDbConnection(connStr)
Public
sqlStrDonor As String = "Select
* from Donor2000"
Public
sqlStrDonation As String = "Select
* from Donation2000"
Public
sqlStrDrive As String = "Select
* from Drive2000"
Public
dataAdapterDonor As New OleDb.OleDbDataAdapter(sqlStrDonor, connDonor)
Public
dataAdapterDrive As New OleDb.OleDbDataAdapter(sqlStrDrive, connDonor)
Public
dataAdapterDonation As New OleDb.OleDbDataAdapter
Public
commandbuilderDonation As OleDb.OleDbCommandBuilder
End Module
Public
Class frmUpdate
Inherits
System.Windows.Forms.Form
Dim
currpath As String = System.Environment.CurrentDirectory
Dim
conStudent As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source= " & currpath & "\stu2000.mdb")
Dim
daStudent As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM tablestu ORDER BY
Idno", conStudent)
Dim
cbStudent As New System.Data.OleDb.OleDbCommandBuilder(daStudent)
Dim
DsStudent1 As New DataSet
Dim
currMang As CurrencyManager
Private Sub btnLast_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
currMang.Position
= currMang.Count - 1
End Sub
Private
Sub btnNext_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
currMang.Position
+= 1
End Sub
Private
Sub btnFirst_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
currMang.Position
= 0
End Sub
Private
Sub btnPrevious_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
currMang.Position
-= 1
End Sub
Private
Sub frmUpdate_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
daStudent.Fill(DsStudent1)
DsStudent1.Tables(0).TableName
= "tablestu"
Catch
err As SystemException
MsgBox(err.Message)
End Try
txtCity.DataBindings.Add(New
Binding("Text", DsStudent1.Tables("tablestu"),
"City"))
txtCredits.DataBindings.Add(New
Binding("Text", DsStudent1.Tables("tablestu"),
"Credits"))
txtGPA.DataBindings.Add(New
Binding("Text", DsStudent1.Tables("tablestu"),
"GPA"))
txtIdno.DataBindings.Add(New
Binding("Text", DsStudent1.Tables("tablestu"),
"Idno"))
txtMajor.DataBindings.Add(New
Binding("Text", DsStudent1.Tables("tablestu"),
"Major"))
txtName.DataBindings.Add(New
Binding("Text", DsStudent1.Tables("tablestu"),
"Name"))
txtState.DataBindings.Add(New
Binding("Text", DsStudent1.Tables("tablestu"),
"State"))
txtYrEntered.DataBindings.Add(New
Binding("Text", DsStudent1.Tables("tablestu"),
"YrEntered"))
currMang
= CType(Me.BindingContext(DsStudent1.Tables("tablestu")), CurrencyManager)
End Sub
Private
Sub btnAdd_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim
newRecord As DataRow = DsStudent1.Tables("tablestu").NewRow
newRecord("Idno") = InputBox("Enter idno", "New Record")
newRecord("Name") = InputBox("Enter name", "New Record")
newRecord("Major") = InputBox("Enter major", "New Record")
newRecord("City") = InputBox("Enter city", "New Record")
newRecord("State") = InputBox("Enter state", "New Record")
newRecord("GPA") = CSng(InputBox("Enter GPA", "New Record"))
newRecord("YrEntered") = InputBox("Enter Year Entered", "New
Record")
newRecord("Credits") = CInt(InputBox("Enter credits",
"New Record"))
DsStudent1.Tables(0).Rows.Add(newRecord)
End Sub
Private
Sub btnChangeDatabase_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnChangeDatabase.Click
If
currMang.Position = currMang.Count - 1 Then
currMang.Position
-= 1
currMang.Position
+= 1
Else
currMang.Position
+= 1
currMang.Position
-= 1
End If
daStudent.Update(DsStudent1,
"tablestu")
End Sub
Private
Sub btnEnd_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
daStudent.Dispose()
Me.Close()
End Sub
Private
Sub btnDelete_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
currMang.RemoveAt(currMang.Position)
End Sub
End Class