Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Public Class frmSale
Dim strConn As String
Dim Conn As New OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim strSQL As String
Dim Check As Boolean
Dim LastRecord As Long
Dim dblSubTotal, dblRecieve, dblChange As Double
Dim IsFindProduct, IsFindMember, IsFindSale, IsFindSaleDetail As Boolean
'----------------------ตัวแปรสำหรับพิมพ์ใบเสร็จ----------------------
Dim lngO_ID As Long = 0
Dim UseFont As New Font("MS Sans Serif", 10)
Dim prDoc As New PrintDocument()
Dim prDlg As New PrintDialog()
Private Sub AddEdit()
cmdAdd.Enabled = False
cmdSave.Enabled = True
cmdCancel.Enabled = True
txtM_ID.Enabled = True
txtP_ID.Enabled = True
cmdAddList.Enabled = True
End Sub
Private Sub SaveCancel()
cmdAdd.Enabled = True
cmdSave.Enabled = False
cmdCancel.Enabled = False
txtM_ID.Enabled = False
txtP_ID.Enabled = False
cmdAddList.Enabled = False
End Sub
Private Sub ClearAllData()
lblS_ID.Text = ""
txtM_ID.Text = ""
lblMName.Text = ""
txtP_ID.Text = ""
lblName.Text = ""
lblPrice.Text = ""
txtQty.Text = ""
lblTotal.Text = ""
lblNet.Text = "0.00"
grdOrder.DataSource = Nothing
End Sub
Private Function CheckList() As Boolean
Check = False
strSQL = "SELECT * FROM Sale_Detail WHERE(S_ID = " & CInt(lblS_ID.Text) & " AND P_ID = '" & txtP_ID.Text & "')"
da = New OleDbDataAdapter(strSQL, Conn)
da.Fill(ds, "List")
If ds.Tables("List").Rows.Count <> 0 Then
Return True
ds.Tables("List").Clear()
Else
Return False
End If
End Function
Private Function CheckDataAdd() As Boolean
Check = False
If lblPrice.Text = "" Or txtQty.Text = "" Or lblTotal.Text = "" Then
MessageBox.Show("กรุณากรอกข้อมูลให้ครบ ", "ข้อมูลไม่ครบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
Else
Return True
End If
End Function
Private Function CheckDataSave() As Boolean
Check = False
If grdOrder.Rows.Count < 1 Then
MessageBox.Show("กรุณาเลือกสินค้า ", "ข้อมูลไม่ครบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
Else
Return True
End If
End Function
Private Sub FormatGrd()
With grdOrder
If .RowCount <> 0 Then
.Columns(0).HeaderText = "รหัส"
.Columns(1).HeaderText = "รายการ"
.Columns(2).HeaderText = "ราคา"
.Columns(3).HeaderText = "จำนวน"
.Columns(4).HeaderText = "รวม"
.Columns(0).Width = 60
.Columns(1).Width = 180
.Columns(2).Width = 60
.Columns(3).Width = 50
.Columns(4).Width = 80
End If
End With
End Sub
Private Sub ShowMember()
If txtM_ID.Text = "" Then
txtP_ID.Focus()
Exit Sub
End If
strSQL = "SELECT * FROM Member WHERE(M_ID = '" & txtM_ID.Text & "')"
da = New OleDbDataAdapter(strSQL, Conn)
If IsFindMember = True Then
ds.Tables("Member").Clear()
End If
da.Fill(ds, "Member")
If ds.Tables("Member").Rows.Count <> 0 Then
lblMName.Text = CStr(ds.Tables("Member").Rows(0).Item("Prefix"))
lblMName.Text &= CStr(ds.Tables("Member").Rows(0).Item("Name"))
lblMName.Text &= " "
lblMName.Text &= CStr(ds.Tables("Member").Rows(0).Item("Surname"))
txtP_ID.Focus()
IsFindMember = True
Else
MessageBox.Show("ไม่พบรหัสสมาชิกนี้ ", "สมาชิก", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtM_ID.SelectAll()
txtM_ID.Focus()
End If
End Sub
End Class