Private Sub loadDGV4()
Connect()
'----------------------------------ดึงจากqueryมาใช้เลย---------------------------------------------------------
With Com
'Summary_Stock_IT_TransContractor
.CommandText = "ViewProduct"
.CommandType = CommandType.StoredProcedure
.Connection = conn
End With
da = New OleDbDataAdapter(Com)
da.Fill(ds, "Product")
If ds.Tables("Product").Rows.Count <> 0 Then
With DGV4
.ReadOnly = True
.DataSource = ds.Tables("Product")
End With
With DGV4
' .ColumnHeadersDefaultCellStyle = cs 'กำหนดข้อความแต่ละคอลัมน์
.Columns(0).HeaderText = "ลำดับที่"
.Columns(1).HeaderText = "ชื่อสินค้า"
.Columns(2).HeaderText = "จำนวน"
.Columns(3).HeaderText = "หน่วย"
.Columns(4).HeaderText = "รายละเอียด"
.Columns(0).Width = 50 'กำหนดความกว้าง
.Columns(1).Width = 200
.Columns(2).Width = 50
.Columns(3).Width = 100
.Columns(4).Width = 300
End With
End If
'--------------------------------------------------------------------------------------------
End Sub
Code (VB.NET)
Private Sub Product_Load(sender As Object, e As EventArgs) Handles MyBase.Load
loadDGV4()
End Sub
[head][/head]
Private Sub BN_Itemin_Click(sender As Object, e As EventArgs) Handles BN_Itemin.Click
If TxTItem.Text = "" Or TxTnum.Text = "" Or CB_unit.Text = "" Or TxTDetail.Text = "" Then
MessageBox.Show("กรุณาใส่ข้อมูล")
Else
Dim Result As MsgBoxResult
Result = CType(MessageBox.Show("คุณต้องการเพิ่มข้อมูลใช่หรือไม่", "คำเตือน", MessageBoxButtons.YesNo), MsgBoxResult)
If Result = MsgBoxResult.Yes Then
Connect()
Dim a As String = CB_unit.Text
Dim name() As String
Dim detail() As String
name = a.Split(CChar("("))
Dim d As String = name(1)
detail = d.Split(CChar(")"))
Dim Sql2 As String = "SELECT idUnit from Unit where (nameUnit LIKE '" & name(0) & "') and (detailUnit like '" & detail(0) & "') "
Dim idUnit As String
Dim com2 As New OleDbCommand()
With com2
.CommandType = CommandType.Text
.CommandText = Sql2
.Connection = conn
idUnit = CStr(.ExecuteScalar())
End With
If idUnit <> "" Then
Dim stautsunit As String = "ใช้งาน"
condata.addOrderProduct(nameProduct:=TxTItem.Text, numProduct:=CInt(TxTnum.Text), idUnit:=CB_unit.Text, detailProduct:=TxTDetail.Text)
MessageBox.Show("ข้อมูลถูกเพิ่มเรียบร้อย")
TxTItem.Text = ""
TxTnum.Text = ""
TxTDetail.Text = ""
Else
MessageBox.Show("กรุณาเลือกหน่วยนับที่มีอยู่ในช่อง")
End If
ElseIf Result = MsgBoxResult.No Then
MessageBox.Show("การเพิ่มข้อมูลถูกยกเลิก")
End If
End If
End Sub