机房收费系统敲了一段时间了,终于懂了一些。之前学生信息管理系统的也明白了。我的思路是先登录,在增加功能!下面是我的代码,手法拙劣,请各位大神多多指教,小第俯首拜谢!
0.0 登录窗体
涉及表——User_Info
接下来是关键代码(仅仅实现功能),
Dim strsql As String
Dim mrc As New Recordset
strsql = "select * from User_Info where userID='"
strsql = strsql + Trim(txtUserName.Text) + "' and PWD='"
strsql = strsql + Trim(txtPassWord.Text) + "'"
Set mrc = ExecuteSQL(strsql, "")
If mrc.EOF Then
MsgBox "账号或密码错误!", vbOKOnly + vbExclamation, "警告!"
txtPassWord.Text = ""
txtUserName.Text = ""
txtUserName.SetFocus
Else
frmmain.Show
mrc.Close
Login.Hide
End If
0.1 查看学生余额
涉及表——student_Info
接下来是代码(仅仅实现功能),
Dim strsql As String
If (txtcardno.Text = "") Then
MsgBox "卡号不能为空!", vbOKOnly + vbInformation, "提示!"
txtcardno.SetFocus
Else
strsql = "select * from student_Info where cardno='" + Trim(txtcardno.Text) + "'"
Set mrc = ExecuteSQL(strsql, "")
If mrc.EOF Then
MsgBox "该卡号不存在,请核查!", vbOKOnly + vbInformation, "提示!"
txtcardno.SetFocus
Else
txtstudentNo.Text = mrc.Fields(1)
txtstudentName.Text = mrc.Fields(2)
txtsex.Text = mrc.Fields(3)
txtdepartment.Text = mrc.Fields(4)
txtgrade.Text = mrc.Fields(5)
txtclass.Text = mrc.Fields(6)
txtstatus.Text = mrc.Fields(10)
txtexplain.Text = mrc.Fields(8)
txtcash.Text = mrc.Fields(7)
End If
End If
0.2 学生充值记录查询
涉及表——Recharge_Info
Dim mrc As ADODB.Recordset
Dim intcount As Integer
Private Sub cmdQuery_Click()
Dim strsql As String
MSHFlexGrid1.Clear
Dim intlbl As Integer
intlbl = 0
strsql = "select * from Recharge_Info where cardno='" + Trim(txtCardno.Text) + "'"
Set mrc = ExecuteSQL(strsql, "")
If mrc.EOF Then
MsgBox "该卡号没有充值记录,请核查!", vbOKOnly + vbInformation, "提示!"
txtCardno.SetFocus
Else
Call display(strsql, intlbl)
End If
End Sub
Private Sub cmdQuit_Click()
txtCardno.Text = ""
Dim strsql As String
strsql = "select * from Recharge_Info"
Call display(strsql, 0)
Unload StQuChRecord
End Sub
Sub display(strsql As String, intlbl2 As Integer)
intcount = intcount + 1
Set mrc = ExecuteSQL(strsql, "")
With MSHFlexGrid1
.Rows = 1
.CellAlignment = 4
.TextMatrix(0, 0) = "卡号"
.TextMatrix(0, 1) = "充值金额"
.TextMatrix(0, 2) = "充值日期"
.TextMatrix(0, 3) = "充值时间"
.TextMatrix(0, 4) = "充值教师"
.ColWidth(7) = 1000
Do While Not mrc.EOF
If intcount = 1 Then .Rows = .Rows + 1
intlbl2 = intlbl2 + 1
'显示数据
.CellAlignment = 4
.TextMatrix(intlbl2, 0) = mrc.Fields(2)
.TextMatrix(intlbl2, 1) = mrc.Fields(3)
.TextMatrix(intlbl2, 2) = mrc.Fields(4)
.TextMatrix(intlbl2, 3) = mrc.Fields(5)
.TextMatrix(intlbl2, 4) = mrc.Fields(6)
mrc.MoveNext
Loop
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
intcount = 0
End Sub
0.3 修改密码
涉及表——User_Info
主要代码:
strsql = "select * from User_Info where userID='"
strsql = strsql + Trim(txtUserName.Text) + "' and PWD='"
strsql = strsql + Trim(txtOldPassword.Text) + "'"
mrc.Fields(0) = mrc.Fields(0)
mrc.Fields(1) = Trim(txtNewPassword.Text)
mrc.Update
MsgBox "口令修改成功!", vbOKOnly + vbInformation, "提示!"
mrc.Close
0.4 金额返还查询
涉及表——CancelCard_Info
主要代码(仅实现功能):
Dim mrc As New ADODB.Recordset
Dim strsql As String
Dim date1 As Date
Dim date2 As Date
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdQuery_Click()
date1 = DTPicker1.Value
date2 = DTPicker2.Value
If DTPicker1.Value > DTPicker2.Value Then MsgBox "起始日期大于终止日期,请重新选择日期!", vbOKOnly + vbInformation, "提示 ": Exit Sub
strsql = "select * from CancelCard_Info where Date >='" & date1 & "' and Date <='" & date2 & "'"
Set mrc = ExecuteSQL(strsql, "")
If mrc.EOF Then
MsgBox "没有充值记录!", vbOKOnly + vbInformation, "提示"
MSFlexGrid1.Clear
MSFlexGrid1.Rows = 0
End If
With MSHFlexGrid1
.Rows = 1
.CellAlignment = 4
.TextMatrix(0, 0) = "卡号"
.TextMatrix(0, 1) = "退还日期"
.TextMatrix(0, 2) = "退还时间"
.TextMatrix(0, 3) = "退还金额"
.TextMatrix(0, 4) = "结账教师"
.TextMatrix(0, 5) = "结账状态"
.ColWidth(7) = 1000
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(4)
.TextMatrix(.Rows - 1, 3) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 4) = US
.TextMatrix(.Rows - 1, 5) = mrc.Fields(6)
mrc.MoveNext
Loop
End With
mrc.Close
End Sub
Private Sub Form_Load()
DTPicker1.Value = Date
DTPicker2.Value = Date
With MSHFlexGrid1
.CellAlignment = 4
.TextMatrix(0, 0) = "卡号"
.TextMatrix(0, 1) = "退还日期"
.TextMatrix(0, 2) = "退还时间"
.TextMatrix(0, 3) = "退还金额"
.TextMatrix(0, 4) = "结账教师"
.TextMatrix(0, 5) = "结账状态"
End With
End Sub
0.5基本数据设定
涉及表——Basicdata_Info
主要代码(仅实现功能):
Dim mrc As New ADODB.Recordset
Dim strsql As String
Private Sub cmdCancel_Click()
Unload Me
txtOneH.Text = ""
txtOneHo.Text = ""
txtaddtime.Text = ""
txtlimittime.Text = ""
txtReadyTime.Text = ""
txtLimitCash.Text = ""
End Sub
Private Sub cmdChange_Click()
txtOneH.Enabled = True
txtOneHo.Enabled = True
txtaddtime.Enabled = True
txtlimittime.Enabled = True
txtReadyTime.Enabled = True
txtLimitCash.Enabled = True
End Sub
Private Sub cmdOk_Click()
strsql = "select * from BasicData_Info"
Set mrc = ExecuteSQL(strsql, "")
mrc.AddNew
mrc.Fields(0) = Trim(txtOneH.Text)
mrc.Fields(1) = Trim(txtOneHo.Text)
mrc.Fields(2) = Trim(txtaddtime.Text)
mrc.Fields(3) = Trim(txtlimittime.Text)
mrc.Fields(4) = Trim(txtReadyTime.Text)
mrc.Fields(5) = Trim(txtLimitCash.Text)
mrc.Fields(6) = Trim(US)
mrc.Fields(7) = Trim(Date)
mrc.Fields(8) = Trim(Time)
mrc.Update
mrc.Close
MsgBox "修改成功!"
End Sub
Private Sub Form_Load()
strsql = "select * from BasicData_Info"
Set mrc = ExecuteSQL(strsql, "")
mrc.MoveFirst
txtOneH.Text = mrc.Fields(0)
txtOneHo.Text = mrc.Fields(1)
txtaddtime.Text = mrc.Fields(2)
txtlimittime.Text = mrc.Fields(3)
txtReadyTime.Text = mrc.Fields(4)
txtLimitCash.Text = mrc.Fields(5)
mrc.Close
txtOneH.Enabled = False
txtOneHo.Enabled = False
txtaddtime.Enabled = False
txtlimittime.Enabled = False
txtReadyTime.Enabled = False
txtLimitCash.Enabled = False
End Sub
0.6 删除用户
涉及表——User_Info
主要代码(仅实现功能):
Dim mrc As New ADODB.Recordset
Dim strsql As String
Private Sub cmdAddUser_Click()
AddUser.Show
End Sub
Private Sub cmdCancel_Click()
Unload Me
MSHFlexGrid1.Clear
End Sub
Private Sub cmdDelete_Click()
MSHFlexGrid1.SelectionMode = flexSelectionByRow
MSHFlexGrid1.FocusRect = flexFocusNone
MSHFlexGrid1.HighLight = flexHighlightWithFocus
If MSHFlexGrid1.Row = 0 Then
MsgBox "第一行不能删!", vbOKOnly + vbInformation, "提示"
End If
If MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 0) = US Then
MsgBox "不能删除正在登录的用户!", vbOKOnly + vbInformation, "提示"
Else
strsql = "select * from User_Info where Level='"
strsql = strsql + Trim(combUserlevel.Text) + "'"
Set mrc = ExecuteSQL(strsql, "")
MSHFlexGrid1.RemoveItem MSHFlexGrid1.Row
mrc.Delete
mrc.Update
mrc.Close
End If
End Sub
Private Sub combUserlevel_Click()
strsql = "select * from User_Info where Level='"
strsql = strsql + Trim(combUserlevel.Text) + "'"
Set mrc = ExecuteSQL(strsql, "")
With MSHFlexGrid1
.Rows = 1
.CellAlignment = 4
.TextMatrix(0, 0) = "用户"
.TextMatrix(0, 1) = "姓名"
.TextMatrix(0, 2) = "级别"
.ColWidth(7) = 1000
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
mrc.MoveNext
Loop
End With
mrc.Close
End Sub
Private Sub Form_Load()
With MSHFlexGrid1
.CellAlignment = 4
.TextMatrix(0, 0) = "用户"
.TextMatrix(0, 1) = "姓名"
.TextMatrix(0, 2) = "级别"
End With
combUserlevel.AddItem "管理员", 0
combUserlevel.AddItem "操作员", 1
combUserlevel.AddItem "一般用户", 2
MSHFlexGrid1.SelectionMode = flexSelectionByRow
MSHFlexGrid1.FocusRect = flexFocusNone
MSHFlexGrid1.HighLight = flexHighlightWithFocus
strsql = "select * from User_Info"
Set mrc = ExecuteSQL(strsql, "")
If mrc.EOF Then
MsgBox "没有记录!", vbOKOnly + vbInformation, "提示"
MSHFlexGrid1.Clear
MSFlexGrid1.Rows = 0
End If
With MSHFlexGrid1
.Rows = 1
.CellAlignment = 4
.TextMatrix(0, 0) = "用户"
.TextMatrix(0, 1) = "姓名"
.TextMatrix(0, 2) = "级别"
.ColWidth(7) = 1000
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
mrc.MoveNext
Loop
End With
mrc.Close
End Sub