Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.OleDb
Imports MySql.Data.MySqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Conn As New OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim IsFind As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
IsFind = False
ShowData()
namesrc.Enabled = False
End Sub
Private Sub ShowData()
Dim strConnString As String
strConnString = ("Database=tailor shop;Data Source=localhost;User Id=root;Password=1234")
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConnString
.Open()
End With
Dim sqlCustomer As String
sqlCustomer = "SELECT ID,Tel,Fname,Lname,ADD "
sqlCustomer = sqlCustomer & " FROM Customer "
sqlCustomer = sqlCustomer & " ORDER BY CustomerID"
If IsFind = True Then
ds.Tables("Customer").Clear()
End If
da = New OleDbDataAdapter(sqlCustomer, Conn)
da.Fill(ds, "Customer")
If findall.Checked = True Then
With DataGridView1
.AllowUserToAddRows = False
.ReadOnly = True
.DataSource = ds
.DataMember = "Customers"
End With
ElseIf findname.Checked = True Then
Dim dvm As New DataViewManager
dvm.DataSet = ds
Dim dvs As DataViewSetting
dvs = dvm.DataViewSettings("Customer")
dvs.RowFilter = "Fname LIKE '" & namesrc.Text & "%'"
dvs.RowFilter = "Lname LIKE '" & namesrc.Text & "%'"
With DataGridView1
.AllowUserToAddRows = False
.ReadOnly = True
.DataSource = dvm
.DataMember = "Customers"
End With
End If
IsFind = True
End Sub
Private Sub ADDbuttom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ADDbuttom.Click
Dim a As New Form2
a.ShowDialog()
End Sub
Private Sub IDTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim b As New Form4
b.ShowDialog()
End Sub
Private Sub findall_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles findall.CheckedChanged
CheckCondition()
ShowData()
End Sub
Private Sub findname_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles findname.CheckedChanged
CheckCondition()
ShowData()
End Sub
Private Sub CheckCondition()
If findall.Checked = True Then
namesrc.Enabled = False
ElseIf findname.Checked = True Then
namesrc.Enabled = True
namesrc.Focus()
End If
namesrc.Text = ""
End Sub
Private Sub finebuttom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles finebuttom.Click
If namesrc.Text = "" Then Exit Sub
ShowData()
End Sub
Private Sub cancle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancle.Click
End
End Sub
End Class