Imports System.Data.SqlClient

Public Class Form10


    Dim DataSet1 As New DataSet
    Dim DataAdapter1 As SqlDataAdapter
    Private Sub Form10_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button16.Visible = False
        txt6.Enabled = False
        gno.Visible = False
        Button2.Enabled = False
        b.Enabled = False
        bpa.Enabled = False
        bn.Enabled = False
        lock()
        searchshow()
        txt1.Enabled = False

        isearch.Enabled = True
        inew.Enabled = True
        isave.Enabled = False
        icancel.Enabled = False
        iupdate.Enabled = False
        idel.Enabled = False
        lbtotal.Text = ""
        totalq.Text = ""
        loddatagrid()
        'txt6.DataBindings.Add("Text", DataSet1, "Table1.product_code")
        'txt7.DataBindings.Add("Text", DataSet1, "Table1.product_name")
        'txt8.DataBindings.Add("Text", DataSet1, "Table1.quantity")
        'txt10.DataBindings.Add("Text", DataSet1, "Table1.product_price")
   
        With grid1


            .ReadOnly = True
            .Columns(0).Width = 120
            .Columns(1).Width = 150
            .Columns(2).Width = 120
            .Columns(3).Width = 120

            .Columns(0).HeaderText = "Product Code"
            .Columns(1).HeaderText = "Product Name"
            .Columns(2).HeaderText = "Quantity"
            .Columns(3).HeaderText = "Product Price"
        End With
        gridtal()
        gridtal2()
        txt7.Enabled = False
        txt8.Enabled = False
        txt10.Enabled = False
    End Sub
    Private Function gridtal() As Double

        Dim Total As Double
        Dim i As Integer
        i = 0
        Total = 0

        Do While i < grid1.RowCount()
            Total += grid1.Item(3, i).Value

            i += 1
        Loop
        lbtotal.Text = Total

    End Function
    Private Function gridtal2() As Double

        Dim Total As Double
        Dim i As Integer
        i = 0
        Total = 0

        Do While i < grid1.RowCount()
            Total += grid1.Item(2, i).Value
            i += 1
        Loop
        totalq.Text = Total

    End Function
    Private Sub autonum()
        Call main()
        Con.Open()
        Dim UserSelect As SqlCommand
        Dim myreader As SqlDataReader
        Dim sql As String
        Dim sum As Integer
        Dim no As Integer

        sql = "select max(patient_id) from Patient_table"
        UserSelect = New SqlCommand(sql, Con)
        myreader = UserSelect.ExecuteReader
        If (myreader.Read = True) Then
            no = 1
            
            txt1.Text = myreader(0)
            sum = txt1.Text + no
            txt1.Text = sum
        Else
            txt1.Text = "12001"

            'clear()


        End If


        Con.Close()
    End Sub
    Private Sub clear()
        txt1.Text = ""
        txt2.Text = ""
        txt3.Text = ""
        txt4.Text = ""
        txt5.Text = ""
        txt6.Text = ""
        txt7.Text = ""
        txt8.Text = ""
        txt9.Text = ""

    End Sub
    Private Sub lock()
        'txt1.Enabled = False
        txt2.Enabled = False
        txt3.Enabled = False
        txt4.Enabled = False
        txt5.Enabled = False
        'txt6.Enabled = False
        'txt7.Enabled = False
        'txt8.Enabled = False
        txt9.Enabled = False
    End Sub
    Private Sub unlock()
        
        'txt1.Enabled = True
        txt2.Enabled = True
        txt3.Enabled = True
        txt4.Enabled = True
        txt5.Enabled = True
        'txt6.Enabled = True
        'txt7.Enabled = True
        'txt8.Enabled = True
        txt9.Enabled = True
    End Sub
    Private Sub save()
        Call main()
        Con.Open()
        Dim adapter As New SqlDataAdapter
        Dim sql As String
        sql = "insert into Pharmacy (patient_id,lname,fname,mname,docname,schedule,total) values('" & txt1.Text & "','" & txt2.Text & "', '" & txt3.Text & "', '" & txt4.Text & "', '" & txt5.Text & "','" & txt9.Text & "','" & lbtotal.Text & "')"
        Try

            adapter.InsertCommand = New SqlCommand(sql, Con)
            adapter.InsertCommand.ExecuteNonQuery()
            MsgBox("Successful To save this record on database", MsgBoxStyle.Information, "Information On Database")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Con.Close()
    End Sub


    Private Sub updatesave()
        Call main()
        Con.Open()
        Dim adapter As New SqlDataAdapter
        Dim sql As String

        sql = "update Pharmacy set patient_id='" & txt1.Text & "',lname='" & txt2.Text & "',fname='" & txt3.Text & "',mname='" & txt4.Text & "',docname='" & txt5.Text & "',schedule='" & txt9.Text & "',total='" & lbtotal.Text & "'  where patient_id ='" & txtsearch.Text & "'"
        Try
            adapter.UpdateCommand = Con.CreateCommand
            adapter.UpdateCommand.CommandText = sql
            adapter.UpdateCommand.ExecuteNonQuery()
            MsgBox("Successful To Update this record on database", MsgBoxStyle.Information, "Information On Database")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Con.Close()
    End Sub

    Private Sub updatepatient()
        Call main()
        Con.Open()
        Dim adapter As New SqlDataAdapter
        Dim sql As String

        sql = "update Patient_table set patient_id='" & txt1.Text & "',lname='" & txt2.Text & "',fname='" & txt3.Text & "',mname='" & txt4.Text & "' where patient_id ='" & txtsearch.Text & "'"
        Try
            adapter.UpdateCommand = Con.CreateCommand
            adapter.UpdateCommand.CommandText = sql
            adapter.UpdateCommand.ExecuteNonQuery()
            'MsgBox("Successful To Update this record on database", MsgBoxStyle.Information, "Information On Database")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Con.Close()
    End Sub
    Private Sub deleterecord()
        Call main()
        Con.Open()


        Dim adapter As New SqlDataAdapter
        Dim sql As String

        sql = "delete Pharmacy where patient_id ='" & txtsearch.Text & "'"
        Try
            adapter.DeleteCommand = Con.CreateCommand
            adapter.DeleteCommand.CommandText = sql
            adapter.DeleteCommand.ExecuteNonQuery()
            MsgBox("Successful To Delete this record on database", MsgBoxStyle.Information, "Information On Database")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Con.Close()
    End Sub
    Private Sub deleterecord1()
        Call main()
        Con.Open()


        Dim adapter As New SqlDataAdapter
        Dim sql As String

        sql = "delete pharmacy_Inventory where patient_id ='" & txtsearch.Text & "'"
        Try
            adapter.DeleteCommand = Con.CreateCommand
            adapter.DeleteCommand.CommandText = sql
            adapter.DeleteCommand.ExecuteNonQuery()
            MsgBox("Successful To Delete this record on database", MsgBoxStyle.Information, "Information On Database")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Con.Close()
    End Sub
    '********auto complete Search*********************
    Private Sub searchshow()
        Call main()
        Con.Open()

        Dim cmd As New SqlCommand("SELECT patient_id FROM Pharmacy", Con)
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(cmd)
        da.Fill(ds, "My List") 'list can be any name u want

        Dim col As New AutoCompleteStringCollection
        Dim i As Integer
        For i = 0 To ds.Tables(0).Rows.Count - 1
            col.Add(ds.Tables(0).Rows(i)("patient_id").ToString())
        Next
        txtsearch.AutoCompleteSource = AutoCompleteSource.CustomSource
        txtsearch.AutoCompleteCustomSource = col
        txtsearch.AutoCompleteMode = AutoCompleteMode.Suggest
        Con.Close()
    End Sub
    Private Sub showsearch()
        Call main()
        Con.Open()
        Dim UserSelect As SqlCommand
        Dim myreader As SqlDataReader
        Dim sql As String

        sql = "select * from Pharmacy where patient_id like '" & (txtsearch.Text) & "%'"
        UserSelect = New SqlCommand(sql, Con)
        myreader = UserSelect.ExecuteReader
        If (myreader.Read = True) Then
            If txtsearch.Text = myreader(0) Then
                unlock()
                inew.Enabled = False
                icancel.Enabled = True
                iupdate.Enabled = True
                idel.Enabled = True

                txt1.Text = myreader(0)
                txt2.Text = myreader(1)
                txt3.Text = myreader(2)
                txt4.Text = myreader(3)
                txt5.Text = myreader(4)
                txt9.Text = myreader(5)
                loddatagrid()

                Button2.Enabled = True
                b.Enabled = False
                gridtal()
                gridtal2()
            End If
        Else
            lock()
            MsgBox("No record Found on Database", MsgBoxStyle.Critical, "Error")
            inew.Enabled = True
            icancel.Enabled = False
            iupdate.Enabled = False
            idel.Enabled = False
            Button2.Enabled = False
            b.Enabled = True
            loddatagrid()
            clear()
        End If

        Con.Close()
    End Sub

    Private Sub inew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles inew.Click
        isearch.Enabled = False
        inew.Enabled = False
        isave.Enabled = True
        icancel.Enabled = True
        iupdate.Enabled = False
        idel.Enabled = False
        txtsearch.Enabled = False
        Button2.Enabled = True
        b.Enabled = True
        clear()
        unlock()
        txtsearch.Text = ""
        autonum()

        txt2.Focus()
        bpa.Enabled = False
        bn.Enabled = True

        autoProductcode()
    End Sub

    Private Sub isave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles isave.Click
        save()
        loddatagrid()
        
        clear()
        lock()
        searchshow()

        isearch.Enabled = True
        inew.Enabled = True
        isave.Enabled = False
        icancel.Enabled = False
        iupdate.Enabled = False
        idel.Enabled = False
        txtsearch.Enabled = True

        If b.Text = "Cancel" Then
            b.Text = "Patient ID is Already"
            b.Enabled = False
        End If
      
    End Sub

    Private Sub icancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles icancel.Click
        lock()
        clear()
        txtsearch.Text = ""
        totalq.Text = ""
        lbtotal.Text = ""
        loddatagrid()
        gridtal()
        gridtal()
        isearch.Enabled = True
        inew.Enabled = True
        isave.Enabled = False
        icancel.Enabled = False
        iupdate.Enabled = False
        idel.Enabled = False
        txtsearch.Enabled = True
    End Sub

    Private Sub iupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iupdate.Click
        On Error GoTo err


        If txtsearch.Text = "" Then
            MsgBox("Sorry you have no record to update!", MsgBoxStyle.Critical, "Error Update")

        Else
            Select Case MsgBox("Are you sure, you want to Update this Record?", MsgBoxStyle.YesNo)
                Case MsgBoxResult.Yes
                    updatesave()
                    updatepatient()

                    gridtal()
                    gridtal2()
                    clear()
                    loddatagrid()
                    txtsearch.Text = ""
                    lock()

                    searchshow()


                    isearch.Enabled = True
                    inew.Enabled = True
                    isave.Enabled = False
                    icancel.Enabled = False
                    iupdate.Enabled = False
                    idel.Enabled = False
                Case MsgBoxResult.No
                    GoTo err
            End Select


        End If
err:
        Exit Sub
    End Sub

    Private Sub idel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles idel.Click
        On Error GoTo err


        If txtsearch.Text = "" Then
            MsgBox("Sorry you have no record to Delete!", MsgBoxStyle.Critical, "Error Delete")


        Else
            Select Case MsgBox("Are you sure, you want to Delete this Record?", MsgBoxStyle.YesNo)
                Case MsgBoxResult.Yes
                    deleterecord()
                    deleterecord1()

                    gridtal()
                    gridtal2()
                    clear()
                    loddatagrid()
                    txtsearch.Text = ""
                    lock()

                    searchshow()


                    isearch.Enabled = True
                    inew.Enabled = True
                    isave.Enabled = False
                    icancel.Enabled = False
                    iupdate.Enabled = False
                    idel.Enabled = False

                Case MsgBoxResult.No
                    GoTo err
            End Select
        End If


err:
        Exit Sub

    End Sub

    Private Sub txtsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.Click
        If txtsearch.Text = "" Then
            clear()
        End If
    End Sub

    Private Sub txtsearch_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearch.KeyUp
        If e.KeyCode = Keys.Enter Then
            showsearch()
        End If
    End Sub

    Private Sub isearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles isearch.Click
        If txtsearch.Text = "" Then
            MsgBox("Search Patient Id is Null ", MsgBoxStyle.Critical, "Error Search")
        Else
            showsearch()
        End If
    End Sub
    Private Sub loddatagrid()
        Call main()
        Con.Open()
      

        DataAdapter1 = New SqlDataAdapter("SELECT [product_code],[product_name],[quantity],[product_price] FROM [dbo].[pharmacy_Inventory] where patient_id='" & txt1.Text & "'", Con)
        DataSet1.Clear()
        DataAdapter1.Fill(DataSet1, "Table1")

        grid1.DataSource = DataSet1
        grid1.DataMember = "Table1"
        grid1.Refresh()
        Con.Close()
    End Sub

    Private Sub txt8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt8.TextChanged
        txt8integer()
    End Sub
    Private Sub txt8integer()
        If txt8.Text = "" Then
            GoTo ex
        Else
            If IsNumeric(txt8.Text) Then
                GoTo ex
            ElseIf txt8.Text = "." Then
                GoTo ex
            Else
                MsgBox("You cannot add alpha characters, please input the Integer or numbers !", vbCritical)
                txt8.Text = ""

            End If
        End If
ex:
        Exit Sub
    End Sub

    Private Sub txt2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt2.KeyUp
        If e.KeyCode = Keys.Enter Then
            txt3.Focus()
        End If
    End Sub

    Private Sub txt3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt3.KeyUp
        If e.KeyCode = Keys.Enter Then
            txt4.Focus()
        End If
    End Sub

    Private Sub txt4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt4.KeyUp
        If e.KeyCode = Keys.Enter Then
            txt5.Focus()
        End If
    End Sub

    Private Sub txt5_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt5.KeyUp
        If e.KeyCode = Keys.Enter Then
            txt6.Focus()
        End If
    End Sub

    Private Sub txt6_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt6.KeyUp
       
        If e.KeyCode = Keys.Enter Then
            If txt6.Text = "" Then
                MsgBox("Product Code Is a Null ,Invalid Search", MsgBoxStyle.Exclamation, "Error Search")
            Else
                productlod()
            End If

        End If
    End Sub

    Private Sub txt7_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt7.KeyUp
        If e.KeyCode = Keys.Enter Then
            txt8.Focus()
        End If
    End Sub

 
  

    Private Sub bpa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bpa.Click
        autonum()

        txt2.Focus()
    End Sub

    Private Sub bn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bn.Click
        isearch.Enabled = False
        inew.Enabled = False
        isave.Enabled = True
        icancel.Enabled = True
        iupdate.Enabled = False
        idel.Enabled = False
        txtsearch.Enabled = False
        b.Enabled = False

        clear()
        unlock()
        txtsearch.Text = ""
        txt2.Focus()

        bpa.Enabled = True
        bn.Enabled = False
    End Sub
    Private Sub autoProductcode()
        Call main()
        Con.Open()

        Dim cmd As New SqlCommand("SELECT productcode FROM PharmacyProduct", Con)
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(cmd)
        da.Fill(ds, "My List") 'list can be any name u want

        Dim col As New AutoCompleteStringCollection
        Dim i As Integer
        For i = 0 To ds.Tables(0).Rows.Count - 1
            col.Add(ds.Tables(0).Rows(i)("productcode").ToString())
        Next
        txt6.AutoCompleteSource = AutoCompleteSource.CustomSource
        txt6.AutoCompleteCustomSource = col
        txt6.AutoCompleteMode = AutoCompleteMode.Suggest
        Con.Close()
    End Sub
    Private Sub productlod()
        Call main()
        Con.Open()
        Dim UserSelect As SqlCommand
        Dim myreader As SqlDataReader
        Dim sql As String

        sql = "select * from PharmacyProduct where productcode like '" & (txt6.Text) & "%'"
        UserSelect = New SqlCommand(sql, Con)
        myreader = UserSelect.ExecuteReader
        If (myreader.Read = True) Then
           
            txt7.Text = myreader(1)
            txt8.Text = myreader(2)
            txt10.Text = "1"

        Else

        MsgBox("No record Found on Database", MsgBoxStyle.Critical, "Error")
        txt7.Text = ""
        txt8.Text = ""
        txt10.Text = ""

        End If

        Con.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Button2.Enabled = False
        isave.Enabled = False
        gno.Visible = True
        lock()
    End Sub

    Private Sub txt6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt6.TextChanged
        autoProductcode()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      
        txt10.Text = txt10.Text & "" & "1"


    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
     
        txt10.Text = txt10.Text & "" & "2"

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
      
        txt10.Text = txt10.Text & "" & "3"

    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
      
        txt10.Text = txt10.Text & "" & "4"

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
       
        txt10.Text = txt10.Text & "" & "5"

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
       
        txt10.Text = txt10.Text & "" & "6"

    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

        txt10.Text = txt10.Text & "" & "7"
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

        txt10.Text = txt10.Text & "" & "8"
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

        txt10.Text = txt10.Text & "" & "9"
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

        txt10.Text = txt10.Text & "" & "0"
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        If txt10.Text = "" Then
            MsgBox("Quantity is a null Please Input The value", MsgBoxStyle.Critical, "Error")
        ElseIf txt10.Text = "0" Then
            MsgBox("Quantity is a 0 Please Input The value", MsgBoxStyle.Critical, "Error")
        Else
            gno.Visible = False
            Button2.Enabled = True
            isave.Enabled = True
        End If
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        txt10.Text = ""
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        If txt10.Text = "" Then
            MsgBox("Quantity is a null Please Input The value", MsgBoxStyle.Critical, "Error")
        ElseIf txt10.Text = "0" Then
            MsgBox("Quantity is a 0 Please Input The value", MsgBoxStyle.Critical, "Error")
        Else
            propricecompute()
            Button2.Enabled = True
            isave.Enabled = True
        End If
    End Sub

    Private Sub propricecompute()
        Call main()
        Con.Open()
        Dim UserSelect As SqlCommand
        Dim myreader As SqlDataReader
        Dim sql As String
        Dim mul As String
        Dim x8 As Double
        Dim x10 As Double
        x10 = txt10.Text
        sql = "select * from PharmacyProduct where productcode like '" & (txt6.Text) & "%'"
        UserSelect = New SqlCommand(sql, Con)
        myreader = UserSelect.ExecuteReader
        If (myreader.Read = True) Then
            x8 = myreader(2)
            mul = x8 * x10
            txt8.Text = mul
            gno.Visible = False
        End If

        Con.Close()
    End Sub

   
    Private Sub b_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b.Click
        If b.Text = "Patient ID is Already" Then
            b.Text = "Cancel"
            txt1.Enabled = True
            searchshow1()
            txt1.Text = ""
            txt2.Text = ""
            txt3.Text = ""
            txt4.Text = ""
            txt1.Focus()
            txt2.Enabled = False
            txt3.Enabled = False
            txt4.Enabled = False
        ElseIf b.Text = "Cancel" Then
            b.Text = "Patient ID is Already"
            txt1.Text = ""
            txt2.Text = ""
            txt3.Text = ""
            txt4.Text = ""
            txt1.Enabled = False
            txt2.Enabled = True
            txt3.Enabled = True
            txt4.Enabled = True
        End If
    End Sub
    Private Sub searchshow1()
        Call main()
        Con.Open()

        Dim cmd As New SqlCommand("SELECT patient_id FROM Patient_table", Con)
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(cmd)
        da.Fill(ds, "My List") 'list can be any name u want

        Dim col As New AutoCompleteStringCollection
        Dim i As Integer
        For i = 0 To ds.Tables(0).Rows.Count - 1
            col.Add(ds.Tables(0).Rows(i)("patient_id").ToString())
        Next
        txt1.AutoCompleteSource = AutoCompleteSource.CustomSource
        txt1.AutoCompleteCustomSource = col
        txt1.AutoCompleteMode = AutoCompleteMode.Suggest
        Con.Close()
    End Sub
    Private Sub showsearch1()
        Call main()
        Con.Open()
        Dim UserSelect As SqlCommand
        Dim myreader As SqlDataReader
        Dim sql As String

        sql = "select * from Patient_table where patient_id like '" & (txt1.Text) & "%'"
        UserSelect = New SqlCommand(sql, Con)
        myreader = UserSelect.ExecuteReader
        If (myreader.Read = True) Then

            'txt1.Text = myreader(0)
            txt2.Text = myreader(1)
            txt3.Text = myreader(2)
            txt4.Text = myreader(3)
            txt5.Focus()


        Else

        MsgBox("No record Found on Database", MsgBoxStyle.Critical, "Error")



        clear()
        End If

        Con.Close()
    End Sub

    Private Sub txt1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt1.KeyUp
        If e.KeyCode = Keys.Enter Then
         

            showsearch1()
        End If

    End Sub

 
    Private Sub txt1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt1.TextChanged
        If txt1.Text = "" Then
            clear()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button1.Text = "Add" Then
            Button1.Text = "Save"
            txt6.Text = ""
            txt7.Text = ""
            txt8.Text = ""
            txt10.Text = ""
            loddatagrid()
            txt6.Enabled = True
            Button16.Visible = True
            txt6.Focus()
        ElseIf Button1.Text = "Save" Then
            verify()
            Button1.Text = "Add"
            txt6.Enabled = False
            txt6.Text = ""
            txt7.Text = ""
            txt8.Text = ""
            txt10.Text = ""
            Button16.Visible = False
        End If
    End Sub
    Private Sub verify()
        Call main()
        Con.Open()
        Dim UserSelect As SqlCommand
        Dim myreader As SqlDataReader
        Dim sql As String

        sql = "select * from Pharmacy where patient_id like '" & (txtsearch.Text) & "%'"
        UserSelect = New SqlCommand(sql, Con)
        myreader = UserSelect.ExecuteReader
        If (myreader.Read = True) Then
            savephar()
            loddatagrid()
            gridtal()
            gridtal2()
        Else
            save()
        End If
        Con.Close()

    End Sub
    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        Button16.Visible = False
        txt6.Text = ""
        txt6.Text = ""
        txt7.Text = ""
        txt8.Text = ""
        txt10.Text = ""
        txt6.Enabled = False
        Button1.Text = "Add"

    End Sub
    Private Sub savephar()

        Call main()
        Con.Open()
        Dim adapter As New SqlDataAdapter
        Dim sql As String
        sql = "insert into pharmacy_Inventory (patient_id,product_code,product_name,quantity,product_price) values('" & txt1.Text & "','" & txt6.Text & "','" & txt7.Text & "', '" & txt8.Text & "', '" & txt10.Text & "')"
        Try

            adapter.InsertCommand = New SqlCommand(sql, Con)
            adapter.InsertCommand.ExecuteNonQuery()
            'MsgBox("Successful To save this record on database", MsgBoxStyle.Information, "Information On Database")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Con.Close()
    End Sub
    Private Sub txtno1()


        If IsNumeric(txt1.Text) Then
            GoTo ex
        ElseIf txt1.Text = "." Then
            GoTo ex
        Else
            MsgBox("You cannot add alpha characters, please input the Integer or numbers !", vbCritical)
            txt1.Text = ""

        End If

ex:
        Exit Sub
    End Sub

  
End Class