⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module1.bas

📁 ATM模拟系统
💻 BAS
字号:
Attribute VB_Name = "Module1"




'*************************公有变量名声明*********************************
Public i As Integer
Public CON As ADODB.Connection
Public RS As ADODB.Recordset
Dim pcount As Integer
Dim str As String
Public j As Integer
Public u As String
Public transcard As String
Public transmoney As String
'*************************验证身份函数*********************************
Public Sub Checkuser()

Set CON = New ADODB.Connection
strr = "DRIVER=SQL Server;SERVER=(local);APP=Microsoft(R) Windows (R) 2000 Operating System;WSID=SX2533;DATABASE=user;Trusted_Connection=Yes"
CON.Open strr
u = Form2.Text1.Text
str = "select 密码 from 用户信息 where 卡号='" & u & "'"
Set RS = New ADODB.Recordset
RS.Open str, CON, adOpenDynamic, adLockPessimistic
If RS.EOF = True Then
If i = 2 Then
Form3.Show
Form3.Label1.Caption = "没有此用户,请检查并重新输入!"
u = ""
Form2.Text1.Text = ""
Form2.Text2.Text = ""
Else
Form3.Show
Form3.Label1.Caption = "No This Customer!"
u = ""
Form2.Text1.Text = ""
Form2.Text2.Text = ""
End If
Exit Sub
End If

If Trim(RS.Fields(0)) = Trim(Form2.Text2.Text) Then
   Form4.Show
   RS.Close
   Unload Form2
      Else
      If i = 2 Then
      If pcount < 3 Then
      pcount = pcount + 1
      Form3.Show
      Form3.Label1.Caption = "密码不正确,请重新输入!"
      Else
      Form3.Show
      Form3.Label1.FontSize = 12
      Form3.Label1.Caption = "由于您已经输错三次密码,您的卡暂时由本行保管请您于明日拿身份证来领取!"
      pcount = 1
      Unload Form2
      Form1.Show
      Form3.SetFocus
      End If
      Else
      If pcount < 3 Then
      pcount = pcount + 1
       Form3.Show
       Form3.Label1.Caption = "Incorrect Password,Please Try Again!"
      Else
       Form3.Show
       Form3.Label1.Caption = "Your Card Have Been Eaten ,Please Take It Tomorrow"
      pcount = 1
      Unload Form2
      Form1.Show
      Form3.SetFocus
      End If
      End If
      
      End If

End Sub
'*************************修改密码函数*********************************
Public Sub changepwd()
If i = 2 Then
If Len(Form6.Text1.Text) <> 6 Or Len(Form6.Text1.Text) <> 6 Then
 Form3.Show
 Form3.Label1.Caption = "请正确输入6位密码"
Form6.Text1.Text = ""
Form6.Text2.Text = ""
Else
If Form6.Text1.Text <> Form6.Text2.Text Then
 Form3.Show
 Form3.Label1.Caption = "您两次输入的密码不一致,请检查!"
Form6.Text1.Text = ""
Form6.Text2.Text = ""
Else
str = "update 用户信息 set [密码]='" & Form6.Text1.Text & "' where 卡号='" & u & "'"
Set RS = New ADODB.Recordset
RS.Open str, CON, adOpenDynamic, adLockPessimistic
If i = 2 Then
Form9.Show
Form9.Label1.Caption = "密码修改成功,请记好您的新密码!"
Else
Form9.Show
Form9.Label1.Caption = "Password Be changed successfully"
End If
Unload Form6
Form11.Show
Form9.SetFocus
End If
End If
Else
If Len(Form6.Text1.Text) <> 6 Or Len(Form6.Text1.Text) <> 6 Then
Form3.Show
Form3.Label1.Caption = "The Length Of Password Must Be Six!"
Form6.Text1.Text = ""
Form6.Text2.Text = ""
Else
If Form6.Text1.Text <> Form6.Text2.Text Then
Form3.Show
Form3.Label1.Caption = "The Two PassWords Are Diferent!"
Form6.Text1.Text = ""
Form6.Text2.Text = ""
Else
str = "update 用户信息 set [密码]='" & Form6.Text1.Text & "' where 卡号='" & u & "'"
Set RS = CON.Execute(str)
If i = 2 Then
Form9.Show
Form9.Label1.Caption = "The PassWord Have Been changed successfully!"
Else
Form9.Show
Form9.Label1.Caption = "The PassWord Have Been changed successfully!"
End If
Unload Form6
Form11.Show
Form9.SetFocus
End If
End If

End If


End Sub
'*************************写入数据库函数*********************************
Public Sub InsertDatabase()
str = "select * from 用户操作表"
Set RS = New ADODB.Recordset
RS.Open str, CON, adOpenDynamic, adLockPessimistic

If j = 1 Then
RS.AddNew
RS.Fields("卡号") = u
RS.Fields("操作") = "取款"
RS.Fields("时间") = Now
RS.Fields("取款金额") = Val(Form5.Text1.Text)
RS.Fields("是否成功") = "是"
RS.Update
RS.Close
Else
If j = 2 Then
RS.AddNew
RS.Fields("卡号") = u
RS.Fields("操作") = "修改密码"
RS.Fields("时间") = Now
RS.Fields("是否成功") = "是"
RS.Update
RS.Close
Else
If j = 3 Then
RS.AddNew
RS.Fields("卡号") = u
RS.Fields("操作") = "转帐"
RS.Fields("时间") = Now
RS.Fields("转帐金额") = transmoney
RS.Fields("转帐卡号") = transcard
RS.Fields("是否成功") = "是"
RS.Update
RS.Close
Else
RS.AddNew
RS.Fields("卡号") = u
RS.Fields("操作") = "查询余额"
RS.Fields("时间") = Now
RS.Fields("是否成功") = "是"
RS.Update
RS.Close
End If
End If
End If
End Sub
'*************************取款函数*********************************
Public Sub TakeMoney()
Dim str1 As String
str1 = "select * from 用户信息 where 卡号='" & u & "'"
Set RS = New ADODB.Recordset
RS.Open str1, CON, adOpenDynamic, adLockPessimistic
If i = 2 Then
m = Form5.Text1.Text
If m = "" Then
Form3.Show
Form3.Label1.Caption = "请您正确输入金额!"
Exit Sub

End If
If m Mod 50 <> 0 Then
Form3.Show
Form3.Label1.Caption = "请您正确输入金额!"
Form5.Text1.Text = ""
Else
If RS.Fields("金额") < CCur(m) Then
Form3.Show
Form3.Label1.Caption = "金额不足!"
Form5.Text1.Text = ""
Exit Sub
Else
Money = RS.Fields("金额")
RS.Fields("金额") = (Money - Form5.Text1.Text)
RS.Update
RS.Close
Call InsertDatabase
Unload Form5
Form9.Show
Form9.Label1.Caption = "交易成功,谢谢您的使用,请拿好您的钞票!"
Form11.Show
Form9.SetFocus
End If
End If
Else
m = Form5.Text1.Text
If m = "" Then
Form3.Show
Form3.Label1.Caption = "Please Input Correct Amount!"
Exit Sub

End If
If m Mod 50 <> 0 Then
Form3.Show
Form3.Label1.Caption = "Please Input Correct Amount!"
Form5.Text1.Text = ""
Else
If RS.Fields("金额") < CCur(m) Then
Form3.Show
Form3.Label1.Caption = "No Enough Money!"
Form5.Text1.Text = ""
Exit Sub
Else
Money = RS.Fields("金额")
RS.Fields("金额") = (Money - Form5.Text1.Text)
RS.Update
RS.Close
Call InsertDatabase
Unload Form5
Form9.Show
Form9.Label1.Caption = "Please Take You money!"
Form11.Show
Form9.SetFocus


End If

End If
End If
End Sub
'*************************查询余额函数*********************************
Public Sub Query()
Dim str2 As String
str2 = "select * from 用户信息 where 卡号='" & u & "'"
Set RS = New ADODB.Recordset
RS.Open str2, CON, adOpenDynamic, adLockPessimistic
Form8.Label5.Caption = RS.Fields("金额")

Call InsertDatabase
End Sub
'************************转帐函数1*********************************
Public Sub Trans()
Dim str3 As String
transcard = Form7.Text1.Text
transmoney = Form7.Text2.Text
str3 = "select * from 用户信息 where 卡号='" & transcard & "'"
Set RS = New ADODB.Recordset
RS.Open str3, CON, adOpenDynamic, adLockPessimistic
If i = 2 Then
If Form7.Text2.Text = "" Or Form7.Text1.Text = "" Then
Form3.Show
Form3.Label1.Caption = "请你正确输入!"
Form7.Text1.Text = ""
Form7.Text2.Text = ""
Exit Sub
End If
If RS.EOF = True Then
Form3.Show
Form3.Label1.Caption = "没有此用户,请检查并重新输入!"
Exit Sub
End If
If transcard = u Then
Form3.Show
Form3.Label1.Caption = "操作错误,同帐户不可以转帐!"
Exit Sub
End If


str6 = "select * from 用户信息 where 卡号='" & u & "'"
Set RS = New ADODB.Recordset
RS.Open str6, CON, adOpenDynamic, adLockPessimistic

If RS.Fields("金额") < Val(Form7.Text2.Text) Then
Form3.Show
Form3.Label1.Caption = "金额不足以转帐,请你重新输入"
Form7.Text2.Text = ""
Exit Sub
Else
Unload Form7
Form10.Text1.Text = transcard
Form10.Text2.Text = transmoney
Form10.Show
End If
Else
''''''

If Form7.Text2.Text = "" Or Form7.Text1.Text = "" Then
Form3.Show
Form3.Label1.Caption = "Please Input Correct Cardnumber Or Amount!"
Form7.Text1.Text = ""
Form7.Text2.Text = ""
Exit Sub
End If
If RS.EOF = True Then
Form3.Show
Form3.Label1.Caption = "No This Customer!"
Exit Sub
End If
If transcard = u Then
Form3.Show
Form3.Label1.Caption = "It Is Wrong To Transfer In The Same Customer!"
Exit Sub
End If

str6 = "select * from 用户信息 where 卡号='" & u & "'"
Set RS = New ADODB.Recordset
RS.Open str6, CON, adOpenDynamic, adLockPessimistic

If RS.Fields("金额") < Val(Form7.Text2.Text) Then
Form3.Show
Form3.Label1.Caption = "No Enough Amount To Transfer"
Form7.Text2.Text = ""
Exit Sub
Else
Unload Form7
Form10.Text1.Text = transcard
Form10.Text2.Text = transmoney
Form10.Show
End If
End If
End Sub
'*************************转帐函数2*********************************
Public Sub Trans2()
Dim str4 As String
str4 = "select * from 用户信息 where 卡号='" & u & "'"
Set RS = New ADODB.Recordset
RS.Open str4, CON, adOpenDynamic, adLockPessimistic
RS.Fields("金额") = RS.Fields("金额") - transmoney
RS.Update
RS.Close
Dim str5 As String
str5 = "select * from 用户信息 where 卡号='" & transcard & "'"
Set RS = New ADODB.Recordset
RS.Open str5, CON, adOpenDynamic, adLockPessimistic
RS.Fields("金额") = RS.Fields("金额") + transmoney
RS.Update
RS.Close


If i = 2 Then
Form9.Label1.Caption = "恭喜您转帐成功!"
Else
Form9.Label1.Caption = "Transfered successfully!"
End If
Form11.Show
Form9.Show

Form9.SetFocus
Call InsertDatabase
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -