VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "msflxgrd.OCX"
Begin VB.Form frmSales 
   Caption         =   "Point of Sales"
   ClientHeight    =   7560
   ClientLeft      =   120
   ClientTop       =   420
   ClientWidth     =   8055
   LinkTopic       =   "Form3"
   ScaleHeight     =   7560
   ScaleWidth      =   8055
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command6 
      Caption         =   "Command6"
      Height          =   615
      Left            =   11880
      TabIndex        =   22
      Top             =   2760
      Width           =   855
   End
   Begin VB.CommandButton Command5 
      Caption         =   "ล้างข้อมูล"
      Height          =   735
      Left            =   6000
      TabIndex        =   21
      Top             =   2040
      Width           =   1335
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Command3"
      Height          =   255
      Left            =   8760
      TabIndex        =   20
      Top             =   5400
      Width           =   615
   End
   Begin VB.TextBox txtName 
      Enabled         =   0   'False
      Height          =   375
      Left            =   2280
      TabIndex        =   16
      Top             =   1320
      Width           =   2535
   End
   Begin MSFlexGridLib.MSFlexGrid flexcart 
      Height          =   1935
      Left            =   360
      TabIndex        =   13
      Top             =   3240
      Width           =   6975
      _ExtentX        =   12303
      _ExtentY        =   3413
      _Version        =   393216
      Rows            =   1
      Cols            =   4
   End
   Begin VB.CommandButton Command4 
      Caption         =   "เพิ่มข้อมูล"
      Height          =   615
      Left            =   6000
      TabIndex        =   12
      Top             =   1080
      Width           =   1455
   End
   Begin VB.TextBox txtQty 
      Enabled         =   0   'False
      Height          =   375
      Left            =   2280
      MaxLength       =   5
      TabIndex        =   11
      Top             =   1920
      Width           =   2175
   End
   Begin VB.CommandButton command2 
      Caption         =   "คิดเงิน"
      Height          =   975
      Left            =   5400
      TabIndex        =   10
      Top             =   5520
      Width           =   1935
   End
   Begin VB.CommandButton cmdesc 
      Caption         =   "ย้อนกลับ"
      Height          =   615
      Left            =   5040
      TabIndex        =   9
      Top             =   6720
      Width           =   2535
   End
   Begin VB.TextBox txtId 
      Height          =   375
      Left            =   2280
      TabIndex        =   4
      Top             =   840
      Width           =   3495
   End
   Begin VB.TextBox txtPay 
      Height          =   495
      Left            =   2520
      MaxLength       =   9
      TabIndex        =   1
      Text            =   "0"
      Top             =   6000
      Width           =   2175
   End
   Begin VB.Label lbdate 
      Height          =   255
      Left            =   6120
      TabIndex        =   19
      Top             =   480
      Width           =   1215
   End
   Begin VB.Label lbtotal2 
      Height          =   375
      Left            =   9480
      TabIndex        =   18
      Top             =   1200
      Width           =   1935
   End
   Begin VB.Label Label5 
      Caption         =   "ชื่อสินค้า"
      Height          =   375
      Left            =   1320
      TabIndex        =   17
      Top             =   1440
      Width           =   735
   End
   Begin VB.Label Label9 
      Caption         =   "ราคารวม"
      Height          =   375
      Left            =   1440
      TabIndex        =   15
      Top             =   5520
      Width           =   855
   End
   Begin VB.Label lbTotal 
      BackColor       =   &H8000000E&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "0"
      Height          =   375
      Left            =   2520
      TabIndex        =   14
      Top             =   5400
      Width           =   2175
   End
   Begin VB.Label Label7 
      Caption         =   "จำนวน"
      Height          =   255
      Left            =   1440
      TabIndex        =   8
      Top             =   2040
      Width           =   495
   End
   Begin VB.Label lbTon 
      BackColor       =   &H8000000E&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "0"
      Height          =   495
      Left            =   2520
      TabIndex        =   7
      Top             =   6600
      Width           =   2175
   End
   Begin VB.Label lbPrice 
      BackColor       =   &H8000000E&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "0"
      Height          =   375
      Left            =   2280
      TabIndex        =   6
      Top             =   2520
      Width           =   2175
   End
   Begin VB.Label Label4 
      Caption         =   "รหัสสินค้า (บาร์โค้ด)"
      Height          =   255
      Left            =   600
      TabIndex        =   5
      Top             =   720
      Width           =   1575
   End
   Begin VB.Label Label3 
      Caption         =   "จำนวนเงินทอน"
      Height          =   255
      Left            =   1080
      TabIndex        =   3
      Top             =   6840
      Width           =   1215
   End
   Begin VB.Label Label2 
      Caption         =   "ราคา"
      Height          =   255
      Left            =   1560
      TabIndex        =   2
      Top             =   2640
      Width           =   375
   End
   Begin VB.Label Label1 
      Caption         =   "รับเงินมาทั้งหมด"
      Height          =   255
      Left            =   1080
      TabIndex        =   0
      Top             =   6240
      Width           =   1335
   End
End
Attribute VB_Name = "frmSales"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim LR As Integer
Dim rsproduct As ADODB.Recordset
Dim RSammo As ADODB.Recordset
Dim RSPOID As ADODB.Recordset
Dim quantityValid As Integer
Public adoRs As New ADODB.Recordset
Dim t As Long
Dim total As Long


Private Sub cmdesc_Click()
t = 0
lbtotal.Caption = "0"
txtPay.Text = "0"
lbTon.Caption = "0"
Unload Me
frmOn.Show

End Sub

Private Sub Command1_Click()
Unload Me
frmOn.Show

End Sub

Private Sub Command3_Click()
frmSell.Show

End Sub

Private Sub Command4_Click()
Dim o As Integer

If txtId = "" Then
MsgBox "กรุณาเลือกสินค้า !", vbExclamation + vbOKOnly, "แจ้งเตือน"
txtId.SetFocus
Exit Sub
End If
Call search1
If txtQty.Text = "" Then
MsgBox "กรุณาใส่จำนวนที่ต้องการด้วย !", vbExclamation + vbOKOnly, "แจ้งเตือน"
o = 0
'Else
'o = txtQty.Text
txtQty.SetFocus
Exit Sub
End If
o = txtQty.Text
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim serchString As String
Dim Sql As String

serchString = Me.txtName.Text
Sql = "select * from tbl_product where productname like '%" & serchString & "%'"
           Set adoRs = Nothing   'เคลียร์เรคคอร์ดเซ็ต
           adoRs.Open Sql, conn, adOpenKeyset, adLockReadOnly 'ชุดของการประมวลผลคำสั่งจำไปใช้งาน
        '   If adoRs.EOF Then     'ตรวจสอบว่าพบข้อมูลหรือไม่ถ้าไม่พบทำบรรทัดถัดไป
         '    MsgBox "xxxxxx", vbExclamation + vbOKOnly, "แจ้งเตือน"
            If o > adoRs!Quantity Then
            MsgBox "สินค้าคงเหลือไม่เพียงพอ", vbExclamation + vbOKOnly, "แจ้งเตือน"
            Exit Sub
            End If
            
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Call search1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim i As Integer
With flexcart
.AddItem txtId.Text & vbTab & txtName.Text & vbTab & txtQty.Text & vbTab & lbPrice.Caption & vbTab & lbtotal2 & vbTab & lbdate
End With
t = t + lbtotal2
lbtotal = t

txtId.Text = ""
txtName.Text = ""
txtQty.Text = ""
lbPrice.Caption = ""
End Sub

Private Sub Command5_Click()
Dim i As Integer
With flexcart
For i = 1 To .Rows - 2
.clear
.Rows = .Rows - 1
Next i
End With
t = 0
lbtotal2 = 0
lbtotal = 0
OrderGrid
txtId.Text = ""
txtName.Text = ""
txtQty = ""
lbPrice = "0"
txtPay = "0"
lbTon = "0"
End Sub


Private Sub OrderGrid()
    With flexcart
    .Cols = 6
.Rows = 1
.Row = 0
        
        .TextMatrix(0, 0) = "รหัสสินค้า"
           .TextMatrix(0, 1) = "ชื่อ"
        .TextMatrix(0, 2) = "จำนวน"
    .TextMatrix(0, 3) = "ราคา"
    .TextMatrix(0, 4) = "ราคารวม"
        .TextMatrix(0, 5) = "วันที่"
        .ColWidth(0) = 1000
        .ColWidth(1) = 2000
    End With
End Sub

Private Sub Command6_Click()
frmProduct.Show

End Sub

Private Sub Command7_Click()
frmProduct.Show

End Sub

Private Sub Command8_Click()
frmSell.Show

End Sub

Private Sub Form_Load()
    
    Call Dbase
    Call RSPOIDLoad
Call lb
    OrderGrid
       Dim dtmTest As Date
dtmTest = DateValue(Now)
lbdate = dtmTest
End Sub

Private Sub RSPOIDLoad()
Set RSPOID = New ADODB.Recordset
    RSPOID.Open "Select*from  dailyrecord ", conn, adOpenStatic, adLockOptimistic
'Set RSammo = New ADODB.Recordset
 '   RSammo.Open "Select*from  tbl_product  ", conn, adOpenStatic, adLockOptimistic
End Sub



'Sub txtid1()
'Set rs2 = New adodb.Recordset
'rs2.Open "select  * from stokdata ", Conn, adOpenKeyset, adLockOptimistic
'While rs.EOF = False
'rs2.Filter = "idproduct LIKE '" & txtId.Text & "%'"
'rs2.MoveNext
'Wend
'rs2.Close
'Set rs = Nothing
'End Sub
Private Sub txtId_Change()
Call search
If txtId.Text = "" Then
txtQty.Enabled = False
Else
txtQty.Enabled = True
End If
'rs1.Filter = "idproduct LIKE '" & txtId.Text & "%"
End Sub

Private Sub txtId_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call search1
End If
End Sub

Private Sub txtPay_Change()
Dim pay As Long
If txtPay.Text = "" Then
labton = 0
pay = 0
lbTon = 0
Exit Sub
End If
If lbtotal > txtPay Then
lbTon = 0

End If

pay = txtPay
lbTon = pay - lbtotal

If lbTon < 1 Then
lbTon = "0"
Else
lbTon = pay - lbtotal
Exit Sub
End If

End Sub

Private Sub txtPay_KeyPress(KeyAscii As Integer)
Dim Character As String
 Character = "0123456789"
    
    KeyAscii = Asc(Chr(KeyAscii))
        If KeyAscii > 26 Then
            If InStr(Character, Chr(KeyAscii)) = 0 Then
                KeyAscii = 0
            End If
        End If
End Sub

Private Sub txtQty_Change()
Dim Character As String
 Character = "0123456789"
    
    KeyAscii = Asc(Chr(KeyAscii))
        If KeyAscii > 26 Then
            If InStr(Character, Chr(KeyAscii)) = 0 Then
                KeyAscii = 0
            End If
        End If
'lbPrice = 20
Call lb

End Sub

Private Sub txtQty_Click()
Call search1
End Sub

Private Sub txtQty_KeyPress(KeyAscii As Integer)
Dim Character As String
 Character = "0123456789"
    KeyAscii = Asc(Chr(KeyAscii))
        If KeyAscii > 26 Then
            If InStr(Character, Chr(KeyAscii)) = 0 Then
                KeyAscii = 0
            End If
        End If
End Sub
Private Sub Command2_Click()
Dim a As Long
Dim serchString As String
'Dim i As String
Dim Sql As String

If txtPay = "" Then
MsgBox "กรุณาใส่จำนวนเงิน", vbExclamation + vbOKOnly, "แจ้งเตือน"
a = 0
Exit Sub
End If
a = txtPay.Text


If flexcart.Rows <= 1 Then
MsgBox "กรุณาเลือกสินค้า !", vbExclamation + vbOKOnly, "แจ้งเตือน"
Exit Sub
End If

If lbtotal.Caption > a Then
MsgBox "จำนวนเงินไม่เพียงพอ", vbExclamation + vbOKOnly, "แจ้งเตือน"
txtPay.SetFocus
Exit Sub
End If

If MsgBox("คุณต้องการคิดเงินหรือไม่", vbQuestion + vbYesNo, "ข้อความ") = vbYes Then
Dim counter As Integer
    With flexcart
         For counter = 1 To .Rows - 1
         
         .Row = counter
            RSPOID.AddNew
            RSPOID!product_ID = .TextMatrix(.Row, 0)
            RSPOID!brand_name = .TextMatrix(.Row, 1)
            RSPOID!noofitems = .TextMatrix(.Row, 2)
            RSPOID!price = .TextMatrix(.Row, 3)
           RSPOID!total = .TextMatrix(.Row, 4)
            RSPOID!purchase_date = .TextMatrix(.Row, 5)
           ' RSPOID!purchase_date = .TextMatrix(.Row, 7)
            RSPOID.Update
            '''''''''''''''''''''''
            serchString = Me.flexcart.TextMatrix(.Row, 0)
Sql = "select * from tbl_product where BarcodeNo like '%" & serchString & "%'"
           Set adoRs = Nothing   'เคลียร์เรคคอร์ดเซ็ต
           adoRs.Open Sql, conn, adOpenKeyset, adLockOptimistic
            If adoRs.EOF Then     'ตรวจสอบว่าพบข้อมูลหรือไม่ถ้าไม่พบทำบรรทัดถัดไป
           MsgBox "ไม่พบข้อมูลสินค้า", vbExclamation + vbOKOnly, "แจ้งเตือน"
           Else
             adoRs!Quantity = adoRs!Quantity - flexcart.TextMatrix(.Row, 2)
        
        adoRs.Update
        End If
        Next
       
End With
flexcart.clear
OrderGrid
t = 0
lbtotal.Caption = "0"
txtPay.Text = "0"
lbTon.Caption = "0"
Exit Sub
End If

End Sub

Sub search()
'Dim serchString1 As String
Dim serchString As String
'Dim i As String
Dim Sql As String
Dim Row As Integer
serchString = Me.txtId.Text
Sql = "select * from tbl_product where BarcodeNo like '%" & serchString & "%'"
           Set adoRs = Nothing   'เคลียร์เรคคอร์ดเซ็ต
           adoRs.Open Sql, conn, adOpenKeyset, adLockReadOnly    'ชุดของการประมวลผลคำสั่งจำไปใช้งาน
           If adoRs.EOF Then     'ตรวจสอบว่าพบข้อมูลหรือไม่ถ้าไม่พบทำบรรทัดถัดไป
               txtName.Text = ""
               lbPrice.Caption = ""
                'MsgBox "ไม่พบรหัสผู้ป่วย"
                Me.MousePointer = 0
                Exit Sub   'ออกจาก Sub Program
        ElseIf txtId.Text = "" Then
        txtName.Text = ""
        lbPrice.Caption = ""
            Else
            txtName.Text = adoRs!ProductName & ""
            lbPrice.Caption = adoRs!price & ""
            'adoRs.Close
            End If
            Me.MousePointer = 0
End Sub

Sub lb()
If txtQty.Text = "" Then
lbtotal2 = ""
Else
lbtotal2 = lbPrice * txtQty
End If
End Sub


Sub search1()
'Dim serchString1 As String
Dim serchString As String
'Dim i As String
Dim Sql As String
Dim Row As Integer
serchString = Me.txtName.Text

Sql = "select * from tbl_product where productname like '%" & serchString & "%'"
           Set adoRs = Nothing   'เคลียร์เรคคอร์ดเซ็ต
           adoRs.Open Sql, conn, adOpenKeyset, adLockReadOnly    'ชุดของการประมวลผลคำสั่งจำไปใช้งาน
           If adoRs.EOF Then     'ตรวจสอบว่าพบข้อมูลหรือไม่ถ้าไม่พบทำบรรทัดถัดไป
           MsgBox "ไม่พบข้อมูลสินค้า", vbExclamation + vbOKOnly, "แจ้งเตือน"
           ElseIf txtName = "" Then
           MsgBox "ไม่พบข้อมูล", vbExclamation + vbOKOnly, "แจ้งเตือน"
           txtId.Text = ""
           Else
           txtId.Text = adoRs!barcodeno & ""
           Exit Sub
           End If
End Sub
