Beispiel #1
0
        private void addNodeToTree(string macn)
        {
            DataRow row = getChucNangByCode(macn);

            // parent node
            if (row != null && row["macnroot"].ToString() == "")
            {
                if (getParentNode(macn) == null)
                {
                    FunctionNode node = new FunctionNode();
                    node.macn     = row["macn"].ToString();
                    node.chucnang = row["chucnang"].ToString();
                    trees.Add(node);
                    initTree();
                }
                return;
            }
            //child node
            FunctionNode child = new FunctionNode();

            child.macn     = row["macn"].ToString();
            child.chucnang = row["chucnang"].ToString();

            string parentCode = row["macnroot"].ToString();

            FunctionNode parent = getParentNode(parentCode);

            if (parent != null)
            {
                FunctionNode newParent = parent;
                newParent.child.Add(child);
                trees.Remove(parent);
                trees.Add(newParent);
            }
            else
            {
                DataRow row1 = getChucNangByCode(parentCode);
                if (row1 != null)
                {
                    FunctionNode parent1 = new FunctionNode();
                    parent1.macn     = row1["macn"].ToString();
                    parent1.chucnang = row1["chucnang"].ToString();
                    parent1.child.Add(child);
                    trees.Add(parent1);
                }
            }

            initTree();
        }
Beispiel #2
0
        private void getChildsForParent(FunctionNode parent, DataTable dt)
        {
            string macn = parent.macn;

            foreach (DataRow rw in dt.Rows)
            {
                if (macn == rw["macnroot"].ToString())
                {
                    FunctionNode child = new FunctionNode();
                    child.macn     = rw["macn"].ToString();
                    child.chucnang = rw["chucnang"].ToString();
                    parent.child.Add(child);
                }
            }
        }
Beispiel #3
0
        private List <FunctionNode> initParents()
        {
            string sql = string.Format("select cn.* from DM_CHUCNANG cn " +
                                       "where (cn.macn not in (select nqcn.macn " +
                                       "from HT_NHOMQUYEN_CHUCNANG nqcn " +
                                       "where nqcn.manhom = '{0}') " +
                                       "or cn.macn in (select distinct a.macnroot " +
                                       "from DM_CHUCNANG a " +
                                       "where a.macnroot is not null " +
                                       "and a.macn not in (select nqcn.macn " +
                                       "from HT_NHOMQUYEN_CHUCNANG nqcn " +
                                       " where nqcn.manhom = '{0}'))) " +
                                       "and macnroot is null", this.nhomQuyenId);

            if (removeFunctionIds != "")
            {
                sql = string.Format("select cn.* from DM_CHUCNANG cn " +
                                    "where (cn.macn not in (select nqcn.macn " +
                                    "from HT_NHOMQUYEN_CHUCNANG nqcn " +
                                    "where nqcn.manhom = '{0}') " +
                                    "or cn.macn in (select distinct a.macnroot " +
                                    "from DM_CHUCNANG a " +
                                    "where a.macnroot is not null " +
                                    "and a.macn not in (select nqcn.macn " +
                                    "from HT_NHOMQUYEN_CHUCNANG nqcn " +
                                    " where nqcn.manhom = '{0}'))) " +
                                    "or cn.macn in ({1}) and macnroot is null", this.nhomQuyenId, removeFunctionIds);
                //sql = string.Format("select cn.* from DM_CHUCNANG cn where cn.macn not in (select nqcn.macn from HT_NHOMQUYEN_CHUCNANG nqcn where nqcn.manhom = '{0}') or cn.macn in ({1}) and macnroot is null", this.nhomQuyenId, removeFunctionIds);
            }

            SQLAdaptor = MTSQLServer.getMTSQLServer().wAdapter(sql, null, false);
            DSetMain   = new DataSet();
            SQLAdaptor.Fill(DSetMain, "DM_CHUCNANG");
            DataTable dt = DSetMain.Tables["DM_CHUCNANG"];

            List <FunctionNode> parents = new List <FunctionNode>();

            foreach (DataRow rw in dt.Rows)
            {
                FunctionNode parent = new FunctionNode();
                parent.macn     = rw["macn"].ToString();
                parent.chucnang = rw["chucnang"].ToString();
                parents.Add(parent);
            }
            return(parents);
        }
Beispiel #4
0
        private void resetTreeNodeData(string macn)
        {
            bool isChild = false;

            foreach (FunctionNode parent in trees)
            {
                if (parent.macn == macn)
                {
                    selectedNode.Add(parent);
                    if (parent.child.Count == 0)
                    {
                        trees.Remove(parent);
                    }

                    break;
                }
                FunctionNode newParent = parent;
                foreach (FunctionNode child in parent.child)
                {
                    if (child.macn == macn)
                    {
                        selectedNode.Add(child);
                        newParent.child.Remove(child);
                        isChild = true;
                        break;
                    }
                }

                if (isChild)
                {
                    trees.Remove(parent);
                    if (newParent.child.Count > 0)
                    {
                        trees.Add(newParent);
                    }
                    else
                    {
                        selectedNode.Add(newParent);
                    }
                    break;
                }
            }
        }