登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

面包会有的

... ...

 
 
 

日志

 
 

VB6数据库查询的一段代码,上下翻页等  

2007-09-24 17:38:48|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

 

 

 

 

Private Sub cancelCommand_Click()
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = False
        Command1.Enabled = True
        Adodc1.Refresh
End Sub

Private Sub Command1_Click()
    Unload Me
End Sub

Private Sub Command2_Click()
    '添加新会员
    txtAddress.Enabled = True
    txtBirthdate.Enabled = True
    txtComment.Enabled = True
    txtDept.Enabled = True
    txtDuty.Enabled = True
    txtEducation.Enabled = True
    txtJobtime.Enabled = True
    txtJointime.Enabled = True
    txtName.Enabled = True
    txtNation.Enabled = True
    txtPersona.Enabled = True
    txtPolitical.Enabled = True
    txtPopulation.Enabled = True
    txtWife.Enabled = True
    comboSex.Enabled = True
    firstCommand.Enabled = False
    previousCommand.Enabled = False
    nextCommand.Enabled = False
    lastCommand.Enabled = False
    editCommand.Enabled = False
    updateCommand.Enabled = False
    cancelCommand.Enabled = False
    deleteCommand.Enabled = False
    Command2.Enabled = False
    Command3.Enabled = True
    Command1.Enabled = False
    Adodc1.Recordset.AddNew
End Sub

Private Sub Command3_Click()
    If Not (Testtxt(txtAddress.Text) And Testtxt(txtBirthdate.Text) And Testtxt(txtComment.Text) And Testtxt(txtDept.Text) And Testtxt(txtDuty.Text) And Testtxt(txtEducation.Text) And Testtxt(txtJobtime.Text) And Testtxt(txtJointime.Text) And Testtxt(txtName.Text) And Testtxt(txtNation.Text) And Testtxt(txtPersona.Text) And Testtxt(txtPolitical.Text) And Testtxt(txtPopulation.Text) And Testtxt(txtWife.Text)) Then
        MsgBox "信息输入不完整,请检查并确认信息!", vbOKOnly + vbExclamation, "请注意"
        txtName.SetFocus
        Exit Sub
    End If
    If Not IsNumeric(Trim(txtPopulation)) Then
        MsgBox "家庭人口,请输入数字!", vbOKOnly + vbExclamation, "请注意"
        txtPopulation.SetFocus
        Exit Sub
    End If
    If Not (IsDate(txtBirthdate.Text) And IsDate(txtJobtime.Text) And IsDate(txtJointime.Text)) Then
        MsgBox "日期时间格式应为:YYYY-MM-DD,请确认输入无误!", vbOKOnly + vbExclamation, "请注意"
        txtBirthdate.SetFocus
    Else
        Adodc1.Recordset.Update
        Call LogPlug("会员信息", "添加新会员:" & Trim(txtName.Text))
        MsgBox "添加会员信息成功!", vbOKOnly + vbExclamation, "恭喜"
        Adodc1.Recordset.MoveLast
    End If
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = False
        Command1.Enabled = True
End Sub

Private Sub Command4_Click()

End Sub

Private Sub Command6_Click()

End Sub

Private Sub deleteCommand_Click()
    str2 = MsgBox("你确定删除当前记录吗?!", vbOKCancel, "删除当前记录")
    If str2 = vbOK Then
        Call LogPlug("会员信息", "删除会员:" & Trim(txtName.Text) & "的信息。")
        If Adodc1.Recordset.RecordCount = 1 Then
            Adodc1.Recordset.Delete
            Unload Me
            Me.Show
        Else
            Adodc1.Recordset.MoveNext
            If Adodc1.Recordset.EOF Then
                Adodc1.Recordset.MoveLast
                Adodc1.Recordset.Delete
                Adodc1.Recordset.MoveFirst
            Else
                Adodc1.Recordset.MovePrevious
                Adodc1.Recordset.Delete
                Adodc1.Recordset.MoveNext
            End If
        End If
    End If
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = False
        Command1.Enabled = True
End Sub

Private Sub editCommand_Click()
    txtAddress.Enabled = True
    txtBirthdate.Enabled = True
    txtComment.Enabled = True
    txtDept.Enabled = True
    txtDuty.Enabled = True
    txtEducation.Enabled = True
    txtJobtime.Enabled = True
    txtJointime.Enabled = True
    txtName.Enabled = True
    txtNation.Enabled = True
    txtPersona.Enabled = True
    txtPolitical.Enabled = True
    txtPopulation.Enabled = True
    txtWife.Enabled = True
    comboSex.Enabled = True
    firstCommand.Enabled = False
    previousCommand.Enabled = False
    nextCommand.Enabled = False
    lastCommand.Enabled = False
    editCommand.Enabled = False
    updateCommand.Enabled = True
    cancelCommand.Enabled = True
    deleteCommand.Enabled = True
    Command2.Enabled = False
    Command3.Enabled = False
    Command1.Enabled = False
End Sub

Private Sub firstCommand_Click()
    '第一条
    Adodc1.Recordset.MoveFirst
End Sub

Private Sub Form_Load()
    Dim Sc As String
    Sc = "driver={Microsoft Access Driver (*.mdb)};dbq=" & App.Path & "\tradeunion.mdb"
    Set cn = New ADODB.Connection
    cn.Open Sc
    Dim OneQuerySql As String
    OneQuerySql = "select* from 会员基本信息表"
    Dim AdoRsTradeMem As New ADODB.Recordset
    If AdoRsTradeMem.State = adStateOpen Then
        AdoRsTradeMem.Close
    End If
    AdoRsTradeMem.Open OneQuerySql, cn, adOpenKeyset, adLockOptimistic
    Set Adodc1.Recordset = AdoRsTradeMem
    If Adodc1.Recordset.EOF Then
        MsgBox "系统内不存在任何会员基本信息,请先添加会员信息", vbOKOnly + vbExclamation, "警告"
        txtAddress.Enabled = True
        txtBirthdate.Enabled = True
        txtComment.Enabled = True
        txtDept.Enabled = True
        txtDuty.Enabled = True
        txtEducation.Enabled = True
        txtJobtime.Enabled = True
        txtJointime.Enabled = True
        txtName.Enabled = True
        txtNation.Enabled = True
        txtPersona.Enabled = True
        txtPolitical.Enabled = True
        txtPopulation.Enabled = True
        txtWife.Enabled = True
        comboSex.Enabled = True
        firstCommand.Enabled = False
        previousCommand.Enabled = False
        nextCommand.Enabled = False
        lastCommand.Enabled = False
        editCommand.Enabled = False
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = False
        Command2.Enabled = False
        Command3.Enabled = True
        Command1.Enabled = False
        Adodc1.Recordset.AddNew
        Exit Sub
    Else
        Adodc1.Recordset.MoveFirst
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = False
        Command1.Enabled = True
    End If
End Sub

Private Sub lastCommand_Click()
    '最后一条
    Adodc1.Recordset.MoveLast
End Sub

Private Sub nextCommand_Click()
    '下一条
    If Adodc1.Recordset.EOF Then
        Adodc1.Recordset.MoveFirst
    Else
        Adodc1.Recordset.MoveNext
    End If
End Sub

Private Sub previousCommand_Click()
    '上一条
    If Adodc1.Recordset.BOF Then
        Adodc1.Recordset.MoveLast
    Else
        Adodc1.Recordset.MovePrevious
    End If
End Sub

Private Sub updateCommand_Click()
    If Not (Testtxt(txtAddress.Text) And Testtxt(txtBirthdate.Text) And Testtxt(txtComment.Text) And Testtxt(txtDept.Text) And Testtxt(txtDuty.Text) And Testtxt(txtEducation.Text) And Testtxt(txtJobtime.Text) And Testtxt(txtJointime.Text) And Testtxt(txtName.Text) And Testtxt(txtNation.Text) And Testtxt(txtPersona.Text) And Testtxt(txtPolitical.Text) And Testtxt(txtPopulation.Text) And Testtxt(txtWife.Text)) Then
        MsgBox "信息输入不完整,请检查并确认信息!", vbOKOnly + vbExclamation, "请注意"
        txtName.SetFocus
        Exit Sub
    End If
    If Not IsNumeric(Trim(txtPopulation)) Then
        MsgBox "家庭人口,请输入数字!", vbOKOnly + vbExclamation, "请注意"
        txtPopulation.SetFocus
        Exit Sub
    End If
    If Not (IsDate(txtBirthdate.Text) And IsDate(txtJobtime.Text) And IsDate(txtJointime.Text)) Then
        MsgBox "日期时间格式应为:YYYY-MM-DD,请确认输入无误!", vbOKOnly + vbExclamation, "请注意"
        txtBirthdate.SetFocus
    Else
        Adodc1.Recordset.Update
        Call LogPlug("会员信息", "修改会员:" & Trim(txtName.Text) & "的信息。")
        MsgBox "修改会员信息成功!", vbOKOnly + vbExclamation, "恭喜"
    End If
   
        '成功更新后,将各输入框重设为不可编辑状态
        txtAddress.Enabled = False
        txtBirthdate.Enabled = False
        txtComment.Enabled = False
        txtDept.Enabled = False
        txtDuty.Enabled = False
        txtEducation.Enabled = False
        txtJobtime.Enabled = False
        txtJointime.Enabled = False
        txtName.Enabled = False
        txtNation.Enabled = False
        txtPersona.Enabled = False
        txtPolitical.Enabled = False
        txtPopulation.Enabled = False
        txtWife.Enabled = False
        comboSex.Enabled = False
        firstCommand.Enabled = True
        previousCommand.Enabled = True
        nextCommand.Enabled = True
        lastCommand.Enabled = True
        editCommand.Enabled = True
        updateCommand.Enabled = False
        cancelCommand.Enabled = False
        deleteCommand.Enabled = True
        Command2.Enabled = True
        Command3.Enabled = False
        Command1.Enabled = True
End Sub

 

 

 

 

 

  评论这张
 
阅读(679)| 评论(0)

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018