Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Imports System.Text
Public Class ThresholdMaintenance

    Private cnstr As String
    Private conn As SqlConnection
    Private command As SqlCommand
    Private ds As DataSet
    Private da As SqlDataAdapter
    Private myQuery As String
    Private Sub ThresholdMaintenance_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = mainForm
        Control.CheckForIllegalCrossThreadCalls = False
        cnstr = mainForm.cnstr
        conn = New SqlConnection(cnstr)
        conn.Open()
        myQuery = "SELECT * FROM PartsThreshold ORDER BY part_number"
        ds = New DataSet
        da = New SqlDataAdapter(myQuery, conn)
        da.Fill(ds, "PartsThreshold")
        DataGridView1.DataSource = ds.Tables(0)
        conn.Close()
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        Try
            conn.Open()
            'myQuery = "TRUNCATE TABLE PartsThreshold"
            'command = New SqlCommand(myQuery, conn)
            'command.ExecuteNonQuery()

            For i As Integer = 0 To DataGridView1.RowCount - 1
                myQuery = "INSERT INTO PartsThreshold VALUES ('" & DataGridView1.Rows(i).Cells(0).Value.ToString & "','" & DataGridView1.Rows(i).Cells(1).Value.ToString & "','" & DataGridView1.Rows(i).Cells(2).Value.ToString & "','" & DataGridView1.Rows(i).Cells(3).Value.ToString & "','" & DataGridView1.Rows(i).Cells(4).Value.ToString & "','" & DataGridView1.Rows(i).Cells(5).Value.ToString & "')"
                command = New SqlCommand(myQuery, conn)
                command.ExecuteNonQuery()
            Next
        Catch ex As Exception
        Finally
            conn.Close()
            conn.Dispose()
        End Try
        MessageBox.Show("Threshold successfully updated!")
    End Sub

    Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub
End Class