课程设计任务书
目录
第1章系统功能概述 (2)
1.1 系统功能 (2)
1.2 系统层次图 (2)
第2章数据库设计 (3)
2.1 需求分析 (3)
2.2 E-R模型 (3)
2.3 关系模型 (4)
2.4 表结构设计 (4)
第3章系统各功能模块的详细设计 (5)
3.1 登陆界面 (5)
3.2 主窗体界面 (6)
3.3 查询界面 (10)
3.4 注册界面 (11)
第4章课设总结 (13)
参考文献 (13)
第1章系统功能概述
1.1 系统功能
个人通讯录管理系统是针对系统服务对象的具体要求设计的,能够输入所有人员的相关信息,实现人员的分类管理和查询。
本系统运用VB 6.0及SQL Server2000实现,主要设计了以下几大功能:
(1)新建、修改、删除通讯录记录
(2)能根据姓名进行模糊查询
(3)能根据电话查询某人
(4)方便的浏览逐条记录
1.2 系统层次图
图1.1系统层次图
第2章数据库设计
2.1 需求分析
本系统运用VB 6.0及SQL Server2000实现,拥有1个登录窗体,1个主窗体,1个查询窗体,一个注册窗体。
登录窗体里可以由单击事件调用注册窗体,登录成功后进入主窗体,主窗体实现信息的录入及各个功能。
本系统在SQL Server2000数据库里设计了2个数据表:
密码表:(用户名,密码) 用于记录注册过的用户名及密码
person:(手机,姓,名,地址,所在组,邮件,公司,职位)
2.2 E-R模型
1.用户实体:
图2.1 用户实体及其属性
2.个人通信信息的E-R模型:
图2.2 个人通信信息实体的E-R模型
2.3 关系模型
本系统设计了2个实体,密码实体,person实体,两个实体不存在联系。
因此可将本系统的E-R模型转化为下述关系模型:
密码表:(用户名,密码)
person:(手机,姓,名,地址,所在组,邮件,公司,职位)
2.4表结构设计
本系统在SQL Server2000数据库里共设计了3个数据表来记录数据:密码表,person。
1.密码表:
表2.1密码表的结构
2.person:
表2.2 person的结构
第3章系统各功能模块的详细设计
3.1 登录界面
输入正确的用户名及密码即可登陆系统,若连续3次输入错误的密码则窗口自动关闭。
图3.1 登录界面
代码:
Private Sub CmdLand_Click()
Static miCount As Integer
Dim sqlstr As String
sqlstr = "Select * From 密码表 where 用户名= '" & Text1 & " '"
Adodc1.RecordSource = sqlstr
Adodc1.Refresh
If Adodc1.Recordset.BOF Then
MsgBox "用户名错误,重新输入", vbExclamation, "警告"
Text1.Text = ""
Text1.SetFocus
Else
If Adodc1.Recordset.Fields("密码") = Text2 Then
Form1.Show
Unload Me
Else
MsgBox "密码错误,重新输入", vbExclamation, "警告"
Text2.Text = ""
Text2.SetFocus
End If
End If
miCount = miCount + 1
If miCount = 3 Then Unload Me
End Sub
Private Sub Command1_Click()
Form4.Show
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
3.2主窗体界面
在本窗口实现信息的浏览,新建,删除以及修改,按确定执行操作,按取消则放弃操作。
图3.2 系统主窗体
代码:
Private Sub CmdAdd_Click()
Adodc1.Recordset.AddNew
CmdAdd.Enabled = False
CmdDel.Enabled = False
CmdChange.Enabled = False
CmdOk.Enabled = True
CmdEsc.Enabled = True
CmdFirst.Enabled = True
CmdPre.Enabled = True
CmdNext.Enabled = False
CmdLast.Enabled = False
Text1.Locked = False
Text2.Locked = False
Text3.Locked = False
Text4.Locked = False
Text5.Locked = False
Text6.Locked = False
Text7.Locked = False
Text8.Locked = False
Text1.SetFocus
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
Private Sub CmdChange_Click()
CmdAdd.Enabled = False
CmdDel.Enabled = False
CmdChange.Enabled = False
CmdOk.Enabled = True
CmdEsc.Enabled = True
Text1.Locked = False
Text2.Locked = False
Text3.Locked = False
Text4.Locked = False
Text5.Locked = False
Text6.Locked = False
Text7.Locked = False
Text8.Locked = False
Text1.SetFocus
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
Private Sub CmdDel_Click()
x = MsgBox("确定要删除当前记录吗?", vbY esNo + vbQuestion, "确认")
If x = vbY es Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
Else
Adodc1.Refresh
End If
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
Private Sub CmdEsc_Click()
Adodc1.Refresh
CmdAdd.Enabled = True
CmdDel.Enabled = True
CmdChange.Enabled = True
CmdOk.Enabled = False
CmdEsc.Enabled = False
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
Private Sub CmdFind_Click()
Form2.Show
End Sub
Private Sub CmdFirst_Click()
Adodc1.Recordset.MoveFirst
CmdFirst.Enabled = False
CmdPre.Enabled = False
CmdNext.Enabled = True
CmdLast.Enabled = True
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
Private Sub CmdLast_Click()
Adodc1.Recordset.MoveLast
CmdFirst.Enabled = True
CmdPre.Enabled = True
CmdNext.Enabled = False
CmdLast.Enabled = False
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
Private Sub CmdN_Click()
Dim n As Integer
n = Text9.Text
Adodc1.Recordset.Move n
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
Private Sub CmdNext_Click()
Adodc1.Recordset.MoveNext
CmdFirst.Enabled = True
CmdPre.Enabled = True
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
CmdNext.Enabled = False
CmdLast.Enabled = False
End If
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount
End Sub
Private Sub CmdOk_Click()
Adodc1.Recordset.Update
CmdAdd.Enabled = True
CmdDel.Enabled = True
CmdChange.Enabled = True
CmdOk.Enabled = False
CmdEsc.Enabled = False
Text1.Locked = True
Text2.Locked = True
Text3.Locked = True
Text4.Locked = True
Text5.Locked = True
Text6.Locked = True
Text7.Locked = True
Text8.Locked = True
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
Private Sub CmdPre_Click()
Adodc1.Recordset.MovePrevious
CmdNext.Enabled = True
CmdLast.Enabled = True
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
CmdFirst.Enabled = False
CmdPre.Enabled = False
End If
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
Private Sub Form_Load()
CmdFirst.Enabled = False
CmdPre.Enabled = False
CmdNext.Enabled = True
CmdLast.Enabled = True
CmdAdd.Enabled = True
CmdDel.Enabled = True
CmdChange.Enabled = True
CmdOk.Enabled = False
CmdEsc.Enabled = False
Label9.Caption = "记录:" & Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub
3.3查询界面
选择要查询的条件,输入查询的信息,按下查询按钮即可显示查询结果,按下返回按钮返回上级窗口。
图3.3 查询界面窗体
代码:
Private Sub CmdBack_Click()
Form1.Show
Unload Me
End Sub
Private Sub CmdFind_Click()
Dim str As String
str = " Select * From person "
str = str & "Where person." & Combo1.Text & " Like '" & Text1 & "% '"
Adodc1.RecordSource = str
Adodc1.Refresh
End Sub
Private Sub Form_Load()
Combo1.AddItem "姓"
Combo1.AddItem "名"
Combo1.AddItem "手机"
Combo1.AddItem "地址"
Combo1.AddItem "公司"
Combo1.AddItem "所在组"
Text1.Text = ""
End Sub
3.4 注册界面
输入要创建的用户名,然后输入两次相同的密码,即可在密码表中增加新的用户及密码,用来登录系统。
图3.4 用户注册窗体
代码:
Private Sub Command1_Click()
Dim sqlstr As String
If Text1 = "" Then
MsgBox "请输入用户名!", vbExclamation, "确认密码"
Text1.SetFocus
Exit Sub
Else
sqlstr = "select * from 密码表where 用户名= '" & Text1 & " '"
Adodc1.RecordSource = sqlstr
Adodc1.Refresh
If Adodc1.Recordset.EOF = False Then
MsgBox "用户名已存在,请重新输入!", vbExclamation, "检验用户名"
Text1 = ""
Text1.SetFocus
Exit Sub
End If
End If
If Text2 <> Text3 Then
MsgBox "二次输入的密码不一致,请重新输入", vbExclamation, "检验密码"
Text2 = ""
Text3 = ""
Text2.SetFocus
Exit Sub
ElseIf Text2 = "" Then
MsgBox "密码不能为空!", vbExclamation, "检验密码" Text2.SetFocus
Else
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("用户名") = Trim(Text1) Adodc1.Recordset.Fields("密码") = Trim(Text2)
Adodc1.Recordset.Update
Me.Hide
MsgBox "成功注册新用户!", vbInformation, "添加用户" End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
第4章课设总结
通过一周时间的努力,终于完成了本次VB数据库课程设计,这次课程设计让我学到了很多东西,比如对整体结构的设计,对细节的把握以及对全局的掌控等。经过几天的自学、查阅书籍、自我摸索及实践,让我掌握了VB数据库设计的基本思想,也学会了对VB 6.0的基本使用。同时我也对VB有了更深入的了解,对VB事件驱动的编程机制有了更熟练的运用。要做一个项目,首先要学会根据实际的问题抽象出概念模型和系统中各个实体的E-R模型;然后将其进行转化为与之相应的关系模型;再由此模型进行数据库的设计以及数据库的检测;有了这几道工序作铺垫,才能够尽善尽美地去编写程序代码来实现系统具体的功能。
总之,这次VB课程设计让我收获颇多,相信这对于我今后工作和学习上的帮助也是不可估量的。
参考文献
[1]刘志妩,张焕君,马秀丽等著. 基于VB和SQL的数据库编程技术.
北京:清华大学出版社. 2008
[2] 杨志强著. Visual Basic 6.0 程序设计教程. 北京:高等教育出版社. 2008
[3] 赵斯思著. Visual Basic 数据库编程与实例. 北京:人民教育出版社. 2009