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 tmpSumCommission As Double = 0
Dim tmptxtMemId 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
AutoGeneratetakeid()
'lbltakeid.Text = tmptakeid
lsvFoodList.Columns.Add("รหัสอาหาร", 82, HorizontalAlignment.Center)
lsvFoodList.Columns.Add("รายการอาหาร", 180, HorizontalAlignment.Left)
lsvFoodList.Columns.Add("ราคา/หน่วย", 82, HorizontalAlignment.Center)
lsvFoodList.Columns.Add("จำนวนที่สั่ง", 90, HorizontalAlignment.Center)
lsvFoodList.Columns.Add("รวมเป็นเงิน", 100, HorizontalAlignment.Center)
lsvFoodList.View = View.Details
lsvFoodList.GridLines = True
Conn = New OleDbConnection(strConn)
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
lbltotal.Text = "0"
txtAmount.Text = "1"
lblSalePrice.Text = "0"
'lbltakeid.Focus()
'AddHandler prDoc.PrintPage, New PrintPageEventHandler(AddressOf Me.StringToPrint_Print)
'prDoc.DocumentName = "ใบเสร็จรับเงิน"
'prDlg.Document = prDoc
lblSumBeforeDiscount.Text = "0"
lblDiscount.Text = "0"
lblNet.Text = "0"
txtMemId.Focus()
txtMemId.Focus()
End Sub
Private Sub AutoGeneratetakeid()
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)
txtMemId.Text = rMem_Id
txtMemName.Text = rMem_Name
txtidcard.Text = rMemId_Card
If rMem_Sex = "ชาย" Then
OptMale.Checked = True
ElseIf rMem_Sex = "หญิง" Then
OptFemale.Checked = True
End If
txtMemAdd.Text = rMem_Add
txtphone.Text = rMem_Phone
txtMemId.Enabled = True
chkNotMember.Checked = False
rMem_Id = ""
rMem_Name = ""
rMemId_Card = ""
rMem_Sex = "0"
rMem_Add = ""
rMem_Phone = ""
rDateRegis = ""
txtMemId.Focus()
End Sub
Private Sub chkNotMember_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNotMember.CheckedChanged
If chkNotMember.Checked = True Then
ClearAllMemberData()
AutoGenerateMemberID()
txtMemId.Enabled = False
'txtidcard.Enabled = False
btnShowMemberList.Enabled = False
txtMemName.Text = ""
txtidcard.Text = ""
txtMemAdd.Text = ""
txtphone.Text = ""
rMem_Id = ""
rMem_Name = ""
rMemId_Card = ""
rMem_Sex = "0"
rMem_Add = ""
rMem_Phone = ""
rIsMember = "1"
txtMemName.Focus()
ElseIf chkNotMember.Checked = False Then
txtMemId.Text = ""
txtMemId.Enabled = True
txtMemId.Focus()
txtMemName.Text = ""
btnShowMemberList.Enabled = True
End If
ClearAllFoodData()
lsvFoodList.Items.Clear()
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
Try
With comTmp
.CommandType = CommandType.Text
.CommandText = sqlTmp
.Connection = Conn
Tmp = .ExecuteReader()
Tmp.Read()
tmpMemberID = CInt(CStr((Tmp.Item("Mem_Id"))))
tmpMemberID = tmpMemberID + 1
txtMemId.Text = tmpMemberID.ToString("0000")
End With
Catch
tmptxtMemId = "0001"
End Try
End Sub
Private Sub ClearAllMemberData()
txtMemId.Text = ""
txtMemName.Text = ""
'cboMemberType.SelectedIndex = 0
OptMale.Checked = True
txtidcard.Text = ""
txtphone.Text = ""
txtMemAdd.Text = ""
End Sub
Private Sub ClearAllFoodData()
txtFoodId.Text = ""
lblTitle.Text = ""
lblSalePrice.Text = ""
End Sub
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)
txtFoodId.Text = rFood_Id
lblTitle.Text = rFood_Name
lblSalePrice.Text = rPrice
'lblBookCost.Text = rBookCost.ToString()
'lblBookInShop.Text = rBookInShop.ToString()
rFood_Id = ""
rFood_Name = ""
rPrice = ""
'Select Case rIsMember
' Case "0"
' lblSalePrice.Text = CStr(rNumberDateRent + rNumDateRentAdd)
' Case "1"
' lblNumberDateRent.Text = rNumberDateRent.ToString()
'End Select
'Try
' picCoverBook.Image = Image.FromFile(rPictureFileName)
'Catch
' picCoverBook.Image = Nothing
'End Try
txtFoodId.Focus()
End Sub
Private Sub ClearAllData()
txtFoodId.Text = ""
lblTitle.Text = ""
lblSalePrice.Text = ""
'txtFoodNum.Text = "0"
'lbltotal.Text = "1"
'lblBookCost.Text = "0"
'lblNumberDateRent.Text = "0"
'lblBookInShop.Text = "0"
lblSumBeforeDiscount.Text = "0"
lblDiscount.Text = "0"
lblNet.Text = "0"
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lsvFoodList.Items.Clear()
ClearAllFoodData()
lblSumBeforeDiscount.Text = "0"
lblDiscount.Text = "0"
lblNet.Text = "0"
txtFoodId.Focus()
End Sub
Private Sub txtMemId_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMemId.KeyDown
If txtMemId.Text <> "" Then
If (e.KeyCode = Keys.Enter) Then
Dim sqlMember As String = ""
sqlMember = "SELECT Mem_id, Mem_Name, MemId_Card, Mem_Sex, Mem_Add, Mem_Phone"
sqlMember &= " FROM Member"
sqlMember &= " WHERE (Mem_id='" & txtMemId.Text & "')"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
If IsFindMember = True Then
ds.Tables("Member").Clear()
End If
da = New OleDbDataAdapter(sqlMember, Conn)
da.Fill(ds, "Member")
If ds.Tables("Member").Rows.Count <> 0 Then
IsFind = True
txtMemId.Text = CStr(ds.Tables("Member").Rows(0).Item("Mem_Id"))
txtMemName.Text = CStr(ds.Tables("Member").Rows(0).Item("Mem_Name"))
txtMemAdd.Text = CStr(ds.Tables("Member").Rows(0).Item("Mem_Add"))
txtidcard.Text = CStr(ds.Tables("Member").Rows(0).Item("MemId_Card"))
txtphone.Text = CStr(ds.Tables("Member").Rows(0).Item("Mem_Phone"))
rIsMember = CStr(ds.Tables("Member").Rows(0).Item("IsMember"))
ClearAllMemberData()
lsvFoodList.Items.Clear()
txtFoodId.Focus()
Else
IsFindMember = False
MessageBox.Show("รายชื่อสมาชิกที่คุณระบุ ไม่มี !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
rMem_Id = ""
rMem_Name = ""
rMemId_Card = ""
rMem_Sex = ""
rMem_Add = ""
rMem_Phone = ""
rDateRegis = "0"
rIsMember = "1"
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_Id,Food_Name,price "
sqlFood &= " FROM Food"
sqlFood &= " WHERE (Food_Id='" & txtFoodId.Text & "')"
If IsFindFood = True Then
ds.Tables("Food").Clear()
End If
da.SelectCommand.CommandText = sqlFood
da.Fill(ds, "Food")
Dim AllDateRent As Integer = 0
If ds.Tables("Food").Rows.Count <> 0 Then
IsFindFood = True
txtFoodId.Text = CStr(ds.Tables("Food").Rows(0).Item("Food_Id"))
lblTitle.Text = CStr(ds.Tables("Food").Rows(0).Item("Food_Name"))
lblSalePrice.Text = CStr(ds.Tables("Food").Rows(0).Item("Price"))
'lbltotal.Text = CStr(ds.Tables("Food").Rows(0).Item("NumberDateRent"))
txtAmount.Focus()
txtAmount.SelectAll()
Else
IsFindFood = False
'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)
txtFoodId.Text = ""
lblTitle.Text = ""
lblSalePrice.Text = "0"
txtAmount.Text = "1"
lbltotal.Text = "0"
txtFoodId.Focus()
txtFoodId.SelectAll()
Exit Sub
End If
Next
Dim FoodTotal As Integer = 0
Dim lvi As ListViewItem
FoodTotal = CInt(lblSalePrice.Text) * CInt(txtAmount.Text)
Dim anyData() As String
anyData = New String() { _
txtFoodId.Text, _
lblTitle.Text, _
lblSalePrice.Text, _
txtAmount.Text, _
lbltotal.Text, _
FoodTotal.ToString("#,##0") _
}
lvi = New ListViewItem(anyData)
lsvFoodList.Items.Add(lvi)
CalculateRent()
ClearAllBookData()
txtFoodId.Focus()
End Sub
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 ClearAllBookData()
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 tmpNetTotal As Integer = 0
'If rIsMember = "1" Then
' rRentRateDiscount = 0
'End If
For i = 0 To lsvFoodList.Items.Count - 1
tmplblSalePrice = CInt(lsvFoodList.Items(i).SubItems(2).Text)
tmptxtAmount = CInt(lsvFoodList.Items(i).SubItems(3).Text)
tmplbltotal = tmplbltotal + (tmplblSalePrice * tmptxtAmount)
tmpSum = tmpSum + (tmptxtAmount * tmplblSalePrice * tmplbltotal)
tmpDiscount = tmpDiscount + CInt((tmptxtAmount * tmplblSalePrice * tmplbltotal) * rRentRateDiscount)
tmpNetTotal = tmpSum - tmpDiscount
Next
lblSumBeforeDiscount.Text = tmpSum.ToString("#,##0.00")
lblDiscount.Text = tmpDiscount.ToString("#,##0.00")
lblNet.Text = tmpNetTotal.ToString("#,##0.00")
'Dim i As Integer = 0
'Dim tmpNetTotal As Single = 0
'For i = 0 To lsvFoodList.Items.Count - 1
' tmpNetTotal = tmpNetTotal + CSng(lsvFoodList.Items(i).SubItems(5).Text)
'Next
'lblNetTotal.Text = tmpNetTotal.ToString("#,##0.00")
End Sub
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 sqlSave As String = ""
Dim comSave As OleDbCommand = New OleDbCommand
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
End Sub
Sub AutoGenerateTranID()
End Sub
End Class
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 tmpSumCommission As Double = 0
Dim tmptxtMemId 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
AutoGeneratetakeid()
'lbltakeid.Text = tmptakeid
lsvFoodList.Columns.Add("รหัสอาหาร", 82, HorizontalAlignment.Center)
lsvFoodList.Columns.Add("รายการอาหาร", 180, HorizontalAlignment.Left)
lsvFoodList.Columns.Add("ราคา/หน่วย", 82, HorizontalAlignment.Center)
lsvFoodList.Columns.Add("จำนวนที่สั่ง", 90, HorizontalAlignment.Center)
lsvFoodList.Columns.Add("รวมเป็นเงิน", 100, HorizontalAlignment.Center)
lsvFoodList.View = View.Details
lsvFoodList.GridLines = True
Conn = New OleDbConnection(strConn)
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
lbltotal.Text = "0"
txtAmount.Text = "1"
lblSalePrice.Text = "0"
'lbltakeid.Focus()
'AddHandler prDoc.PrintPage, New PrintPageEventHandler(AddressOf Me.StringToPrint_Print)
'prDoc.DocumentName = "ใบเสร็จรับเงิน"
'prDlg.Document = prDoc
lblSumBeforeDiscount.Text = "0"
lblDiscount.Text = "0"
lblNet.Text = "0"
txtMemId.Focus()
txtMemId.Focus()
End Sub
Private Sub AutoGeneratetakeid()
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)
txtMemId.Text = rMem_Id
txtMemName.Text = rMem_Name
txtidcard.Text = rMemId_Card
If rMem_Sex = "ชาย" Then
OptMale.Checked = True
ElseIf rMem_Sex = "หญิง" Then
OptFemale.Checked = True
End If
txtMemAdd.Text = rMem_Add
txtphone.Text = rMem_Phone
txtMemId.Enabled = True
chkNotMember.Checked = False
rMem_Id = ""
rMem_Name = ""
rMemId_Card = ""
rMem_Sex = "0"
rMem_Add = ""
rMem_Phone = ""
rDateRegis = ""
txtMemId.Focus()
End Sub
Private Sub chkNotMember_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNotMember.CheckedChanged
If chkNotMember.Checked = True Then
ClearAllMemberData()
AutoGenerateMemberID()
txtMemId.Enabled = False
'txtidcard.Enabled = False
btnShowMemberList.Enabled = False
txtMemName.Text = ""
txtidcard.Text = ""
txtMemAdd.Text = ""
txtphone.Text = ""
rMem_Id = ""
rMem_Name = ""
rMemId_Card = ""
rMem_Sex = "0"
rMem_Add = ""
rMem_Phone = ""
rIsMember = "1"
txtMemName.Focus()
ElseIf chkNotMember.Checked = False Then
txtMemId.Text = ""
txtMemId.Enabled = True
txtMemId.Focus()
txtMemName.Text = ""
btnShowMemberList.Enabled = True
End If
ClearAllFoodData()
lsvFoodList.Items.Clear()
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
Try
With comTmp
.CommandType = CommandType.Text
.CommandText = sqlTmp
.Connection = Conn
Tmp = .ExecuteReader()
Tmp.Read()
tmpMemberID = CInt(CStr((Tmp.Item("Mem_Id"))))
tmpMemberID = tmpMemberID + 1
txtMemId.Text = tmpMemberID.ToString("0000")
End With
Catch
tmptxtMemId = "0001"
End Try
End Sub
Private Sub ClearAllMemberData()
txtMemId.Text = ""
txtMemName.Text = ""
'cboMemberType.SelectedIndex = 0
OptMale.Checked = True
txtidcard.Text = ""
txtphone.Text = ""
txtMemAdd.Text = ""
End Sub
Private Sub ClearAllFoodData()
txtFoodId.Text = ""
lblTitle.Text = ""
lblSalePrice.Text = ""
End Sub
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)
txtFoodId.Text = rFood_Id
lblTitle.Text = rFood_Name
lblSalePrice.Text = rPrice
'lblBookCost.Text = rBookCost.ToString()
'lblBookInShop.Text = rBookInShop.ToString()
rFood_Id = ""
rFood_Name = ""
rPrice = ""
'Select Case rIsMember
' Case "0"
' lblSalePrice.Text = CStr(rNumberDateRent + rNumDateRentAdd)
' Case "1"
' lblNumberDateRent.Text = rNumberDateRent.ToString()
'End Select
'Try
' picCoverBook.Image = Image.FromFile(rPictureFileName)
'Catch
' picCoverBook.Image = Nothing
'End Try
txtFoodId.Focus()
End Sub
Private Sub ClearAllData()
txtFoodId.Text = ""
lblTitle.Text = ""
lblSalePrice.Text = ""
'txtFoodNum.Text = "0"
'lbltotal.Text = "1"
'lblBookCost.Text = "0"
'lblNumberDateRent.Text = "0"
'lblBookInShop.Text = "0"
lblSumBeforeDiscount.Text = "0"
lblDiscount.Text = "0"
lblNet.Text = "0"
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lsvFoodList.Items.Clear()
ClearAllFoodData()
lblSumBeforeDiscount.Text = "0"
lblDiscount.Text = "0"
lblNet.Text = "0"
txtFoodId.Focus()
End Sub
Private Sub txtMemId_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMemId.KeyDown
If txtMemId.Text <> "" Then
If (e.KeyCode = Keys.Enter) Then
Dim sqlMember As String = ""
sqlMember = "SELECT Mem_id, Mem_Name, MemId_Card, Mem_Sex, Mem_Add, Mem_Phone"
sqlMember &= " FROM Member"
sqlMember &= " WHERE (Mem_id='" & txtMemId.Text & "')"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
If IsFindMember = True Then
ds.Tables("Member").Clear()
End If
da = New OleDbDataAdapter(sqlMember, Conn)
da.Fill(ds, "Member")
If ds.Tables("Member").Rows.Count <> 0 Then
IsFind = True
txtMemId.Text = CStr(ds.Tables("Member").Rows(0).Item("Mem_Id"))
txtMemName.Text = CStr(ds.Tables("Member").Rows(0).Item("Mem_Name"))
txtMemAdd.Text = CStr(ds.Tables("Member").Rows(0).Item("Mem_Add"))
txtidcard.Text = CStr(ds.Tables("Member").Rows(0).Item("MemId_Card"))
txtphone.Text = CStr(ds.Tables("Member").Rows(0).Item("Mem_Phone"))
rIsMember = CStr(ds.Tables("Member").Rows(0).Item("IsMember"))
ClearAllMemberData()
lsvFoodList.Items.Clear()
txtFoodId.Focus()
Else
IsFindMember = False
MessageBox.Show("รายชื่อสมาชิกที่คุณระบุ ไม่มี !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
rMem_Id = ""
rMem_Name = ""
rMemId_Card = ""
rMem_Sex = ""
rMem_Add = ""
rMem_Phone = ""
rDateRegis = "0"
rIsMember = "1"
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_Id,Food_Name,price "
sqlFood &= " FROM Food"
sqlFood &= " WHERE (Food_Id='" & txtFoodId.Text & "')"
If IsFindFood = True Then
ds.Tables("Food").Clear()
End If
da.SelectCommand.CommandText = sqlFood
da.Fill(ds, "Food")
Dim AllDateRent As Integer = 0
If ds.Tables("Food").Rows.Count <> 0 Then
IsFindFood = True
txtFoodId.Text = CStr(ds.Tables("Food").Rows(0).Item("Food_Id"))
lblTitle.Text = CStr(ds.Tables("Food").Rows(0).Item("Food_Name"))
lblSalePrice.Text = CStr(ds.Tables("Food").Rows(0).Item("Price"))
'lbltotal.Text = CStr(ds.Tables("Food").Rows(0).Item("NumberDateRent"))
txtAmount.Focus()
txtAmount.SelectAll()
Else
IsFindFood = False
'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)
txtFoodId.Text = ""
lblTitle.Text = ""
lblSalePrice.Text = "0"
txtAmount.Text = "1"
lbltotal.Text = "0"
txtFoodId.Focus()
txtFoodId.SelectAll()
Exit Sub
End If
Next
Dim FoodTotal As Integer = 0
Dim lvi As ListViewItem
FoodTotal = CInt(lblSalePrice.Text) * CInt(txtAmount.Text)
Dim anyData() As String
anyData = New String() { _
txtFoodId.Text, _
lblTitle.Text, _
lblSalePrice.Text, _
txtAmount.Text, _
lbltotal.Text, _
FoodTotal.ToString("#,##0") _
}
lvi = New ListViewItem(anyData)
lsvFoodList.Items.Add(lvi)
CalculateRent()
ClearAllBookData()
txtFoodId.Focus()
End Sub
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 ClearAllBookData()
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 tmpNetTotal As Integer = 0
'If rIsMember = "1" Then
' rRentRateDiscount = 0
'End If
For i = 0 To lsvFoodList.Items.Count - 1
tmplblSalePrice = CInt(lsvFoodList.Items(i).SubItems(2).Text)
tmptxtAmount = CInt(lsvFoodList.Items(i).SubItems(3).Text)
[font=Verdana]tmplbltotal = tmplbltotal + (tmplblSalePrice * tmptxtAmount)[/font]
'มันเป็น For Loop คุนเอา ค่า tmplbltotal มารวม อีก ความจริงต้อง clear ออก
[font=Verdana]tmplbltotal = tmplblSalePrice * tmptxtAmount[/font]
[font=Verdana]tmpSum = tmpSum + (tmptxtAmount * tmplblSalePrice * tmplbltotal)[/font]
'มันเป็น summary ของ tmplbltotal มิใช่หรือ
[font=Verdana]tmpSum = tmpSum + tmplbltotal[/font]
tmpDiscount = tmpDiscount + CInt((tmptxtAmount * tmplblSalePrice * tmplbltotal) * rRentRateDiscount)
tmpNetTotal = tmpSum - tmpDiscount
Next
lblSumBeforeDiscount.Text = tmpSum.ToString("#,##0.00")
lblDiscount.Text = tmpDiscount.ToString("#,##0.00")
lblNet.Text = tmpNetTotal.ToString("#,##0.00")
'Dim i As Integer = 0
'Dim tmpNetTotal As Single = 0
'For i = 0 To lsvFoodList.Items.Count - 1
' tmpNetTotal = tmpNetTotal + CSng(lsvFoodList.Items(i).SubItems(5).Text)
'Next
'lblNetTotal.Text = tmpNetTotal.ToString("#,##0.00")
End Sub
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 sqlSave As String = ""
Dim comSave As OleDbCommand = New OleDbCommand
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
End Sub
Sub AutoGenerateTranID()
End Sub
End Class