Public SpID As String Public SpName As String Public SpDb As String Public ScalerMsg As String Public KBNo As Double Public GdKg As Double Public GdNo As Double Public GdDs As String Public GdPr As Double Public GdUnit As Double Public GdAmt As Double Public CasherStat As String Dim CartNo(30) As Double Dim CartDs(30) As String Dim CartPr(30) As Double Dim CartUnit(30) As Double Dim CartAmt(30) As Double Public CartPcs As Double Public CartTotal As Double Public CartPaid As Double Public CartPaidS As String Public CartDiscount As Double Public COFlag As Boolean Public COOKFlag As Boolean Public DetailFlag As Boolean Public SpFlag As Boolean '======================================================= '專案->設定用引用項目->Microsoft DAO 3.6 object library '順位要排在第5以上 '要有一個data1 物件給rs read用 '要有另一個data2 物件給rs write用 '======================================================= Private daoDB36 As Database Private rs As DAO.Recordset Dim sPath As String Dim rs1 As Recordset Dim rs2 As Recordset Dim rs3 As Recordset Dim rs4 As Recordset Private Sub Form_Load() SpID = "DG088" SpName = "綠誰啞憍珨虛" SpDb = "\Work-008.mdb" 'SpDb = "\test.mdb" ResetAll 'Reset all number ->blank SetGdDB 'Open Gd DATA BASE Form3.KeyPreview = True 'Active KeyBoard Sniff Timer1.Enabled = True 'Active Timer = Scaler OK Timer1.Interval = 500 'avg=1.5s/scaler RS 232 MSComm1.CommPort = 2 'COM3 Scaler MSComm1.Settings = "9600,n,8,1" 'for scaler MSComm1.PortOpen = True MSComm2.CommPort = 1 'COM1 LED MSComm2.Settings = "2400,n,8,1" 'for customer LCD MSComm2.PortOpen = True RichTextBox1.Text = "" RichTextBox1.Visible = False RichTextBox2.Text = "" RichTextBox2.Visible = False ShowLED End Sub Private Sub ResetAll() ScalerMsg = "" KBNo = 0 GdKg = 0 GdNo = 0 GdDs = "" GdPr = 0 GdUnit = 0 GdAmt = 0 CartPcs = 0 CartTotal = 0 CartPaid = 0 CartPaidS = "" CartDiscount = 0 COFlag = False COOKFlag = False DetailFlag = False CasherStat = "N" 'Do nothing Label1.Caption = "靡:" Label2.Caption = "等歎:" Label3.Caption = "笭講:" Label4.Caption = "踢塗:" Label5.Caption = "苤數:" 'RichTextBox3.Visible = False Text1.Text = "" End Sub Private Sub SetGdDB() 'GdDB-1.mdb sPath = App.Path & SpDb Set daoDB36 = DBEngine(0).OpenDatabase(sPath, False, False, "MS Access;PWD=") 'Set rs1 = daoDB36.OpenRecordset("GdMain") 'Set Data1.Recordset = rs1 Set rs2 = daoDB36.OpenRecordset("GdSubPr") Set Data1.Recordset = rs2 Set rs4 = daoDB36.OpenRecordset("q-Pr") Set Data1.Recordset = rs4 '====================================== '要有一個data1 物件給rs read用 '要有另一個data2 物件給rs write用 '====================================== Set rs3 = daoDB36.OpenRecordset("TrMain") Set Data2.Recordset = rs3 End Sub Private Sub Form_Keypress(KeyAscii As Integer) Dim tempKB As Double Dim TempS As String Dim i As Integer tempKB = KeyAscii - 48 '48=0 57=9 'Print "key------------->" & tempKB '---------------- "ESC" ASCII=27 Cancel --------------------------------------------- If tempKB = -21 Then ResetAll CasherStat = "N" 'Do nothing ShowLED End If '---------------- "+" ASCII=43 Check Out --------------------------------------------- If tempKB = -5 And CartPcs <> 0 And CartTotal <> 0 Then COFlag = True DetailFlag = True Label1.Caption = "掛棒蝠眢賦梛笢" Label2.Caption = "茼彶踢塗:" & Format(CartTotal, "0.00") & "啋" Label3.Caption = "妗彶踢塗:" & Format(CartPaid, "0.00") & "啋" Label4.Caption = "殏踢塗:" & Format(CartDiscount, "0.00") & "啋" CasherStat = "S2" ShowLED CasherStat = Trim(Str(CartTotal)) ShowLED End If '---------------- "*" ASCII=42 See Cart Detail --------------------------------------- If tempKB = -6 Then If DetailFlag Then 'reverse flag DetailFlag = False Else DetailFlag = True End If End If If COFlag = True Then '-------------------------- Check Out ---------------------------------- '---------------- Get Paid Amount 0-9 ------------------------------- If tempKB >= 0 And tempKB <= 9 Then CartPaidS = CartPaidS & Trim(Str(tempKB)) 'Print "CartPaidS------------->" & CartPaidS End If '---------------- Get Paid Amount "." ------------------------------- If tempKB = -2 Then CartPaidS = CartPaidS & "." 'Print "CartPaidS------------->" & CartPaidS End If '------------- Enter ASCII = 13 to Enter Paid Amount or Finish Check Out--------------- If tempKB = -35 Then If COOKFlag = False Then '--------------- 1st Enter to Enter Paid Amount ---------------------- CartPaid = Val(CartPaidS) Label3.Caption = "妗彶踢塗:" & Format(CartPaid, "0.00") & "啋" CartDiscount = CartTotal - CartPaid '---------------- Amount OK COOKFlag = True CasherStat = "S3" ShowLED CasherStat = Trim(Str(CartPaid)) ShowLED Label4.Caption = "殏踢塗:" & Format((CartDiscount), "0.00") & "啋" OpenCasherBox Else '--------------- 2nd Enter to Finish Check Out ---------------------- WriteTradeRecord PrintRec CasherStat = "S4" ShowLED CasherStat = Trim(Str(Format(CartDiscount, "0.00"))) ' CasherStat = Trim(Str(CartDiscount)) ShowLED ResetAll Label5.Caption = "掛棒蝠眢俇傖" End If End If Else '------------------------ Not Check Out yet ----------------------------- '---------------- Get 3 digit Item No without Enter---------------- If tempKB >= 0 And tempKB <= 9 Then KBNo = KBNo * 10 + tempKB 'Print "item#------------->" & KBNo '---------------- Excluding Bar Code 69XXXXXXXXXX If KBNo > 100 And KBNo < 1000 And Int(KBNo / 10) <> 69 Then GdNo = KBNo KBNo = 0 GotGdInfor GdUnit = GdKg * 1000 GdAmt = Round((GdUnit / 500 * GdPr + 0.05), 1) '---------- 0.1 --> 0.2 ---------------------- ' If Int((GdAmt - Int(GdAmt)) * 10) = 1 Then GdAmt = GdAmt + 0.1 ' If Int((GdAmt - Int(GdAmt)) * 10) < 1 Then GdAmt = GdAmt + 0.2 'Print "--->" & GdAmt 'Print "--->" & (Int((GdAmt - Int(GdAmt)) * 10) <= 1) ShowMsg End If End If '---------------- Buy One by Scaler ---------------------------------- If tempKB = -35 And KBNo = 0 Then 'Print "BUY ONE OK!" GdUnit = GdKg * 1000 GdAmt = Round((GdUnit / 500 * GdPr + 0.05), 1) If GdAmt <> 0 Then '---------- 0.1 --> 0.2 ---------------------- ' If Int((GdAmt - Int(GdAmt)) * 10) = 1 Then GdAmt = GdAmt + 0.1 ' If Int((GdAmt - Int(GdAmt)) * 10) < 1 Then GdAmt = GdAmt + 0.2 BuyOneItem ShowMsg End If End If '------------------ Buy One by BAR CODE=13 digi + CR---------------------------------------- 'Print "Bar Code--->" & (KBNo > 6900000000000#) ' If tempKB = -35 And KBNo > 6900000000000# Then If tempKB = -35 Then 'print "key------------->" & tempKB GdNo = KBNo KBNo = 0 GotGdInfor If GdPr = 0 Then Exit Sub GdUnit = 1 GdAmt = GdUnit * GdPr '---------- 0.1 --> 0.2 ---------------------- ' If Int((GdAmt - Int(GdAmt)) * 10) = 1 Then GdAmt = GdAmt + 0.1 ' If Int((GdAmt - Int(GdAmt)) * 10) < 1 Then GdAmt = GdAmt + 0.2 BuyOneItem ShowMsg 'reset for next item GdNo = 0 GdDs = "" GdPr = 0 GdAmt = 0 End If End If ShowDetail End Sub Private Sub Timer1_Timer() AmPmCheck If COFlag = False Then GotKg_1 End If End Sub Private Sub GotKg_1() Dim SM1 As String Dim i As Integer SM1 = MSComm1.Input ScalerMsg = ScalerMsg & SM1 RichTextBox1.Text = RichTextBox1.Text & SM1 '-------------- sample-----G.W. :+ 0.000kg i = 1 Do While i < Len(ScalerMsg) - 2 And Len(ScalerMsg) > 6 If Mid(ScalerMsg, i, 2) = "kg" Then RichTextBox2.Text = ScalerMsg i = i - 5 If i > 1 Then GdKg = Val(Mid(ScalerMsg, i, 5)) End If ScalerMsg = "" ShowMsg '------------- Take Off the item and Not C/O ---- If GdKg = 0 Then GdNo = 0 GdDs = "" GdPr = 0 GdAmt = 0 ShowMsg End If If GdNo <> 0 Then GdUnit = GdKg * 2 'GdAmt = GdUnit * GdPr GdAmt = Round((GdUnit * GdPr + 0.05), 1) ShowMsg End If End If i = i + 1 Loop End Sub Private Sub GotGdInfor() Dim tempNo As String tempNo = Trim(Str(GdNo)) '------------ Read Description --------- 'rs1.MoveFirst 'Do While Not rs1.EOF ' If rs1.Fields("GdNo") = tempNo Then ' GdDs = rs1.Fields("GdDs") 'Print rs1.Fields("GdNo") 'Print rs1.Fields("GdDs") ' rs1.MoveLast ' End If ' rs1.MoveNext 'Loop '------------ Read Pricing + Description--------- rs4.MoveFirst GdPr = 0 Do While Not rs4.EOF If rs4.Fields("GdNoL") = tempNo Then '----- Bar Code or AM/PM OK ---------- If GdNo > 100 Or rs2.Fields("SpFlag") = SpFlag Then GdPr = rs4.Fields("GdPr") GdDs = rs4.Fields("GdDs") 'Print rs2.Fields("GdNo") 'Print rs2.Fields("GdPr") rs4.MoveLast End If End If rs4.MoveNext Loop End Sub Private Sub BuyOneItem() CartPcs = CartPcs + 1 CartTotal = Round((CartTotal + GdAmt) * 100) / 100 CartNo(CartPcs) = GdNo CartDs(CartPcs) = GdDs CartPr(CartPcs) = GdPr CartUnit(CartPcs) = GdUnit CartAmt(CartPcs) = GdAmt End Sub Private Sub ShowMsg() 'GdKg = 1 Label1.Caption = "靡:" & GdDs Label2.Caption = "等歎:" & GdPr & "啋/踝(500g)" Label3.Caption = "笭講:" & GdKg * 1000 & "親" Label4.Caption = "踢塗:" & Format(GdAmt, "0.00") & "啋" Label5.Caption = "苤數:" & Format(CartTotal, "0.00") & "啋 僕" & CartPcs & "璃" '------------Wait for Scaler Reading ------------ If GdKg = 0 And GdNo <> 0 Then Label3.Caption = "笭講:黍笢......" Label4.Caption = "踢塗:黍笢......" End If '-----------Bar Code Item ------------------- If GdNo > 100000 Then Label2.Caption = "等歎:" & GdPr & "啋/等弇" Label3.Caption = "#:" & GdNo Label4.Caption = "踢塗:" & Format(GdAmt, "0.00") & "啋" End If CasherStat = "S1" ShowLED CasherStat = Trim(Str(Format(GdAmt, "0.00"))) ShowLED End Sub Private Sub ShowDetail() Dim i As Integer If DetailFlag Then RichTextBox3.Visible = True RichTextBox3.Text = "" For i = 1 To CartPcs TempS = "晤瘍:" & Trim(Str(CartNo(i))) & " 靡:" & CartDs(i) & " 等歎:" _ & Trim(Str(CartPr(i))) & "啋 杅講:" & Trim(Str(CartUnit(i))) & " 苤數:" _ & Trim(Str(CartAmt(i))) & "啋" & vbCr RichTextBox3.Text = RichTextBox3.Text & TempS Next Else RichTextBox3.Visible = False End If End Sub Private Sub ShowLED() Dim DA(13) As Byte Dim i As Integer Dim j As String Dim k As Integer DA(0) = &H1B 'ESC Select Case CasherStat '------- Reset ----- Case "N" i = 1 DA(1) = &H40 '------- 單價 ----- Case "S1" i = 2 DA(1) = &H73 DA(2) = &H31 '------- 總計 ----- Case "S2" i = 2 DA(1) = &H73 DA(2) = &H32 '------- 收款 ----- Case "S3" i = 2 DA(1) = &H73 DA(2) = &H33 '------- 找零 ----- Case "S4" i = 2 DA(1) = &H73 DA(2) = &H34 '------- 數字 ----- Case Else DA(1) = &H51 'Q DA(2) = &H41 'A If Mid(CasherStat, 1, 1) = "." Then CasherStat = "0" & CasherStat j = CasherStat For i = 1 To Len(j) DA(i + 2) = Asc(Mid(j, i, 1)) Next i = Len(j) + 3 DA(i) = &HD 'CR End Select '------- Trim DA()---- For k = i + 1 To 12 DA(k) = 0 Next MSComm2.Output = DA() End Sub Private Sub WriteTradeRecord() Dim i As Integer '--------------- Detail --------------- For i = 1 To CartPcs rs3.AddNew rs3.Fields("GdNo") = CartNo(i) rs3.Fields("GdDs") = CartDs(i) rs3.Fields("GdPr") = CartPr(i) rs3.Fields("GdUnit") = CartUnit(i) rs3.Fields("GdAmt") = CartAmt(i) rs3.Fields("TrDate") = Format(Now, "yyyy-mm-dd hh:mm:ss") rs3.Fields("SpID") = SpID rs3.Fields("SpName") = SpName rs3.Update Next '--------------- Sub Total ------------ rs3.AddNew rs3.Fields("GdNo") = "TT" rs3.Fields("GdPr") = CartTotal 'CartPaid rs3.Fields("GdUnit") = CartPcs rs3.Fields("GdAmt") = CartPaid 'CartTotal rs3.Fields("GdDsc") = Format(CartDiscount, "0.00") 'CartDiscount rs3.Fields("TrDate") = Format(Now, "yyyy-mm-dd hh:mm:ss") rs3.Fields("SpID") = SpID rs3.Fields("SpName") = SpName rs3.Update End Sub Private Sub OpenCasherBox() '1B 70 00 36 FF 07 open POS casher box Open "LPT1" For Output As #1 Print #1, Chr(27) & Chr(112) & Chr(0) & Chr(54) & Chr(255) & Chr(7) Close #1 End Sub Private Sub PrintRec() Dim temp1 As String Dim temp2 As String Dim temp3 As String Open "LPT1" For Output As #1 '------------ Header ------------------------------- Print #1, " 蟯鎖汜珅閉庈" Print #1, "" Print #1, "虛瘍:" & SpID & " 虛靡:" & SpName Print #1, String(32, "=") '------------ Detail ------------------------------- For i = 1 To CartPcs temp1 = Mid(CartDs(i), 1, 5) temp1 = Format(temp1, "!@@@@@@") If CartNo(i) < 1000 Then temp2 = Trim(Str(CartUnit(i))) & "親" temp2 = Format(temp2, "!@@@@@@@@@@@@@") 'tt=13 chinese=2 Else temp2 = Trim(Str(CartNo(i))) temp2 = Format(temp2, "!@@@@@@@@@@@@@@") 'tt=14 no chinese End If temp3 = Format(Trim(Str(Round(CartAmt(i) * 100) / 100)), "0.00") Print #1, temp1 & temp2 & temp3 Next '------------ Total ------------------------------- Print #1, "" Print #1, " 軞數:ㄓ" & Format(CartTotal, "0.00") & "啋" Print #1, " 彶遴:ㄓ" & Format(CartPaid, "0.00") & "啋" If CartDiscount <> 0 Then Print #1, " 殏:ㄓ" & Format(CartDiscount, "0.00") & "啋" End If Print #1, "" '------------ Tail ------------------------------- Print #1, String(32, "-") Print #1, Format(Now, "yyyy-mm-dd hh:mm:ss") & " 嗣郅需嘈 :)" Print #1, "" Print #1, "" Print #1, "" Close #1 End Sub Private Sub AmPmCheck() Dim AP As Integer AP = 100 'No AM/PM If Hour(Now) < AP Then 'AM '===========AM No Special Pricing ============ SpFlag = False Label6.Caption = "蟯鎖汜珅閉庈" & SpName & "奻敁疑 " Else '===========PM With Special Pricing ============ SpFlag = True Label6.Caption = "蟯鎖汜珅閉庈" & SpName & "狟敁疑" End If End Sub