Hello dharmendr,
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GetRawTank1()
GetRaw1()
End Sub
Private Sub GetRawTank1()
' CLEAR COMBOBOX
cbxrawtank1.Items.Clear()
' QUERY raw_tanks TABLE
SQL.RunQuery("SELECT tank_name FROM raw_tanks where tank_name = 'Raw_Tank_A'")
' IF RECORDS ARE FOUND, ADD THEM TO THE COMBOBOX
If SQL.RecordCount > 0 Then
For Each r As DataRow In SQL.SQLDS.Tables(0).Rows
cbxrawtank1.Items.Add(r("tank_name"))
Next
ElseIf SQL.Exception <> "" Then
MsgBox(SQL.Exception)
End If
End Sub
Private Sub GetRaw1()
' CLEAR COMBOBOX
cbxraw1.Items.Clear()
' QUERY raw_materials TABLE
SQL.RunQuery("SELECT material_name FROM raw_materials")
' IF RECORDS ARE FOUND, ADD THEM TO THE COMBOBOX
If SQL.RecordCount > 0 Then
For Each r As DataRow In SQL.SQLDS.Tables(0).Rows
cbxraw1.Items.Add(r("material_name"))
Next
ElseIf SQL.Exception <> "" Then
MsgBox(SQL.Exception)
End If
End Sub
Private Sub GetReading1(Tank1 As String)
' ADD SEARCH PARAMETER
SQL.AddParam("@tank1", Tank1)
' RUN QUERY
SQL.RunQuery("SELECT reading from DATAGRID WHERE tank_name = '" & cbxrawtank1.Text & "' and material_name = @tank1")
' IF Tank IS FOUND, SEND Reading TO OUT TEXTBOX
If SQL.RecordCount > 0 Then txt1.Text = SQL.SQLDS.Tables(0).Rows(0).Item("reading")
End Sub
Private Sub cbxraw1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxraw1.SelectedIndexChanged
GetReading1(cbxraw1.Text)
End Sub
Private Sub cmdupdate1_Click(sender As Object, e As EventArgs) Handles cmdupdate1.Click
Dim UpdateCmd As String = "UPDATE DATAGRID " & _
"SET reading +='" & txtupdate1.Text & "' " & _
"WHERE tank_name ='" & cbxrawtank1.Text & "' AND material_name = '" & cbxraw1.Text & "'"
If SQL.Update(UpdateCmd) = 0 Then
MsgBox("The Specified raw_tank could not be found!")
End If
GetReading11(cbxraw1.Text)
End Sub
Private Sub cmdfill1_Click(sender As Object, e As EventArgs) Handles cmdfill1.Click
If txtupdate1.Text <> "" Or txt8.Text <> "" Or txt22.Text <> "" Or txt15.Text <> "" Then
SQL.RunQuery("SELECT * FROM Report WHERE Report.tank_name = '" & cbxrawtank1.Text & "' and Report.material_name = '" & cbxraw1.Text & "' ")
If SQL.SQLDS.Tables(0).Rows.Count > 0 Then
MsgBox("Tank Already filled with another Material!")
Exit Sub
Else
CreateUser()
MsgBox("Instance is added to Report!")
End If
End If
txtupdate1.Clear()
txt8.Clear()
txt15.Text = 0.0
txt22.Text = 0.0
GetReading1(cbxraw1.Text)
End Sub
Private Sub cmdreset1_Click(sender As Object, e As EventArgs) Handles cmdreset1.Click
Dim ResetCmd As String = "UPDATE DATAGRID " & _
"SET reading ='" & 0.0 & "' " & _
"WHERE tank_name ='" & cbxrawtank1.Text & "' AND material_name = '" & cbxraw1.Text & "'"
If SQL.Update(ResetCmd) = 0 Then
MsgBox("The Specified raw_tank could not be found!")
End If
GetReading1(cbxraw1.Text)
End Sub
Private Sub cmdsub1_Click(sender As Object, e As EventArgs) Handles cmdsub1.Click
Dim mynum1 As Integer = txt8.Text
Dim mynum2 As Integer = txt1.Text
If mynum1 <= mynum2 Then
Dim subcmd As String = "UPDATE DATAGRID " & _
"SET reading -='" & mynum1 & "' " & _
"WHERE tank_name ='" & cbxrawtank1.Text & "' AND material_name = '" & cbxraw1.Text & "'"
If SQL.Update(subcmd) = 0 Then
MsgBox("The Specified tank could not be found!")
End If
Else
MsgBox("You Can not Extract that amount!")
End If
GetReading12(cbxraw1.Text)
End Sub
Public Sub CreateUser()
Dim created_at As DateTime
created_at = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")
' ADD MEMBER TO DATABASE
SQL.Addtank1(cbxrawtank1.Text, cbxraw1.Text, txt1.Text, txtupdate1.Text, txt15.Text, txt8.Text, txt22.Text, created_at)
End Sub
Public Sub Addtank1(tank_name As String, material_name As String, before_add As String, added_value As String, after_add As String, exit_value As String, after_exit As String, created_at As DateTime)
Try
Dim strInsert As String = "INSERT INTO Report (tank_name,material_name,before_add,added_value,after_add,exit_value,after_exit,created_at) " & _
"VALUES (" & _
" ' " & tank_name & " '," & _
" ' " & material_name & " '," & _
" ' " & before_add & " '," & _
" ' " & added_value & " '," & _
" ' " & after_add & " '," & _
" ' " & exit_value & " '," & _
" ' " & after_exit & " '," & _
" ' " & created_at & " ')"
SQLCon.Open()
SQLCmd = New SqlCommand(strInsert, SQLCon)
SQLCmd.ExecuteNonQuery()
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub cbxrawtank1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxrawtank1.SelectedIndexChanged
GetReading1(cbxraw1.Text)
txt15.Text = 0.0
txt22.Text = 0.0
End Sub