修改公寓名称: If Text3.Text = "" Then MsgBox "选择要修改的公寓", , "提示" Exit Sub End If If Command12.Caption = "修改" Then Text2.Text = Text3.Text Label6.Caption = "输入想要修改的公寓名称" Command12.Caption = "更新" Command3.Enabled = False Command7.Enabled = False ElseIf Command12.Caption = "更新" Then Command3.Enabled = True Command7.Enabled = True Label6.Caption = "输入想要添加的公寓名称" Adodc1.Recordset.Fields("公寓名称") = Text2.Text Adodc1.Recordset.Update Adodc2.Recordset.ActiveConnection.Execute "update qinshi set 公寓名称='" & Text2.Text & "' where 公寓名称='" & Trim(Text3.Text) & "'" Adodc2.Recordset.Update Command12.Caption = "修改" End If Set DataGrid2.datasource = Adodc1 DataGrid2.Refresh Adodc5.Recordset.Update Set main.DataGrid1.datasource = Adodc5 main.DataGrid1.Refresh 删除公寓名称 If Text3.Text = "" Then MsgBox "选择所要删除公寓的名称", , "提示" Exit Sub End If If (MsgBox("你真的想删除公寓名称为 " & Text3.Text & " 的记录吗?", vbOKCancel, "系统提示")) = vbOK Then Adodc1.Recordset.Delete Adodc1.Recordset.Update End If Text3.Text = "" Set DataGrid2.datasource = Adodc1 DataGrid2.Refresh (2) 寝室设置 ①寝室设置效果图 图4.5寝室设置 ②界面制作与实现方法 此界面实现相对比公寓设置来说相对复杂一些。用到的控件主要是Sstab与Treeview。但是在程序方面比较复杂。 在添加一个寝室前先要选择所要添加寝室所在的公寓。这个公寓可以点击下面的树中的节点,也可以在列表框中选择。树中的节点在点击后会把父节点显示在选择公寓后面的列表框中,而选中的节点会出现在寝室名称里。你也可以自己进行添写,确认公寓后即可添加完成了。添加后会把Treeview重新刷新一下。以显示更新后的记录。 添加源码: Adodc1.Refresh Adodc1.Recordset.Find "公寓名称='" & Combo1.Text & "'" If Adodc1.Recordset.EOF = True Then MsgBox "此公寓不存在", , "提示" Adodc1.Recordset.MoveFirst Exit Sub End If If Combo1.Text = "" Or Text1.Text = "" Then MsgBox "请输入所要添加的寝室及其所属公寓", , "提示" Exit Sub End If With Adodc2 .Recordset.AddNew .Recordset.Fields(0).Value = Combo1.Text .Recordset.Fields(1).Value = Text1.Text .Recordset.Update End With Combo1.Text = "" Text1.Text = "" Call startree1 修改操作可以把当前选中的寝室进行名称修改与其所属公寓进行修改。当要对名称进行修改时,先要选择所要修改的寝室名,选择后会在寝室名称里显示出来,把当前寝室名称改成要修改的寝室名称,然后点击修改即完成名称修改操作。当要对当前寝室的所属公寓进行修改时,需要先选择所要修改的寝室,然后在上面的公寓名称后填写所要修改的寝室名称。点击修改后完成此操作。但是这种操作不是常见。 修改源码: Adodc1.Refresh Adodc1.Recordset.Find "公寓名称='" & Combo1.Text & "'" If Adodc1.Recordset.EOF = True Then MsgBox "此公寓不存在", , "提示" Adodc1.Recordset.MoveFirst Exit Sub End If Dim sql As String On Error Resume Next If Combo1.Text = "" Or Text1.Text = "" Then MsgBox "请在下面选择所要修改的寝室", , "提示" Exit Sub End If 'sql = "select * form qinshi where 公寓名称='" & Trim(Combo1.Text) & "' and 寝室='" & Trim(Text1.Text) & "'" Adodc2.Recordset.ActiveConnection.Execute "update qinshi set 寝室='" & Text1.Text & "',公寓名称='" & Trim(Combo1.Text) & "'where 寝室='" & Trim(Text6.Text) & "'and 公寓名称='" & Trim(Text7.Text) & "'" Adodc2.Recordset.Update Combo1.Text = "" Text1.Text = "" Call startree1 删除操作可以删除掉当前树型显示中的任何一个子节点,也就是这个树型节点中的寝室名称,注意的是,删除后这个记录只在qinshi表中删除,其相关记录不会被删除掉的,如果想删除,还需要人工操作。实现的方法主要是对qinshi表操作,先对其进行查询,查询当前想要被删除的表是否存在,如果不存在,则给出提示,如果存在这条记录,则在表中把它删除掉,删除后调用生成树过程,把当前寝室设置中的树型结构重新生成,更新记录。实现的部分代码如下所示: If Combo1.Text = "" Or Text1.Text = "" Or Combo1.Text = "公寓管理系统" Then MsgBox "选择所要删除的寝室", , "提示" Exit Sub End If If (MsgBox("你真的想删除 " & Combo1.Text & " " & "寝室为" & Text1.Text & " 的记录吗?", vbOKCancel, "系统提示")) = vbOK Then Adodc2.Refresh Adodc2.Recordset.ActiveConnection.Execute "delete from qinshi where 公寓名称='" & Trim(Combo1.Text) & "' and 寝室='" & Trim(Text1.Text) & "'" Adodc2.Recordset.Update End If Combo1.Text = "" Text1.Text = "" Call startree1 在treeview点击的时候,上面的文本框中会显示相应的记录,这主要是对treeview进行了设置,代码如下: Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node) On Error Resume Next Text1.Text = TreeView1.SelectedItem.Text Combo1.Text = TreeView1.SelectedItem.Parent Text6.Text = TreeView1.SelectedItem.Text Text7.Text = TreeView1.SelectedItem.Parent End Sub (3)班级设置 ①班级设置效果图 图4.6班级设置 ②界面制作与实现方法 此界面制作与公寓设置基本一致。在这个界面中主要用到了一个Sstab控件与一个显示表中内容的Datagrid控件。以及起到美观作用的Frame控件。 在右下角的文本框中可以输入想要添加的班级名称。然后点击添加即可完成添加操作。Datagrid中会立即刷新显示更新内容。要修改某条记录时,要先对所要修改的记录进行选择,确认选择后,点击下面的修改按钮,会在下面的文本中显示出所要修改班级的名称,此时即可输入要修改的名字。然后点击更新就会完成此操作。Datagrid也会即时更新其内容。删除操作更为简单,选择想要删除的班级名称,点击删除,确认后完成此操作。 添加班级源码: Adodc3.Recordset.Find "class='" & Text4.Text & "'" If Adodc3.Recordset.EOF = False Then MsgBox "此班级已存在", , "提示" Adodc3.Recordset.MoveFirst Exit Sub End If Text5.Text = "" If Text4.Text = "" Then MsgBox "输入所要添加班级的名称", , "提示" Exit Sub End If Adodc3.Recordset.AddNew Adodc3.Recordset.Fields("class") = Text4.Text Adodc3.Recordset.Update Adodc3.RecordSource = "class" Text4.Text = "" Set DataGrid3.datasource = Adodc3 DataGrid3.Refresh 修改班级源码: If Command10.Caption = "修改" Then Text4.Text = Text5.Text Label6.Caption = "输入想要修改的班级名称" Command10.Caption = "更新" Command6.Enabled = False Command9.Enabled = False ElseIf Command10.Caption = "更新" Then Command9.Enabled = True Command6.Enabled = True Label6.Caption = "输入想要添加的班级名称" Adodc3.Recordset.Fields("class") = Text4.Text Adodc3.Recordset.Update Command10.Caption = "修改" End If 删除班级源码: If Text5.Text = "" Then MsgBox "选择所要删除班级的名称", , "提示" Exit Sub End If If (MsgBox("你真的想删除班级名称 为 " & Text5.Text & " 的记录吗?", vbOKCancel, "系统提示")) = vbOK Then Adodc3.Recordset.Delete Adodc3.Recordset.Update End If Text5.Text = "" Set DataGrid3.datasource = Adodc3 DataGrid3.Refresh End Sub 4.3.3数据备份: 数据备份是一个数据库软件必不可少的一部分,利用它可以把当前数据库表进行全面的备份,以备以后使用。因为在操作中可能会导致数据遭到破坏,或者是系统的原因使数据库损坏,或者是一些其它的人为原因,这样你可以用此功能把数据恢复到最后一次备份的状态,使损失做到最少,经常备份,操作起来更有安全感。 ①数据备份效果图 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] 下一页 |