资源描述
沈阳理工大学课程设计专用纸
摘 要
随着现代生活的发展,我国经济迅速发展,人民生活水平越来越好,家家户户都买了各种家电和生活用品,家庭物品也就越来越丰富了。但是,我们的家庭总是有限的,对于这些家庭物品我们需要有一个系统的整理。
通过对数据库的学习,学习了一些对数据的整理,对此,为家庭物品做了一个管理系统。用Visual Basic 6。0作为前端开发工具,利用其提供的集成开发环境及支持面向对象的各种标准化的控件,尤其是对ADO的支持完成对数据库的各种操作.使这个系统能够添加、修改、删除家庭各成员与物品的信息相关信息,当进入到系统时,可以直接通过查询用户名或购买日期来浏览物品的信息,登陆到系统之后,就可以对房间和物品信息进行添加、修改删除了,从而完成对家庭物品的整理,使各家庭成员更加方便地了解自己家里的物品信息
关键字:家庭物品整理方便
0
沈阳理工大学课程设计专用纸
目 录
1 系统功能概述3
2 数据库设计3
1。1 需求分析3
1.2 关系模型3
1.3 E-R模型4
1。4表结构设计5
3系统各功能模块的详细设计7
3.1主窗体7
3。2登录9
3。3查询11
3。4用户信息13
3。5物品信息18
3.6房间信息25
4参考文献28
沈阳理工大学课程设计专用纸
1 系统功能概述
为该家庭物品管理系统设计一个MDI窗体作为主界面,在菜单栏创建了四个菜单:文件、查询、添加、用户名。
(1) 文件中有两个子菜单:登录和退出。这两个子菜单分别控制登录用户和退出整个程序。
(2) 查询中有两个子菜单:按用户名查询和按日期查询。按用户名查询可以在用户输入某个用户名之后,显示该用户的物品情况;按日期查找可以在输入一个日期之后,显示该日期之后购买的所有物品。
(3) 添加中有三个子菜单:添加用户、添加房间、添加物品.点击添加用户,可以对用户信息进行增删改查;点击添加房间,可以对房间信息进行增删改查操作;点击添加物品,则可以对物品信息进行增删改查操作.
(4) 用户名按钮有一个子菜单:注销。用来注销已经成功登录的用户,如没有登录用户,该子菜单显示无用户,成功登录之后即显示已登录用户的名称。
2 数据库设计
1.1 需求分析
(1)根据家庭成员的身份,为每个成员分配有一个专门的账号。
(2)此家庭物品系统管理能够添加、删除、修改、查询家庭成员的信息以及与房间、物品之间的联系。
(3)在进入到家庭物品管理系统之后,不需要登陆就可以直接查询属于某个人的物品信息,也可以查询某个日期之后所购买的物品.
(4)当用户成功登录时,菜单栏上能够显示该用户的名称,此时,用户才能对物品信息和家庭成员信息进行添加、修改、删除
1。2 关系模型
(1)家庭成员信息表
Uuser:userName、password、sex、age、birthday、status、profession、hobby、wage
(2)物品信息表
Item:itemDate、purchaseDate、price、usedTime、quantity、publicItem、roomNumber、category
(3)房间表
Room: roomNumber、roomName
(4)归属表
Belong:itemName、userName、itemNumber
1。3 E—R模型
Uuser
Belong
Item
整体E—R图
mn
n
Room
save
1
图2-1
用户信息:
userName
hobby
Uuser
profession
password
birthday
sex
wage
age
status
图2-2
物品信息:
Item
roomNumber
purchaseDate
quantity
usedTime
publicItem
itemData
price
category
图2—3
房间信息:
Room
roomNumber
roomName
图2-4
归属信息:
Belong
userName
itemNumber
itemName
图2—5
1。4表结构设计
Uuser表:
create table Uuser
(userName varchar(6) primary key,
password char(6) not null ,
sex char(2) check (sex in('男’,’女’)),
age smallint check (age〉0 and age〈150),
birthday datetime,
status varchar(10),
profession varchar(20),
hobby varchar(30),
wage int
)
图2-6
Item表:
create table Item
(itemName varchar(20) primary key,
purchaseDate datetime,
price int ,
usedTime datetime ,
quantity smallint,
publicItem char(2) check(publicItem in ('是’,'否’)),
roomNumber varchar(3),
category varchar(10)
)
图2-7
Room表:
create table Room
(roomNumber varchar(3) primary key ,
roomName varchar(10),
)
图2—8
Belong表:
create table Belong
(itemName varchar(20),
userName varchar(6),
itemNumber smallint,
primary key (itemName,userName),
foreign key (itemName) references Item(itemName)
on delete cascade
on update cascade,
foreign key (userName) references Uuser(userName)
on delete cascade
on update cascade,
)
图2-9
3系统各功能模块的详细设计
3。1主窗体
主窗口设计
进入主窗体之后,用户只能有查询的权限,用户只有登录成功之后才能拥有添加的权限。在添加菜单栏可以对物品、用户、房间进行增删改查功能。
图3-1
代码如下:
Private Sub MDIForm_load()
'设置加载主窗口是在电脑中间显示,且添加按钮不可用
Move (Screen。Width - Width) / 2, (Screen。Height — Height) / 2
添加.Enabled = False
End Sub
Private Sub 按日期_Click(Index As Integer)
按日期查找.Show
End Sub
Private Sub 按用户_Click(Index As Integer)
按用户查找。Show
End Sub
Private Sub 登陆_Click(Index As Integer)
'检查是否有用户已经登录
If Not 用户。Caption = "无用户" Then
MsgBox ”以检测到登录用户!请先注销再登录!”, vbDefaultButton1, ”警告”
Exit Sub
End If
登录。Show
登录。ScaleTop = (MDIForm1.ScaleHeight — 登录。ScaleHeight) / 2
End Sub
Private Sub 添加房间_Click(Index As Integer)
房间.Show ‘显示房间信息窗口
End Sub
Private Sub 添加物品_Click(Index As Integer)
物品。Show ‘显示物品信息窗口
End Sub
Private Sub 添加用户信息_Click(Index As Integer)
账户.Show ‘显示用户信息窗口
End Sub
Private Sub 退出_Click(Index As Integer)
Unload Me ’退出系统
End Sub
Private Sub 用户_Click()
If 用户。Caption = "无用户" Then
MsgBox ”请先登录,谢谢!”, vbDefaultButton1, ”提示"
登录.Show
End If
End Sub
Private Sub 注销_Click()
‘将主界面还原成无用户登录状态
用户。Caption = "无用户"
添加.Enabled = False
End Sub
3。2登录
登录窗口设计
用户只有在成功登录之后才能点击添加按钮,当输入的用户名与数据库中的用户名和密码一样时即登录成功,在主窗体菜单栏上显示在线用户的名称,而且主窗体只能登录一个用户,若要切换用户,可以在主窗体点击注销即可。
图3—2
代码如下:
Private Sub Command1_Click()
Dim a As String ’定义一个常量以记录用户名
a = Text1。Text
If Text1.Text = ”” Then
MsgBox "请输入用户名!”, vbOKOnly, ”提示”
Text1。SetFocus
Exit Sub
Else
If Text2.Text = ”" Then
MsgBox "请输入密码!", vbOKOnly, ”提示"
Text2。SetFocus
Exit Sub
End If
End If
Dim sqlstr As String ‘定义sql语句的常量
sqlstr = "Select password From Uuser Where userName= '” & Text1。Text & ”’ "
Adodc1。RecordSource = sqlstr
Adodc1.Refresh
If Adodc1.Recordset。BOF Then
MsgBox "用户名错误,重新输入”, vbExclamation, "警告”
Text1。Text = ””
Text1。SetFocus
Exit Sub
Else ’ 判断密码是否正确
If Not Adodc1。Recordset。Fields(”password”) = Text2。Text Then
MsgBox ”密码错误,重新输入 ", vbExclamation, ”警告”
Text2。Text = "”
Text2.SetFocus
Exit Sub
End If
End If
MDIForm1.用户.Caption = a
If Not MDIForm1。用户。Caption = "无用户" Then
MDIForm1.添加.Enabled = True ’用户成功登录后修改主窗体
End If
Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Move (MDIForm1。Width — Width) / 2, (MDIForm1。Height — Height) / 2
End Sub
3.3查询
(1) 按用户名查询窗口设计
在用户输入一个日期之后,点击查询,在datagrid控件里就会显示所输入日期之后的所有物品的信息.
图3—3
代码如下:
Private Sub Command1_Click()
Dim sqlstr3 As String
If Text1.Text = ”" Then
MsgBox ”请输入查询用户名!”, vbDefaultButton1, ”提示"
Exit Sub
End If
sqlstr3 = ”Select * from byUser Where purchaseDate 〉= ’” & Text1。Text & "' "
Adodc1.RecordSource = sqlstr3
Adodc1。Refresh
DataGrid1。Visible = True ‘显示所查询的结果
End Sub
Private Sub Command2_Click()
Unload Me ’退回主窗体
End Sub
Private Sub Form_Load()
Move (Screen。Width — Width) / 2, (Screen。Height - Height) / 2
End Sub
(2) 按日期查询窗口设计
在用户输入一个用户名之后,在datagrid控件里就会显示此用户的所有物品信息。
图3—4
代码如下:
Private Sub Command1_Click()
Dim sqlstr2 As String
If Text1。Text = ”” Then
MsgBox "请输入查询用户名!”, vbDefaultButton1, "提示”
Exit Sub
End If
sqlstr2 = ”Select * from byUser Where userName= ’" & Text1。Text & "' "
Adodc2。RecordSource = sqlstr2
Adodc2。Refresh
DataGrid1。Visible = True
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Move (Screen。Width - Width) / 2, (Screen。Height — Height) / 2
End Sub
3。4用户信息
用户窗口设计
从主界面进入用户信息界面后,可以在每个文本框里填写新用户的基本 信息,填写完成后,点击添加按钮,弹出添加成功,即成功添加。也可以在此界面里通过输入用户名查找每个家庭成员的基本信息,可以点击上一个、下一个进行浏览。查找之后对结果也可以进行修改、删除操作。
图3—5
代码如下:
Private Sub Command1_Click()
If Text1。Text = ”” Or Text2。Text = "" Then
MsgBox ”请输入完整的添加信息!”, vbCritical, ”提醒”
Else‘将输入的信息写进数据库中
Adodc1.Recordset。AddNew
Adodc1。Recordset。Fields("userName”) = Text1。Text
Adodc1。Recordset。Fields("password”) = Text2。Text
If Option1.Value = True Then
Adodc1。Recordset.Fields(”sex”) = Label6。Caption
Else
Adodc1。Recordset.Fields(”sex") = Label7。Caption
End If
Adodc1。Recordset。Fields(”birthday”) = Text3.Text
Adodc1。Recordset。Fields(”age”) = Text4。Text
Adodc1。Recordset。Fields("status”) = Text5。Text
Adodc1。Recordset。Fields(”profession”) = Text6。Text
Adodc1。Recordset。Fields(”hobby”) = Text7。Text
Adodc1。Recordset.Fields(”wage”) = Text8。Text
Adodc1。Recordset。Update
Adodc1。Refresh
MsgBox "添加用户成功!”, vbDefaultButton1, ”提示”
End If
End Sub
Private Sub Command2_Click()
If Text1.Text = ”” Or Text2.Text = ”” Then
MsgBox ”请输入完整的添加信息!”, vbCritical, "提醒”
Else
If Not Text2.Text = Adodc1。Recordset。Fields(”password") Then
MsgBox "密码不正确!您无权修改!”, vbCritical, ”错误”
Else
If Option1。Value = True Then
Adodc1。Recordset.Fields("sex”) = Label6。Caption
Else
Adodc1.Recordset。Fields(”sex") = Label7。Caption
End If
Adodc1.Recordset。Fields("birthday”) = Text3.Text
Adodc1。Recordset.Fields(”age") = Text4。Text
Adodc1。Recordset.Fields(”status”) = Text5。Text
Adodc1。Recordset。Fields(”profession") = Text6.Text
Adodc1.Recordset。Fields(”hobby”) = Text7.Text
If Not Text8。Text = ”” Then
Adodc1。Recordset.Fields("wage”) = Text8。Text
End If
Adodc1.Recordset.Update’更新后台数据库
Adodc1。Refresh
MsgBox ”修改成功!”, vbDefaultButton1, "提醒"
End If
End If
End Sub
Private Sub Command3_Click()
If Text1。Text = "” Or Text2.Text = ”” Then
MsgBox ”请输入完整的添加信息!", vbCritical, ”提醒”
Else’判断是否有删除的权限
If Not Text2.Text = Adodc1。Recordset.Fields("password”) Then
MsgBox ”密码不正确!您无权删除此用户!", vbCritical, ”错误"
Else
Adodc1。Recordset.Delete
Adodc1。Recordset.Update
Adodc1。Refresh
Text1。Text = ””
Text2。Text = ””
Option1。Value = False
Option2.Value = False
Text3.Text = ”"
Text4。Text = "”
Text5。Text = ””
Text6。Text = ”"
Text7。Text = "”
Text8.Text = ””
MsgBox ”用户删除成功!”, vbDefaultButton1, ”提醒”
End If
End If
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Command5_Click()
Adodc1。Recordset。MoveNext
If Adodc1。Recordset。EOF Then‘判断记录指针的位置
Adodc1.Recordset.MoveLast
Command5.Enabled = False
Command6.Enabled = True
MsgBox "已经是最后一个用户了!”, vbDefaultButton1, "提示"
Exit Sub
End If
Text1.Text = Adodc1.Recordset。Fields(”userName")
Text2。Text = Adodc1。Recordset.Fields("password”)
If Adodc1。Recordset。Fields("sex”) = ”男” Then
Option1。Value = True
Else
Option2。Value = True
End If
Text3.Text = Adodc1.Recordset。Fields(”birthday")
Text4。Text = Adodc1。Recordset.Fields(”age”)
Text5。Text = Adodc1。Recordset。Fields("status”)
Text6.Text = Adodc1.Recordset。Fields("profession”)
Text7.Text = Adodc1.Recordset。Fields(”hobby")
Text8.Text = Adodc1.Recordset.Fields(”wage”)
End Sub
Private Sub Command6_Click()
Adodc1.Recordset.MovePrevious‘将记录指针向上移
If Adodc1。Recordset.BOF Then
Adodc1。Recordset.MoveFirst
Command6.Enabled = False
Command5.Enabled = True
MsgBox "已经是第一个用户了!", vbDefaultButton1, ”提示”
Exit Sub
End If
Text1。Text = Adodc1。Recordset.Fields(”userName")
Text2。Text = Adodc1。Recordset。Fields(”password”)
If Adodc1。Recordset。Fields(”sex”) = ”男” Then
Option1.Value = True
Else
Option2。Value = True
End If
Text3.Text = Adodc1。Recordset.Fields(”birthday")
Text4。Text = Adodc1.Recordset。Fields(”age”)
Text5。Text = Adodc1。Recordset.Fields("status”)
Text6。Text = Adodc1.Recordset.Fields(”profession”)
Text7.Text = Adodc1。Recordset.Fields(”hobby”)
Text8.Text = Adodc1.Recordset。Fields(”wage”)
If Adodc1。Recordset.EOF Then
Command5。Enabled = False
End If
End Sub
Private Sub Command7_Click()
Command5.Enabled = True
Command6.Enabled = True
Dim sql As String
sql = "select * from Uuser"
If Text1。Text = ”" Or Text2。Text = ”” Then
MsgBox "请输入用户名和密码!”, vbCritical, ”提醒”
Exit Sub
End If
Adodc1.RecordSource = sql
Adodc1。Refresh
If Adodc1.Recordset.BOF Then
MsgBox ”无此用户,请重新输入”, vbExclamation, ”警告”
Text1.Text = ””
Text1.SetFocus
Exit Sub
Else ’ 判断密码是否正确
If Not Adodc1。Recordset.Fields("password”) = Text2.Text Then
MsgBox "密码错误,重新输入 ", vbExclamation, ”警告”
Text2。Text = "”
Text2.SetFocus
Exit Sub
Else
If Adodc1。Recordset.Fields("sex") = "男” Then
Option1。Value = True
Else
Option2.Value = True
End If
Text3.Text = Adodc1.Recordset。Fields("birthday”)
Text4.Text = Adodc1。Recordset.Fields(”age")
Text5.Text = Adodc1。Recordset.Fields(”status”)
Text6。Text = Adodc1。Recordset.Fields("profession”)
Text7。Text = Adodc1。Recordset。Fields(”hobby”)
Text8.Text = Adodc1。Recordset。Fields("wage")
End If
End If
End Sub
Private Sub Form_Load()
Move (Screen。Width — Width) / 2, (Screen。Height — Height) / 2
Command5。Enabled = False
Command6。Enabled = False
End Sub
3。5物品信息
物品窗口设计
进入物品信息窗口之后,可以在文本框中输入要添加的物品信息,然后点击添加按钮,弹出添加成功的对话框,即添加物品信息成功!也可以通过输入物品名称、购买日期、是否是公用品、所有者来精确查找某条或某类物品信息。上一个、下一个可以浏览物品信息。修改完信息之后,也可以点击修改按钮来修改此物品信息.点击删除按钮即可直接删除此物品信息。退出即可直接返回主界面。
图3—6
代码如下:
Private Function setNull() ’构造一个置空的函数
Text1.Text = ””
Text2.Text = ””
Text3.Text = "”
Text4。Text = "”
Text5。Text = ””
Text6.Text = ””
Text7。Text = ""
Text8。Text = ”"
Combo1。Text = ”"
End Function
Private Sub Combo1_LostFocus()
If Combo1。Text = ”是" Then
Label9。Visible = False
Text8.Visible = False
End If
If Combo1.Text = "否” Then
Label9。Visible = True
Text8.Visible = True
End If
End Sub
Private Sub Command1_Click()
If Text1。Text = ”” Or Combo1.Text = ”” Then
MsgBox "请输入添加信息!”, vbCritical, "错误”
Exit Sub
End If
If Combo1.Text = "是" Then
Adodc1。Recordset.AddNew ‘添加物品信息
Adodc1。Recordset.Fields(”itemName”) = Text1。Text
Adodc1.Recordset。Fields(”purchaseDate”) = Text2。Text
Adodc1.Recordset。Fields("price”) = Text3。Text
Adodc1。Recordset.Fields(”usedTime”) = Text4.Text
Adodc1。Recordset。Fields(”quantity”) = Text5。Text
Adodc1.Recordset。Fields(”category") = Text6。Text
Adodc1。Recordset.Fields(”roomnumber”) = Text7.Text
Adodc1。Recordset.Fields("publicItem”) = Combo1。Text
Adodc1。Recordset.Update
Adodc1。Refresh
setNull
MsgBox ”添加成功!”, vbDefaultButton1, "提示"
Exit Sub
End If
If Combo1。Text = ”否" Then
Dim sqls As String
sqls = "select * from Item"
Adodc1.RecordSource = sqls
Adodc1.Recordset.AddNew
Adodc1。Recordset。Fields("itemName") = Text1.Text
Adodc1。Recordset。Fields(”purchaseDate") = Text2.Text
Adodc1。Recordset。Fields("price") = Text3.Text
Adodc1.Recordset。Fields("usedTime”) = Text4。Text
Adodc1。Recordset.Fields(”quantity”) = Text5。Text
Adodc1。Recordset.Fields(”category") = Text6。Text
Adodc1。Recordset。Fields("roomnumber") = Text7。Text
Adodc1。Recordset。Fields("publicItem") = Combo1。Text
Adodc1.Recordset。Update
Adodc1.Refresh
Dim sql As String
sql7 = ”select * from Belong"
Adodc1.RecordSource = sql7
Adodc1.Recordset。AddNew
Adodc1.Recordset。Fields(”itemName”) = Text1.Text
Adodc1.Recordset。Fields(”userName”) = Text8.Text
Adodc1。Recordset。Fields("itemNumber”) = Text5.Text
Adodc1。Recordset.Update
Adodc1。Refresh
setNull
MsgBox "添加成功!", vbDefaultButton1, "提示”
Exit Sub
End If
End Sub
Private Sub Command2_Click()
If Combo1。Text = ”是” Then
Adodc1。Recordset。Fields(”itemName”) = Text1。Text
Adodc1。Recordset.Fields("purchaseDate") = Text2。Text
Adodc1。Recordset。Fields(”price”) = Text3。Text
Adodc1。Recordset.Fields(”usedTime”) = Text4。Text
Adodc1。Recordset。Fields(”quantity”) = Text5。Text
Adodc1。Recordset。Fields(”category") = Text6。Text
Adodc1。Recordset.Fields(”roomnumber”) = Text7。Text
Adodc1。Recordset。Fields("publicItem") = Combo1。Text
Adodc1。Recordset.Update
Adodc1.Refresh
setNull ’调用置空函数
MsgBox "修改成功!”, vbDefaultButton1, "提示"
Exit Sub
End If
End Sub
Private Sub Command3_Click()
Adodc1。Recordset.Delete ‘删除物品信息
Adodc1。Recordset。Update
Adodc1。Refresh
MsgBox ”删除成功!”, vbDefaultButton1, "提示"
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Command5_Click()
Command6.Enabled = True
Command7.Enabled = True
If Not Text1。Text = ”" Then
Dim sql1 As String
sql1 = ”Select * From item Where itemName= ’” & Text1.Text & ”' "
Adodc1。RecordSource = sql1
Adodc1。Refresh
Text2。Text = Adodc1.Recordset。Fields(”purchaseDate”)
Text3。Text = Adodc1。Recordset。Fields(”price")
Text4。Text = Adodc1。Recordset.Fields(”usedTime”)
Text5。Text = Adodc1。Recordset.Fields(”quantity”)
Text6。Text = Adodc1。Recordset。Fields("category")
Text7。Text = Adodc1。Recordset.Fields(”roomnumber”)
Combo1.Text = Adodc1。Recordset。Fields(”publicItem”)
If Combo1.Text = "否" Then
Text8.Text
展开阅读全文