on Strict On
'Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Public Class AllEquipmentt
Inherits System.Windows.Forms.Form
Dim strConnection As String = "Data Source=PC201110091237\SQLEXPRESS;Initial Catalog=SQL;Integrated Security=True"
Dim Conn As New SqlConnection(strConnection)
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim comTypeProducts As SqlCommand
Dim AddData As String
Dim dt As DataTable = Nothing
Dim IsFind As Boolean = False
Dim ToClose As Boolean = False
Private Sub AllEquipmentt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Cursor.Current = Cursors.WaitCursor
'dtpDateCheck_P.Enabled = False
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConnection
.Open()
End With
ShowData()
FormatDataGridWithData()
Cursor.Current = Cursors.Default
End Sub
Private Sub ShowData()
Dim comTypeProducts As String = ""
comTypeProducts = "SELECT * FROM I_Equipment "
comTypeProducts &= " ORDER BY ID_P"
If IsFind = True Then
ds.Tables("I_Equipment").Clear()
End If
da = New SqlDataAdapter(comTypeProducts, Conn)
da.Fill(ds, "I_Equipment")
If ds.Tables("I_Equipment").Rows.Count <> 0 Then
IsFind = True
With dgvEmployee
.AllowNavigation = False
.ReadOnly = True
.DataSource = ds.Tables("I_Equipment")
End With
Else
IsFind = False
dgvEmployee.DataSource = Nothing
End If
End Sub
Private Sub FormatDataGridWithData()
'ข้อมูลที่ต้องการใส่ใน ดาต้ากิจ
Dim grdTS As DataGridTableStyle = New DataGridTableStyle
With grdTS
.AlternatingBackColor = Color.LemonChiffon
.BackColor = Color.White
.MappingName = "I_Equipment"
End With
Dim cs1 As New DataGridTextBoxColumn
With cs1
.HeaderText = "รหัสอุปกรณ์"
.MappingName = "ID_P"
.ReadOnly = True
.Width = 100
End With
grdTS.GridColumnStyles.Add(cs1)
Dim cs2 As New DataGridTextBoxColumn
With cs2
.HeaderText = "ชื่ออุปกรณ์"
.MappingName = "Name_P"
.ReadOnly = True
.Width = 100
End With
grdTS.GridColumnStyles.Add(cs2)
Dim cs3 As New DataGridTextBoxColumn
With cs3
.HeaderText = "จำนวนอุปกรณ์"
.MappingName = "Remain_P"
.ReadOnly = True
.Width = 100
End With
grdTS.GridColumnStyles.Add(cs3)
With dgvEmployee
.TableStyles.Clear()
.CaptionFont = New Font("MS Sans Serif", 10.0, FontStyle.Regular)
.CaptionText = "รายชื่ออุปกรณ์"
.FlatMode = True
.TableStyles.Add(grdTS)
End With
End Sub
Private Sub dgvEmployee_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgvEmployee.MouseUp
Dim UserSelectRow As Integer = 0
If IsFind = True Then
UserSelectRow = dgvEmployee.CurrentRowIndex
rID_P = CStr(dgvEmployee.Item(UserSelectRow, 0))
rName_P = CStr(dgvEmployee.Item(UserSelectRow, 1))
rRemain_P = CInt(dgvEmployee.Item(UserSelectRow, 2))
'rPriceUnit_P = CInt(grdProducts.Item(UserSelectRow, 3))
End If
Me.Close()
End Sub