Esempio n. 1
0
    private void SaveRight(TreeNodeCollection TNC)
    {
        IList <Right_Assign> assignlist = (IList <Right_Assign>)ViewState["RightAssign"];

        foreach (TreeNode node in TNC)
        {
            int model  = 1;
            int action = 1;
            if (node.Value.StartsWith("M"))
            {
                model  = int.Parse(node.Value.Substring(1));
                action = 1;
            }
            else
            {
                action = int.Parse(node.Value.Substring(1));

                if (node.Parent != null)
                {
                    model = int.Parse(node.Parent.Value.Substring(1));
                }
            }

            Right_Assign assign = assignlist.FirstOrDefault(m => m.Module == model && m.Action == action);
            if (node.Checked)
            {
                if (assign == null)
                {
                    Right_Assign_BLL bll = new Right_Assign_BLL();
                    bll.Model.Module   = model;
                    bll.Model.Action   = action;
                    bll.Model.RoleName = tr_Role.SelectedValue;
                    bll.Model.Based_On = 2;
                    bll.Add();
                }
            }
            else
            {
                if (assign != null)
                {
                    Right_Assign_BLL bll = new Right_Assign_BLL(assign.ID);
                    bll.Delete();
                }
            }

            if (node.ChildNodes.Count > 0)
            {
                SaveRight(node.ChildNodes);
            }
        }
    }
    private void SaveRight(TreeNodeCollection TNC)
    {
        IList<Right_Assign> assignlist = (IList<Right_Assign>)ViewState["RightAssign"];
        foreach (TreeNode node in TNC)
        {
            int model = 1;
            int action = 1;
            if (node.Value.StartsWith("M"))
            {
                model = int.Parse(node.Value.Substring(1));
                action = 1;
            }
            else
            {
                action = int.Parse(node.Value.Substring(1));

                if (node.Parent != null)
                    model = int.Parse(node.Parent.Value.Substring(1));
            }

            Right_Assign assign = assignlist.FirstOrDefault(m => m.Module == model && m.Action == action);
            if (node.Checked)
            {
                if (assign == null)
                {
                    Right_Assign_BLL bll = new Right_Assign_BLL();
                    bll.Model.Module = model;
                    bll.Model.Action = action;
                    bll.Model.RoleName = tr_Role.SelectedValue;
                    bll.Model.Based_On = 2;
                    bll.Add();
                }
            }
            else
            {
                if (assign != null)
                {
                    Right_Assign_BLL bll = new Right_Assign_BLL(assign.ID);
                    bll.Delete();
                }
            }

            if (node.ChildNodes.Count > 0)
            {
                SaveRight(node.ChildNodes);
            }
        }
    }