หน้าแรก
 การบ้าน
  C/C++ new
  Java new
  Windows Phone
  แจ้งเรื่องที่ต้องการ
 บทความ
  .NET
  Android
  Blackberry
  C++Builder
  Delphi
  Java
  Mobile
  Open Source
  Pocket PC
  Visual Basic
  Web
  Windows Phone
  Others
 แบบเรียนฟรี
  ASP
  ASP.NET Webmatrix
  C++
  eVB
  J2ME
  Java
  PHP
 ซอร์สโค้ด
  Android
  ASP
  C++
  VC++
  CGI-Perl
  Delphi
  Java
  jQuery
  PHP
  Visual Basic
  .NET
 บริการจากเรา
  เปิดท้าย... ขายโค้ด
  Freeware
  อัตราค่าโฆษณา
  รายชื่อลูกค้า
  สถิติผู้เข้าเว็บ
 ดาว์นโหลด
 ค้นหาข้อมูล
 กระดานสนทนา
  .NET
  C/C++
  Delphi
  Java
  Palm/PocketPC
  Visual Basic
  Web
  อื่นๆ
 กระดานงาน
 ลิงค์เว็บ
 เกี่ยวกับผม
 อัตราค่าโฆษณา
Social Network

Facebook  Twitter  YouTube
 New Article
 Webboard
 Freelanceboard
Freeware
โปรแกรมเบอร์ดี (BerDee)
โปรแกรมเบอร์ดี (Android)
เกมส์เป่ายิ้งฉุบ
เกมส์เป่ายิ้งฉุบ(Android)
WebcamMonitor
WebcamMonitor(Windows)
scSendMail
scSendMail(Windows)
MSN Caption
MSN Caption(Windows)
  Freelance comment
  ติดต่อสอบถามมาได้ตลอดนะ...
2015-07-29 13:35:58
  ถ้าผมต้องการเว็บที่พัฒน...
2015-01-18 15:33:54
  ถ้าผมต้องการเว็บที่พัฒน...
2015-01-18 15:32:51
  ติดต่อสอบถามเข้ามาได้นะ...
2014-01-06 12:47:38
  ถ้ายังหาคนสอนไม่ได้ ก็ลอ...
2013-07-06 01:04:37
  สนใจส่งขอบเขตมาคุยราคาก...
2013-03-24 18:54:20
  ถ้ายังไม่มีคนรับงานติดต...
2012-12-16 19:18:14
  สนใจคะ ติดต่อ 0905076277...
2012-11-12 11:07:46
  รับทำโปรเจ็คนักศึกษาหรื...
2012-10-29 03:10:46
  sukit_te34@hotmail.com...
2012-10-29 03:09:36
  Webboard comment
  เขียนโปรแกรมภาษาจาวา
1.โ...

2023-09-12 11:40:28
  ต้องลอง debug ดูเองครับ
ไล่...

2023-06-08 18:03:06
  ร้านค้าแห่งหนึ่ง จะต้องน...
2021-09-21 08:47:08
  จงเขียนโปรแกรมดำเนินการ...
2021-05-07 15:06:11
  จงเขียนโปรแกรมสำหรับคำน...
2021-03-09 14:21:45
  ขอดู...
2021-01-04 23:56:45
  ขอโค้ดเพื่อทำการเรียนกา...
2020-12-09 23:02:09
  แล้ว ?...
2020-12-09 10:56:34
  จ้า...
2020-10-18 16:53:21
  พอดีผมเหลื่อแค่ตัดสต๊อก...
2020-05-31 21:49:43
  Homework comment
  เขียนโปรแกรมเพื่อรับค่า...
2022-02-24 10:45:17
  จากโค้ดนี้อะครับ พอดีลอง...
2021-03-22 01:22:39
  จากโค้ดนี้อะครับ พอดีลอง...
2021-03-22 01:22:39
  โจทย์การบ้าน c++ เขียนรูปแ...
2020-04-06 11:01:33
  แบบนี้ขอเป็น ภาษา php หน่อย...
2019-09-18 14:36:34
  ผมไม่อยากให้คุณได้คะแนน...
2019-04-27 01:29:07
  อาจารย์เขาบอกแนวข้อสอบม...
2019-04-27 00:44:29
  ขอสอบถามการเขียน c++ ครับ เ...
2018-04-02 12:19:21
  โค้ดตัวอย่างศึกษาให้เข้...
2017-11-26 14:50:05
  คำนวณค่าน้ำโดยรับค่ามิเ...
2017-11-20 23:15:26
  Article comment
  เท่าที่อ่าน error คือพื้นที่...
2022-03-23 13:56:48
  เรียน สอบถามปัญหา กับ อ.คร...
2022-01-24 17:39:49
  ต้องการ ให้เขียน โปรแกรม ...
2019-12-09 11:39:58
  รับเขียน arx จาก vc++ 2017 ล็อคโปร...
2019-09-19 09:48:09
  ทำการ register ไฟล์ที่ชื่อ mswinsck.oc...
2019-09-17 14:05:56
  ใน vb 6 ไม่มี component winsock เลยค่ะ ส...
2019-09-03 10:31:02
  รบกวนขอสอบถามหน่อยนะครั...
2019-03-04 05:31:04
  สามารถนำตัวหนังสือจากภา...
2018-12-25 08:54:32
  มีcode ของ VB ไหมค่ะ ถ้ามีรบกว...
2017-09-28 16:50:02
  น่าจะได้ครับ ไม่เคยลอง
...

2017-07-11 09:59:35
  9Mcode comment

Link Exchange

อัตราค่าโฆษณา
 
 Webboard

- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -

กระทู้ #2584 [Vb] (จาก IP: 61.90.165.123)

อยากรู้เกี่ยวกับcode vb ใช้vb2008 เกี่ยวกับเครื่องมือ tab

คือตอนแรกนะค่ะแบ่งเป็นหน้าๆ แล้วเขียนcode ไว้ แต่จะเปลี่ยนเป็นสร้างหน้าหลักขึ้นมาว่า frmtotal แล้วใช้tab ในการเลือกหน้าจะมีหน้า เลือก,ร้านค้า,รายละเอียด,ประเภท,ดูข้อมูล แล้วใส่code แต่ละหน้าลงไปในหน้า frmtotal นี้
** หน้าเก่ายังไม่ได้ลบด้วยนะค่ะ ไม่ทราบว่าเกี่ยวกับหรือเปล่านะค่ะ รบกวนผู้รู้ด้วยนะค่ะ ขอบคุณล่วงหน้าเลยค่ะ สำหรับคำแนะนำค่ะ
code ที่เขียนไว้นะค่ะ
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Data.SqlServerCe
Imports System.Data
Imports System
Imports System.Xml
Imports System.Data.Common
Imports System.IO
Imports System.IO.FileStream
Imports System.Drawing.Image
Imports System.Drawing.Bitmap
Public Class frmtotal

End Class
\' เลือก \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class frmchoose
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean

Public Sub New()
\'This call is required by the Windows Form Designer.
InitializeComponent()
\'Add any initialization after the InitializeComponent() call.
End Sub
Private Sub frmChoose_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If testDataSetUtil.DesignerUtil.IsRunTime Then
\'TODO: Delete this line of code to remove the default AutoFill for \'TestDataSet.shop\'.
Me.ShopTableAdapter.Fill(Me.TestDataSet.shop)
End If
\'If testDataSetUtil.DesignerUtil.IsRunTime Then
\' \'TODO: Delete this line of code to remove the default AutoFill for \'TestDataSet.shop\'.
\' Me.ShopTableAdapter(Me.TestDataSet.shop)
\'End If
\'TODO: This line of code loads data into the \'TestDataSet.shop\' table. You can move, or remove it, as needed.
Me.ShopTableAdapter.Fill(Me.TestDataSet.shop)
Dim strSql As String = \"select shopid,shopname from shop WHERE shopname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by shopid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"shop\")
ShopDataGrid.DataSource = ds.Tables(\"shop\")

End Sub
\'เหตุการณ์เมื่อคลิกที่ปุ่ม <
Private Sub Ptbb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ptbb.Click
bs.MovePrevious() \'เลื่อนไปเรคคอร์ดก่อนหน้า
ShopDataGrid.Text = CStr(bs.Position + 1) \'แสดงตำแหน่งเรคคอร์ดปัจจุบัน
End Sub
\'เหตุการณ์เมื่อคลิกที่ปุ่ม >
Private Sub Ptbn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ptbn.Click
bs.MoveNext() \'เลื่อนไปเรคคอร์ดถัดไป
ShopDataGrid.Text = CStr(bs.Position + 1) \'แสดงตำแหน่งเรคคอร์ดปัจจุบัน
End Sub

Private Sub searchtext() \' Function ค้นหาข้อมูลบริการ
Dim strSql As String = \"select shopid,shopname from shop WHERE shopname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by shopid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"shop\")
ShopBindingSource.DataSource = ds.Tables(\"shop\")
Me.Refresh()
End Sub
\'Event เมื่อพิมค่าในช่องค้นหา แล้วกด Enter
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
\'searchtext() \'เรียก Function ค้นหา
Dim strSql As String = \"select shopid,shopname from shop WHERE shopname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by shopid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")

Dim ds As New DataSet
adt.Fill(ds, \"shop\")
ShopBindingSource.DataSource = ds.Tables(\"shop\")
Me.Refresh()

End Sub

Private Sub ShopDataGrid_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ShopDataGrid.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (ShopDataGrid Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
ShopDataGrid = DirectCast(sender, DataGrid)
hitTest = ShopDataGrid.HitTest(e.X, e.Y)


If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub ShopDataGrid_MouseUp1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ShopDataGrid.MouseUp
Dim irow As Integer = ShopDataGrid.CurrentCell.RowNumber
Dim icol As Integer = ShopDataGrid.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (ShopDataGrid Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = ShopDataGrid.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"
Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = ShopDataGrid(irow, 0).ToString()
Dim frmInshop As New frmInshop(ShopDataGrid(irow, 0).ToString())
If frmInshop.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmInshop.TextBox1.Text = ShopDataGrid(irow, 1).ToString()
\' \' \'Me.RefreshData()
End If
\'frmInshop.ShowDialog() = Windows.Forms.DialogResult.OK
\' frmInshop.TextBox1.Text = ShopDataGrid(irow, 0).ToString()
End If
End If
Cursor.Current = Cursors.Default
End Sub

Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click

Dim ds As New DataSet
Dim strSql As String = \"select * from kindproduct WHERE kindname LIKE \'%\" & Me.TextBox2.Text & \"%\' \"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
adt.Fill(ds, \"kindproduct\")
KproDataGrid.DataSource = ds.Tables(\"kindproduct\")

\'FrmType.Show()
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text = \"ชื่อร้านค้า\" Then
PictureBox1.Visible = True
PictureBox2.Visible = False
PictureBox3.Visible = False
ShopDataGrid.Visible = True
KproDataGrid.Visible = False
PronDataGrid.Visible = False
End If

If ComboBox1.Text = \"ประเภทสินค้า\" Then
PictureBox1.Visible = False
PictureBox2.Visible = True
PictureBox3.Visible = False
ShopDataGrid.Visible = False
KproDataGrid.Visible = True
PronDataGrid.Visible = False
End If

If ComboBox1.Text = \"ชื่อสินค้า\" Then
PictureBox1.Visible = False
PictureBox2.Visible = False
PictureBox3.Visible = True
ShopDataGrid.Visible = False
KproDataGrid.Visible = False
PronDataGrid.Visible = True
End If
End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Dim strSql As String = \"select shopid,shopname from shop WHERE shopname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by shopid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"shop\")
ShopDataGrid.DataSource = ds.Tables(\"shop\")
End Sub

Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
Dim strSql As String = \"select productid,productname,shopname from product p ,shop s WHERE p.shopid = s.shopid and p.productname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by productid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"product\")
PronDataGrid.DataSource = ds.Tables(\"product\")
End Sub

Private Sub KproDataGrid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles KproDataGrid.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (KproDataGrid Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
KproDataGrid = DirectCast(sender, DataGrid)
hitTest = KproDataGrid.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub KproDataGrid_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles KproDataGrid.MouseUp
Dim irow As Integer = KproDataGrid.CurrentCell.RowNumber
Dim icol As Integer = KproDataGrid.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (KproDataGrid Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = KproDataGrid.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"

Else
dataView.Sort = columnName

End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = KproDataGrid(irow, 0).ToString()
Dim frmType As New FrmType(KproDataGrid(irow, 0).ToString())
If frmType.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmType.TextBox2.Text = KproDataGrid(irow, 1).ToString()
\' \' \'Me.RefreshData()
End If
\'frmType.ShowDialog() = Windows.Forms.DialogResult.OK
\' frmType.TextBox1.Text = KproDataGrid(irow, 0).ToString()
End If
End If

Cursor.Current = Cursors.Default

End Sub

Private Sub PronDataGrid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PronDataGrid.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (PronDataGrid Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
PronDataGrid = DirectCast(sender, DataGrid)
hitTest = PronDataGrid.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub PronDataGrid_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PronDataGrid.MouseUp
Dim irow As Integer = PronDataGrid.CurrentCell.RowNumber
Dim icol As Integer = PronDataGrid.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (PronDataGrid Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = PronDataGrid.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"

Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = PronDataGrid(irow, 0).ToString()
Dim frmDetail As New frmDetail(PronDataGrid(irow, 0).ToString())
If frmDetail.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmDetail.id = PronDataGrid(irow, 1).ToString()
\' \' \'Me.RefreshData()
End If
\'frmType.ShowDialog() = Windows.Forms.DialogResult.OK
\' frmType.TextBox1.Text =PronDataGrid(irow, 0).ToString()
End If
End If
Cursor.Current = Cursors.Default
End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' เลือก
\'*******************************************************************************************************************************
\' ร้านค้า \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class frmInshop
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean
Public Sub New(ByVal shopid As Integer)
InitializeComponent()
Me.TextBox1.Text = shopid
End Sub

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
frmView.Show()
End Sub
Private Sub frmInshop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim id As String = \"0\"
Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")
Dim cmd As New SqlCeCommand(\"SELECT * FROM shop WHERE shopid = \" & Me.TextBox1.Text, con)

Try
con.Open()

Dim rdr As SqlCeDataReader = cmd.ExecuteReader
If rdr.Read Then
id = rdr.Item(\"shopid\")
Me.TextBox1.Text = rdr.Item(\"shopname\")
End If

Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
con.Close()
End Try

Try
Dim strSql As String = \"select productid,productname from product WHERE shopid = \'\" & id & \"\' order by productid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"shop\")
Me.dtginshop.DataSource = ds.Tables(\"shop\")
Me.Refresh()

Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
con.Close()
End Try
End Sub
\'Private Sub FormatDatagrid()

\' With dtginshop
\' If .RowCount > 0 Then

\' .Columns(0).HeaderText = \"รหัสสินค้า\" \'กำหนดข้อความ\'
\' .Columns(1).HeaderText = \"ชื่อสินค้า\"

\' .Columns(0).Width = 50 \'กำหนดความกว้าง\'

\' dtginshop.columns(0).Width = 50 \'กำหนดความกว้าง\'
\' dtginshop.columns(1).Width = 150
\' End If

\' End With
Private Sub dtginshop_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub dtginshop_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim hitTest As DataGrid.HitTestInfo

If Not (dtginshop Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
dtginshop = DirectCast(sender, DataGrid)
hitTest = dtginshop.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub dtginshop_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim irow As Integer = dtginshop.CurrentCell.RowNumber
Dim icol As Integer = dtginshop.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (dtginshop Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = dtginshop.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"
Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = ShopDataGrid(irow, 0).ToString()
Dim frmDetail As New frmDetail(dtginshop(irow, 0).ToString())
If frmDetail.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmDetail.id = dtginshop(irow, 0).ToString()
\'Me.RefreshData()
End If
\'frmInshop.ShowDialog() = Windows.Forms.DialogResult.OK
\'frmInshop.TextBox1.Text = ShopDataGrid(irow, 0).ToString()
End If
End If
End Sub
Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click

End Sub

Private Sub dtginshop_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtginshop.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (dtginshop Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
dtginshop = DirectCast(sender, DataGrid)
hitTest = dtginshop.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub dtginshop_MouseUp1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtginshop.MouseUp
Dim irow As Integer = dtginshop.CurrentCell.RowNumber
Dim icol As Integer = dtginshop.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (dtginshop Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = dtginshop.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"
Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = ShopDataGrid(irow, 0).ToString()
Dim frmDetail As New frmDetail(dtginshop(irow, 0).ToString())
If frmDetail.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmDetail.id = dtginshop(irow, 0).ToString()
\'Me.RefreshData()
End If
\'frmInshop.ShowDialog() = Windows.Forms.DialogResult.OK
\'frmInshop.TextBox1.Text = ShopDataGrid(irow, 0).ToString()
End If
End If
End Sub

Private Sub dtginshop_CurrentCellChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtginshop.CurrentCellChanged

End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' ร้านค้า
\'*******************************************************************************************************************************
\' รายละเอียด \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class frmDetail
Public id As String = \"\"
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean
Dim s As FileStream
Dim shopid As String
Dim proid As String
Dim shopname As String
Public Sub New(ByVal productid As Integer)
InitializeComponent()
id = productid
End Sub
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
\'frmInshop.show()
End Sub

Private Sub frmDetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")

Try

Dim cmd As New SqlCeCommand(\"select * from product p,shop s WHERE s.shopid = p.shopid And p.productid = \" & id, con)
con.Open()

Dim rdr As SqlCeDataReader = cmd.ExecuteReader
If rdr.Read Then
Me.Label6.Text = rdr.Item(\"productstart\")
Me.Label7.Text = rdr.Item(\"productstop\")
Me.Label8.Text = rdr.Item(\"productprice\")
Me.Label9.Text = rdr.Item(\"productpro\")
Me.ListBox1.Items.Add(rdr.Item(\"productdetail\"))
Me.Label11.Text = rdr.Item(\"productname\")
shopid = rdr.Item(\"shopid\")
proid = rdr.Item(\"productid\")
shopname = rdr.Item(\"shopname\")
Ptbpic = rdr.Item(\"productpicture\")


If Convert.ToString(rdr.Item(\"productpicture\")) = \"\" Then
Ptbpic.Image = Nothing

Else
\'Ptbpic.Image = Image.FromHbitmap(Convert.ToString(rdr.Item(\"productpicture\")))
\' Ptbpic.Image = Image.FromFile(rdr.Item(\"productpicture\"))
s = File.OpenRead(\"\\My Documents\\images\\\" + rdr(\"productpicture\").ToString().Trim())
\'sourcePic1 = \"\\My Documents\\images\\\"+rdr[\"productpicture\"].ToString().Trim()
Dim bitm As New Bitmap(s)
Ptbpic.Image = bitm
s.Close()


\'Ptbpic.Image = Image.FromHbitmap(Convert.ToString(rdr.Item(\"productpicture\")))

End If


End If
Catch
End Try
End Sub


Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click


Dim conSave As New SqlCeCommand
Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")


Dim strSql As String = \"select count(productid) as Cou from productchoose WHERE productid LIKE \'%\" & Me.proid & \"%\'\"
Dim adt As New SqlCeDataAdapter(strSql, con)
Dim ds As New DataSet
adt.Fill(ds, \"productchoose\")

Dim ca As New Integer
ca = ds.Tables(\"productchoose\").Rows(0).Item(\"Cou\")

If ca > 0 Then
MessageBox.Show(\"คุณเลือกรายการซ้ำ\", \"ตรวจสอบ\", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)

Return
Else

Dim sql As String = \"INSERT INTO productchoose (productid, productname,shopname,productstop,shopid) VALUES(\'\" & proid & \"\',\'\" & Me.Label11.Text & \"\',\'\" & shopname & \"\',\'\" & Me.Label7.Text & \"\',\'\" & shopid & \"\' )\"
With con
If .State = ConnectionState.Open Then .Close()
.ConnectionString = \"Data Source=.\\test.sdf;\"
.Open()
End With
Try

With conSave
\'.CommandType = CommandType.Text
.CommandText = sql
.Connection = con
.ExecuteNonQuery()
End With

Catch ErrProcess As Exception

MessageBox.Show(\"เกิดข้อผิดพลาดขณะบันทึกข้อมูล เนื่องจาก \" & ErrProcess.Message, \"ข้อผิดพลาด\", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
Exit Sub
End Try
End If
frmView.Show()
End Sub

Private Sub Label6_ParentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.ParentChanged

End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
frmView.Show()
End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' รายละเอียด
\'*******************************************************************************************************************************
\' ประเภทสินค้า \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class FrmType
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean
Public Sub New(ByVal kindid As Integer)
InitializeComponent()
Me.TextBox2.Text = kindid
End Sub
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
frmView.Show()
End Sub
Private Sub frmType_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim id As String = \"0\"
Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")
Dim cmd As New SqlCeCommand(\"SELECT * FROM kindproduct WHERE kindid = \" & Me.TextBox2.Text, con)

Try
con.Open()

Dim rdr As SqlCeDataReader = cmd.ExecuteReader
If rdr.Read Then
id = rdr.Item(\"kindid\")
Me.TextBox2.Text = rdr.Item(\"kindname\")

End If

Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
con.Close()
End Try


Try
Dim strSql As String = \"select productid,productname,shopname from product p ,shop s WHERE p.shopid = s.shopid and s.shopid = \'\" & id & \"\' order by p.productid \"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"product\")
Me.dtgtype.DataSource = ds.Tables(\"product\")
Me.Refresh()

Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
con.Close()
End Try


End Sub

Private Sub dtgtype_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtgtype.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (dtgtype Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
dtgtype = DirectCast(sender, DataGrid)
hitTest = dtgtype.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub dtgtype_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtgtype.MouseUp
Dim irow As Integer = dtgtype.CurrentCell.RowNumber
Dim icol As Integer = dtgtype.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (dtgtype Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = dtgtype.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"
Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = ShopDataGrid(irow, 0).ToString()
Dim frmDetail As New frmDetail(dtgtype(irow, 0).ToString())
If frmDetail.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmDetail.id = dtgtype(irow, 0).ToString()
\'Me.RefreshData()
End If
\'frmType.ShowDialog() = Windows.Forms.DialogResult.OK
\'frmType.TextBox1.Text = ShopDataGrid(irow, 0).ToString()
End If
End If
End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' ประเภทสินค้า
\'*******************************************************************************************************************************
\' ดูรายการ \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class frmView
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean
Private Sub frmView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strSql As String = \"select productid,productname,shopname,productstop from productchoose\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"productchoose\")
Me.dgview.DataSource = ds.Tables(\"productchoose\")
End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
MsgBox(\"ขอบคุณที่ใช้บริการค่ะ กรุณาเก็บหน้านี้ไว้เพื่อยืนยันกับพนักงานขายค่ะ\")
End Sub

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Dim irow As Integer = dgview.CurrentCell.RowNumber
Dim ID As Integer
ID = dgview(irow, 0).ToString()

Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")
Dim conSave As New SqlCeCommand
Dim strSql As String = \"Delete productchoose where productid = \'\" & ID & \"\'\"
con.Open()
With conSave
.CommandText = strSql
.Connection = con
.ExecuteNonQuery()
End With
MsgBox(\"ลบข้อมูลเรียบร้อยแล้ว\")
reload()
Me.Refresh()
End Sub
Sub reload()
Dim strSql As String = \"select productid,productname,shopname,productstop from productchoose\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"productchoose\")
Me.dgview.DataSource = ds.Tables(\"productchoose\")
End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' ดูรายการ

คือตอนแรกนะค่ะแบ่งเป็นหน้าๆ แล้วเขียนcode ไว้ แต่จะเปลี่ยนเป็นสร้างหน้าหลักขึ้นมาว่า frmtotal แล้วใช้tab ในการเลือกหน้าจะมีหน้า เลือก,ร้านค้า,รายละเอียด,ประเภท,ดูข้อมูล แล้วใส่code แต่ละหน้าลงไปในหน้า frmtotal นี้
** หน้าเก่ายังไม่ได้ลบด้วยนะค่ะ ไม่ทราบว่าเกี่ยวกับหรือเปล่านะค่ะ รบกวนผู้รู้ด้วยนะค่ะ ขอบคุณล่วงหน้าเลยค่ะ สำหรับคำแนะนำค่ะ
code ที่เขียนไว้นะค่ะ
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Data.SqlServerCe
Imports System.Data
Imports System
Imports System.Xml
Imports System.Data.Common
Imports System.IO
Imports System.IO.FileStream
Imports System.Drawing.Image
Imports System.Drawing.Bitmap
Public Class frmtotal

End Class
\' เลือก \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class frmchoose
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean

Public Sub New()
\'This call is required by the Windows Form Designer.
InitializeComponent()
\'Add any initialization after the InitializeComponent() call.
End Sub
Private Sub frmChoose_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If testDataSetUtil.DesignerUtil.IsRunTime Then
\'TODO: Delete this line of code to remove the default AutoFill for \'TestDataSet.shop\'.
Me.ShopTableAdapter.Fill(Me.TestDataSet.shop)
End If
\'If testDataSetUtil.DesignerUtil.IsRunTime Then
\' \'TODO: Delete this line of code to remove the default AutoFill for \'TestDataSet.shop\'.
\' Me.ShopTableAdapter(Me.TestDataSet.shop)
\'End If
\'TODO: This line of code loads data into the \'TestDataSet.shop\' table. You can move, or remove it, as needed.
Me.ShopTableAdapter.Fill(Me.TestDataSet.shop)
Dim strSql As String = \"select shopid,shopname from shop WHERE shopname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by shopid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"shop\")
ShopDataGrid.DataSource = ds.Tables(\"shop\")

End Sub
\'เหตุการณ์เมื่อคลิกที่ปุ่ม <
Private Sub Ptbb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ptbb.Click
bs.MovePrevious() \'เลื่อนไปเรคคอร์ดก่อนหน้า
ShopDataGrid.Text = CStr(bs.Position + 1) \'แสดงตำแหน่งเรคคอร์ดปัจจุบัน
End Sub
\'เหตุการณ์เมื่อคลิกที่ปุ่ม >
Private Sub Ptbn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ptbn.Click
bs.MoveNext() \'เลื่อนไปเรคคอร์ดถัดไป
ShopDataGrid.Text = CStr(bs.Position + 1) \'แสดงตำแหน่งเรคคอร์ดปัจจุบัน
End Sub

Private Sub searchtext() \' Function ค้นหาข้อมูลบริการ
Dim strSql As String = \"select shopid,shopname from shop WHERE shopname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by shopid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"shop\")
ShopBindingSource.DataSource = ds.Tables(\"shop\")
Me.Refresh()
End Sub
\'Event เมื่อพิมค่าในช่องค้นหา แล้วกด Enter
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
\'searchtext() \'เรียก Function ค้นหา
Dim strSql As String = \"select shopid,shopname from shop WHERE shopname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by shopid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")

Dim ds As New DataSet
adt.Fill(ds, \"shop\")
ShopBindingSource.DataSource = ds.Tables(\"shop\")
Me.Refresh()

End Sub

Private Sub ShopDataGrid_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ShopDataGrid.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (ShopDataGrid Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
ShopDataGrid = DirectCast(sender, DataGrid)
hitTest = ShopDataGrid.HitTest(e.X, e.Y)


If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub ShopDataGrid_MouseUp1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ShopDataGrid.MouseUp
Dim irow As Integer = ShopDataGrid.CurrentCell.RowNumber
Dim icol As Integer = ShopDataGrid.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (ShopDataGrid Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = ShopDataGrid.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"
Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = ShopDataGrid(irow, 0).ToString()
Dim frmInshop As New frmInshop(ShopDataGrid(irow, 0).ToString())
If frmInshop.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmInshop.TextBox1.Text = ShopDataGrid(irow, 1).ToString()
\' \' \'Me.RefreshData()
End If
\'frmInshop.ShowDialog() = Windows.Forms.DialogResult.OK
\' frmInshop.TextBox1.Text = ShopDataGrid(irow, 0).ToString()
End If
End If
Cursor.Current = Cursors.Default
End Sub

Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click

Dim ds As New DataSet
Dim strSql As String = \"select * from kindproduct WHERE kindname LIKE \'%\" & Me.TextBox2.Text & \"%\' \"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
adt.Fill(ds, \"kindproduct\")
KproDataGrid.DataSource = ds.Tables(\"kindproduct\")

\'FrmType.Show()
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text = \"ชื่อร้านค้า\" Then
PictureBox1.Visible = True
PictureBox2.Visible = False
PictureBox3.Visible = False
ShopDataGrid.Visible = True
KproDataGrid.Visible = False
PronDataGrid.Visible = False
End If

If ComboBox1.Text = \"ประเภทสินค้า\" Then
PictureBox1.Visible = False
PictureBox2.Visible = True
PictureBox3.Visible = False
ShopDataGrid.Visible = False
KproDataGrid.Visible = True
PronDataGrid.Visible = False
End If

If ComboBox1.Text = \"ชื่อสินค้า\" Then
PictureBox1.Visible = False
PictureBox2.Visible = False
PictureBox3.Visible = True
ShopDataGrid.Visible = False
KproDataGrid.Visible = False
PronDataGrid.Visible = True
End If
End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Dim strSql As String = \"select shopid,shopname from shop WHERE shopname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by shopid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"shop\")
ShopDataGrid.DataSource = ds.Tables(\"shop\")
End Sub

Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
Dim strSql As String = \"select productid,productname,shopname from product p ,shop s WHERE p.shopid = s.shopid and p.productname LIKE \'%\" & Me.TextBox2.Text & \"%\' order by productid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"product\")
PronDataGrid.DataSource = ds.Tables(\"product\")
End Sub

Private Sub KproDataGrid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles KproDataGrid.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (KproDataGrid Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
KproDataGrid = DirectCast(sender, DataGrid)
hitTest = KproDataGrid.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub KproDataGrid_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles KproDataGrid.MouseUp
Dim irow As Integer = KproDataGrid.CurrentCell.RowNumber
Dim icol As Integer = KproDataGrid.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (KproDataGrid Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = KproDataGrid.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"

Else
dataView.Sort = columnName

End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = KproDataGrid(irow, 0).ToString()
Dim frmType As New FrmType(KproDataGrid(irow, 0).ToString())
If frmType.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmType.TextBox2.Text = KproDataGrid(irow, 1).ToString()
\' \' \'Me.RefreshData()
End If
\'frmType.ShowDialog() = Windows.Forms.DialogResult.OK
\' frmType.TextBox1.Text = KproDataGrid(irow, 0).ToString()
End If
End If

Cursor.Current = Cursors.Default

End Sub

Private Sub PronDataGrid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PronDataGrid.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (PronDataGrid Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
PronDataGrid = DirectCast(sender, DataGrid)
hitTest = PronDataGrid.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub PronDataGrid_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PronDataGrid.MouseUp
Dim irow As Integer = PronDataGrid.CurrentCell.RowNumber
Dim icol As Integer = PronDataGrid.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (PronDataGrid Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = PronDataGrid.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"

Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = PronDataGrid(irow, 0).ToString()
Dim frmDetail As New frmDetail(PronDataGrid(irow, 0).ToString())
If frmDetail.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmDetail.id = PronDataGrid(irow, 1).ToString()
\' \' \'Me.RefreshData()
End If
\'frmType.ShowDialog() = Windows.Forms.DialogResult.OK
\' frmType.TextBox1.Text =PronDataGrid(irow, 0).ToString()
End If
End If
Cursor.Current = Cursors.Default
End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' เลือก
\'*******************************************************************************************************************************
\' ร้านค้า \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class frmInshop
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean
Public Sub New(ByVal shopid As Integer)
InitializeComponent()
Me.TextBox1.Text = shopid
End Sub

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
frmView.Show()
End Sub
Private Sub frmInshop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim id As String = \"0\"
Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")
Dim cmd As New SqlCeCommand(\"SELECT * FROM shop WHERE shopid = \" & Me.TextBox1.Text, con)

Try
con.Open()

Dim rdr As SqlCeDataReader = cmd.ExecuteReader
If rdr.Read Then
id = rdr.Item(\"shopid\")
Me.TextBox1.Text = rdr.Item(\"shopname\")
End If

Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
con.Close()
End Try

Try
Dim strSql As String = \"select productid,productname from product WHERE shopid = \'\" & id & \"\' order by productid\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"shop\")
Me.dtginshop.DataSource = ds.Tables(\"shop\")
Me.Refresh()

Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
con.Close()
End Try
End Sub
\'Private Sub FormatDatagrid()

\' With dtginshop
\' If .RowCount > 0 Then

\' .Columns(0).HeaderText = \"รหัสสินค้า\" \'กำหนดข้อความ\'
\' .Columns(1).HeaderText = \"ชื่อสินค้า\"

\' .Columns(0).Width = 50 \'กำหนดความกว้าง\'

\' dtginshop.columns(0).Width = 50 \'กำหนดความกว้าง\'
\' dtginshop.columns(1).Width = 150
\' End If

\' End With
Private Sub dtginshop_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub dtginshop_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim hitTest As DataGrid.HitTestInfo

If Not (dtginshop Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
dtginshop = DirectCast(sender, DataGrid)
hitTest = dtginshop.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub dtginshop_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim irow As Integer = dtginshop.CurrentCell.RowNumber
Dim icol As Integer = dtginshop.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (dtginshop Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = dtginshop.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"
Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = ShopDataGrid(irow, 0).ToString()
Dim frmDetail As New frmDetail(dtginshop(irow, 0).ToString())
If frmDetail.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmDetail.id = dtginshop(irow, 0).ToString()
\'Me.RefreshData()
End If
\'frmInshop.ShowDialog() = Windows.Forms.DialogResult.OK
\'frmInshop.TextBox1.Text = ShopDataGrid(irow, 0).ToString()
End If
End If
End Sub
Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click

End Sub

Private Sub dtginshop_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtginshop.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (dtginshop Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
dtginshop = DirectCast(sender, DataGrid)
hitTest = dtginshop.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub dtginshop_MouseUp1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtginshop.MouseUp
Dim irow As Integer = dtginshop.CurrentCell.RowNumber
Dim icol As Integer = dtginshop.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (dtginshop Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = dtginshop.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"
Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = ShopDataGrid(irow, 0).ToString()
Dim frmDetail As New frmDetail(dtginshop(irow, 0).ToString())
If frmDetail.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmDetail.id = dtginshop(irow, 0).ToString()
\'Me.RefreshData()
End If
\'frmInshop.ShowDialog() = Windows.Forms.DialogResult.OK
\'frmInshop.TextBox1.Text = ShopDataGrid(irow, 0).ToString()
End If
End If
End Sub

Private Sub dtginshop_CurrentCellChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtginshop.CurrentCellChanged

End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' ร้านค้า
\'*******************************************************************************************************************************
\' รายละเอียด \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class frmDetail
Public id As String = \"\"
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean
Dim s As FileStream
Dim shopid As String
Dim proid As String
Dim shopname As String
Public Sub New(ByVal productid As Integer)
InitializeComponent()
id = productid
End Sub
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
\'frmInshop.show()
End Sub

Private Sub frmDetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")

Try

Dim cmd As New SqlCeCommand(\"select * from product p,shop s WHERE s.shopid = p.shopid And p.productid = \" & id, con)
con.Open()

Dim rdr As SqlCeDataReader = cmd.ExecuteReader
If rdr.Read Then
Me.Label6.Text = rdr.Item(\"productstart\")
Me.Label7.Text = rdr.Item(\"productstop\")
Me.Label8.Text = rdr.Item(\"productprice\")
Me.Label9.Text = rdr.Item(\"productpro\")
Me.ListBox1.Items.Add(rdr.Item(\"productdetail\"))
Me.Label11.Text = rdr.Item(\"productname\")
shopid = rdr.Item(\"shopid\")
proid = rdr.Item(\"productid\")
shopname = rdr.Item(\"shopname\")
Ptbpic = rdr.Item(\"productpicture\")


If Convert.ToString(rdr.Item(\"productpicture\")) = \"\" Then
Ptbpic.Image = Nothing

Else
\'Ptbpic.Image = Image.FromHbitmap(Convert.ToString(rdr.Item(\"productpicture\")))
\' Ptbpic.Image = Image.FromFile(rdr.Item(\"productpicture\"))
s = File.OpenRead(\"\\My Documents\\images\\\" + rdr(\"productpicture\").ToString().Trim())
\'sourcePic1 = \"\\My Documents\\images\\\"+rdr[\"productpicture\"].ToString().Trim()
Dim bitm As New Bitmap(s)
Ptbpic.Image = bitm
s.Close()


\'Ptbpic.Image = Image.FromHbitmap(Convert.ToString(rdr.Item(\"productpicture\")))

End If


End If
Catch
End Try
End Sub


Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click


Dim conSave As New SqlCeCommand
Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")


Dim strSql As String = \"select count(productid) as Cou from productchoose WHERE productid LIKE \'%\" & Me.proid & \"%\'\"
Dim adt As New SqlCeDataAdapter(strSql, con)
Dim ds As New DataSet
adt.Fill(ds, \"productchoose\")

Dim ca As New Integer
ca = ds.Tables(\"productchoose\").Rows(0).Item(\"Cou\")

If ca > 0 Then
MessageBox.Show(\"คุณเลือกรายการซ้ำ\", \"ตรวจสอบ\", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)

Return
Else

Dim sql As String = \"INSERT INTO productchoose (productid, productname,shopname,productstop,shopid) VALUES(\'\" & proid & \"\',\'\" & Me.Label11.Text & \"\',\'\" & shopname & \"\',\'\" & Me.Label7.Text & \"\',\'\" & shopid & \"\' )\"
With con
If .State = ConnectionState.Open Then .Close()
.ConnectionString = \"Data Source=.\\test.sdf;\"
.Open()
End With
Try

With conSave
\'.CommandType = CommandType.Text
.CommandText = sql
.Connection = con
.ExecuteNonQuery()
End With

Catch ErrProcess As Exception

MessageBox.Show(\"เกิดข้อผิดพลาดขณะบันทึกข้อมูล เนื่องจาก \" & ErrProcess.Message, \"ข้อผิดพลาด\", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
Exit Sub
End Try
End If
frmView.Show()
End Sub

Private Sub Label6_ParentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.ParentChanged

End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
frmView.Show()
End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' รายละเอียด
\'*******************************************************************************************************************************
\' ประเภทสินค้า \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class FrmType
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean
Public Sub New(ByVal kindid As Integer)
InitializeComponent()
Me.TextBox2.Text = kindid
End Sub
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
frmView.Show()
End Sub
Private Sub frmType_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim id As String = \"0\"
Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")
Dim cmd As New SqlCeCommand(\"SELECT * FROM kindproduct WHERE kindid = \" & Me.TextBox2.Text, con)

Try
con.Open()

Dim rdr As SqlCeDataReader = cmd.ExecuteReader
If rdr.Read Then
id = rdr.Item(\"kindid\")
Me.TextBox2.Text = rdr.Item(\"kindname\")

End If

Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
con.Close()
End Try


Try
Dim strSql As String = \"select productid,productname,shopname from product p ,shop s WHERE p.shopid = s.shopid and s.shopid = \'\" & id & \"\' order by p.productid \"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"product\")
Me.dtgtype.DataSource = ds.Tables(\"product\")
Me.Refresh()

Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
con.Close()
End Try


End Sub

Private Sub dtgtype_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtgtype.MouseDown
Dim hitTest As DataGrid.HitTestInfo

If Not (dtgtype Is Nothing) Then
If e.Button = MouseButtons.Left Then
Try
dtgtype = DirectCast(sender, DataGrid)
hitTest = dtgtype.HitTest(e.X, e.Y)

If hitTest.Type = DataGrid.HitTestType.ColumnHeader Then
\' column header
pressColHeader = True
ElseIf hitTest.Column = 1 Then
\' column zero
pressColZero = True
ElseIf hitTest.Type = DataGrid.HitTestType.RowHeader Then
\' row header
pressRowHeader = True
End If
Catch
End Try
End If
End If
End Sub

Private Sub dtgtype_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtgtype.MouseUp
Dim irow As Integer = dtgtype.CurrentCell.RowNumber
Dim icol As Integer = dtgtype.CurrentCell.ColumnNumber
Dim hitTest As DataGrid.HitTestInfo
Dim dataTable As DataTable
Dim dataView As DataView
Dim columnName As String
Dim dataGrid As DataGrid

If Not (dtgtype Is Nothing) Then
If (e.Button = MouseButtons.Left) AndAlso pressColHeader Then
pressColHeader = False
dataGrid = DirectCast(sender, DataGrid)
hitTest = dtgtype.HitTest(e.X, e.Y)
If hitTest.Type = dataGrid.HitTestType.ColumnHeader Then
dataTable = DirectCast(dataGrid.DataSource, DataTable)
dataView = dataTable.DefaultView
columnName = dataTable.Columns(hitTest.Column).ColumnName

If dataView.Sort = columnName Then
dataView.Sort = columnName & \" DESC\"
Else
dataView.Sort = columnName
End If
End If
ElseIf ((e.Button = MouseButtons.Left) AndAlso pressRowHeader) OrElse ((e.Button = MouseButtons.Left) AndAlso pressColZero) Then
pressRowHeader = False
pressColZero = False

\'TextBox2.Text = ShopDataGrid(irow, 0).ToString()
Dim frmDetail As New frmDetail(dtgtype(irow, 0).ToString())
If frmDetail.ShowDialog() = Windows.Forms.DialogResult.OK Then
frmDetail.id = dtgtype(irow, 0).ToString()
\'Me.RefreshData()
End If
\'frmType.ShowDialog() = Windows.Forms.DialogResult.OK
\'frmType.TextBox1.Text = ShopDataGrid(irow, 0).ToString()
End If
End If
End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' ประเภทสินค้า
\'*******************************************************************************************************************************
\' ดูรายการ \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Public Class frmView
Dim bs As New BindingSource
Private pressColHeader As Boolean
Private pressColZero As Boolean
Private pressRowHeader As Boolean
Private Sub frmView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strSql As String = \"select productid,productname,shopname,productstop from productchoose\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"productchoose\")
Me.dgview.DataSource = ds.Tables(\"productchoose\")
End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
MsgBox(\"ขอบคุณที่ใช้บริการค่ะ กรุณาเก็บหน้านี้ไว้เพื่อยืนยันกับพนักงานขายค่ะ\")
End Sub

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Dim irow As Integer = dgview.CurrentCell.RowNumber
Dim ID As Integer
ID = dgview(irow, 0).ToString()

Dim con As New SqlCeConnection(\"Data Source=.\\test.sdf;\")
Dim conSave As New SqlCeCommand
Dim strSql As String = \"Delete productchoose where productid = \'\" & ID & \"\'\"
con.Open()
With conSave
.CommandText = strSql
.Connection = con
.ExecuteNonQuery()
End With
MsgBox(\"ลบข้อมูลเรียบร้อยแล้ว\")
reload()
Me.Refresh()
End Sub
Sub reload()
Dim strSql As String = \"select productid,productname,shopname,productstop from productchoose\"
Dim adt As New SqlCeDataAdapter(strSql, \"Data Source=.\\test.sdf;\")
Dim ds As New DataSet
adt.Fill(ds, \"productchoose\")
Me.dgview.DataSource = ds.Tables(\"productchoose\")
End Sub
End Class \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' ดูรายการ
จากคุณ : al [2009-06-08 21:33:39]  
ตอบกระทู้
  • ห้ามการโฆษณา หากต้องการติดต่อหาลูกค้า ติดต่อโฆษณาโดยตรงได้ที่ webmaster@sourcecode.in.th
  • ห้ามใช้คำหยาบและคำพูดที่ไม่เหมาะสม
  • ขอสงวนสิทธิหากตรวจพบ ข้อความที่ไม่เหมาะสม ข้อความนั้นจะถูกลบทันที
ชื่อ
อีเมล์
รายละเอียด

- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -

 
 
คลิปสอนเขียนโปรแกรม
เรียนเขียนโปรแกรมดอทเน็ต
เรียนเขียนโปรแกรมแอนดรอยด์
เรียนเขียนโปรแกรมเบล็คเบอร์รี่
เรียนเขียนโปรแกรมซี ซีพลัสพลัส
เรียนเขียนโปรแกรมจาวา
เรียนการใช้งานลินุกส์
เรียนการเขียนโปรแกรมวินโดว์โฟน
เรียนการเขียนโปรแกรมพีเฮชพี มายเอสคิวเอล
อัตราค่าโฆษณา
 
Tutorial
eVB Tutorial
ASP.NET Webmatrix Tutorial
J2ME Tutorial
C++  Tutorial
Java  Tutorial
PHP Tutorial
ASP Tutorial
 
แบบสำรวจ

Home - Article - Tutorial - Sourcecode - Dev Handbook - Search - WebBoard - Links - About Us

สงวนลิขสิทธิ์ ห้ามคัดลอก ทำซ้ำ แก้ไข ดัดแปลง ไม่ว่าในรูปแบบใด โดยไม่ได้รับอนุญาตเป็นลายลักษณ์อักษร
เลขทะเบียนพาณิชย์อิเล็กทรอนิกส์จากกระทรวงพาณิชย์: 7100503002000
Copyright 2001 SourceCode.in.th