📄 form_kchzh.frm
字号:
Width = 1200
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "卡编号"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 1680
TabIndex = 8
Top = 2760
Width = 900
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "元"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 5040
TabIndex = 7
Top = 3240
Width = 300
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "卡余额"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 1680
TabIndex = 6
Top = 3240
Width = 900
End
Begin VB.Label Label6
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "卡充值"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 285
Left = 1560
TabIndex = 5
Top = 420
Width = 900
End
End
Attribute VB_Name = "Form_kchzh"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim CardNumber As Double
Dim chzh_cn As New Connection
Dim yue As Recordset
Dim r_chzhjl As Recordset
Private Sub Command1_Click()
If Trim(Text1) <> "" And Trim(Text2) <> "" And Trim(Text3) <> "" And Trim(Text6) <> "" Then
If CDbl(Text3.Text) >= 0 Then
Set yue = New Recordset
yue.CursorLocation = adUseClient
yue.CursorType = adOpenDynamic
yue.LockType = adLockOptimistic
yue.Open "select * from 卡资料 where 卡编号='" & Trim(Text1.Text) & "'", chzh_cn
yue.Fields("姓名") = Trim(Text4.Text)
yue.Fields("性别") = Trim(Combo1.Text)
yue.Fields("身份证号") = Trim(Text5.Text)
yue.Fields("卡余额") = yue.Fields("卡余额") + CDbl(Text3.Text)
yue.Fields("时间") = Date + Time
yue.Fields("累计消费") = CDbl(Text6.Text)
yue.Update
yue.Close
If CDbl(Text3.Text) > 0 Then
Set r_chzhjl = New Recordset
r_chzhjl.CursorLocation = adUseClient
r_chzhjl.CursorType = adOpenDynamic
r_chzhjl.LockType = adLockOptimistic
r_chzhjl.Open "select top 1 * from 卡充值记录", chzh_cn
r_chzhjl.AddNew
r_chzhjl.Fields("卡编号") = Trim(Text1.Text)
r_chzhjl.Fields("充值金额") = CDbl(Text3.Text)
r_chzhjl.Fields("日期") = Date
r_chzhjl.Fields("时间") = Date + Time
r_chzhjl.Fields("操作人") = yonghuming
If Time < #6:00:00 AM# Then
r_chzhjl.Fields("出帐日期") = Date - 1
Else
r_chzhjl.Fields("出帐日期") = Date
End If
r_chzhjl.Update
'----------------------
MsgBox "充值成功!充值额:" & Text3.Text & "元。", vbInformation, "充值提示"
Else
MsgBox "资料修改成功!", vbInformation, "充值提示"
End If
End If
MSComm1.PortOpen = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Combo1.Text = ""
Text5.Text = ""
Text6.Text = ""
Command2.SetFocus
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
MSComm1.CommPort = com_x '串口号,
MSComm1.Settings = "9600,N,8,1" '串口的属性
MSComm1.InputLen = 0 '接收缓冲区的大小
MSComm1.InputMode = comInputModeBinary '二进制接受方式
MSComm1.RThreshold = 7 '每7个字节响应消息
MSComm1.PortOpen = True '打开通信串口
With chzh_cn
.ConnectionString = dblianjie
.Open
End With
Combo1.AddItem "男"
Combo1.AddItem "女"
End Sub
Private Sub Form_Unload(Cancel As Integer)
chzh_cn.Close
Set kayue_cn = Nothing
If (MSComm1.PortOpen) Then
MSComm1.PortOpen = False
End If
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent '串口事件
Case comEvReceive '接收到数据
Dim Buffer As Variant '存储数据的缓冲区
Dim StringBuf(8) As String '数据数组
Buffer = MSComm1.Input '清理接收缓冲区,此时,接收的字节数已经为0
'Dim CardNumber As Long '卡号
CardNumber = CDec(Buffer(3)) * 2 ^ 24 + (Buffer(4) * 2 ^ 16) + (Buffer(5) * 2 ^ 8) + Buffer(6) '单个字节数据左移
'----------------------------------
Set yue = New Recordset
yue.CursorLocation = adUseClient
yue.CursorType = adOpenDynamic
yue.Open "select * from 卡资料 where 卡号='" & CStr(CardNumber) & "'", chzh_cn
If yue.RecordCount > 0 Then
If Trim(yue.Fields("卡状态")) = "正常" Then
Text1.Text = Trim(yue.Fields("卡编号"))
Text2.Text = Format(yue.Fields("卡余额"), "0.00")
Text4.Text = Trim(yue.Fields("姓名"))
Combo1.Text = Trim(yue.Fields("性别"))
Text5.Text = Trim(yue.Fields("身份证号"))
Text6.Text = Format(yue.Fields("累计消费"), "0.00")
Text3.Text = "0"
Text3.SetFocus
If (MSComm1.PortOpen) Then
MSComm1.PortOpen = False
End If
Else
If (MSComm1.PortOpen) Then
MSComm1.PortOpen = False
End If
MsgBox "本卡已挂失!", vbExclamation, "读卡提示"
MSComm1.PortOpen = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Combo1.Text = ""
Text5.Text = ""
Text6.Text = ""
End If
Else
If (MSComm1.PortOpen) Then
MSComm1.PortOpen = False
End If
MsgBox "非本系统注册的卡!", vbExclamation, "读卡提示"
MSComm1.PortOpen = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Combo1.Text = ""
Text5.Text = ""
Text5.Text = ""
End If
End Select
End Sub
Private Sub Text3_GotFocus()
Text3.SelStart = 0
Text3.SelLength = Len(Text3)
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If Not (Chr(KeyAscii) Like "[0-9]" Or Chr(KeyAscii) = "." Or KeyAscii = vbKeyBack Or KeyAscii = 13) Then
KeyAscii = 0
End If
If KeyAscii = 13 And Text3.Text <> "" Then
Command1.SetFocus
End If
End Sub
Private Sub Text6_KeyPress(KeyAscii As Integer)
If Not (Chr(KeyAscii) Like "[0-9]" Or Chr(KeyAscii) = "." Or KeyAscii = vbKeyBack Or KeyAscii = 13) Then
KeyAscii = 0
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -