Imports System.Data
Imports System.Data.OleDb
Imports System.Text
Public Class frmCountTools
Dim Conn As New OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim sb As New StringBuilder
Dim IsFind As Boolean = False
Dim Com As OleDbCommand
Dim dr As OleDbDataReader
Dim dt As DataTable
Dim PathFile As String = ""
Private Sub frmCountTools_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
ShowData()
End Sub
Private Sub ShowData()
dgvFame.Rows.Clear()
Try
'Dim com As New OleDbCommand("SELECT Category.CateName, Tools.ToolName , COUNT(Tools.CateID) As row FROM Tools INNER JOIN Category ON Tools.CateID = Category.CateID GROUP BY CateID", Conn)
'Dim com As New OleDbCommand("SELECT Tools.CateID,Category.CateName,COUNT(Tools.CateID) As row FROM Tools GROUP BY Tools.CateID INNER JOIN Category ON Tools.CateID = Category.CateID ", Conn) '/////****ใช้งานได้
Dim com As New OleDbCommand("SELECT CateName, COUNT(CateName) As row FROM Tools GROUP BY CateName ", Conn) '/////****ใช้งานได้
'Dim com As New OleDbCommand("SELECT Tools.CateID,Tools.CateName, COUNT(CateID) As row FROM Tools INNER JOIN Category ON Tools.CateID = Category.CateID GROUP BY CateID ", Conn) '/////****ใช้งานได้
Dim dr As OleDbDataReader = com.ExecuteReader
Dim i As Integer = 0
Dim num As Integer = 0
If dr.HasRows Then
While dr.Read
dgvFame.Rows.Add()
num = num + 1
dgvFame.Rows(i).Cells(0).Value = num
dgvFame.Rows(i).Cells(1).Value = dr.Item(0)
dgvFame.Rows(i).Cells(2).Value = dr.Item(1)
'dgvFame.Rows(i).Cells(2).Value = dr.Item(2)
'num = num + 1
'dgvFame.Rows(i).Cells(1).Value = num
i = i + 1
'If dgvFame.Rows(i).Cells(0).Value = dr.Item(0) = dgvFame.Rows(i).Cells("CateName").Value Then
' num = num + 1
' dgvFame.Rows(i).Cells(1).Value = num
' 'dgvFame.Rows(i).Cells(0).Value = dr.Item(0)
'End If
End While
dr.Close()
End If
Catch ex As Exception
End Try
ShowDataCancel()
formatDataGridView()
End Sub
Private Sub ShowDataCancel()
'dgvFame.Rows.Clear()
Try
'Dim com As New OleDbCommand("SELECT Category.CateName, Tools.ToolName , COUNT(Tools.CateID) As row FROM Tools INNER JOIN Category ON Tools.CateID = Category.CateID GROUP BY CateID", Conn)
'Dim com As New OleDbCommand("SELECT Tools.CateID,Category.CateName,COUNT(Tools.CateID) As row FROM Tools GROUP BY Tools.CateID INNER JOIN Category ON Tools.CateID = Category.CateID ", Conn) '/////****ใช้งานได้
Dim com2 As New OleDbCommand("SELECT CateName, COUNT(CateName) As aaa FROM Tools WHERE Status = 'เสีย' GROUP BY CateName ", Conn) '/////****ใช้งานได้
Dim dr As OleDbDataReader = com2.ExecuteReader
Dim i As Integer = 0
Dim num As Integer = 0
If dr.HasRows Then
While dr.Read
dgvFame.Rows.Add()
dgvFame.Rows(i).Cells(3).Value = dr.Item(0)
dgvFame.Rows(i).Cells(4).Value = dr.Item(1)
i = i + 1
End While
dr.Close()
End If
Catch ex As Exception
End Try
'ShowData2()
'formatDataGridView()
End Sub
Private Sub formatDataGridView()
With dgvFame
If .Rows.Count > 0 Then
.Columns(0).HeaderText = "ที่"
.Columns(1).HeaderText = "ชื่อเครื่องมือ"
.Columns(2).HeaderText = "จำนวนทั้งหมด"
.Columns(3).HeaderText = "ชื่ออุปกรเสีย"
.Columns(4).HeaderText = "จำนวนที่เสีย"
.Columns(5).HeaderText = "คงเหลือ"
.Columns(0).Width = 50
.Columns(1).Width = 250
.Columns(2).Width = 150
.Columns(3).Width = 150
.Columns(4).Width = 150
.Columns(5).Width = 150
'.Columns(1).Visible = False
'.AlternatingRowsDefaultCellStyle.BackColor = Color.Gold
'.BackgroundColor = Color.Orange
.ForeColor = Color.Black
End If
End With
End Sub
End Class
Tag : .NET, Win (Windows App), VB.NET, VS 2010 (.NET 4.x), Windows