Public Class FrmMain1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub EmployerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmployerToolStripMenuItem.Click
FrmEmp1.MdiParent = Me
FrmEmp1.Show()
End Sub
Private Sub ITEquipmentAwaitingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ITEquipmentAwaitingToolStripMenuItem.Click
ITEquipmentAwaiting.MdiParent = Me
Plan_List_Dialog.MdiParent = Me
DG_SearchTrans_TransContractor.MdiParent = Me
ITEquipmentAwaiting.Show()
End Sub
Private Sub PlannedITEquipToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlannedITEquipToolStripMenuItem.Click
FrmPlannedITEquip.MdiParent = Me
FrmPlannedITEquip.Show()
End Sub
End Class
Code หน้า ITEquipmentAwaiting
Public Class ITEquipmentAwaiting
Public sendVar As String
Private Sub ITEquipmentAwaiting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub BNSearch2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BNSearch2.Click
Plan_List_Dialog.Show()
End Sub
Private Sub BNSearch1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BNSearch1.Click
DG_SearchTrans_TransContractor.Show()
End Sub
Private Sub CBIPL_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBITPlanndList.SelectedIndexChanged
End Sub
End Class
Code หน้า Plan_list_Dialog
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.DataRow
Public Class Plan_List_Dialog
Dim conn As New OleDbConnection
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
'Dim dvm As DataViewManager
Public sendVar As Integer
Dim dt As DataTable
Dim dr As DataRow
Private Sub Plan_List_Dialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With conn
If .State = ConnectionState.Open Then .Close()
' .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\paweenawat\Documents\Visual Studio 2010\Projects\test_add_delete_select_update\WindowsApplication7\Database11.accdb"
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\paweenawat\Documents\Visual Studio 2010\Visual Studio 2010\Projects\PMCBL\PMCBL\PMCBL\PMCBL\PMCBL\PMCBL\PMCBL\PMCBL_ITINV_V0.8.accdb"
.Open()
End With
End Sub
Private Sub BNSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BNSearch.Click
Try
Dim sql_search As String
Dim search As String
Dim search2 As String
search = CBContractor.Text
search2 = TXTItem.Text
Dim num As Integer
If search = "" Then
If search2 = "" Then
num = 0
Else
num = 1
End If
Else
If search2 = "" Then
num = 2
Else
num = 3
End If
End If
sql_search = " SELECT IT_PlannedList.PlannedListID, IT_Description.Item_Desc AS Item, IT_PlannedList.Remark, Contractor.Contractor_Name AS CT, IT_PlannedList.OrderedTimes, IT_PlannedList.Qty, IT_TransContractor.ReceivedQty AS [Rec Qty], IT_PlannedList.Qty - IT_TransContractor.ReceivedQty AS [Awaiting Qty], IT_PlannedList.Unit FROM (((Contractor INNER JOIN IT_PlannedList ON Contractor.Contractor_ID = IT_PlannedList.ContractorID) INNER JOIN IT_TransContractor ON IT_PlannedList.ItemNo = IT_TransContractor.ItemNo AND IT_PlannedList.ContractorID = IT_TransContractor.ContractorID AND IT_PlannedList.OrderedTimes = IT_TransContractor.OrderedTimes) INNER JOIN IT_Description ON IT_TransContractor.ItemNo = IT_Description.ItemNo) "
Dim sqlWhere As String = ""
Select Case num
Case 0 : sqlWhere = ""
Case 1 : sqlWhere = "where Item_Desc LIKE'" & search2 & "'"
Case 2 : sqlWhere = "where Contractor_Name LIKE '" & search & "'"
Case 3 : sqlWhere = "where Contractor_Name LIKE '" & search & "' and Item_Desc LIKE'" & search2 & "'"
End Select
Dim sqlemp As String
sqlemp = sql_search & sqlWhere
' MessageBox.Show(num)
da = New OleDbDataAdapter(sqlemp, conn)
da.Fill(ds, "Contractor")
If ds.Tables("Contractor").Rows.Count <> 0 Then
With DataGridView1
.ReadOnly = True
.DataSource = ds.Tables("Contractor")
End With
Else
End If
'------------------------------- ตาราง -----------------------------------
'Dim cs As New DataGridViewCellStyle()
'cs.Font = New Font("Ms Sans Serif", 10, FontStyle.Bold)
With DataGridView1
' .ColumnHeadersDefaultCellStyle = cs 'กำหนดข้อความแต่ละคอลัมน์
.Columns(0).HeaderText = "PlannedListId"
.Columns(1).HeaderText = "Item"
.Columns(2).HeaderText = "Remark"
.Columns(3).HeaderText = "CT"
.Columns(4).HeaderText = "Ordertimes"
.Columns(5).HeaderText = "Qty"
.Columns(6).HeaderText = "Rec Qty"
.Columns(7).HeaderText = "Awaiting Qty"
.Columns(8).HeaderText = "Unit"
.Columns(0).Width = 100 'กำหนดความกว้าง
.Columns(1).Width = 210
.Columns(2).Width = 210
.Columns(2).Width = 210
.Columns(3).Width = 75
.Columns(4).Width = 75
.Columns(5).Width = 50
.Columns(6).Width = 50
.Columns(7).Width = 50
.Columns(8).Width = 50
End With
'------------------------------- ตาราง -----------------------------------
Catch ex As Exception
MessageBox.Show("ไม่พบข้อมูล", "Error !!", MessageBoxButtons.OK, MessageBoxIcon.Information)
'MessageBox.Show(ex.Message)
End Try
End Sub
Public Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex = -1 Then Exit Sub
Dim frm As New ITEquipmentAwaiting
Dim frm2 As New Plan_List_Dialog
frm2.temp.Text = ""
frm.CBITPlanndList.Text = ""
sendVar = CStr(DataGridView1.Rows.Item(e.RowIndex).Cells.Item(0).Value)
'frm2.temp.Text = DataGridView1.Rows.Item(e.RowIndex).Cells.Item(0).Value
' frm2.temp.Text = frm2.sendVar
' frm.CBITPlanndList.Text = frm2.temp.Text
Me.Close()
frm.CBITPlanndList.Text = sendVar
'frm2.temp.Text = sendVar
' MessageBox.Show(frm.CBITPlanndList.Text)
MessageBox.Show(sendVar)
' MessageBox.Show(DataGridView1.Rows.Item(e.RowIndex).Cells.Item(0).Value)
End Sub
End Class
Tag : .NET, Ms Access, Win (Windows App), VS 2010 (.NET 4.x), Windows