'This source code has been developed by Cuong Pham (cuong@nmsu.edu)
'Any use of this software MUST contain this message
Imports System.IO
Public Class FrBacterial

    Inherits System.Windows.Forms.Form
    Private MyImage As Bitmap


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TxBacterialID As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TxGenus As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents TxStrain As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents TxSpecies As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents TxPreservedForm As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents TxLocation As System.Windows.Forms.TextBox
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents TxDateCollected As System.Windows.Forms.TextBox
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents ButAdd As System.Windows.Forms.Button
    Friend WithEvents ButUpdate As System.Windows.Forms.Button
    Friend WithEvents ButDelete As System.Windows.Forms.Button
    Friend WithEvents ButQuit As System.Windows.Forms.Button
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents TxDescription As System.Windows.Forms.TextBox
    Friend WithEvents TxImgPath As System.Windows.Forms.TextBox
    Friend WithEvents TxSource As System.Windows.Forms.TextBox
    Friend WithEvents img As System.Windows.Forms.PictureBox
    Friend WithEvents Tximagepath As System.Windows.Forms.TextBox
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.Label1 = New System.Windows.Forms.Label
        Me.TxBacterialID = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.TxGenus = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.TxStrain = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.TxSpecies = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.TxPreservedForm = New System.Windows.Forms.TextBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.TxLocation = New System.Windows.Forms.TextBox
        Me.Label7 = New System.Windows.Forms.Label
        Me.TxDateCollected = New System.Windows.Forms.TextBox
        Me.Label8 = New System.Windows.Forms.Label
        Me.Tximagepath = New System.Windows.Forms.TextBox
        Me.ButAdd = New System.Windows.Forms.Button
        Me.ButUpdate = New System.Windows.Forms.Button
        Me.ButDelete = New System.Windows.Forms.Button
        Me.ButQuit = New System.Windows.Forms.Button
        Me.Label9 = New System.Windows.Forms.Label
        Me.TxDescription = New System.Windows.Forms.TextBox
        Me.TxSource = New System.Windows.Forms.TextBox
        Me.img = New System.Windows.Forms.PictureBox
        Me.Label10 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = "Bacterial_Strains"
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(8, 8)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(568, 232)
        Me.DataGrid1.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 251)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(136, 24)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Bacterial ID :"
        '
        'TxBacterialID
        '
        Me.TxBacterialID.Location = New System.Drawing.Point(144, 251)
        Me.TxBacterialID.Name = "TxBacterialID"
        Me.TxBacterialID.Size = New System.Drawing.Size(232, 20)
        Me.TxBacterialID.TabIndex = 2
        Me.TxBacterialID.Text = "TextBox1"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 284)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(128, 24)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Genus"
        '
        'TxGenus
        '
        Me.TxGenus.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxGenus.Location = New System.Drawing.Point(144, 281)
        Me.TxGenus.Name = "TxGenus"
        Me.TxGenus.Size = New System.Drawing.Size(232, 20)
        Me.TxGenus.TabIndex = 4
        Me.TxGenus.Text = "TextBox2"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8, 316)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(128, 24)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "Strain"
        '
        'TxStrain
        '
        Me.TxStrain.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxStrain.Location = New System.Drawing.Point(144, 312)
        Me.TxStrain.Name = "TxStrain"
        Me.TxStrain.Size = New System.Drawing.Size(232, 20)
        Me.TxStrain.TabIndex = 6
        Me.TxStrain.Text = "TxStrain"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(8, 352)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(136, 24)
        Me.Label4.TabIndex = 7
        Me.Label4.Text = "Species"
        '
        'TxSpecies
        '
        Me.TxSpecies.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxSpecies.Location = New System.Drawing.Point(144, 349)
        Me.TxSpecies.Name = "TxSpecies"
        Me.TxSpecies.Size = New System.Drawing.Size(232, 20)
        Me.TxSpecies.TabIndex = 8
        Me.TxSpecies.Text = "TextBox2"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(8, 392)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(136, 24)
        Me.Label5.TabIndex = 9
        Me.Label5.Text = "Preserved Form"
        '
        'TxPreservedForm
        '
        Me.TxPreservedForm.Location = New System.Drawing.Point(144, 384)
        Me.TxPreservedForm.Name = "TxPreservedForm"
        Me.TxPreservedForm.Size = New System.Drawing.Size(232, 20)
        Me.TxPreservedForm.TabIndex = 10
        Me.TxPreservedForm.Text = "TextBox1"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(8, 424)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(128, 24)
        Me.Label6.TabIndex = 11
        Me.Label6.Text = "Location"
        '
        'TxLocation
        '
        Me.TxLocation.Location = New System.Drawing.Point(144, 424)
        Me.TxLocation.Name = "TxLocation"
        Me.TxLocation.Size = New System.Drawing.Size(232, 20)
        Me.TxLocation.TabIndex = 12
        Me.TxLocation.Text = "TextBox1"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(8, 464)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(128, 24)
        Me.Label7.TabIndex = 13
        Me.Label7.Text = "Date Collected"
        '
        'TxDateCollected
        '
        Me.TxDateCollected.Location = New System.Drawing.Point(144, 464)
        Me.TxDateCollected.Name = "TxDateCollected"
        Me.TxDateCollected.Size = New System.Drawing.Size(232, 20)
        Me.TxDateCollected.TabIndex = 14
        Me.TxDateCollected.Text = "TextBox1"
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(8, 502)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(128, 24)
        Me.Label8.TabIndex = 15
        Me.Label8.Text = "Origin"
        '
        'Tximagepath
        '
        Me.Tximagepath.Location = New System.Drawing.Point(144, 575)
        Me.Tximagepath.Name = "Tximagepath"
        Me.Tximagepath.Size = New System.Drawing.Size(312, 20)
        Me.Tximagepath.TabIndex = 16
        Me.Tximagepath.Text = "TextBox1"
        '
        'ButAdd
        '
        Me.ButAdd.Location = New System.Drawing.Point(392, 376)
        Me.ButAdd.Name = "ButAdd"
        Me.ButAdd.Size = New System.Drawing.Size(184, 40)
        Me.ButAdd.TabIndex = 17
        Me.ButAdd.Text = "Add Bacterial"
        '
        'ButUpdate
        '
        Me.ButUpdate.Location = New System.Drawing.Point(392, 424)
        Me.ButUpdate.Name = "ButUpdate"
        Me.ButUpdate.Size = New System.Drawing.Size(184, 40)
        Me.ButUpdate.TabIndex = 18
        Me.ButUpdate.Text = "Update"
        '
        'ButDelete
        '
        Me.ButDelete.Location = New System.Drawing.Point(392, 472)
        Me.ButDelete.Name = "ButDelete"
        Me.ButDelete.Size = New System.Drawing.Size(184, 40)
        Me.ButDelete.TabIndex = 19
        Me.ButDelete.Text = "Delete"
        '
        'ButQuit
        '
        Me.ButQuit.Location = New System.Drawing.Point(392, 528)
        Me.ButQuit.Name = "ButQuit"
        Me.ButQuit.Size = New System.Drawing.Size(184, 40)
        Me.ButQuit.TabIndex = 20
        Me.ButQuit.Text = "Quit"
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(8, 608)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(128, 24)
        Me.Label9.TabIndex = 21
        Me.Label9.Text = "Comments"
        '
        'TxDescription
        '
        Me.TxDescription.Location = New System.Drawing.Point(144, 608)
        Me.TxDescription.Name = "TxDescription"
        Me.TxDescription.Size = New System.Drawing.Size(432, 20)
        Me.TxDescription.TabIndex = 22
        Me.TxDescription.Text = "TextBox1"
        '
        'TxSource
        '
        Me.TxSource.Location = New System.Drawing.Point(144, 502)
        Me.TxSource.Name = "TxSource"
        Me.TxSource.Size = New System.Drawing.Size(232, 20)
        Me.TxSource.TabIndex = 24
        Me.TxSource.Text = "TextBox1"
        '
        'img
        '
        Me.img.Location = New System.Drawing.Point(384, 243)
        Me.img.Name = "img"
        Me.img.Size = New System.Drawing.Size(192, 128)
        Me.img.TabIndex = 25
        Me.img.TabStop = False
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(8, 574)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(128, 26)
        Me.Label10.TabIndex = 26
        Me.Label10.Text = "Image Path"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(463, 573)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(113, 32)
        Me.Button1.TabIndex = 27
        Me.Button1.Text = "Select Image . . ."
        '
        'FrBacterial
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(584, 638)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label10)
        Me.Controls.Add(Me.img)
        Me.Controls.Add(Me.TxSource)
        Me.Controls.Add(Me.TxDescription)
        Me.Controls.Add(Me.Tximagepath)
        Me.Controls.Add(Me.TxDateCollected)
        Me.Controls.Add(Me.TxLocation)
        Me.Controls.Add(Me.TxPreservedForm)
        Me.Controls.Add(Me.TxSpecies)
        Me.Controls.Add(Me.TxStrain)
        Me.Controls.Add(Me.TxGenus)
        Me.Controls.Add(Me.TxBacterialID)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.ButQuit)
        Me.Controls.Add(Me.ButDelete)
        Me.Controls.Add(Me.ButUpdate)
        Me.Controls.Add(Me.ButAdd)
        Me.Controls.Add(Me.Label8)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.DataGrid1)
        Me.Name = "FrBacterial"
        Me.Text = "FrBacterial"
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
    Private ID As String
    Private Mode As Integer



#End Region

    Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click

    End Sub
    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click

    End Sub
    Private Sub TxSource_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxImgPath.TextChanged

    End Sub
    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click

    End Sub
    Private Sub TxGenus_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxGenus.TextChanged

    End Sub
    Private Sub Load_Bacterial()
        On Error Resume Next
        ' create a connection string 
        Init()

        Dim connString As String = strConn
        Dim myConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection
        myConnection.ConnectionString = connString
        ' create a data adapter 
        Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("Select BacterialID,Genus, Strain, Species,PreservedForm, Location,datecollected,Source,Imagepath,description from Bacterial_Strains", myConnection)
        ' create a new dataset 
        Dim ds As DataSet = New DataSet
        ' fill dataset 
        da.Fill(ds, "Bacterial_Strains")

        ' write dataset contents to an xml file by calling WriteXml method 
        ' Attach DataSet t DataGrid

        DataGrid1.DataSource = ds.DefaultViewManager
        DataGrid1.ColumnHeadersVisible = True
        DataGrid1.DataMember = "Bacterial_Strains"
        DataGrid1.Refresh()
        TxBacterialID.Text = ""
        TxGenus.Text = ""
        TxStrain.Text = ""
        TxSpecies.Text = ""
        TxPreservedForm.Text = ""
        TxLocation.Text = ""
        TxDateCollected.Text = ""
        TxSource.Text = ""
        Tximagepath.Text = ""
        TxDescription.Text = ""
    End Sub
    Private Sub FrBacterial_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' create a connection string 
        ShowToolTip()
        Load_Bacterial()
    End Sub
    Private Sub ButUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButUpdate.Click
        Dim strSQL As String
        On Error Resume Next

        OpenConn()

        If Mode = 0 Then
            If TxBacterialID.Text = "" Then
                MsgBox("Bacterial ID can not be left blank, pls enter Bacterial ID")
                TxBacterialID.Focus()
                Exit Sub
            End If



            strSQL = "INSERT INTO Bacterial_Strains(BacterialID,Genus,Strain,Species,PreservedForm,Location,DateCollected,Source, ImagePath, Description) VALUES ('" & TxBacterialID.Text & _
             "','" & TxGenus.Text & _
             "','" & TxStrain.Text & _
             "','" & TxSpecies.Text & _
             "','" & TxPreservedForm.Text & _
             "','" & TxLocation.Text & _
             "','" & TxDateCollected.Text & _
             "','" & TxSource.Text & _
             "','" & Tximagepath.Text & _
             "','" & TxDescription.Text & "')"


            Dim myCommand As New OleDb.OleDbCommand(strSQL, myConnection)
            myCommand.Connection = myConnection
            'myCommand.Connection.Open()
            myCommand.ExecuteNonQuery()

            myCommand.Dispose()

            'Redraw
            Init()

            Dim myCon As OleDb.OleDbConnection = New OleDb.OleDbConnection
            myCon.ConnectionString = strConn
            ' create a data adapter 
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("Select BacterialID,Genus, Strain, Species,PreservedForm, Location,datecollected,Source,Imagepath,description from Bacterial_Strains", myConnection)

            ' create a new dataset 
            Dim ds As DataSet = New DataSet
            ' fill dataset 
            da.Fill(ds, "Bacterial_Strains")

            ' write dataset contents to an xml file by calling WriteXml method 
            ' Attach DataSet to DataGrid

            DataGrid1.DataSource = ds.DefaultViewManager
            DataGrid1.ColumnHeadersVisible = True
            DataGrid1.Refresh()

            da.Dispose()
            ds.Dispose()
            myCon.Close()

        End If



        If Mode = 1 Then
            If TxBacterialID.Text = "" Then
                MsgBox("Bacterial ID can not be left blank, pls enter Bacterial ID")
                TxBacterialID.Focus()
                Exit Sub
            End If
            strSQL = "UPDATE Bacterial_Strains SET BacterialID= '" & TxBacterialID.Text & "'," & _
             " Genus= '" & TxGenus.Text & "'," & _
             " Strain= '" & TxStrain.Text & "'," & _
             " Species= '" & TxSpecies.Text & "'," & _
             " PreservedForm= '" & TxPreservedForm.Text & "'," & _
             " Location= '" & TxLocation.Text & "'," & _
             " Datecollected= '" & TxDateCollected.Text & "'," & _
             " ImagePath= '" & Tximagepath.Text & "'," & _
             " Description= '" & TxDescription.Text & _
             "' WHERE BacterialID='" & ID & "'"

            Dim myCommand As New OleDb.OleDbCommand(strSQL)
            myCommand.Connection = myConnection
            myCommand.ExecuteNonQuery()


            DataGrid1.Item(DataGrid1.CurrentRowIndex, 0) = TxBacterialID.Text
            DataGrid1.Item(DataGrid1.CurrentRowIndex, 1) = TxGenus.Text
            DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) = TxStrain.Text
            DataGrid1.Item(DataGrid1.CurrentRowIndex, 3) = TxSpecies.Text
            DataGrid1.Item(DataGrid1.CurrentRowIndex, 4) = TxPreservedForm.Text
            DataGrid1.Item(DataGrid1.CurrentRowIndex, 5) = TxLocation.Text
            DataGrid1.Item(DataGrid1.CurrentRowIndex, 6) = TxDateCollected.Text
            DataGrid1.Item(DataGrid1.CurrentRowIndex, 7) = TxSource.Text
            DataGrid1.Item(DataGrid1.CurrentRowIndex, 8) = Tximagepath.Text
            DataGrid1.Item(DataGrid1.CurrentRowIndex, 9) = TxDescription.Text
            myCommand.Dispose()

        End If

        myConnection.Close()


    End Sub

    Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click

    End Sub
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub
    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub
    Private Sub ButQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButQuit.Click
        Me.Hide()
        '        CloseConn()
    End Sub
    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click

    End Sub
    Private Sub TxBacterialID_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxBacterialID.TextChanged

    End Sub
    Private Sub TxDateCollected_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxDateCollected.TextChanged

    End Sub
    Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate

    End Sub
    Private Sub TxLocation_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxLocation.TextChanged

    End Sub
    Private Sub TxStrain_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxStrain.TextChanged

    End Sub
    Private Sub TxSpecies_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxSpecies.TextChanged

    End Sub
    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    End Sub
    Private Sub Flush()
        TxBacterialID.Text = ""
        TxGenus.Text = ""
        TxStrain.Text = ""
        TxSpecies.Text = ""
        TxPreservedForm.Text = ""
        TxLocation.Text = " -80 Freezer "
        TxDateCollected.Text = ""
        TxSource.Text = ""
        Tximagepath.Text = ""
        TxDescription.Text = ""

    End Sub
    Private Sub ShowToolTip()
        Dim toolTip1 As New ToolTip

        ' Set up the delays for the ToolTip.
        toolTip1.AutoPopDelay = 5000
        toolTip1.InitialDelay = 1000
        toolTip1.ReshowDelay = 500
        ' Force the ToolTip text to be displayed whether or not the form is active.
        toolTip1.ShowAlways = True

        ' Set up the ToolTip text for the Button and Checkbox.
        toolTip1.SetToolTip(Me.Label1, "Name given to bacterial sample isolated")
        toolTip1.SetToolTip(Me.Label2, "Taxonomic group containing one or more species")
        toolTip1.SetToolTip(Me.Label3, "a lineage or race (breed, variety, etc )")
        toolTip1.SetToolTip(Me.Label5, "What medium can the isolate be grown on eg. PDA,LB, GNSA etc. for removing contaminating strains")
        toolTip1.SetToolTip(Me.Label6, "Location of Glycerol Stocks")
        toolTip1.SetToolTip(Me.Label7, "Date purified (Date of So)")
        toolTip1.SetToolTip(Me.Label8, "Where sample came from (was it a plant endophyte? If so, what genus and species was it isolated from? Did it come from soil ? water?)")
        toolTip1.SetToolTip(Me.Label10, "Where image of bacteria is located (ie. Gram stain slides or pics in Microbiology folder, etc.)")
        toolTip1.SetToolTip(Me.Label9, "Any further information needed on this particular strain... Include comments such as how long the stocks take to appear on agar media, approximate doubling time, other media the strain is known to grow on, etc.")
    End Sub

    Private Sub ButAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButAdd.Click
        TxBacterialID.Text = ""
        TxGenus.Text = ""
        TxStrain.Text = ""
        TxSpecies.Text = ""
        TxPreservedForm.Text = ""
        TxLocation.Text = " -80 Freezer "
        TxDateCollected.Text = ""
        TxSource.Text = ""
        Tximagepath.Text = ""
        TxDescription.Text = ""
        TxBacterialID.Focus()
        Mode = 0
    End Sub
    Private Sub DataGrid1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
        Dim i As Integer
        Dim t As Boolean
        t = False
        Mode = 1
        i = 0
        Flush()
        On Error Resume Next
        While (t = False)
            If DataGrid1.IsSelected(i) Then
                ID = DataGrid1.Item(i, 0)
                TxBacterialID.Text() = DataGrid1.Item(i, 0)
                TxGenus.Text() = DataGrid1.Item(i, 1)
                TxStrain.Text() = DataGrid1.Item(i, 2)
                TxSpecies.Text() = DataGrid1.Item(i, 3)
                TxPreservedForm.Text() = DataGrid1.Item(i, 4)
                TxLocation.Text() = DataGrid1.Item(i, 5)
                TxDateCollected.Text() = DataGrid1.Item(i, 6)
                TxSource.Text() = DataGrid1.Item(i, 7)
                Tximagepath.Text() = ""
                Tximagepath.Text() = DataGrid1.Item(i, 8)
                TxDescription.Text() = DataGrid1.Item(i, 9)
                '   img.BackgroundImage() = Tximagepath.Text()

                If Len(Tximagepath.Text()) > 0 Then
                    ShowMyImage(Tximagepath.Text(), 192, 128, True)
                Else
                    'ShowMyImage(Tximagepath.Text(), 192, 128, False)
                End If
                '         img.Refresh()
                ButUpdate.Enabled = True
                ButDelete.Enabled = True
                t = True
            End If
            i = i + 1
        End While
    End Sub
    Private Sub ButDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButDelete.Click
        On Error Resume Next
        Dim msg As String
        Dim title As String
        Dim style As MsgBoxStyle
        Dim response As MsgBoxResult
        msg = "Do you  really want to delete the bacterial :" & ID & " ?"  ' Define message.
        style = MsgBoxStyle.DefaultButton2 Or _
           MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
        title = "Delete Comfirmation"   ' Define title.
        ' Display message.
        response = MsgBox(msg, style, title)
        If response = MsgBoxResult.Yes Then   ' User chose Yes.

            strSQL = "DELETE FROM Bacterial_Strains  WHERE BacterialID='" & ID & "'"
            OpenConn()

            Dim myCommand As New OleDb.OleDbCommand(strSQL)
            myCommand.Connection = myConnection
            myCommand.ExecuteNonQuery()
            DataGrid1.Refresh()
            myCommand.Dispose()
            myConnection.Close()
            Load_Bacterial()
        Else
            ' Perform some other action.
        End If

    End Sub
    Public Sub ShowMyImage(ByVal fileToDisplay As String, ByVal xSize As Integer, _
    ByVal ySize As Integer, ByVal b As Boolean)
        ' Sets up an image object to be displayed.

        If Not (MyImage Is Nothing) Then
            MyImage.Dispose()
        End If

        ' Stretches the image to fit the pictureBox. 
        img.SizeMode = PictureBoxSizeMode.StretchImage
        MyImage = New Bitmap(fileToDisplay)
        img.ClientSize = New Size(xSize, ySize)
        img.Image = CType(MyImage, Image)
        If b = False Then
            MyImage.Dispose()
        Else
            img.Show()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fileName As String

        OpenFileDialog1.ShowDialog()
        fileName = OpenFileDialog1.FileName()
        Tximagepath.Text = Trim(fileName)

    End Sub


End Class


