?? module1.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 + -