'This source code has been developed by Cuong Pham (cuong@nmsu.edu) & Mary Lucero
'Any use of this software MUST contain this message.
Public Class FrFind
    Inherits System.Windows.Forms.Form

#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 Label1 As System.Windows.Forms.Label
    Friend WithEvents cbType As System.Windows.Forms.ComboBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents ButSearch As System.Windows.Forms.Button
    Friend WithEvents ButQuit As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents cbDes As System.Windows.Forms.ComboBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.cbType = New System.Windows.Forms.ComboBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.ButSearch = New System.Windows.Forms.Button
        Me.ButQuit = New System.Windows.Forms.Button
        Me.Label3 = New System.Windows.Forms.Label
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.cbDes = New System.Windows.Forms.ComboBox
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(136, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Type of Sample to find"
        '
        'cbType
        '
        Me.cbType.Location = New System.Drawing.Point(144, 12)
        Me.cbType.Name = "cbType"
        Me.cbType.Size = New System.Drawing.Size(264, 21)
        Me.cbType.TabIndex = 1
        Me.cbType.Text = "ComboBox1"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(9, 50)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(128, 24)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "Enter Description"
        '
        'ButSearch
        '
        Me.ButSearch.Location = New System.Drawing.Point(144, 88)
        Me.ButSearch.Name = "ButSearch"
        Me.ButSearch.Size = New System.Drawing.Size(120, 32)
        Me.ButSearch.TabIndex = 4
        Me.ButSearch.Text = "Search"
        '
        'ButQuit
        '
        Me.ButQuit.Location = New System.Drawing.Point(296, 88)
        Me.ButQuit.Name = "ButQuit"
        Me.ButQuit.Size = New System.Drawing.Size(112, 32)
        Me.ButQuit.TabIndex = 5
        Me.ButQuit.Text = "Exit"
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(11, 135)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(397, 32)
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "Search Results"
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(3, 165)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(741, 144)
        Me.DataGrid1.TabIndex = 7
        '
        'cbDes
        '
        Me.cbDes.Location = New System.Drawing.Point(143, 49)
        Me.cbDes.Name = "cbDes"
        Me.cbDes.Size = New System.Drawing.Size(264, 21)
        Me.cbDes.TabIndex = 8
        Me.cbDes.Text = "ComboBox1"
        '
        'FrFind
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(752, 310)
        Me.Controls.Add(Me.cbDes)
        Me.Controls.Add(Me.DataGrid1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.ButQuit)
        Me.Controls.Add(Me.ButSearch)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.cbType)
        Me.Controls.Add(Me.Label1)
        Me.Name = "FrFind"
        Me.Text = "Find Sample"
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub FrFind_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cbDes.Text = ""
        cbType.Items.Clear()
        cbType.Items.Add("Bacterial")
        cbType.Items.Add("Tissue")
        cbType.Items.Add("Genomic DNA")
        cbType.Items.Add("PCR Product")
        cbType.Items.Add("Clone")
        cbType.Text = "Tissue"
    End Sub

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

    Private Sub ButSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButSearch.Click
        Init()
        On Error Resume Next
        Dim SQLs As String
        Dim table As String
        Dim connString As String = strConn
        Dim myConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection
        myConnection.ConnectionString = connString
        ' create a data adapter 

        If (cbType.Text = "Tissue") Then
            SQLs = "SELECT * FROM Tissues WHERE Description LIKE '%" & Trim(cbDes.Text) & "%'"
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(SQLs, myConnection)
            ' create a new dataset 
            Dim ds As DataSet = New DataSet
            ' fill dataset 
            da.Fill(ds, "Tissues")

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

            DataGrid1.DataSource = ds.DefaultViewManager
            DataGrid1.DataMember = "Tissues"
        End If
        If (cbType.Text = "Genomic DNA") Then
            'cbDes.Items.Clear()
            'FillComboBox(cbDes, "GenomicDNA_Stocks", "Description")
            SQLs = "SELECT * FROM GenomicDNA_Stocks WHERE Description LIKE '%" & Trim(cbDes.Text) & "%'"
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(SQLs, myConnection)
            ' create a new dataset 
            Dim ds As DataSet = New DataSet
            ' fill dataset 
            da.Fill(ds, "GenomicDNA_Stocks")

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

            DataGrid1.DataSource = ds.DefaultViewManager
            DataGrid1.DataMember = "GenomicDNA_Stocks"
        End If
        If (cbType.Text = "PCR Product") Then
            'cbDes.Items.Clear()
            'FillComboBox(cbDes, "PCR_Product", "Description")
            SQLs = "SELECT * FROM PCR_Product WHERE Description LIKE '%" & Trim(cbDes.Text) & "%'"
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(SQLs, myConnection)
            ' create a new dataset 
            Dim ds As DataSet = New DataSet
            ' fill dataset 
            da.Fill(ds, "PCR_Product")

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

            DataGrid1.DataSource = ds.DefaultViewManager
            DataGrid1.DataMember = "PCR_Product"


        End If

        If (cbType.Text = "Bacterial") Then
            SQLs = "SELECT * FROM Bacterial_Strains WHERE BacterialID LIKE '%" & Trim(cbDes.Text) & "%'"
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(SQLs, 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.DataMember = "Bacterial_Strains"
        End If

        DataGrid1.ColumnHeadersVisible = True
        DataGrid1.Refresh()
        myConnection.Close()
        cbDes.Text = ""
    End Sub
    Private Sub Search()
        Init()
        On Error Resume Next
        Dim SQLs As String
        Dim table As String
        Dim connString As String = strConn
        Dim myConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection
        myConnection.ConnectionString = connString
        ' create a data adapter 
        If (cbType.Text = "Tissue") Then
            cbDes.Items.Clear()
            FillComboBox(cbDes, "Tissues", "Description")
            SQLs = "SELECT Description,Column1,Row, BoxName,Location FROM Tissues WHERE Description ='" & Trim(cbDes.Text) & "'"
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(SQLs, myConnection)
            ' create a new dataset 
            Dim ds As DataSet = New DataSet
            ' fill dataset 
            da.Fill(ds, "Tissues")

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

            DataGrid1.DataSource = ds.DefaultViewManager
            DataGrid1.DataMember = "Tissues"
        End If
        If (cbType.Text = "Genomic DNA") Then
            cbDes.Items.Clear()
            FillComboBox(cbDes, "GenomicDNA_Stocks", "Description")
            SQLs = "SELECT Description,Column1,Row, BoxName,Location FROM GenomicDNA_Stocks WHERE Description ='" & Trim(cbDes.Text) & "'"
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(SQLs, myConnection)
            ' create a new dataset 
            Dim ds As DataSet = New DataSet
            ' fill dataset 
            da.Fill(ds, "GenomicDNA_Stocks")

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

            DataGrid1.DataSource = ds.DefaultViewManager
            DataGrid1.DataMember = "GenomicDNA_Stocks"
        End If
        If (cbType.Text = "PCR Product") Then
            cbDes.Items.Clear()
            FillComboBox(cbDes, "PCR_Product", "Description")
            SQLs = "SELECT Description,Column1,Row, BoxName,Location FROM PCR_Product WHERE Description ='" & Trim(cbDes.Text) & "'"
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(SQLs, myConnection)
            ' create a new dataset 
            Dim ds As DataSet = New DataSet
            ' fill dataset 
            da.Fill(ds, "PCR_Product")

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

            DataGrid1.DataSource = ds.DefaultViewManager
            DataGrid1.DataMember = "PCR_Product"


        End If
        If (cbType.Text = "Bacterial") Then
            cbDes.Items.Clear()
            FillComboBox(cbDes, "Bacterial_Strains", "BacterialID")
            SQLs = "SELECT Description,Column1,Row, BoxName,Location FROM Tissues WHERE Description ='" & Trim(cbDes.Text) & "'"
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(SQLs, myConnection)
            ' create a new dataset 
            Dim ds As DataSet = New DataSet
            ' fill dataset 
            da.Fill(ds, "Tissues")

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

            DataGrid1.DataSource = ds.DefaultViewManager
            DataGrid1.DataMember = "Tissues"
        End If


        DataGrid1.ColumnHeadersVisible = True
        DataGrid1.Refresh()
        myConnection.Close()
        cbDes.Text = ""
    End Sub

    Private Sub cbDes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbDes.SelectedIndexChanged


    End Sub

    Private Sub cbType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbType.SelectedIndexChanged
        If (cbType.Text = "Tissue") Then
            cbDes.Items.Clear()
            FillComboBox(cbDes, "Tissues", "Description")
        End If
        If (cbType.Text = "Genomic DNA") Then
            cbDes.Items.Clear()
            FillComboBox(cbDes, "GenomicDNA_Stocks", "Description")
        End If
        If (cbType.Text = "PCR Product") Then
            cbDes.Items.Clear()
            FillComboBox(cbDes, "PCR_Product", "Description")
        End If
        If (cbType.Text = "Bacterial") Then
            cbDes.Items.Clear()
            FillComboBox(cbDes, "Bacterial_Strains", "BacterialID")
        End If
    End Sub
End Class
