Imports System.Data
Imports System.Data.OleDb
Public Class frmTrans
' Setup Connection Object; con will hold the connection object
Dim con As New OleDb.OleDbConnection ' Transaction table
Dim con2 As New OleDb.OleDbConnection ' 2 is for the Charges
Dim con3 As New OleDb.OleDbConnection ' 3 is for the Patient
' *************************************************************************************************************
' NOTE: Doing the con2 and con3 are the only way I know how to do this. It's a really bad hack, but it works.
' Eventually I'll need to clean this up to make it run smoother and faster.
' *************************************************************************************************************
Dim ds As New DataSet ' DataSet
Dim ds2 As New DataSet
Dim ds3 As New DataSet
Dim da As OleDb.OleDbDataAdapter ' Data adapter
Dim da2 As OleDb.OleDbDataAdapter
Dim da3 As OleDb.OleDbDataAdapter
Dim sql As String ' Holds the query
Dim sql2 As String
Dim sql3 As String
Dim MaxRows As Integer ' Will hold Maximum # of Rows
Dim inc As Integer ' Used for navigating through dataset
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub frmTrans_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' **********************************************************************************************
con2.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = c:\ProFees\profees.mdb"
con2.Open()
sql2 = "Select * From tblCharges"
da2 = New OleDb.OleDbDataAdapter(sql2, con2)
da2.Fill(ds2, "Charges")
If ds2.Tables("Charges").Rows.Count > 0 Then
With dgvCharges
.DataSource = ds2.Tables("Charges")
End With
End If
' **********************************************************************************************
'TODO: This line of code loads data into the 'ProfeesDataSet.tblTrans' table. You can move, or remove it, as needed.
Me.TblTransTableAdapter.Fill(Me.ProfeesDataSet.tblTrans)
'TODO: This line of code loads data into the 'ProfeesDataSet.tblPatient' table. You can move, or remove it, as needed.
Me.TblPatientTableAdapter.Fill(Me.ProfeesDataSet.tblPatient)
'TODO: This line of code loads data into the 'ProfeesDataSet.tblInsurance' table. You can move, or remove it, as needed.
Me.TblInsuranceTableAdapter.Fill(Me.ProfeesDataSet.tblInsurance)
'TODO: This line of code loads data into the 'ProfeesDataSet.tblPhys' table. You can move, or remove it, as needed.
Me.TblPhysTableAdapter.Fill(Me.ProfeesDataSet.tblPhys)
'TODO: This line of code loads data into the 'ProfeesDataSet.tblCharges' table. You can move, or remove it, as needed.
Me.TblChargesTableAdapter.Fill(Me.ProfeesDataSet.tblCharges)
End Sub
Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
' Validating that Account number has been entered.
If txtAccount.Text = "" Then
MsgBox("Please Enter Account Number")
Exit Sub
txtAccount.Focus()
End If
' Validating that the Charge number has been entered
If txtCharge.Text = "" Then
MsgBox("Please Enter Charge Number")
Exit Sub
txtCharge.Focus()
End If
' Setup the Connection String; con is the connection string
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = c:\ProFees\profees.mdb"
' Open the connection to the database
con.Open()
sql = "Select * From tblTrans"
' Create the data adapter
da = New OleDb.OleDbDataAdapter(sql, con)
' Fill the DataSet from the data adapter
da.Fill(ds, "ProFees") ' ProFees is the identifier. Does not have to be name of table.
' Close the connection to the database
con.Close()
MaxRows = ds.Tables("ProFees").Rows.Count ' Stores how many rows are in the DataSet
inc = MaxRows
If inc <> -1 Then ' Make sure there is a valid record to add
Dim cb As New OleDb.OleDbCommandBuilder(da) ' Command Builder
Dim dsNewRow As DataRow ' DataRow Object - needed for adding new rows to DataSet
dsNewRow = ds.Tables("ProFees").NewRow() ' Creates the new DataRow object, stores it in dsNewRow variable
'**********************************************************************************
' Update the Dataset
dsNewRow.Item("Account") = txtAccount.Text
dsNewRow.Item("AllowedAmnt") = txtAllowed.Text
dsNewRow.Item("PaymentAmnt") = txtPayment.Text
dsNewRow.Item("PatPortion") = txtPatPortion.Text
dsNewRow.Item("PatPaid") = txtPatPaid.Text
dsNewRow.Item("Charge") = txtCharge.Text
dsNewRow.Item("DOS") = dtpDOS.Value.ToShortDateString
dsNewRow.Item("Post") = dtpPost.Value.ToShortDateString
dsNewRow.Item("FaceSheet") = chkFaceSheet.CheckState
dsNewRow.Item("Insurance") = cboInsurance.Text
dsNewRow.Item("Physician") = cboPhysician.Text
'*********************************************************************************
ds.Tables("ProFees").Rows.Add(dsNewRow) ' This method adds the Row to the DataSet
da.Update(ds, "ProFees") ' DataAdapter update
End If
'*************************************************************************************
' Udate the DataBase from the DataSet
ds.Tables("ProFees").Rows(inc).Item("Account") = txtAccount.Text
ds.Tables("ProFees").Rows(inc).Item("AllowedAmnt") = txtAllowed.Text
ds.Tables("ProFees").Rows(inc).Item("PaymentAmnt") = txtPayment.Text
ds.Tables("ProFees").Rows(inc).Item("PatPortion") = txtPatPortion.Text
ds.Tables("ProFees").Rows(inc).Item("PatPaid") = txtPatPaid.Text
ds.Tables("ProFees").Rows(inc).Item("Charge") = txtCharge.Text
ds.Tables("ProFees").Rows(inc).Item("DOS") = dtpDOS.Value.ToShortDateString
ds.Tables("ProFees").Rows(inc).Item("Post") = dtpPost.Value.ToShortDateString
ds.Tables("ProFees").Rows(inc).Item("FaceSheet") = chkFaceSheet.CheckState
ds.Tables("ProFees").Rows(inc).Item("Insurance") = cboInsurance.Text
ds.Tables("ProFees").Rows(inc).Item("Physician") = cboPhysician.Text
'*************************************************************************************
da.Update(ds, "ProFees") ' This line here is what actually updates the database!!!!
MsgBox("Data updated")
' Clear labels
txtAccount.Text = ""
txtCharge.Text = ""
dtpDOS.Value = Today
dtpPost.Value = Today
txtAllowed.Text = "0"
txtPayment.Text = "0"
txtPatPortion.Text = "0"
txtPatPaid.Text = "0"
lblFirstName.Visible = False
lblLastName.Visible = False
' Set focus back to txtAccount
txtAccount.Focus()
End Sub
Private Sub txtCharge_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCharge.TextChanged
' Filter the datagrid as the user types in the textbox
Dim aFilter As String
Dim aRows As Integer
If txtCharge.Text.Trim = "" Then
aFilter = ""
Else
aFilter = "Code = " & txtCharge.Text
End If
ds2.Tables("Charges").DefaultView.RowFilter = aFilter
aRows = ds2.Tables("Charges").DefaultView.Count
End Sub
Private Sub txtAccount_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAccount.Leave
' This will run a SQL to determine if the patient is in the system based on the Count.
' If the patient is in the system, then display in the labels.
' If the patient isn't in the system, then bring up the frmNewPatient form.
' TODO: There is a bug where the label isn't showing the correct Patient. It is showing the previous
' patient name that was used. Not sure why it is doing that.
If txtAccount.Text <> "" Then ' Only run through this is something is entered into the Account field
con3.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = c:\ProFees\profees.mdb"
con3.Open()
sql3 = "Select * FROM tblPatient WHERE Account = " & txtAccount.Text
da3 = New OleDb.OleDbDataAdapter(sql3, con3)
da3.Fill(ds3, "Patient")
If ds3.Tables("Patient").Rows.Count < 1 Then ' Patient isn't in the system
frmNewPatient.Show()
con3.Close() ' Close connection
Else
lblFirstName.Visible = True
lblLastName.Visible = True
lblFirstName.Text = ds3.Tables("Patient").Rows(0).Item(1)
lblLastName.Text = ds3.Tables("Patient").Rows(0).Item(2)
End If
con3.Close() ' Close connection
End If
End Sub
Private Sub txtAccount_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAccount.TextChanged
End Sub
End Class