예제 #1
0
        void AddRows(ChartOfAccounts tree, DataTable dt, bool ClearRows)
        {
            if (ClearRows)
            {
                Rows = new ObservableCollectionAdv<TreeNode>();
                _root = new TreeNode();
                _root.Tree = this;
                _root.Children = new TreeNode.NodeCollection(_root);
                _root.Nodes = new ReadOnlyCollection<TreeNode>(_root.Children);
                tree.lstParents = new List<TreeNode>();
                tree.AllTreeNodes = new List<TreeNode>();
            }

            int ColumnCount = dt.Columns.Count - 4;
            int i = tree.Rows.Count;
            for (; i < dt.Rows.Count; i++)
            {
                TreeNode node = new TreeNode();
                node.Tree = tree;
                node.Children = new TreeNode.NodeCollection(node);
                node.Nodes = new ReadOnlyCollection<TreeNode>(node.Children);

                node.IsExpandedOnce = true;
                node.AssignIsExpanded(true);

                node.Id = Convert.ToInt32(dt.Rows[i][0].ToString());

                node.IsGroup = Convert.ToBoolean(dt.Rows[i]["IsGroup"].ToString());
                node.LevelNo = Convert.ToInt16(dt.Rows[i]["Depth"].ToString());
                //node.NodeIndex = dt.Rows[i]["NodeIndex"].ToString();

                if (ColumnCount > 0)
                    node.Field1 = dt.Rows[i][1].ToString();
                if (ColumnCount > 1)
                    node.Field2 = dt.Rows[i][2].ToString();
                if (ColumnCount > 2)
                    node.Field3 = dt.Rows[i][3].ToString();
                if (ColumnCount > 3)
                    node.Field4 = dt.Rows[i][4].ToString();
                if (ColumnCount > 4)
                    node.Field5 = dt.Rows[i][5].ToString();
                if (ColumnCount > 5)
                    node.Field6 = dt.Rows[i][6].ToString();

                if (node.IsGroup)
                    node.ColorBrush = tree.GroupColorBrush;
                else
                    node.ColorBrush = tree.ItemColorBrush;

                tree.Rows.Add(node);
                tree.AllTreeNodes.Add(node);

                if (node.IsGroup)
                {
                    if (tree.lstParents.Count > 0)
                    {
                        if (node.LevelNo > tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                        {
                            tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                            tree.lstParents.Add(node);
                        }
                        else if (node.LevelNo == tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                        {

                            tree.lstParents.RemoveAt(tree.lstParents.Count - 1);
                            tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                            tree.lstParents.Add(node);
                        }
                        else if (node.LevelNo < tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                        {
                            for (int j = tree.lstParents.Count - 1; j >= 0; j--)
                            {
                                if (node.LevelNo <= tree.lstParents[j].LevelNo)
                                {
                                    tree.lstParents.RemoveAt(tree.lstParents.Count - 1);
                                }
                                else
                                    break;
                            }
                            tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                            tree.lstParents.Add(node);
                        }
                    }
                    else
                        tree.lstParents.Add(node);
                }
                else
                {
                    if (node.LevelNo > tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                    {
                        tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                    }
                    else if (node.LevelNo == tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                    {
                        for (int j = tree.lstParents.Count - 1; j >= 0; j--)
                        {
                            if (node.LevelNo <= tree.lstParents[j].LevelNo)
                            {
                                tree.lstParents.RemoveAt(tree.lstParents.Count - 1);
                            }
                            else
                                break;
                        }
                        tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                    }
                    else if (node.LevelNo < tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                    {
                        for (int j = tree.lstParents.Count - 1; j >= 0; j--)
                        {
                            if (node.LevelNo <= tree.lstParents[j].LevelNo)
                            {
                                tree.lstParents.RemoveAt(tree.lstParents.Count - 1);
                            }
                            else
                                break;
                        }
                        tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                    }

                }

            }
            if (tree.Root.Children.Count == 0 && tree.lstParents.Count() > 0)
                tree.Root.Children.Add(tree.lstParents[0]);
        }
예제 #2
0
        void AddRows(ChartOfAccounts tree, DataTable dt, bool ClearRows)
        {
            if (ClearRows)
            {
                Rows              = new ObservableCollectionAdv <TreeNode>();
                _root             = new TreeNode();
                _root.Tree        = this;
                _root.Children    = new TreeNode.NodeCollection(_root);
                _root.Nodes       = new ReadOnlyCollection <TreeNode>(_root.Children);
                tree.lstParents   = new List <TreeNode>();
                tree.AllTreeNodes = new List <TreeNode>();
            }

            int ColumnCount = dt.Columns.Count - 4;
            int i           = tree.Rows.Count;

            for (; i < dt.Rows.Count; i++)
            {
                TreeNode node = new TreeNode();
                node.Tree     = tree;
                node.Children = new TreeNode.NodeCollection(node);
                node.Nodes    = new ReadOnlyCollection <TreeNode>(node.Children);


                node.IsExpandedOnce = true;
                node.AssignIsExpanded(true);


                node.Id = Convert.ToInt32(dt.Rows[i][0].ToString());

                node.IsGroup = Convert.ToBoolean(dt.Rows[i]["IsGroup"].ToString());
                node.LevelNo = Convert.ToInt16(dt.Rows[i]["Depth"].ToString());
                //node.NodeIndex = dt.Rows[i]["NodeIndex"].ToString();

                if (ColumnCount > 0)
                {
                    node.Field1 = dt.Rows[i][1].ToString();
                }
                if (ColumnCount > 1)
                {
                    node.Field2 = dt.Rows[i][2].ToString();
                }
                if (ColumnCount > 2)
                {
                    node.Field3 = dt.Rows[i][3].ToString();
                }
                if (ColumnCount > 3)
                {
                    node.Field4 = dt.Rows[i][4].ToString();
                }
                if (ColumnCount > 4)
                {
                    node.Field5 = dt.Rows[i][5].ToString();
                }
                if (ColumnCount > 5)
                {
                    node.Field6 = dt.Rows[i][6].ToString();
                }


                if (node.IsGroup)
                {
                    node.ColorBrush = tree.GroupColorBrush;
                }
                else
                {
                    node.ColorBrush = tree.ItemColorBrush;
                }

                tree.Rows.Add(node);
                tree.AllTreeNodes.Add(node);

                if (node.IsGroup)
                {
                    if (tree.lstParents.Count > 0)
                    {
                        if (node.LevelNo > tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                        {
                            tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                            tree.lstParents.Add(node);
                        }
                        else if (node.LevelNo == tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                        {
                            tree.lstParents.RemoveAt(tree.lstParents.Count - 1);
                            tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                            tree.lstParents.Add(node);
                        }
                        else if (node.LevelNo < tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                        {
                            for (int j = tree.lstParents.Count - 1; j >= 0; j--)
                            {
                                if (node.LevelNo <= tree.lstParents[j].LevelNo)
                                {
                                    tree.lstParents.RemoveAt(tree.lstParents.Count - 1);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                            tree.lstParents.Add(node);
                        }
                    }
                    else
                    {
                        tree.lstParents.Add(node);
                    }
                }
                else
                {
                    if (node.LevelNo > tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                    {
                        tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                    }
                    else if (node.LevelNo == tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                    {
                        for (int j = tree.lstParents.Count - 1; j >= 0; j--)
                        {
                            if (node.LevelNo <= tree.lstParents[j].LevelNo)
                            {
                                tree.lstParents.RemoveAt(tree.lstParents.Count - 1);
                            }
                            else
                            {
                                break;
                            }
                        }
                        tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                    }
                    else if (node.LevelNo < tree.lstParents[tree.lstParents.Count - 1].LevelNo)
                    {
                        for (int j = tree.lstParents.Count - 1; j >= 0; j--)
                        {
                            if (node.LevelNo <= tree.lstParents[j].LevelNo)
                            {
                                tree.lstParents.RemoveAt(tree.lstParents.Count - 1);
                            }
                            else
                            {
                                break;
                            }
                        }
                        tree.lstParents[tree.lstParents.Count - 1].Children.Add(node);
                    }
                }
            }
            if (tree.Root.Children.Count == 0 && tree.lstParents.Count() > 0)
            {
                tree.Root.Children.Add(tree.lstParents[0]);
            }
        }