Code
[code][/code]Code (VB.NET) Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing.Printing
Public Class frmSale
Dim Conn As New OleDbConnection(strConn)
Dim connect As New OleDbConnection
Dim da As New OleDbDataAdapter
Dim ds As DataSet = New DataSet
Dim dt As DataTable
'Dim prDoc As PrintDocument = New PrintDocument
Private prDlg As PrintDialog = New PrintDialog
Dim tmpSumCommission As Double = 0
Dim tmptxtMemId As String = ""
Dim tmptakeid As String = ""
Dim IsFind As Boolean = False
Dim IsFindMember As Boolean = False
Dim IsFindFood As Boolean = False
Dim ToClose As Boolean = False
Dim LastTransID As String = ""
Private Sub frmSale_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
With cboTable
.Items.Add("")
'.Items.Add("")
'.Items.Add("")
.SelectedIndex = 0
End With
tmptakeid = CStr(Tmp.Item("Pay_No"))
tmptakeid = (CInt(tmptakeid) + 1).ToString("00000")
End With
Catch
tmptakeid = "00001"
End Try
'Tmp.Close()
End Sub
Private Sub btnShowMemberList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowMemberList.Click
Dim fAllMember As New frmMemberList
fAllMember.ShowDialog(Me)
Private Sub chkNotMember_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNotMember.CheckedChanged
If chkNotMember.Checked = True Then
lblSumBeforeDiscount.Text = "0"
lblDiscount.Text = "0"
lblNet.Text = "0"
'txtFoodId.Focus()
End Sub
Private Sub AutoGenerateMemberID()
Dim sqlTmp As String = ""
Dim comTmp As OleDbCommand = New OleDbCommand
Dim Tmp As OleDbDataReader
Dim tmpMemberID As Integer = 0
sqlTmp = "SELECT TOP 1 Mem_Id FROM Member ORDER BY Mem_Id DESC"
Conn = New OleDbConnection(strConn)
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Private Sub btnShowOrderList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowOrderList.Click
If txtMemId.Text = "" Then
MessageBox.Show("กรุณาป้อนข้อมูลลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemId.Focus()
Exit Sub
End If
Dim fAllFood As New frmOrderFoodList
fAllFood.ShowDialog(Me)
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lsvFoodList.Items.Clear()
ClearAllFoodData()
txtMemId.Focus()
txtMemId.SelectAll()
End If
End If
End If
End Sub
Private Sub txtFoodId_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFoodId.KeyDown
If txtFoodId.Text <> "" Then
If (e.KeyCode = Keys.Enter) Then
If txtFoodId.Text = "" Then
MessageBox.Show("กรุณาป้อนข้อมูลลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtFoodId.Focus()
Exit Sub
End If
Dim sqlFood As String = ""
sqlFood = "SELECT Food.Food_Id,Food.Food_Name,Food.price,Sale.totle"
sqlFood &= " FROM Food, Sale"
sqlFood &= " WHERE (Food.Food_Id = Sale.Food_Id)"
sqlFood &= " AND (Food.Food_Id='" & txtFoodId.Text & "')"
'sqlFood = "SELECT Food_Id,Food_Name,price "
'sqlFood &= " FROM Food"
'sqlFood &= " WHERE (Food_Id='" & txtFoodId.Text & "')"
If IsFindFood = True Then
ds.Tables("Food").Clear()
End If
MessageBox.Show("ไม่พบรหัสอาหารตามที่คุณระบุ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
ClearAllFoodData()
txtFoodId.Focus()
txtFoodId.SelectAll()
End If
End If
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If (txtFoodId.Text = "") Or (lblTitle.Text = "") Or (lblSalePrice.Text = "") Or (txtAmount.Text = "") Or (lbltotal.Text = "") Then
txtFoodId.Focus()
Exit Sub
End If
Dim i As Integer = 0
Dim tmpFoodId As String = ""
For i = 0 To lsvFoodList.Items.Count - 1
tmpFoodId = lsvFoodList.Items(i).SubItems(0).Text
If txtFoodId.Text = tmpFoodId Then
MessageBox.Show("คุณเลือกรหัสอาหารซ้ำกัน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Private Sub lsvFoodList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lsvFoodList.DoubleClick
Dim i As Integer = 0
For i = 0 To lsvFoodList.SelectedItems.Count - 1
Dim lvi As ListViewItem
lvi = lsvFoodList.SelectedItems(i)
lsvFoodList.Items.Remove(lvi)
Next
CalculateRent()
End Sub
Sub CalculateRent()
Dim i As Integer = 0
Dim tmplblSalePrice As Integer = 0 'ราคา
Dim tmptxtAmount As Integer = 0 'จำนวนที่ขาย
Dim tmplbltotal As Integer = 0 'รวมเป็นเเงิน
Dim tmpSum As Integer = 0 'ผลรวม
Dim tmpDiscount As Integer = 0 'ส้วนลด กรณีเป็นลูกค้า
Dim tmpNet As Integer = 0 'ยอดที่ต้องจ่าย
If rIsMember = "1" Then
rRentRateDiscount = 0
End If
For i = 0 To lsvFoodList.Items.Count - 1
tmptxtAmount = CInt(lsvFoodList.Items(i).SubItems(2).Text)
tmplblSalePrice = CInt(lsvFoodList.Items(i).SubItems(3).Text)
tmplbltotal = CInt(lsvFoodList.Items(i).SubItems(4).Text)
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtMemId.Text = "" Then
MessageBox.Show("กรุณาระบุรหัสลูกค้าด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemId.Focus()
Exit Sub
End If
If chkNotMember.Checked = True Then
If txtMemName.Text = "" Then
MessageBox.Show("กรุณาระบุชื่อลูกค้าด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMemName.Focus()
Exit Sub
End If
End If
If lsvFoodList.Items.Count = 0 Then
MessageBox.Show("กรุณาป้อนรายการสั่งอาหารด้วยค่ะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtFoodId.Focus()
Exit Sub
End If
Dim sqlAdd As String = ""
Dim comAdd As OleDbCommand = New OleDbCommand
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Try
If MessageBox.Show("คุณต้องการบันทึกรายการอาหารที่สั่ง ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlAdd
.Connection = Conn
'MessageBox.Show(comAdd.CommandText.ToString())
comAdd.ExecuteNonQuery()
End With
Dim i As Integer = 0
Dim tmpFoodId As String = ""
Dim sqlFood As String = ""
Dim tmptxtAmount As Integer = 0
Dim tmplbltotal As Integer = 0
Dim tmpAmount As Integer = 0
Dim tmplblSalePrice As Integer = 0
Dim tmpSum As Integer = 0
Dim tmpDiscount As Integer = 0
Dim tmpNet As Integer = 0
If IsInstallPrinter() = True Then
If prDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
'prDoc.Print()
End If
Else
MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Catch ErrProcess As Exception
MessageBox.Show("ไม่สามารถบันทึกรายการสั่งอาหารได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End Try
End Sub
Private Function IsInstallPrinter() As Boolean
'IsInstallPrinter = False
''If prDoc.PrinterSettings.PrinterName = "<no default printer>" Then
'IsInstallPrinter = False
'Else
'IsInstallPrinter = True
'End If
End Function
Private Sub StringToPrint_Print(ByVal sender As Object, ByVal e As PrintPageEventArgs)
End Sub
Private Sub AnyString(ByVal g As Graphics, ByVal printString As String, ByVal xPos As Integer, ByVal yPos As Integer)