[size=2]Dim bmbAdd As BindingManagerBase
Dim S As String = "$0.00"
Dim dTotal As Double = 0.0
Dim dHaul As Double = 0.0
Dim dStor As Double = 0.0
Dim dAdd As Double = 0.0
Dim dTAmount As Double = 0.0
Dim dDAmount As Double = 0.0
Dim Count As Integer = 1
Dim dsDup As DataSet
Private Sub frmAdd_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daAdd.Fill(DsAdd2, "Primary Table")
daTower.Fill(DsTower2, "Tower")
bmbAdd = Me.BindingContext(DsAdd2, "Primary Table")
RecordCount = bmbAdd.Count
InitialLoad()
dtpReport.Value = Date.Today
dtpTow.Value = Date.Today
End Sub
Private Function SetButtons(ByVal State As Boolean)
txtStock.ReadOnly = False
txtCheck.ReadOnly = False
txtHaul.ReadOnly = False
txtStor.ReadOnly = False
txtAdd.ReadOnly = False
txtTAmount.ReadOnly = False
cboTower.Enabled = True
txtDAmount.ReadOnly = False
dtpReport.Enabled = True
dtpTow.Enabled = True
chbMain.Enabled = True
txtComment.ReadOnly = False
End Function
#Region "3.1"
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click
If bmbAdd.Position = RecordCount - 1 Then
MessageBox.Show("There are no morerecords", "Last Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
bmbAdd.Position += 1
InitialLoad()
End If
End Sub
'3.2 The PREVIOUS button
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrev.Click
If bmbAdd.Position = 0 Then
MessageBox.Show("There are no more records", "First Record",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
bmbAdd.Position -= 1
InitialLoad()
End If
End Sub
'3.3 The FIRST button
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFirst.Click
bmbAdd.Position = 0
InitialLoad()
End Sub
'3.4 The LAST button
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLast.Click
bmbAdd.Position = RecordCount
InitialLoad()
End Sub
#End Region
Private Sub FillNulls()
If txtStock.Text = "" Then
MessageBox.Show("Please enter a valid Stock number", "Stock
Entry Error", MessageBoxButtons.OK)
txtStock.Focus()
End If
If txtCheck.Text = Nothing Then
txtCheck.Text = ""
End If
If txtHaul.Text = "$0.00" Then
txtHaul.Text = "0"
End If
If txtStor.Text = "$0.00" Then
txtStor.Text = "0"
End If
If txtAdd.Text = "$0.00" Then
txtAdd.Text = "0"
End If
If txtTAmount.Text = "$0.00" Then
txtTAmount.Text.ToString()
End If
If cboTower.Text = Nothing Then
cboTower.Text = "System"
End If
'If txtDAmount.Text = 0 Then
' txtDAmount.Text = 0
'End If
If txtReport.Text = Nothing Then
txtReport.Text = Date.Today.ToString
End If
If txtTow.Text = Nothing Then
txtTow.Text = Date.Today.ToString
End If
If chbMain.Text = Nothing Then
chbMain.Text = ""
End If
If txtComment.Text = Nothing Then
txtComment.Text = ""
End If
InitialLoad()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
SetButtons(False)
If Count <> 1 Then
dHaul = 0
dStor = 0
dAdd = 0
dTAmount = 0
dDAmount = 0
dTotal = 0
FillNulls()
Dim dv As New DataView(DsAdd2.Primary_Table())
dv.RowFilter = "Stock = '" & txtStock.Text & "'"
If dv.Count > 0 Then
MessageBox.Show(" ")
txtStock.Text = ""
Exit Sub
End If
bmbAdd.EndCurrentEdit()
daAdd.Update(DsAdd2, "Primary Table")
Else
Count = 2
End If
bmbAdd.AddNew()
InitialLoad()
txtStock.Focus()
txtReport.Text = Me.dtpReport.Value.ToString
txtTow.Text = Me.dtpTow.Value.ToString
End Sub
#Region "5.1"
'Setting up the Return Key for each textbox
Private Sub StockFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtStock.KeyDown
If e.KeyCode = Keys.Return = True Then
If txtStock.Focus = True Then
txtCheck.Focus()
End If
End If
End Sub
Private Sub CheckFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtCheck.KeyDown
If e.KeyCode = Keys.Return = True Then
If txtCheck.Focus = True Then
txtHaul.Focus()
End If
End If
End Sub
Private Sub HaulFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtHaul.KeyDown
If e.KeyCode = Keys.Return = True Then
If txtHaul.Focus = True Then
txtStor.Focus()
dHaul = Val(txtHaul.Text)
txtHaul.Text = Format(dHaul, "Currency")
dTotal = dTotal + dHaul
Totals()
End If
End If
End Sub
Private Sub StorFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtStor.KeyDown
If e.KeyCode = Keys.Return = True Then
If txtStor.Focus = True Then
txtAdd.Focus()
dStor = Val(txtStor.Text)
txtStor.Text = Format(dStor, "Currency")
dTotal = dTotal + dStor
Totals()
End If
End If
End Sub
Private Sub AddFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtAdd.KeyDown
If e.KeyCode = Keys.Return = True Then
If txtAdd.Focus = True Then
txtTAmount.Focus()
dAdd = Val(txtAdd.Text)
txtAdd.Text = Format(dAdd, "Currency")
dTotal = dTotal + dAdd
Totals()
End If
End If
End Sub
Private Sub TAmountFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtTAmount.KeyDown
If e.KeyCode = Keys.Return = True Then
If txtTAmount.Focus = True Then
cboTower.Focus()
dTAmount = Val(txtTAmount.Text)
txtTAmount.Text = Format(dTAmount, "Currency")
dTotal = dTotal + dTAmount
Totals()
End If
End If
End Sub
Private Sub TowerFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles cboTower.KeyDown
If e.KeyCode = Keys.Return = True Then
If cboTower.Focus = True Then
txtDAmount.Focus()
End If
End If
End Sub
Private Sub DAmountFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtDAmount.KeyDown
If e.KeyCode = Keys.Return = True Then
If txtDAmount.Focus = True Then
dtpReport.Focus()
dDAmount = Val(txtDAmount.Text)
txtDAmount.Text = Format(dDAmount, "Currency")
End If
End If
End Sub
Private Sub ReportFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles dtpReport.KeyDown
If e.KeyCode = Keys.Return = True Then
If dtpReport.Focus = True Then
dtpTow.Focus()
End If
End If
End Sub
Private Sub TowFocus(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles dtpTow.KeyDown
If e.KeyCode = Keys.Return = True Then
If dtpTow.Focus = True Then
btnAdd.Focus()
End If
End If
End Sub
#End Region
Private Sub Totals()
dTotal = dHaul + dStor + dAdd + dTAmount
lblTotal.Text = Format(dTotal, "Currency")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub InitialLoad()
dHaul = Val(txtHaul.Text)
txtHaul.Text = Format(dHaul)
dTotal = dTotal + dHaul
dStor = Val(txtStor.Text)
txtStor.Text = Format(dStor, "Currency")
dTotal = dTotal + dStor
dAdd = Val(txtAdd.Text)
txtAdd.Text = Format(dAdd, "Currency")
dTotal = dTotal + dAdd
dTAmount = Val(txtTAmount.Text)
txtTAmount.Text = Format(dTAmount, "Currency")
dTotal = dTotal + dTAmount
Totals()
dDAmount = Val(txtDAmount.Text)
txtDAmount.Text = Format(dDAmount, "Currency")
End Sub
#Region "Finding Stock"
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFind.Click
If txtFind.Text = "" Then
MessageBox.Show("Please enter a valid Stock number", "Stock
Entry Error", MessageBoxButtons.OK)
Else
strSQL = "SELECT Id, Check#, Hauling, Storage, Additional,
Towing, First, [Driver Amount], [Report Date], [Tow Date], [Mainstay Tow],
Comments, ID FROM [Primary Table] WHERE Stock ='" & txtFind.Text & "'"
If SqlConnection1.State = False Then
SqlConnection1.Open()
End If
cmd = New SqlClient.SqlCommand(strSQL, SqlConnection1)
objRead = cmd.ExecuteReader
While objRead.Read
txtStock.Text = txtFind.Text
If IsDBNull(objRead("Check#")) Then
txtCheck.Text = ""
Else
txtCheck.Text = objRead("Check#")
End If
If IsDBNull(objRead("Hauling")) Then
txtHaul.Text = 0
Else
txtHaul.Text = objRead("Hauling")
End If
If IsDBNull(objRead("Storage")) Then
txtStor.Text = 0
Else
txtStor.Text = objRead("Storage")
End If
If IsDBNull(objRead("Additional")) Then
txtAdd.Text = 0
Else
txtAdd.Text = objRead("Additional")
End If
If IsDBNull(objRead("Towing")) Then
txtTAmount.Text = 0
Else
txtTAmount.Text = objRead("Towing")
End If
If IsDBNull(objRead("First")) Then
cboTower.Text = "System"
Else
cboTower.Text = objRead("First")
End If
If IsDBNull(objRead("Driver Amount")) Then
txtDAmount.Text = 0
Else
txtDAmount.Text = objRead("Driver Amount")
End If
If IsDBNull(objRead("Report Date")) Then
dtpReport.Value = Date.Today
Else
dtpReport.Value = objRead("Report Date")
End If
If IsDBNull(objRead("Tow Date")) Then
dtpTow.Value = Date.Today
Else
dtpTow.Value = objRead("Tow Date")
End If
If IsDBNull(objRead("Mainstay Tow")) Then
chbMain.Text = ""
Else
chbMain.Text = objRead("Mainstay Tow")
End If
If IsDBNull(objRead("Comments")) Then
txtComment.Text = ""
Else
txtComment.Text = objRead("Comments")
End If
InitialLoad()
End While
objRead.Close()
End If
txtFind.Text = ""
End Sub
#End Region
Private Sub btnAdd2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd2.Click
Dim confirm As Integer
confirm = MessageBox.Show("Are you sure you want to remove stock: "
& txtStock.Text & " ?", "Delete Confirmation", MessageBoxButtons.YesNo)
If confirm = 6 Then
bmbAdd.RemoveAt(bmbAdd.Position)
bmbAdd.EndCurrentEdit()
'daAdd.DeleteCommand.
End If
End Sub
Private Sub dtpReport_ValueChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles dtpReport.ValueChanged
Me.txtReport.Text = Me.dtpReport.Value
End Sub
Private Sub btnModify_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnModify.Click[/size]
[size=2]SetButtons(False)
End Sub
End Class[/size]