001.
Imports
System.Data
002.
Imports
System.Data.OleDb
003.
Imports
System.Text
004.
Public
Class
frmCountTools
005.
Dim
Conn
As
New
OleDbConnection
006.
Dim
da
As
OleDbDataAdapter
007.
Dim
ds
As
New
DataSet
008.
Dim
sb
As
New
StringBuilder
009.
Dim
IsFind
As
Boolean
=
False
010.
Dim
Com
As
OleDbCommand
011.
Dim
dr
As
OleDbDataReader
012.
Dim
dt
As
DataTable
013.
Dim
PathFile
As
String
=
""
014.
Private
Sub
frmCountTools_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
015.
With
Conn
016.
If
.State = ConnectionState.Open
Then
.Close()
017.
.ConnectionString = strConn
018.
.Open()
019.
End
With
020.
ShowData()
021.
End
Sub
022.
Private
Sub
ShowData()
023.
024.
dgvFame.Rows.Clear()
025.
Try
026.
027.
028.
029.
Dim
com
As
New
OleDbCommand(
"SELECT CateName, COUNT(CateName) As row FROM Tools GROUP BY CateName "
, Conn)
030.
031.
032.
033.
034.
Dim
dr
As
OleDbDataReader = com.ExecuteReader
035.
Dim
i
As
Integer
= 0
036.
Dim
num
As
Integer
= 0
037.
If
dr.HasRows
Then
038.
While
dr.Read
039.
040.
041.
042.
043.
044.
dgvFame.Rows.Add()
045.
046.
num = num + 1
047.
048.
dgvFame.Rows(i).Cells(0).Value = num
049.
dgvFame.Rows(i).Cells(1).Value = dr.Item(0)
050.
dgvFame.Rows(i).Cells(2).Value = dr.Item(1)
051.
052.
053.
054.
055.
056.
i = i + 1
057.
058.
059.
060.
061.
062.
063.
064.
065.
066.
067.
068.
069.
070.
071.
072.
073.
074.
075.
076.
End
While
077.
dr.Close()
078.
End
If
079.
080.
081.
Catch
ex
As
Exception
082.
083.
End
Try
084.
ShowDataCancel()
085.
086.
formatDataGridView()
087.
End
Sub
088.
089.
Private
Sub
ShowDataCancel()
090.
091.
092.
Try
093.
094.
095.
096.
Dim
com2
As
New
OleDbCommand(
"SELECT CateName, COUNT(CateName) As aaa FROM Tools WHERE Status = 'เสีย' GROUP BY CateName "
, Conn) '/////****ใช้งานได้
097.
098.
099.
Dim
dr
As
OleDbDataReader = com2.ExecuteReader
100.
Dim
i
As
Integer
= 0
101.
Dim
num
As
Integer
= 0
102.
If
dr.HasRows
Then
103.
While
dr.Read
104.
105.
106.
dgvFame.Rows.Add()
107.
108.
dgvFame.Rows(i).Cells(3).Value = dr.Item(0)
109.
110.
dgvFame.Rows(i).Cells(4).Value = dr.Item(1)
111.
112.
113.
114.
i = i + 1
115.
116.
117.
118.
End
While
119.
dr.Close()
120.
End
If
121.
122.
123.
Catch
ex
As
Exception
124.
125.
End
Try
126.
127.
128.
End
Sub
129.
130.
131.
132.
Private
Sub
formatDataGridView()
133.
With
dgvFame
134.
If
.Rows.Count > 0
Then
135.
136.
.Columns(0).HeaderText =
"ที่"
137.
.Columns(1).HeaderText =
"ชื่อเครื่องมือ"
138.
.Columns(2).HeaderText =
"จำนวนทั้งหมด"
139.
.Columns(3).HeaderText =
"ชื่ออุปกรเสีย"
140.
.Columns(4).HeaderText =
"จำนวนที่เสีย"
141.
.Columns(5).HeaderText =
"คงเหลือ"
142.
143.
144.
145.
.Columns(0).Width = 50
146.
.Columns(1).Width = 250
147.
.Columns(2).Width = 150
148.
.Columns(3).Width = 150
149.
.Columns(4).Width = 150
150.
.Columns(5).Width = 150
151.
152.
153.
154.
155.
156.
157.
158.
.ForeColor = Color.Black
159.
End
If
160.
End
With
161.
End
Sub
162.
163.
End
Class