Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
If cboTypeList.Text = "" Then
MessageBox.Show("กรุณาเลือกประเภทการค้นหาและกรอกข้อมูลที่ต้องการค้นหาด้วย !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim dtMemberSIC As New DataTable()
Dim Sql As String = ""
Com = New SqlCommand()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Sql = "SELECT S.BarCode,S.DateAdd,T.NameTypeProduct,S.SizePackaging,S.NumberPackagingPer,S.PackagingPer,S.TotalWeight,S.NameCustomer,F.Name_F"
Sql &= " FROM StockInventoryControl AS S,TypeProduct AS T,FactoryStaff AS F,StorkProduct AS SP"
Sql &= " WHERE S.DateAdd BETWEEN @dtpStard AND @dtpEnd AND S.ID_TypeProduct=T.ID_TypeProduct AND S.IDFactoryStaffdgv=F.IDFactoryStaff AND SP.TypeProduct=S.TypeProduct"
If cboTypeList.SelectedIndex = 1 Then
Sql &= " AND S.BarCode=@BarCode"
ElseIf cboTypeList.SelectedIndex = 2 Then
Sql &= " AND S.NameCustomer LIKE @NameCustomer"
End If
dtMemberSIC = New DataTable()
With Com
.Parameters.Clear()
.CommandType = CommandType.Text
.CommandText = Sql
.Connection = Conn
.Parameters.Add("@dtpStard", SqlDbType.DateTime).Value = dtpstart.Value
.Parameters.Add("@dtpEnd", SqlDbType.DateTime).Value = dtpend.Value
If cboTypeList.SelectedIndex = 1 Then
.Parameters.Add("@BarCode", SqlDbType.NVarChar).Value = mtbBarcode.Text
ElseIf cboTypeList.SelectedIndex = 2 Then
.Parameters.Add("@NameCustomer", SqlDbType.NVarChar).Value = txtSearch.Text
End If
dr = .ExecuteReader()
If dr.HasRows Then
dgvRawMaterialStorck.Columns.Clear()
dtMemberSIC.Load(dr)
dgvRawMaterialStorck.DataSource = dtMemberSIC
With dgvRawMaterialStorck
.Columns(0).Width = 153
.Columns(1).Width = 112
.Columns(2).Width = 119
.Columns(3).Width = 71
.Columns(4).Width = 77
.Columns(5).Width = 73
.Columns(6).Width = 69
.Columns(7).Width = 97
.Columns(8).Width = 79
.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
Else
dgvRawMaterialStorck.Columns.Clear()
MessageBox.Show("ไม่มีข้อมูลที่ระบุไว้ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
End With
dr.Close()
Conn.Close()
End Sub