修改公寓名称: 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.Pa 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] 下一页 |