Пример #1
0
        /// <summary>
        /// Parses the json tree recursive.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="treeJson">The tree json.</param>
        private void ParseJsonTreeRecursive(ASTreeViewNode parent, JsonArray treeJson)
        {
            for (int i = 0; i < treeJson.Count; i++)
            {
                IJsonType type = treeJson[i];

                if (type is JsonObject)
                {
                    JsonObject     joTreeNode = (JsonObject)type;
                    ASTreeViewNode curNode    = ParseJsonToNode(joTreeNode);

                    if (i + 1 < treeJson.Count)
                    {
                        //test next item
                        IJsonType nextType = treeJson[i + 1];
                        if (nextType is JsonArray)
                        {
                            //has children
                            ParseJsonTreeRecursive(curNode, (JsonArray)nextType);

                            //skip next
                            i++;
                        }
                    }

                    parent.AppendChild(curNode);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Converts the XML node recursive.
        /// </summary>
        /// <param name="parentNode">The parent node.</param>
        /// <param name="node">The node.</param>
        private void ConvertXmlNodeRecursive(ASTreeViewNode parentNode, XmlNode node)
        {
            XmlNodeList childNodes = node.SelectNodes("astreeview-nodes/astreeview-node");

            if (childNodes == null || childNodes.Count == 0)
            {
                return;
            }

            foreach (XmlNode childNode in childNodes)
            {
                ASTreeViewNode treeNode = ConvertXmlNodeToTreeNode(childNode);

                parentNode.AppendChild(treeNode);

                ConvertXmlNodeRecursive(treeNode, childNode);
            }
        }
        /// <summary>
        /// Builds the tree from data source.
        /// </summary>
        /// <param name="parentNode">The parent node.</param>
        /// <param name="dataSource">The data source.</param>
        /// <param name="parentNodeValue">The parent node value.</param>
        public override void BuildTreeFromDataSource(ASTreeViewNode parentNode, object dataSource, object parentNodeValue)
        {
            DataTable dt          = (DataTable)dataSource;
            string    parentValue = ( string )parentNodeValue;

            if (string.IsNullOrEmpty(this.NodeTextColumnName) ||
                string.IsNullOrEmpty(this.NodeValueColumnName) ||
                string.IsNullOrEmpty(this.ParentNodeValueColumnName))
            {
                throw new ArgumentNullException("Missing minimal descriptor information!");
            }

            string whereClause = string.Empty;

            if (parentValue != null)
            {
                string pattern = this.AddSingleQuotationOnQuery ? "[{0}]='{1}'" : "[{0}]={1}";

                whereClause = string.Format(pattern, this.ParentNodeValueColumnName, parentValue);
            }
            else
            {
                whereClause = string.Format("[{0}] is NULL", this.ParentNodeValueColumnName);
            }

            DataRow[] drs = dt.Select(whereClause);
            foreach (DataRow dr in drs)
            {
                //convert node
                ASTreeViewNode node = new ASTreeViewNode();
                node.NodeText  = GetString(dr[this.NodeTextColumnName], true);
                node.NodeValue = GetString(dr[this.NodeValueColumnName], true);
                parentNode.AppendChild(node);


                string currentNodeValue = node.NodeValue;
                //call recursively
                BuildTreeFromDataSource(node, dt, currentNodeValue);
            }
        }