前端程序开发平台为VB6.0,编程语言为Visual Basic
窗体系统登录
Private Sub Command登录_Click()
Dim 账号text As String '定义变量存储账号
Dim 密码text As String '定义变量存储密码
If Trim(Me.Text账号) <> "" Then '输入账号不能为空
账号text = Me.Text账号 '存储录入账号到变量中(可拓展更多判断,如字符长度等)
Else
MsgBox "账号不能为空!"
Exit Sub
End If
If Trim(Me.Text密码) <> "" Then '输入密码不能为空
If Len(Trim(Me.Text密码)) < 6 Then
MsgBox "密码长度不能小于6位!"
Exit Sub
End If
密码text = Me.Text密码 '存储录入密码到变量中(可拓展更多判断,如字符长度等)
Else
MsgBox "密码不能为空!"
Exit Sub
End If
'-账号密码验证
Dim login_conn As New ADODB.Connection '连接到ACCESS数据库
With login_conn 'mdb格式连接
.ConnectionString = "Provider = microsoft.jet.oledb.4.0;data source=" & App.Path & "\db_rw.mdb;Jet OLEDB:DataBase password=abc123;persist security info=false"
.Open
End With
Dim login_rs As New ADODB.Recordset
Dim login_sql As String
login_sql = "select * from 账号表 where 账号= '" & Me.Text账号 & "' and 密码='" & Me.Text密码 & "'" '查询用户表
login_rs.Open login_sql, login_conn, adOpenDynamic, adLockOptimistic
If login_rs.EOF = False Then '循环表的内容
'--
On Error Resume Next
login_name = login_rs.Fields("账号").Value '账号密码赋值到公共变量之后使用
login_pw = login_rs.Fields("密码").Value
user_name = login_rs.Fields("姓名").Value
user_role = login_rs.Fields("角色").Value
全部任务权限 = login_rs.Fields("全部任务").Value
任务查看权限 = login_rs.Fields("任务查看").Value
任务添加权限 = login_rs.Fields("任务添加").Value
任务更新权限 = login_rs.Fields("任务更新").Value
任务删除权限 = login_rs.Fields("任务删除").Value
常见任务管理权限 = login_rs.Fields("常见任务管理").Value
负责人管理权限 = login_rs.Fields("负责人管理").Value
任务类型管理权限 = login_rs.Fields("任务类型管理").Value
任务状态管理权限 = login_rs.Fields("任务状态管理").Value
MsgBox "登录成功", , "提示"
Unload Me '关闭登录窗体
frm系统主页.Show
Else
MsgBox "账号或密码错误,请重新登录"
login_count = login_count 1 '登录错误3次,退出
If login_count = 3 Then
MsgBox "账号或密码错误达3次"
Unload Me
End If
End If
login_rs.Close
Set login_rs = Nothing
login_conn.Close
Set login_conn = Nothing
Exit Sub
登录失败错误:
MsgBox Err.Description
End Sub
Private Sub Command退出_Click()
Unload Me
End Sub
Private Sub Command用户注册_Click()
frm用户注册.Show 1
End Sub
系统主页
Private Sub cjrw_Click(Index As Integer)
If 常见任务管理权限 = False Then
MsgBox "无权限"
Exit Sub
End If
frm常见任务.Show 1
End Sub
Private Sub fhdl_Click()
Unload Me
frm系统登录.Show
login_name = ""
login_pw = ""
user_name = ""
user_role = ""
全部任务权限 = False
任务查看权限 = False
任务添加权限 = False
任务更新权限 = False
任务删除权限 = False
常见任务管理权限 = False
负责人管理权限 = False
任务类型管理权限 = False
任务状态管理权限 = False
End Sub
Private Sub Form_Load()
StatusBar1.Panels(2).Text = login_name
StatusBar1.Panels(3).Text = user_name
StatusBar1.Panels(4).Text = user_role
Label日期.Caption = Date
'当前登录用户添加的任务
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_rw.mdb;Jet OLEDB:DataBase password=abc123;Persist Security Info=False"
Adodc1.CommandType = adCmdUnknown
Adodc1.RecordSource = "Select * From 今日任务查询 where " & "创建账号 ='" & login_name & "'"
Adodc1.Refresh '刷新
End Sub
Private Sub fzr_Click(Index As Integer)
If 负责人管理权限 = False Then
MsgBox "无权限"
Exit Sub
End If
frm负责人.Show 1
End Sub
Private Sub grxx_Click()
frm个人信息.Show 1
End Sub
Private Sub qbrw_Click(Index As Integer)
If 全部任务权限 = False Then
MsgBox "无权限"
Exit Sub
End If
frm全部任务.Show 1
End Sub
Private Sub rwcx_Click(Index As Integer)
If 任务查看权限 = False Then
MsgBox "无权限"
Exit Sub
End If
frm任务查询.Show 1
End Sub
Private Sub rwlx_Click(Index As Integer)
If 任务类型管理权限 = False Then
MsgBox "无权限"
Exit Sub
End If
frm任务类型.Show 1
End Sub
Private Sub rwtj_Click(Index As Integer)
If 任务添加权限 = False Then
MsgBox "无权限"
Exit Sub
End If
frm任务添加.Show 1
End Sub
Private Sub rwzt_Click(Index As Integer)
If 任务状态管理权限 = False Then
MsgBox "无权限"
Exit Sub
End If
frm任务状态.Show 1
End Sub
Private Sub tcxt_Click()
Unload Me
End Sub
Private Sub xgmm_Click()
frm修改密码.Show 1
End Sub
常见任务
Option Explicit
Public frm_title As String '存储窗体标题
Public frm_datatype As Integer '存储当前管理状态(添加,修改,查询)
Public key_data As String '存储修改主键
Dim search_filter As String '存储筛选条件
Dim search_order As String '存储排序条件
Private Sub Command保存_Click()
On Error GoTo 保存失败错误
'========================================================================为添加状态时
If frm_datatype = 1 Then
'判断数据不能为空
If Text1(0).Text <> "" Then
'满足条件添加记录
'----------------------------------
Dim add_conn As New ADODB.Connection '连接数据
Dim add_rs As New AdoDB.Recordset
With add_conn
.ConnectionString = "Provider = microsoft.jet.oledb.4.0;data source=" & App.Path & "\db_rw.mdb;Jet OLEDB:DataBase password=abc123;persist security info=false"
.Open
End With
add_rs.Open "常见任务表", add_conn, adOpenKeyset, adLockOptimistic '连接表生成记录集
add_rs.AddNew '添加记录
On Error Resume Next
add_rs!任务名称 = Text1(0).Text '新记录赋值
add_rs.Update '更新
add_rs.Close '关闭清空记录集和连接
Set add_rs = Nothing
add_conn.Close
Set add_conn = Nothing
MsgBox "添加完成"
Text1(0).Text = ""
Adodc1.Refresh '刷新显示结果
DataGrid1.Refresh
Text1(0).SetFocus '第一个录入数据控件获得焦点继续录入
'----------------------------------
Else
MsgBox "任务名称不能为空"
Exit Sub
End If
End If
'========================================================================为修改状态时
If frm_datatype = 2 Then
'判断数据不能为空
If Text1(0).Text <> "" Then
'判断主键不能重复
If key_data <> Text1(0).Text Then '主键修改,判断主键是否重复
If dcountlink("任务名称", "常见任务表", "任务名称='" & Text1(0) & "'", 0) > 0 Then
MsgBox "该任务名称已存在,请修改后重试"
Exit Sub
End If
End If
'满足条件添加记录
'----------------------------------
'连接数据库并更新
Dim update_conn As New ADODB.Connection
Dim update_rs As New ADODB.Recordset
With update_conn
.ConnectionString = "Provider = microsoft.jet.oledb.4.0;data source=" & App.Path & "\db_rw.mdb;Jet OLEDB:DataBase password=abc123;persist security info=false"
.Open
End With
Dim update_sql As String
update_sql = "Select * From 常见任务表 Where 任务名称='" & key_data & "'"
update_rs.Open update_sql, update_conn, adOpenKeyset, adLockOptimistic
'--字段更新
On Error Resume Next
With update_rs
!任务名称 = Text1(0).Text '新记录赋值
End With
update_rs.Update
update_rs.Close
Set update_rs = Nothing
update_conn.Close
Set update_conn = Nothing
key_data = Text1(0) '主键赋值
MsgBox "更新完成!"
Adodc1.Refresh '刷新显示结果
DataGrid1.Refresh
Text1(0).SetFocus '第一个录入数据控件获得焦点
'----------------------------------
Else
MsgBox "任务名称不能为空"
Exit Sub
End If
End If
Exit Sub
保存失败错误:
MsgBox Err.Description
End Sub
Private Sub Command取消_Click()
frm_datatype = 5
Call changetitle(frm_datatype)
Dim i '清空控件中的数据
For i = 1 To Text1.Count
Text1(i - 1).Text = ""
Next i
'点击取消时显示全部记录,清空条件
search_filter = ""
Adodc1.Refresh
DataGrid1.Refresh
End Sub
Private Sub Command删除_Click()
On Error GoTo 删除失败错误
Dim del_data As String
del_data = DataGrid1.Columns(0).Text
If MsgBox("是否删除任务名称为【" & del_data & "】 的记录?", vbYesNo, "提示") <> vbYes Then '删除前提醒
Exit Sub
End If
'执行删除操作
Dim del_conn As New ADODB.Connection
Dim del_sql As String
del_sql = "delete from 常见任务表 Where 任务名称='" & del_data & "'" '定义删除sql语句
With del_conn
.ConnectionString = "Provider = microsoft.jet.oledb.4.0;data source=" & App.Path & "\db_rw.mdb;Jet OLEDB:DataBase password=abc123;persist security info=false"
.Open
.Execute del_sql '执行删除
End With
del_conn.Close
Set del_conn = Nothing
MsgBox "删除成功"
Adodc1.Refresh '刷新显示结果
DataGrid1.Refresh
Exit Sub
删除失败错误:
MsgBox Err.Description
End Sub
Private Sub Command添加_Click()
frm_datatype = 1
Call changetitle(frm_datatype)
Dim i
For i = 1 To Text1.Count '控件取消锁定可录入数据
Text1(i - 1).Text = ""
Text1(i - 1).Locked = False
Next i
Text1(0).Locked = False
Text1(0).SetFocus '第一个控件获得焦点
End Sub
Private Sub Command修改_Click()
key_data = 0
frm_datatype = 2
Call changetitle(frm_datatype)
End Sub
Private Sub DataGrid1_DblClick()
If frm_datatype <> 2 Then '判断是否为修改状态
MsgBox "需要修改数据,请先进入修改状态"
Exit Sub
End If
Dim i
For i = 0 To Text1.UBound '获取选择记录的数据
Text1(i).Text = DataGrid1.Columns(i).Text
Next i
'解除锁定(数据可编辑)
For i = 0 To Text1.UBound
Text1(i).Locked = False
Next i
Text1(0).Locked = False
Text1(0).SetFocus
key_data = Text1(0).Text '主键赋值
End Sub
Private Sub Form_Load() '窗体加载
frm_title = "常见任务管理" '赋值标题到变量
frm_datatype = 5 '设置窗体当前管理数据类型
Call changetitle(frm_datatype)
Dim i
For i = 1 To Text1.Count '控件锁定不可录入数据
Text1(i - 1).Text = ""
Text1(i - 1).Locked = True
Next i
Adodc1.Refresh '刷新
End Sub
Private Sub Text1_GotFocus(Index As Integer) '文本框获得焦点,背景色修改,选中原有文本
Text1(Index).BackColor = &HFFFF00
Text1(Index).SelStart = 0
Text1(Index).SelLength = Len(Text1(Index))
End Sub
Private Sub Text1_LostFocus(Index As Integer) '文本框失去焦点设计填充颜色(恢复)
Text1(Index).BackColor = &H80000005
End Sub
Sub changetitle(ByVal frmdatatype As Integer) '根据状态显示不同标题,设置按钮状态
Select Case frmdatatype
Case 1 '添加
Me.Caption = frm_title & "(添加)"
'按钮状态设置
Me.Command添加.Enabled = False
Me.Command修改.Enabled = False
Me.Command保存.Enabled = True
Me.Command取消.Enabled = True
Me.Command删除.Enabled = False
Case 2 '添加
Me.Caption = frm_title & "(修改)"
'按钮状态设置
Me.Command添加.Enabled = False
Me.Command修改.Enabled = False
Me.Command保存.Enabled = True
Me.Command取消.Enabled = True
Me.Command删除.Enabled = False
Case 3 '删除
Me.Caption = frm_title
Case 5 '取消
Me.Caption = frm_title
'按钮状态设置
Me.Command添加.Enabled = True
Me.Command修改.Enabled = True
Me.Command保存.Enabled = False
Me.Command取消.Enabled = True
Me.Command删除.Enabled = True
key_data = 0
'锁定所有控件
Dim i
For i = 0 To Text1.UBound
Text1(i).Locked = True
Next i
Case Else
Me.Caption = frm_title
'按钮状态设置
Me.Command添加.Enabled = False
Me.Command修改.Enabled = False
Me.Command保存.Enabled = False
Me.Command取消.Enabled = False
Me.Command删除.Enabled = False
End Select
End Sub
常见任务选择