Imports System.Data
Imports MySql.Data.MySqlClient
Public Class FrmSale
Private Sub BtnSeachCus_Click(sender As System.Object, e As System.EventArgs) Handles BtnSeachCus.Click
Dim sqlQuery As String = "SELECT * FROM Sale WHERE SaleID = '" & TexIDCus.Text & "' "
MsgBox(sqlQuery)
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlCmd As New MySqlCommand
Dim sqlTable As New DataTable
'Dim i As Integer
With sqlCmd
.CommandText = sqlQuery
.Connection = con
End With
With sqlAdapter
.SelectCommand = sqlCmd
.Fill(sqlTable)
End With
DataGridView1.DataSource = sqlTable
End Sub
Private Sub BtndelCus_Click(sender As System.Object, e As System.EventArgs) Handles BtndelCus.Click
Dim Query As String
Query = "INSERT INTO Sale"
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=tree;User ID=root;Password=123456;")
Dim sql As MySqlCommand = New MySqlCommand(Query, con)
Query = "INSERT INTO Sale(SaleAmount,SaleID,SalePrice,ProductName,CustomerID,SaleDate)VALUES("
Query = Query + TexIDCus.Text + ",'" + TextBox2.Text + "','" + TextBox4.Text + "','" + TextBox3.Text + "','" + TextBox5.Text + "' ,'" + TextBox6.Text + "')"
con.Open()
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
Dim i As Integer = cmd.ExecuteNonQuery()
'If (i > 0) Then
'lblMsg.Text = "Record is Successfully Inserted"
'Else
'lblMsg.Text = "Record is not Inserted"
'End If
con.Close()
loadfile()
End Sub
Public Sub loadfile()
Dim sqlQuery As String
sqlQuery = "Select SaleID as รหัสรายการขาย,SaleAmount as จำนวนการขาย,SalePrice as ราคาในการขายขณะนั้น,ProductName as ชื่อสินค้า,CustomerID as รหัสสินค้า,SaleDate as วันที่ขาย from Sale"
Dim sqlAdapter As New MySqlDataAdapter
Dim sqlCmd As New MySqlCommand
Dim sqlTable As New DataTable
'Dim i As Integer
With sqlCmd
.CommandText = sqlQuery
.Connection = con
End With
With sqlAdapter
.SelectCommand = sqlCmd
.Fill(sqlTable)
End With
DataGridView1.DataSource = sqlTable
End Sub
Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim i As Integer
i = DataGridView1.CurrentRow.Index
TexIDCus.Text = DataGridView1.Item(0, i).Value
TextBox2.Text = DataGridView1.Item(1, i).Value
TextBox4.Text = DataGridView1.Item(2, i).Value
TextBox3.Text = DataGridView1.Item(3, i).Value
TextBox5.Text = DataGridView1.Item(4, i).Value
TextBox6.Text = DataGridView1.Item(5, i).Value
End Sub
Private Sub FrmSale_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If con.State = ConnectionState.Closed Then
con.Open()
End If
loadfile()
con.Close()
End Sub
Private Sub BtnAddCus_Click(sender As System.Object, e As System.EventArgs) Handles BtnAddCus.Click
Dim Query As String
Query = "INSERT INTO Sale"
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=tree;User ID=root;Password=123456;")
Dim sql As MySqlCommand = New MySqlCommand(Query, con)
Query = "INSERT INTO Sale(SaleAmount,SaleID,SalePrice,ProductName,CustomerID,SaleDate)VALUES("
Query = Query + TextBox3.Text + "','" + TextBox5.Text + "' ,'" + TextBox6.Text + "')"
con.Open()
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
Dim i As Integer = cmd.ExecuteNonQuery()
'If (i > 0) Then
'lblMsg.Text = "Record is Successfully Inserted"
'Else
'lblMsg.Text = "Record is not Inserted"
'End If
con.Close()
loadfile()
End Sub
End Class