01.
02.
Private
Sub
txtTSearch_KeyDown(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyEventArgs)
Handles
txtTSearch.KeyDown
03.
If
txtTSearch.Text <>
""
Then
04.
If
e.KeyCode = Keys.Enter
Then
05.
06.
Dim
sqlBook
As
String
=
""
07.
sqlBook =
"SELECT * FROM Book "
08.
09.
If
cboSearch.SelectedIndex = 0
Then
10.
sqlBook &=
"WHERE (ISBN='"
& txtISBN.Text &
"')"
11.
12.
ElseIf
cboSearch.SelectedIndex = 1
Then
13.
sqlBook &=
"WHERE (Title LIKE '%"
& txtTSearch.Text &
"%')"
14.
ElseIf
cboSearch.SelectedIndex = 2
Then
15.
16.
sqlBook &=
"WHERE (Detail LIKE '%"
& txtTSearch.Text &
"%')"
17.
End
If
18.
19.
20.
sqlBook &=
" ORDER BY ISBN"
21.
22.
ContoData()
23.
24.
If
IsFind =
True
Then
25.
ds.Tables(
"Book"
).Clear()
26.
End
If
27.
28.
29.
da.SelectCommand.CommandText = sqlBook
30.
31.
da.Fill(ds,
"Book"
)
32.
33.
34.
If
ds.Tables(
"Book"
).Rows.Count <> 0
Then
35.
IsFind =
True
36.
ClearAllBinding()
37.
38.
With
cboBookType
39.
.DataSource = ds.Tables(
"BookType"
)
40.
.DisplayMember =
"BookTypeName"
41.
.ValueMember =
"BookTypeCode"
42.
.DataBindings.Add(
"SelectedValue"
, ds,
"Book.BookTypeCode"
)
43.
End
With
44.
45.
txtISBN.DataBindings.Add(
"Text"
, ds,
"Book.ISBN"
)
46.
txtTitle.DataBindings.Add(
"Text"
, ds,
"Book.Title"
)
47.
txtDetail.DataBindings.Add(
"Text"
, ds,
"Book.Detail"
)
48.
txtPrice.DataBindings.Add(
"Text"
, ds,
"Book.Price"
)
49.
50.
txtBookCost.DataBindings.Add(
"Text"
, ds,
"Book.BookCost"
)
51.
txtNumberDateRent.DataBindings.Add(
"Text"
, ds,
"Book.NumberDateRent"
)
52.
txtFineRate.DataBindings.Add(
"Text"
, ds,
"Book.FineRate"
)
53.
54.
txtBookInShop.DataBindings.Add(
"Text"
, ds,
"Book.BookInShop"
)
55.
txtBookInRent.DataBindings.Add(
"Text"
, ds,
"Book.BookInRent"
)
56.
txtBookTotal.DataBindings.Add(
"Text"
, ds,
"Book.BookTotal"
)
57.
58.
59.
60.
dt = ds.Tables(
"Book"
)
61.
62.
ShowPosition()
63.
64.
65.
cmdAdd.Enabled =
False
66.
cmdEdit.Enabled =
True
67.
68.
cmdMoveFirst.Enabled =
True
69.
cmdMoveLast.Enabled =
True
70.
cmdMoveNext.Enabled =
True
71.
cmdMovePrevious.Enabled =
True
72.
73.
cmdEdit.Focus()
74.
Else
75.
IsFind =
False
76.
77.
MessageBox.Show(
"หนังสือที่คุณระบุ ไม่มี!!!"
,
"ผลการค้นหา"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
78.
79.
ClearData()
80.
81.
lblShowPositions.Text =
""
82.
83.
cmdAdd.Enabled =
True
84.
cmdEdit.Enabled =
False
85.
86.
cmdMoveFirst.Enabled =
False
87.
cmdMoveLast.Enabled =
False
88.
cmdMoveNext.Enabled =
False
89.
cmdMovePrevious.Enabled =
False
90.
91.
txtTSearch.Focus()
92.
txtTSearch.SelectAll()
93.
Exit
Sub
94.
End
If
95.
End
If
96.
End
If
97.
End
Sub