#region 绑定树控件
bool[] islastNode;
/// <summary>
/// 添加监控点
/// </summary>
/// <param name="node"></param>
/// <param name="control"></param>
/// <param name="parent_id"></param>
private void AddTreeView(TreeNode node, control_unit[] control, int parent_id)
{
for (int i = 0; i < control.Length; i++)
{
if (control[i].Parent_id == parent_id)
{
TreeNode nextnode = new TreeNode();
nextnode.Name = control[i].Control_unit_id.ToString();
nextnode.Text = control[i].Name;
if (islastNode[i])
{
//加载设备
getDevice(control[i].Control_unit_id, nextnode);
}
else
{
//加载字项
AddTreeView(nextnode, control, control[i].Control_unit_id);
}
node.Nodes.Add(nextnode);
}
}
}
/// <summary>
/// 加载设备
/// </summary>
/// <param name="control_unit_id"></param>
/// <param name="parentNode"></param>
private void getDevice(int control_unit_id, TreeNode parentNode)
{
if (Service.Common.device != null && Service.Common.device.Length > 0)
{
for (int i = 0; i < Service.Common.device.Length; i++)
{
if (Service.Common.device[i].Control_unit_id == control_unit_id)
{
TreeNode divenode = new TreeNode();
divenode.Name = Service.Common.device[i].Device_id.ToString();
divenode.Text = Service.Common.device[i].Name;
//加载摄像头
if (Service.Common.camera != null && Service.Common.camera.Length > 0)
{
for (int k = 0; k < Service.Common.camera.Length; k++)
{
TreeNode cameranode = new TreeNode();
cameranode.Name = Service.Common.camera[k].Camera_id.ToString();
cameranode.Text = Service.Common.camera[k].Name;
divenode.Nodes.Add(cameranode);
}
}
parentNode.Nodes.Add(divenode);
}
}
}
}
/// <summary>
/// 树形目录
/// </summary>
private void loadTreeView(TreeView tree)
{
//DataService.control_unit[] control = Service.Common.data.getControl_list(-1, -1);
islastNode = new bool[Service.Common.control.Length];
//找出没有子项的借点
for (int i = 0; i < Service.Common.control.Length; i++)
{
islastNode[i] = true;
for (int j = Service.Common.control.Length - 1; j >= 0; j--)
{
if (Service.Common.control[i].Control_unit_id == Service.Common.control[j].Parent_id)
{
islastNode[i] = false;
}
}
}
for (int i = 0; i < Service.Common.control.Length; i++)
{
if (Service.Common.control[i].Parent_id == 0)
{
TreeNode node = new TreeNode();
node.Name = Service.Common.control[i].Control_unit_id.ToString();
node.Text = Service.Common.control[i].Name;
if (islastNode[i])
{
//加载设备
getDevice(Service.Common.control[i].Control_unit_id, node);
}
else
{
//加载字项
AddTreeView(node, Service.Common.control, Service.Common.control[i].Control_unit_id);
}
tree.Nodes.Add(node);
}
}
}
#endregion