📄 frmlocation.frm
字号:
End Sub
Private Sub Fill_Building_tree(NodeKey As String, building_id As String)
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
txtSQL = "select * from tbl_room where building_id = " & building_id
Set rst = ExecuteSQL(txtSQL, MsgText, HasError)
Do While Not rst.EOF
Set nd = TreeView1.Nodes.Add(NodeKey, tvwChild, "room_" & rst.Fields("room_id"), rst.Fields("room_name"), 4)
rst.MoveNext
Loop
End Sub
Private Sub TreeView1_NodeClick(ByVal nd As MSComctlLib.Node)
txtName.Text = nd.Text
name_old = nd.Text
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim oNodex As Node
Dim skey As String
Dim iIndex As Integer
Dim loc As String
Dim id As String
loc = ""
On Error Resume Next
Select Case Button.key
Case "新建"
txtName = ""
iIndex = TreeView1.SelectedItem.Index
Set sel_nd = TreeView1.Nodes(iIndex)
If sel_nd.Image = 1 Then '根节点
txtName = "新添加校区"
Set mrc = ExecuteSQL("select top 1 area_id from tbl_area order by area_id desc", MsgText, HasError)
If mrc.EOF = False Then
newid = mrc.Fields("area_id") + 1
End If
txtSQL = "insert into tbl_area values("
txtSQL = txtSQL & Quote(newid) & ","
txtSQL = txtSQL & Quote(txtName)
txtSQL = txtSQL & ")"
Set mrc = ExecuteSQL(txtSQL, MsgText, HasError)
Set nd = TreeView1.Nodes.Add(sel_nd.key, tvwChild, "area_" & newid, txtName, 2)
nd.EnsureVisible
ElseIf sel_nd.Image = 2 Then
txtName = "新添加楼栋"
Set mrc = ExecuteSQL("select top 1 building_id from tbl_building order by building_id desc", MsgText, HasError)
If mrc.EOF = False Then
newid = mrc.Fields("building_id") + 1
End If
txtSQL = "insert into tbl_building values("
txtSQL = txtSQL & Quote(newid) & ","
txtSQL = txtSQL & Quote(txtName) & ","
txtSQL = txtSQL & Quote(Replace(sel_nd.key, "area_", ""))
txtSQL = txtSQL & ")"
Set mrc = ExecuteSQL(txtSQL, MsgText, HasError)
Set nd = TreeView1.Nodes.Add(sel_nd.key, tvwChild, "building_" & newid, txtName, 3)
nd.EnsureVisible
ElseIf sel_nd.Image = 3 Then
Set sel_parent_nd = TreeView1.SelectedItem.Parent
txtName = "新添加房间"
Set mrc = ExecuteSQL("select top 1 room_id from tbl_room order by room_id desc", MsgText, HasError)
If mrc.EOF = False Then
newid = mrc.Fields("room_id") + 1
End If
txtSQL = "insert into tbl_room values("
txtSQL = txtSQL & Quote(newid) & ","
txtSQL = txtSQL & Quote(txtName) & ","
txtSQL = txtSQL & Quote(Replace(sel_parent_nd.key, "area_", "")) & ","
txtSQL = txtSQL & Quote(Replace(sel_nd.key, "building_", ""))
txtSQL = txtSQL & ")"
Set mrc = ExecuteSQL(txtSQL, MsgText, HasError)
Set nd = TreeView1.Nodes.Add(sel_nd.key, tvwChild, "room_" & newid, txtName, 4)
nd.EnsureVisible
ElseIf sel_nd.Image = 4 Then
End If
Case "保存"
If Trim(txtName.Text) <> Trim(name_old) Then
iIndex = TreeView1.SelectedItem.Index
Set sel_nd = TreeView1.Nodes(iIndex)
If sel_nd.Image = 1 Then '根节点
ElseIf sel_nd.Image = 2 Then
loc = "area"
id = Replace(sel_nd.key, "area_", "")
ElseIf sel_nd.Image = 3 Then
loc = "building"
id = Replace(sel_nd.key, "building_", "")
ElseIf sel_nd.Image = 4 Then
loc = "room"
id = Replace(sel_nd.key, "room_", "")
End If
txtSQL = "update tbl_" & loc & " set "
txtSQL = txtSQL & loc & "_name=" & Quote(txtName.Text)
txtSQL = txtSQL & " where " & loc & "_id =" & id
Set mrc = ExecuteSQL(txtSQL, MsgText, HasError)
sel_nd.Text = txtName
sel_nd.EnsureVisible
End If
Case "删除"
iIndex = TreeView1.SelectedItem.Index
Set sel_nd = TreeView1.Nodes(iIndex)
Set sel_parent_nd = TreeView1.SelectedItem.Parent
If sel_nd.Image = 1 Then '根节点
ElseIf sel_nd.Image = 2 Then
id = Replace(sel_nd.key, "area_", "")
Set mrc = ExecuteSQL("select top 1 * from tbl_building where area_id = " & Quote(id), MsgText, HasError)
If mrc.EOF = False Then
MsgBox "该校区下有楼栋,无法删除!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
txtSQL = "delete from tbl_area "
txtSQL = txtSQL & " where area_id =" & Quote(id)
Set mrc = ExecuteSQL(txtSQL, MsgText, HasError)
ElseIf sel_nd.Image = 3 Then
id = Replace(sel_nd.key, "building_", "")
Set mrc = ExecuteSQL("select top 1 * from tbl_room where building_id = " & Quote(id), MsgText, HasError)
If mrc.EOF = False Then
MsgBox "该楼栋下有房间,无法删除!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
txtSQL = "delete from tbl_building "
txtSQL = txtSQL & " where building_id =" & Quote(id)
Set mrc = ExecuteSQL(txtSQL, MsgText, HasError)
ElseIf sel_nd.Image = 4 Then
id = Replace(sel_nd.key, "room_", "")
Set mrc = ExecuteSQL("select top 1 * from tbl_device where room_id = " & Quote(id), MsgText, HasError)
If mrc.EOF = False Then
MsgBox "该房间内有设备,无法删除!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
txtSQL = "delete from tbl_room "
txtSQL = txtSQL & " where room_id =" & Quote(id)
Set mrc = ExecuteSQL(txtSQL, MsgText, HasError)
End If
TreeView1.Nodes.Remove iIndex
sel_parent_nd.EnsureVisible
Case "关闭"
Unload Me
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -