资源描述
VB程序设计
课程设计
课程设计题目
设备管理系统
目 录
一、课程设计的目的与要求
二、任务描述
对系统要实现的功能进行确切的描述。
三、设计
详细说明程序的设计思想,所用到的算法、数据结构技巧等
四、效果及存在问题
说明系统的运行效果(附上界面图形)、存在哪些不足以及预期的解决办法
五、总结
课程设计的目的与要求
1、教学目的
使学生在理论课程结束后,通过课程设计能进一步巩固对VB编程机制的理解,真正掌握运用VB进行软件开发的方法和原理,从而锻炼学生开发能力、程序调试的能力,及程序错误处理的能力。
2、教学要求
从课程设计的目的出发,通过课程设计的各个环节,达到以下教学要求
(1)进一步掌握VB语言程序设计的基本思想和方法;
(2)掌握面向对象的可视化程序设计的基本原理及应用;
任务描述
建立设备数据库表,存储设备的信息,包括设备的名称、数量、型号、规格等信息;能够实现对设备的查询、修改、添加等操作。
设计
1、设备管理系统的功能
1、查看设备:用来实现对设备的浏览、删除
2、查询设备:用来实现对设备的查询
3、添加设备:用来实现对设备的添加
2、连接数据源
利用ADO控件将Access数据源连接到程序中
建立Access数据库
打开Access,建立名为“设备”的数据库。在数据库中选择“使用设计器创建表”输入名称、型号、单价、数量、规格、购买日期。保存命名为“设备管理”。
3、窗体
名称
标题
From1
登陆界面
From2
查看设备
From3
添加设备
From4
查找设备
(1)登陆界面
From1 代码如下:
Private Sub Command1_Click()
Form2.Show
End Sub
(2)查看设备
Form2 代码如下:
Private Sub Command1_Click()
Adodc1.Recordset.MovePrevious ’数据移到上一条
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
MsgBox "已经是第一条"
End If
End Sub
Private Sub Command2_Click()
Adodc1.Recordset.MoveNext ’ 数据移到下一条
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
MsgBox "已经是最后一条"
End If
End Sub
Private Sub Command3_Click()
Form3.Show
End Sub
Private Sub Command4_Click()
Form4.Show
End Sub
Private Sub Command5_Click()
On Error Resume Next
If MsgBox("确定删除该记录?", vbOKCancel, "提示") = vbOK Then
Adodc1.Recordset.Delete ’删除正显示的记录
Adodc1.Recordset.MoveNext ’显示下一条数据
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
End If
End Sub
Private Sub Command6_Click()
End
End Sub
Private Sub Command7_Click()
Adodc1.Recordset.MoveFirst ’ 显示第一条数据
End Sub
Private Sub Command8_Click()
Adodc1.Recordset.MoveLast ’ 显示最后一条数据
End Sub
(3)添加设备
Form3 代码如下:
Private Sub Command1_Click()
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(1) = Trim(Text1)
Adodc1.Recordset.Fields(2) = Trim(Text2)
Adodc1.Recordset.Fields(3) = Trim(Text3)
Adodc1.Recordset.Fields(4) = Trim(Text4)
Adodc1.Recordset.Fields(5) = Trim(Text5)
Adodc1.Recordset.Fields(6) = Trim(Text6) ’将文本框中的值赋值给数据库
Adodc1.Recordset.Update
Adodc1.Recordset.MoveLast
MsgBox "该设备已添加"
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
Private Sub Command3_Click()
Unload Me
Form2.Show
End Sub
Form4 代码如下:
Private Sub Command1_Click()
Dim check As Integer
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
M = Trim(Text1)
While Adodc1.Recordset.EOF <> True
If Adodc1.Recordset.Fields(1) = M Then
Text2.Text = Adodc1.Recordset.Fields(2)
Text3.Text = Adodc1.Recordset.Fields(3)
Text4.Text = Adodc1.Recordset.Fields(4)
Text5.Text = Adodc1.Recordset.Fields(5)
Text6.Text = Adodc1.Recordset.Fields(6)
check = check + 1 ’用循环语句判断文本框中的
End If 值 是否等于数据库中相应
Adodc1.Recordset.MoveNext 的值
Wend
Adodc1.Refresh
X = Trim(Text2)
While Adodc1.Recordset.EOF <> True
If Adodc1.Recordset.Fields(2) = X Then
Text1.Text = Adodc1.Recordset.Fields(1)
Text3.Text = Adodc1.Recordset.Fields(3)
Text4.Text = Adodc1.Recordset.Fields(4)
Text5.Text = Adodc1.Recordset.Fields(5)
Text6.Text = Adodc1.Recordset.Fields(6)
check = check + 1
End If
Adodc1.Recordset.MoveNext
Wend
Adodc1.Refresh
D = Val(Trim(Text3))
While Adodc1.Recordset.EOF <> True
If Adodc1.Recordset.Fields(3) = D Then
Text1.Text = Adodc1.Recordset.Fields(1)
Text2.Text = Adodc1.Recordset.Fields(2)
Text4.Text = Adodc1.Recordset.Fields(4)
Text5.Text = Adodc1.Recordset.Fields(5)
Text6.Text = Adodc1.Recordset.Fields(6)
check = check + 1
End If
Adodc1.Recordset.MoveNext
Wend
Adodc1.Refresh
S = Val(Trim(Text4))
Adodc1.Recordset.MoveFirst
While Adodc1.Recordset.EOF <> True
If Adodc1.Recordset.Fields(4) = S Then
Text1.Text = Adodc1.Recordset.Fields(1)
Text2.Text = Adodc1.Recordset.Fields(2)
Text3.Text = Adodc1.Recordset.Fields(3)
Text5.Text = Adodc1.Recordset.Fields(5)
Text6.Text = Adodc1.Recordset.Fields(6)
check = check + 1
End If
Adodc1.Recordset.MoveNext
Wend
Adodc1.Refresh
G = Trim(Text5)
While Adodc1.Recordset.EOF <> True
If Adodc1.Recordset.Fields(5) = G Then
Text1.Text = Adodc1.Recordset.Fields(1)
Text2.Text = Adodc1.Recordset.Fields(2)
Text3.Text = Adodc1.Recordset.Fields(3)
Text4.Text = Adodc1.Recordset.Fields(4)
Text6.Text = Adodc1.Recordset.Fields(6)
check = check + 1
End If
Adodc1.Recordset.MoveNext
Wend
Adodc1.Refresh
R = Trim(Text6)
While Adodc1.Recordset.EOF <> True
If Adodc1.Recordset.Fields(6) = R Then
Text1.Text = Adodc1.Recordset.Fields(1)
Text2.Text = Adodc1.Recordset.Fields(2)
Text3.Text = Adodc1.Recordset.Fields(3)
Text4.Text = Adodc1.Recordset.Fields(4)
Text5.Text = Adodc1.Recordset.Fields(5)
check = check + 1
End If
Adodc1.Recordset.MoveNext
Wend
If check = 0 Then
MsgBox ("无此设备!")
End If
Text1.Locked = True ’显示查询结果后,文本框内容不可更改
Text2.Locked = True
Text3.Locked = True
Text4.Locked = True
Text5.Locked = True
Text6.Locked = True
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text1.Locked = False ’按清除键后,文本框内容不可更改
Text2.Locked = False
Text3.Locked = False
Text4.Locked = False
Text5.Locked = False
Text6.Locked = False
End Sub
效果及存在问题
不能将添加的设备马上显示出来,功能较为简单,不够完善
总结
通过这次实验周的实践,我感受到了VB设计的趣味性,了解了VB的实用性。
虽然在实践时出现了许多问题,但通过老师和同学们的帮助,顺利的完成了课程设计,使我对VB有了进一步的认识,更渐渐喜欢上VB。
展开阅读全文