机房收费系统之十一(优化)

来源:互联网 发布:宁波软件开发 编辑:程序博客网 时间:2024/05/22 11:54

机房基本功能实现了,可是还有很多地方不够完善,需要优化。我们要站在用户的立场考虑,尽可能的让软件更加美观,简单,实用。

1、时间控件的优化(以学生基本信息维护窗体为例)


使用时间控件的好处:使用文本框,当输入时间的时候很繁琐,而且还要注意时间格式。如果换成时间控件,那么直接选择就可以了,简单高效。

我们有时候想的 很好,可是真正实现起来,并不是那么容易的。

比如我们想实现:当字段名选择了日期或者时间,查询内容就变成时间控件;当字段名选择了非日期和时间选项,查询内容就变成文本框。单就这么一个问题,我就尝试了很多次。代码如下:

'如果选择日期,使用时间控件Private Sub cmbfield_Click(Index As Integer)      If cmbfield(0).Text = "日期" Then        DTP1.Format = dtpShortDate        txtCxnr(0).Visible = False        txtCxnr(0).Enabled = False        DTP1.Visible = True     ElseIf cmbfield(0).Text = "时间" Then         DTP1.Format = dtpTime  '将控件的输入内容改变为时间         txtCxnr(0).Visible = False         txtCxnr(0).Enabled = False         DTP1.Visible = True     ElseIf cmbfield(0).Text <> "时间" And cmbfield(0).Text <> "日期" Then        DTP1.Visible = False        txtCxnr(0).Visible = True        txtCxnr(0).Enabled = True     End If

这个问题解决了,还不算完呢,困难的还在后面。因为后面是组合查询。当字段名选择了日期或者时间,组合查询就要调用时间控件的值去搜索;当字段名选择了非日期和时间选项,组合查询就要调用文本框的值去搜所。那么它该如何这么智能的去变换查询呢?这个问题困扰了我一天,最后在我的聪明尝试下,解决啦!我的思路是:定义一系列的变量,运用条件判断去实现。代码如下:

Private Sub cmdquery_Click()    Dim ctrl As Control    Dim mrc As ADODB.Recordset    Dim txtSQL As String    Dim msgText As String    Dim i, iCols As Integer '让所有列都居中显示文字    Dim a0, a1, a2     '检查条件输入     If cmbfield(0).Text = "日期" Or cmbfield(0).Text = "时间" Then          a0 = DTP1.Value     Else          a0 = txtCxnr(0).Text     End If     If cmbfield(1).Text = "日期" Or cmbfield(1).Text = "时间" Then          a1 = DTP2.Value     Else          a1 = txtCxnr(1).Text     End If     If cmbfield(2).Text = "日期" Or cmbfield(2).Text = "时间" Then          a2 = DTP3.Value     Else          a2 = txtCxnr(2).Text     End If     '检查条件输入    If Trim(cmbfield(0).Text) = "" Or Trim(cmboperator(0).Text) = "" Or Trim(txtCxnr(0).Text) = "" Then        MsgBox "请输入完整的查询条件", , "提示"        Exit Sub    End If'     If cmbfield(0).Text = "时间" Or cmbfield(0).Text = "日期" Then''        If IsDate(Format(txtCxnr(0).Text, "yyyy-mm-dd")) = False Then '判断是否是日期'          MsgBox "请输入正确的时间类型", vbOKOnly + vbExclamation, "提示"'          txtCxnr(0).Text = ""'          txtCxnr(0).SetFocus'          Exit Sub'        End If'     End If        iCols = MSFlexGrid1.Cols    For i = 0 To iCols - 1        MSFlexGrid1.ColAlignment(i) = flexAlignCenterCenter    Next i    txtSQL = "select * from student_Info where "    txtSQL = txtSQL & Trim(field(cmbfield(0).Text)) & Trim(cmboperator(0).Text) & "'" & Trim(a0) & "'"    If Trim(cmbzhgx(0).Text <> "") Then '第一个组合关系存在        If Trim(cmbfield(1).Text) = "" Or Trim(cmboperator(1).Text = "") Or Trim(a0 = "") Then            MsgBox "你已经选择了第一个组合关系,请输入第二行查询条件", , "提示"            Exit Sub        Else            txtSQL = txtSQL & field(Trim(cmbzhgx(0).Text)) & " " & field(cmbfield(1).Text) & cmboperator(1).Text & "'" & Trim(a1) & "'"        End If    End If    If Trim(cmbzhgx(1).Text <> "") Then '第二个组合关系存在        If Trim(cmbfield(2).Text) = "" Or Trim(cmboperator(2).Text) = "" Or Trim(a2) = "" Then            MsgBox "你已经选择了第二个组合关系,请输入第三行查询条件", , "提示"            Exit Sub        Else            txtSQL = txtSQL & field(cmbzhgx(1).Text) & " " & field(cmbfield(2).Text) & cmboperator(2).Text & "'" & Trim(a2) & "'"        End If    End If    Set mrc = ExecuteSQL(txtSQL, msgText)    If mrc.EOF = True Then '检查信息是否存在,如果不存在给出提示并清空所有文本框        MsgBox "没有查询到结果,可能会你输入的信息不存在,或者信息矛盾"        '...清空所有文本框        Exit Sub    End If    With MSFlexGrid1        .Rows = 1        .TextMatrix(0, 0) = "卡号"        .TextMatrix(0, 1) = "学号"        .TextMatrix(0, 2) = "姓名"        .TextMatrix(0, 3) = "性别"        .TextMatrix(0, 4) = "系别"        .TextMatrix(0, 5) = "年级"        .TextMatrix(0, 6) = "班级"        .TextMatrix(0, 7) = "金额"        .TextMatrix(0, 8) = "类型"        .TextMatrix(0, 9) = "状态"        .TextMatrix(0, 10) = "日期"        .TextMatrix(0, 11) = "时间"     Do While Not mrc.EOF            .Rows = .Rows + 1            .TextMatrix(.Rows - 1, 0) = Trim(mrc!cardno)            .TextMatrix(.Rows - 1, 1) = Trim(mrc!studentNo)            .TextMatrix(.Rows - 1, 2) = Trim(mrc!studentName)            .TextMatrix(.Rows - 1, 3) = Trim(mrc!sex)            .TextMatrix(.Rows - 1, 4) = Trim(mrc!department)            .TextMatrix(.Rows - 1, 5) = Trim(mrc!grade)            .TextMatrix(.Rows - 1, 6) = Trim(mrc!Class)            .TextMatrix(.Rows - 1, 7) = Trim(mrc!cash)            .TextMatrix(.Rows - 1, 8) = Trim(mrc!Type)            .TextMatrix(.Rows - 1, 9) = Trim(mrc!Status)            .TextMatrix(.Rows - 1, 10) = Trim(mrc!Date)            .TextMatrix(.Rows - 1, 11) = Trim(mrc!Time)                                   mrc.MoveNext                   Loop    End With    mrc.CloseEnd Sub

2、禁止输入特殊字符,防止SQL注入问题。

     这个问题需要对ASCII码表熟悉,禁止键盘输入特殊字符对应的十进制数字,问题并不难解决。看代码:

Private Sub txtuser_KeyPress(KeyAscii As Integer) '防止输入特殊字符  Select Case KeyAscii    Case 48 To 57    Case 65 To 90    Case 97 To 122    Case 8    Case Else      KeyAscii = 0  End SelectEnd Sub


3、登录界面优化

        之前的登录界面总觉得不够简洁,于是自己看了QQ的登录界面和新浪的登录界面,很是喜欢,于是自己就尝试改了改。虽然还是有点LOW,但是比之前好很多了。效果如下:





实现代码:

Private Sub txtuser_GotFocus()    If Not txtuser.Text = "" Then        txtuser.Text = ""        Label2.Visible = True    End IfEnd SubPrivate Sub txtuser_LostFocus()    If txtuser.Text = "" Then        txtuser.Text = "用户名"        Label2.Visible = False    End IfEnd SubPrivate Sub txtpws_GotFocus()    If Not txtpws.Text = "" Then        txtpws.Text = ""        txtpws.PasswordChar = "*"        Label3.Visible = True    End IfEnd SubPrivate Sub txtpws_LostFocus()    If txtpws.Text = "" Then        txtpws.Text = "密码"        txtpws.PasswordChar = ""        Label3.Visible = False        End IfEnd Sub
字体颜色变化代码:

Private Sub Timer1_Timer()    Label1.ForeColor = RGB(255 * Rnd + 5, 255 * Rnd + 5, 255 * Rnd + 5)End Sub



暂时先写到这,有空接着补充。

感谢您的阅读,欢迎提出宝贵建议!



原创粉丝点击