当前位置:网站首页>使用TreeView树型菜单栏(递归调用数据库自动创建菜单)
使用TreeView树型菜单栏(递归调用数据库自动创建菜单)
2020-11-09 12:12:00 【程序猿欧文】
在做工控上位机项目时,当项目过于庞大,细分的流程就很多,需要管理的页面也就会增加很多,这时可以使用.NET控件TreeView进行页面的切换管理,并且实现TreeView间的互相切换。Intouch和Wonderware可以导入并使用TreeView控件。
一、使用VS开发TreeView控件
创建一个控件项目解决方案
拖一个TreeView控件,可以简单的进行节点编辑

Tag是需要向外传递的数据

二、出现的问题
在项目后期,对方会提出很多的改进需求,这时如果一个项目中存在过多的TreeView控件,每次改进,对于上位机系统来说就需要重新导入一次,重复过程太多,太繁琐。
解决方案:在数据库中创建菜单表,项目运行时菜单栏自动生成
三、创建数据库
创建数据库表,MenuId是菜单序号,MenuName为TreeView显示的页面名称,MenuCode为Tag,ParentId为该子节点的根节点

四、编写代码自动生成
按照两层架构来完成

实体类TreeViewNode
1 public class TreeViewNode 2 { 3 public int MenuId { get; set; } 4 5 public string MenuName { get; set; } 6 7 public string MenuCode { get; set; } 8 9 public string ParentId { get; set; }10 }
Service层:MenuService
1 /// <summary> 2 /// 获取所有的菜单子项 3 /// </summary> 4 /// <returns></returns> 5 public List<TreeViewNode> GetAllMenu() 6 { 7 string sql = "select MenuId,MenuName,MenuCode,ParentId from MenuList"; 8 List<TreeViewNode> nodeList = new List<TreeViewNode>(); 9 SqlDataReader objRead = SQLHelper.GetReader(sql);10 while (objRead.Read())11 {12 nodeList.Add(new TreeViewNode()13 {14 MenuId = Convert.ToInt32(objRead["MenuId"]),15 MenuName = objRead["MenuName"].ToString(),16 MenuCode = objRead["MenuCode"].ToString(),17 ParentId = objRead["ParentId"].ToString()18 });19 }20 objRead.Close();21 return nodeList;22 }
TreeViewMenu控件:
1 public partial class TreeViewMenu: UserControl 2 { 3 public TreeViewMenu() 4 { 5 InitializeComponent(); 6 Lo.........
版权声明
本文为[程序猿欧文]所创,转载请带上原文链接,感谢
https://my.oschina.net/mikeowen/blog/4709320
边栏推荐
- Adobe experience design / XD 2020 software installation package (with installation tutorial)
- inet_ Pton () and INET_ Detailed explanation of ntop() function
- 在嵌入式设备中实现webrtc的第三种方式③
- Looking for better dynamic getter and setter solutions
- As a user, you can't get rid of the portrait!
- Handwriting Koa.js Source code
- 10款必装软件,让Windows使用效率飞起!
- 如何保证消息不被重复消费?(如何保证消息消费的幂等性)
- 苏宁基于知识图谱的大规模告警收敛和根因定位实践
- JVM学习(六)-内存模型和线程
猜你喜欢
![[design pattern] Chapter 4: Builder mode is not so difficult](/img/18/12e488e344183788b0477f8114fe21.jpg)
[design pattern] Chapter 4: Builder mode is not so difficult

Mac 必备优质工具推荐

JVM learning (4) - garbage collector and memory allocation

SEO见风使舵,是对还是错?

开源ERP招聘了

Android rights

Depth analysis based on synchronized lock

Download Netease cloud music 10W + music library with Python

Implement crud operation

Three practical skills of Medical Project Management
随机推荐
Introduction to zero based im development (4): what is message timing consistency in IM systems?
做用户,绕不开画像!
for与for...in、for Each和map和for of
Understanding task and async await
解决IDEA快捷键 Alt+Insert 失效的问题
10款必装软件,让Windows使用效率飞起!
Recommended tools for Mac
注意.NET Core进行请求转发问题
真正拖垮你的,是沉没成本
Wealth and freedom? Ant financial services suspended listing, valuation or decline after regulation
Large scale project Objective-C - nsurlsession access SMS verification code application example sharing
线上服务的FGC问题排查,看这篇就够了!
配置交换机Trunk接口流量本地优先转发(集群/堆叠)
20201107第16课,使用Apache服务部署静态网站;使用Vsftpd服务传输文件
Shoes? Forecasting stock market trends? Taobao second kill? Python means what you want
微信圈子
AI fresh student's annual salary has increased to 400000, you can still make a career change now!
使用CopyMemory API出现 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
Implement crud operation
Mac 必备优质工具推荐