zoukankan      html  css  js  c++  java
  • winfrom_权限设置_TreeView的相关问题

    1.获取TreeView的值:

      循环TreeView,获取checked每个节点的Text,串起来用逗号“,”隔开,保存到数据库。

     1  List<string> list = new List<string>();
     2             foreach (TreeNode treeNode in this.tv1.Nodes)
     3             {
     4                 bool @checked = treeNode.Checked;
     5                 if (@checked)
     6                 {
     7                     bool flag = treeNode.Nodes.Count != 0;
     8                     if (flag)
     9                     {
    10                         foreach (TreeNode treeNode2 in treeNode.Nodes)
    11                         {
    12                             list.Add(treeNode.Text + "," + treeNode2.Text);
    13                         }
    14                     }
    15                     else
    16                     {
    17                         list.Add(treeNode.Text);
    18                     }
    19                 }
    20             }
    21             txtTypeRemarks.Text = string.Join(",", list.ToArray());
    22 
    23             model.Remarks = txtTypeRemarks.Text;

    2.修改权限TreeView时:

       获取数据库的权限数据,将字符串转数组,循环匹配TreeViewd 节点,相同的节点checked

    1                     ----Load事件-----
    2                     txtTypeRemarks.Text = list[0].Remarks;
    3                         foreach (TreeNode tnSub in tv1.Nodes)
    4                         {
    5                             FindTreeView(tnSub);
    6                         }
     1  private void FindTreeView(TreeNode tn)
     2         {
     3             string[] strArray = txtTypeRemarks.Text.Split(','); //字符串转数组
     4             
     5             tn.Checked = false;
     6             string remark = string.Empty;
     7             string tv = string.Empty;
     8             for (int i = 0; i < strArray.Length; i++)
     9             {
    10                 remark = strArray[i].ToString().Trim();
    11                 tv = tn.Name.Trim();
    12                 if (remark == tv)
    13                 {
    14                     tn.Checked = true;
    15                 }
    16             }
    17             
    18         }

    3.用户登录后,权限效果显示:

          用户登录成功后,从数据库获取该用户的权限详情,传到首界面,在点击某个模块时,匹配有权限这可以看到相应界面,否则弹出提示

     1   public static string UserPower{ get;set;}
    2 public string LoginUser { get; set; } 3 4 private void FrmMainAdmin_Load(object sender, EventArgs e) 5 {
    //从登录界面获取的权限详情字符串
    6 FrmMainAdmin.UserPower = this.LoginUser;
    7
    8 } 9 //菜单栏 10 private void menu_SelectedIndexChanged(object sender, EventArgs e) 11 { 12 if (typeof(UIMenuBar).IsInstanceOfType(sender)) 13 { 14 UIMenuBar menuBar = (UIMenuBar)sender; 15 switch (menuBar.SelectedItem.TargetModule) 16 { 17 case "学习内容管理":
    18 bool flag = !FrmMainAdmin.UserPower.Contains("学习内容管理"); 19 if (flag) 20 { 21 MessageBox.Show("您没有“学习内容管理”权限!"); 22 } 23 else 24 { 25 AddTabPagesByForm(new Frm学习内容管理()); 26 } 27 break;
  • 相关阅读:
    第 9 章 用户自己建立数据类型
    第 10 章 对文件的输入输出
    第 7 章 用函数实现模块化程序设计
    第 4 章 选择结构程序设计
    第 5 章 循环结构程序设计
    第 6 章 利用数组处理批量数据
    第 3 章 最简单的 C 程序设计——顺序程序设计
    第 1 章 程序设计和 C 语言
    第 2 章 算法——程序的灵魂
    SQL(SQL Server) 批量替换两列的数据
  • 原文地址:https://www.cnblogs.com/bonnie-w/p/8144950.html
Copyright © 2011-2022 走看看