机房逻辑捋一捋(一)

前端之家收集整理的这篇文章主要介绍了机房逻辑捋一捋(一)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


前言:

第一遍机房收费系统,已经敲完了,也进行了第一次项目的验收,感觉效果不是很好,有很多需要修改的地方,下面我就把我机房的一些逻辑给大家讲一讲,希望对读者有所帮助!




正文:

登录&判断:


登录成功判断条件:

1.提交的用户名是否含有特殊字符串 ……&*()—— 或者为空

2.提交的密码是否含有特殊字符串或者为空

3.密码和用户名长度是否符合要求

关键代码

    If Test(txtUserID.Text,2) Then
        MsgBox "用户名为空",vbOKOnly + vbExclamation,"提示!"
        txtUserID.SetFocus
        txtUserID.Text = ""
        txtPWD.Text = ""
        Exit Sub
    End If
    
    If Test(txtPWD.Text,2) Then
        MsgBox "密码为空","提示!"
        txtPWD.SetFocus
        txtPWD.Text = ""
        Exit Sub
    End If
    
    If Test(txtUserID,1) Then
        MsgBox "密码中不能有特殊字符","提示!"
        txtUserID.SetFocus
        txtUserID.Text = ""
        Exit Sub
    End If
    
    If mrc.EOF = True Then
        MsgBox "用户不存在","提示!"
        txtUserID.SetFocus
        txtUserID.Text = ""
        txtPWD.Text = ""
        Exit Sub
    ElseIf Trim(mrc.Fields(1)) = txtPWD.Text Then
        UserIDBookmark = mrc!UserID
        UserLevelBookmark = mrc!Level
        Unload Me
        FormMain.Show
    Else
        MsgBox "用户密码错误,重新输入","提示!"
        txtPWD.SetFocus
        txtPWD.Text = ""
        Exit Sub
    End If
Public Function Test(tx1 As String,i As Integer) As Boolean
  Select Case i
  Case 1                    '返回 false 表示字符符合规则
    For i = 1 To Len(tx1)
      If (Mid(tx1,i,1) >= 0 And Mid(tx1,1) <= 9) Or (Mid(tx1,1) >= "A" And Mid(tx1,1) <= "Z") Or (Mid(tx1,1) >= "a" And Mid(tx1,1) <= "z") Then
        Test = False
      Else
        Test = True
        GoTo a
      End If
    Next i
  Case 2
    If Trim(tx1) = "" Then
      Test = True
    Else
      Test = False
    End If
  Case 3
    For i = 1 To Len(tx1)
      If (Mid(tx1,1) <= 9) Then
        Test = False
      Else
        Test = True
        GoTo a
      End If
    Next i
  End Select
a: End Function
 

学生信息查看:



查询条件:

1.查询窗口输入的卡号是否是已注册且可以使用的账号


关键代码

Private Sub Search_Click()
    Dim mrc As ADODB.Recordset
    Dim Mesg As String
    Dim sql As String
    
    sql = "select * from student_info where cardno='" & StuNo & "'"
    Set mrc = Executesql(sql,Mesg)
    
    If mrc.EOF And mrc.BOF Then
        
        MsgBox "未查到用户,请确认卡号是否正确!","提示!"
        StuNo.SetFocus
        
    ElseIf Trim(mrc.Fields(10)) = "不使用" Then
        
        MsgBox "此账户已经停用,请重新注册","提示!"
        StuNo.SetFocus
        
    Else
        
        StuNum.Text = mrc.Fields(1)
        StuName.Text = mrc.Fields(2)
        Sex.Text = mrc.Fields(3)
        Dept.Text = mrc.Fields(4)
        Grade.Text = mrc.Fields(5)
        Class.Text = mrc.Fields(6)
        Status.Text = mrc.Fields(10)
        Cash.Text = mrc.Fields(7)
        Exp.Text = mrc.Fields(8)
        
    End If
    
End Sub

注:上边代码,我没有进行判断是否为空,如果大家在做这个项目的时候,需要的话可以自行加上


未完待续

原文链接:https://www.f2er.com/vb/256361.html

猜你在找的VB相关文章