前言:
注册是在学生信息表中添加新的学生,在机房中注册一张新的卡号。所以需要对新注册的信息进行一些判断。下面是流程图:
判断充值金额时,需要查询基础表中的最少充值金额,然后进行判断,所以先在窗体加载时显示出来。
代码展示:
Private Sub Form_Load()
Dim txtsql As String
Dim msgstring As String
Dim mrss As ADODB.Recordset
'设置窗体大小
Me.Width = 12804
Me.Height = 8448
'给combo添加内容
combosex.AddItem "男"
combosex.AddItem "女"
combostate.AddItem "使用"
combotype.AddItem "固定用户"
combotype.AddItem "临时用户"
'设定文本框的字符限制
txtcardno.MaxLength = 9
txtsid.MaxLength = 9
txtname.MaxLength = 9
txtcash.MaxLength = 6
txtdept.MaxLength = 5
txtclass.MaxLength = 5
txtgrade.MaxLength = 5
txtcomment.MaxLength = 25
'显示最少充值金额
txtsql = "select * from basicdata_info"
Set mrss = ExecuteSQL(txtsql, msgstring)
txtbalance.Caption = Trim(mrss!limitcash)
End Sub
注册卡号时需要充值,所以注册一个卡时也要在充值记录表中添加一条记录:
Private Sub Command3_Click()
Dim txtsql As String
Dim msgtext As String
Dim msgstring As String
Dim mrc As ADODB.Recordset
Dim mrs As ADODB.Recordset
Dim mrss As ADODB.Recordset
Dim mrcu As ADODB.Recordset
Dim Smrc As ADODB.Recordset
Label1.Caption = ""
'判断卡号
If Not Testtxt(txtcardno.Text) Then
Label1.Caption = "卡号为空,请输入卡号!"
txtcardno.SetFocus
Exit Sub
End If
If Not IsNumeric(txtcardno.Text) Then
Label1.Caption = "卡号请输入数字!"
txtcardno.Text = ""
txtcardno.SetFocus
Exit Sub
End If
txtsql = "select * from student_info where cardno='" & Trim(txtcardno.Text) & "' and status='使用'"
Set mrc = ExecuteSQL(txtsql, msgtext)
If mrc.EOF = False Then
Label1.Caption = "此卡已被注册,请重新输入"
txtcardno.Text = ""
txtcardno.SetFocus
Exit Sub
Else
If Not Testtxt(txtcash.Text) Then
Label1.Caption = "请输入充值金额!" '判断充值金额
Exit Sub
End If
If Not IsNumeric(txtcash.Text) Then
Label1.Caption = "充值金额请输入数字!"
txtcash.Text = ""
txtcash.SetFocus
Exit Sub
End If
If Val(txtcash.Text) < Val(txtbalance.Caption) Then
Label1.Caption = "充值金额不能低于最少充值金额!"
txtcash.Text = ""
txtcash.SetFocus
Exit Sub
End If
If Trim(txtsid.Text) = "" Then
Label1.Caption = "学号不能为空!" '判断学生信息
txtsid.Text = ""
txtsid.SetFocus
Exit Sub
Else
txtsql = "select * from student_info where studentno='" & Trim(txtsid.Text) & "'"
Set Smrc = ExecuteSQL(txtsql, msgtext)
If Smrc.EOF = False Then
Label1.Caption = "学号已存在,请重新输入!"
txtsid.Text = ""
txtsid.SetFocus
Exit Sub
End If
End If
If Not IsNumeric(txtsid.Text) Then
Label1.Caption = "学号请输入数字!"
txtsid.Text = ""
txtsid.SetFocus
Exit Sub
End If
If Trim(txtname.Text) = "" Then
Label1.Caption = "姓名不能为空!"
txtname.Text = ""
txtname.SetFocus
Exit Sub
End If
If Trim(txtsex.Text) = "" Then
Label1.Caption = "性别不能为空!"
txtsex.SetFocus
Exit Sub
End If
If Trim(txtdept.Text) = "" Then
Label1.Caption = "系别不能为空!"
txtdept.Text = ""
txtdept.SetFocus
Exit Sub
End If
If Trim(txtgrade.Text) = "" Then
Label1.Caption = "年级不能为空!"
txtgrade.Text = ""
txtgrade.SetFocus
Exit Sub
End If
If Trim(txtclass.Text) = "" Then
Label1.Caption = "班级不能为空!"
txtclass.Text = ""
txtclass.SetFocus
Exit Sub
End If
If Trim(txtstate.Text) = "" Then
Label1.Caption = "状态不能为空!"
txtstate.SetFocus
Exit Sub
End If
If Trim(txttype.Text) = "" Then
Label1.Caption = "类型不能为空!"
txttype.SetFocus
Exit Sub
End If
If Trim(txtcomment.Text = "") Then Trim (txtcomment.Text = "无")
txtsql = "select * from Student_info"
Set mrs = ExecuteSQL(txtsql, msgstring)
'添加新记录
mrs.AddNew
mrs.Fields(0) = Trim(txtcardno.Text)
mrs.Fields(1) = Trim(txtsid.Text)
mrs.Fields(2) = Trim(txtname.Text)
mrs.Fields(3) = Trim(txtsex.Text)
mrs.Fields(4) = Trim(txtdept.Text)
mrs.Fields(5) = Trim(txtgrade.Text)
mrs.Fields(6) = Trim(txtclass.Text)
mrs.Fields(7) = Trim(txtcash.Text)
mrs.Fields(8) = Trim(txtcomment.Text)
mrs.Fields(9) = UserName
mrs.Fields(10) = Trim(txtstate.Text)
mrs.Fields(14) = Trim(txttype.Text)
mrs.Fields(12) = Date
mrs.Fields(13) = Time
mrs.Fields(11) = "未结账"
mrs.Update
mrs.Close
'更新充值记录表
txtsql = "select * from recharge_info"
Set mrs = ExecuteSQL(txtsql, msgtext)
mrs.AddNew
mrs.Fields(1) = Trim(txtsid.Text)
mrs.Fields(2) = Trim(txtcardno.Text)
mrs.Fields(3) = Trim(txtcash.Text)
mrs.Fields(4) = Date
mrs.Fields(5) = Time
mrs.Fields(6) = UserName
mrs.Fields(7) = "未结账"
mrs.Update
MsgBox "注册成功!", vbInformation + vbOKOnly, "注册成功"
Call Command2_Click
End If
End Sub
注册一个卡号就完成了。