อยากรู้เกี่ยวกับ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 \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' ดูรายการ
|