Ebrookhouse
New member
- Joined
- Jun 10, 2011
- Messages
- 1
- Programming Experience
- 3-5
I'm looking for a better way to have a form/application that checks a value in SQL, gives the user an option to run a batch file - clicking to initiate the batch file sets a 'timer' variable, and the system sleeps for 5 minutes, once the 5 minutes are up I want to compare the first sql check to another to make sure there was change. If so, enable the second button.
I would prefer to check SQL store the value. The user clicks go - and we know to enable the second button when the SQL table updates. The goal will allow for just a timer to wait, rather than SQL reflecting the change, but I guess that is the lazy way ...
This mostly works, the sql table is checked, the textboxes are updated on start but the second check of sql to see if the tables changed, and activating the button seems to lock the whole app up -
In the below code, any obvious pointers that anyone can share?
Imports System.Data.SqlClient
Imports System.Windows.Forms
Public Class Form1
Dim DisplayIn As Integer
Dim DisplayOut As Integer
Dim Timer1 As Integer = 0
Private Sub MyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AuthInStart.Text = AuthIn()
AuthOutStart.Text = AuthOut()
If Timer1 = 0 Then
Button3.Enabled = False
End If
End Sub
Public Function AuthIn() As Integer
Dim conn As New SQLConnection()
Dim cmd As New SQLCommand()
Dim invalue As Integer
conn.ConnectionString = "Data Source=Umbriel;Initial Catalog=MYDB;User ID=sa;Password=PASSWORD"
cmd.CommandText = "SELECT COUNT(*) FROM BATCH_AUTH_IN"
Try
conn.Open()
cmd.Connection = conn
invalue = CByte(cmd.ExecuteScalar())
conn.Close()
AuthIn = invalue
Catch ex As Exception
AuthIn = invalue
End Try
End Function
Public Function AuthOut() As Integer
Dim conn As New SqlConnection()
Dim cmd As New SqlCommand()
Dim outvalue As Integer
conn.ConnectionString = "Data Source=Umbriel;Initial Catalog=MYDB;User ID=sa;Password=PASSWORD"
cmd.CommandText = "SELECT COUNT(*) FROM BATCH_AUTH_OUT"
Try
conn.Open()
cmd.Connection = conn
outvalue = CByte(cmd.ExecuteScalar())
AuthOut = outvalue
Catch ex As Exception
AuthOut = outvalue
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'create a quit button
Dim intResponse As Integer
intResponse = MsgBox("Are you sure you want to quit?", _
vbYesNo + vbQuestion, _
"Quit")
If intResponse = vbYes Then
End
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim process As New Process()
Try
process.Start("C:\scripts\OP\Create_AUTH.bat")
Button2.Image = My.Resources.yellow
Button2.Text = "Waiting"
Timer1 = 2
Catch ex As Exception
End Try
For i = 1 To 100
Threading.Thread.Sleep(i * 1000)
'Application.DoEvents()
Next
Button3.Enabled = True
AuthIn2.Text = AuthIn()
AuthOut2.Text = AuthOut()
MsgBox("If the counts are increased reasonably go ahead and process")
Button3.Enabled = True
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim process As New Process()
Try
process.Start("C:\scripts\OP\Process_AUTH.bat")
Button2.Image = My.Resources.yellow
Button2.Text = "Waiting"
Timer1 = 3
Catch ex As Exception
End Try
AuthIn2.Text = AuthIn()
AuthOut2.Text = AuthOut()
End Sub
End Class
I would prefer to check SQL store the value. The user clicks go - and we know to enable the second button when the SQL table updates. The goal will allow for just a timer to wait, rather than SQL reflecting the change, but I guess that is the lazy way ...
This mostly works, the sql table is checked, the textboxes are updated on start but the second check of sql to see if the tables changed, and activating the button seems to lock the whole app up -
In the below code, any obvious pointers that anyone can share?
Imports System.Data.SqlClient
Imports System.Windows.Forms
Public Class Form1
Dim DisplayIn As Integer
Dim DisplayOut As Integer
Dim Timer1 As Integer = 0
Private Sub MyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AuthInStart.Text = AuthIn()
AuthOutStart.Text = AuthOut()
If Timer1 = 0 Then
Button3.Enabled = False
End If
End Sub
Public Function AuthIn() As Integer
Dim conn As New SQLConnection()
Dim cmd As New SQLCommand()
Dim invalue As Integer
conn.ConnectionString = "Data Source=Umbriel;Initial Catalog=MYDB;User ID=sa;Password=PASSWORD"
cmd.CommandText = "SELECT COUNT(*) FROM BATCH_AUTH_IN"
Try
conn.Open()
cmd.Connection = conn
invalue = CByte(cmd.ExecuteScalar())
conn.Close()
AuthIn = invalue
Catch ex As Exception
AuthIn = invalue
End Try
End Function
Public Function AuthOut() As Integer
Dim conn As New SqlConnection()
Dim cmd As New SqlCommand()
Dim outvalue As Integer
conn.ConnectionString = "Data Source=Umbriel;Initial Catalog=MYDB;User ID=sa;Password=PASSWORD"
cmd.CommandText = "SELECT COUNT(*) FROM BATCH_AUTH_OUT"
Try
conn.Open()
cmd.Connection = conn
outvalue = CByte(cmd.ExecuteScalar())
AuthOut = outvalue
Catch ex As Exception
AuthOut = outvalue
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'create a quit button
Dim intResponse As Integer
intResponse = MsgBox("Are you sure you want to quit?", _
vbYesNo + vbQuestion, _
"Quit")
If intResponse = vbYes Then
End
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim process As New Process()
Try
process.Start("C:\scripts\OP\Create_AUTH.bat")
Button2.Image = My.Resources.yellow
Button2.Text = "Waiting"
Timer1 = 2
Catch ex As Exception
End Try
For i = 1 To 100
Threading.Thread.Sleep(i * 1000)
'Application.DoEvents()
Next
Button3.Enabled = True
AuthIn2.Text = AuthIn()
AuthOut2.Text = AuthOut()
MsgBox("If the counts are increased reasonably go ahead and process")
Button3.Enabled = True
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim process As New Process()
Try
process.Start("C:\scripts\OP\Process_AUTH.bat")
Button2.Image = My.Resources.yellow
Button2.Text = "Waiting"
Timer1 = 3
Catch ex As Exception
End Try
AuthIn2.Text = AuthIn()
AuthOut2.Text = AuthOut()
End Sub
End Class