• 绑定树控件


    #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

  • 相关阅读:
    react 使用 redux 的时候 用 ref获取子组件的state
    node-rsa 非对称加密和解密
    electron 前端开发桌面应用
    react-router v4 使用 history 控制路由跳转
    react 写一个贪吃蛇
    【Java并发编程】:并发新特性—塞队列和阻塞栈
    【Java并发编程】:并发新特性—Executor框架与线程池
    【Java并发编程】:深入Java内存模型—内存操作规则总结
    【Java并发编程】:深入Java内存模型——happen-before规则及其对DCL的分析
    【Java并发编程】:加锁和volatile变量
  • 原文地址:https://www.cnblogs.com/lmcblog/p/2597821.html
Copyright © 2020-2023  润新知