Private Sub assignnumber()
If Label22.Text = "" Then
newrecord()
assignvonum()
Else
' MsgBox("You have already assigned a number!")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
assignbutton = True
assignnumber()
End Sub
Private Sub assignvonum()
If visitid = "" Then
newvisit = True
newrecord()
End If
Connection1.Close()
Connection1.Open()
Dim currentdate As Date
currentdate = Now
Dim cmdupdatevovisit As New SqlClient.SqlCommand("insert into tblPAVoucher (lngvisitid, strcreated, dtmcreated ) values ('" & visitid & "','" & PAAss & "','" & currentdate & "') ", Connection1)
Try
cmdupdatevovisit.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim cmdvoucherid As New Data.SqlClient.SqlCommand("Select max(lngvoucher) from tblPAVoucher where lngvisitid = '" & visitid & "'", Connection1)
Try
voucherid = cmdvoucherid.ExecuteScalar.ToString
' trans1.Commit()
Catch ex As Exception
MsgBox(ex.Message)
End Try
'Get Next Voucher Number from tblPAVoucher using auto numbering
Dim cmd2 As New Data.SqlClient.SqlCommand("Select max(strVoucher) from tblPAVoucher", Connection1)
Try
vonumber = cmd2.ExecuteScalar.ToString
Catch ex As Exception
MsgBox(ex.Message)
End Try
vonumber = "0" & vonumber + 1
Label22.Text = vonumber
Dim cmdupdatevonum As New SqlClient.SqlCommand("update tblPAVoucher set strvoucher = '" & vonumber & "' where lngvoucher = '" & voucherid & "'", Connection1)
Try
cmdupdatevonum.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
updatevo()
End Sub
Private Sub newrecord()
'If comboTest.Text = " " Then
' newrecord()
'insert into newvisit
' If nextrec = False Then
Connection1.Close()
Connection1.Open()
If newvisit = True Then
'If comboTest.Text = " " Then
Connection1.Close()
Connection1.Open()
If visitid = "" Then
Dim trans As SqlTransaction = Connection1.BeginTransaction(IsolationLevel.Serializable)
Dim cmdupdatevisit As New SqlClient.SqlCommand("insert into tblPAVisit ( lngPatientid,dtmcontact,bytvisit,memvisit,bytPartD) values ('" & lngpatientid & "', '" & DateTimePicker1.Text & "', '" & visittype & "', '" & TextBox1.Text.Replace("'", "''") & "', '" & partd & "')", Connection1, trans)
Try
cmdupdatevisit.ExecuteNonQuery()
Catch ex As Exception
'MsgBox(ex.Message)
End Try
'Get Next Voucher Number from tblPAVoucher
Dim cmd2 As New Data.SqlClient.SqlCommand("Select max(lngvisitid) from tblPAVisit with (TABLOCK)", Connection1, trans)
Try
visitid = cmd2.ExecuteScalar.ToString
SqlParametersDB.Name.visitid = visitid
trans.Commit()
Catch ex As Exception
'MsgBox(ex.Message)
trans.Rollback()
End Try
visitidscroll = visitid
End If
newvisit = False
refreshscroll()
End If
End Sub
|