Beispiel #1
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Loads category trees. </summary>
        ///
        /// <remarks>   SV Milovanov, 30.01.2018. </remarks>
        ///
        /// <param name="parentNode">   The parent node. </param>
        /// <param name="parentValue">  The parent value. </param>
        /// <param name="prevValue">    (Optional) The previous value. </param>
        ///-------------------------------------------------------------------------------------------------

        void LoadCategoryTrees(CategoryTree parentNode, string parentValue, string prevValue = null)
        {
            _DCT.Execute(data =>
            {
                var byDataId = false;

                if (string.IsNullOrEmpty(parentValue))
                {
                    var div = WebWorker.WebDocument.GetElementsByTagName("div").Cast <HtmlElement>()
                              .LastOrDefault(q => q.GetAttribute("className") == "form-category js-form-category_param");
                    if (div != null)
                    {
                        parentValue = div.GetAttribute("data-param-id");
                        byDataId    = true;
                    }
                }
                if (string.IsNullOrEmpty(parentValue) || parentValue == prevValue)
                {
                    return;
                }

                if (!checkedIds.Contains(parentValue))
                {
                    checkedIds.Add(parentValue);
                }
                else if (byDataId)
                {
                    return;
                }


                var level = byDataId
                    ? WebWorker.WebDocument.GetElementsByTagName("input").Cast <HtmlElement>()
                            .Where(q => q.GetAttribute("type") == "radio" && q.GetAttribute("name") == $"params[{parentValue}]")
                    : WebWorker.WebDocument.GetElementsByTagName("input").Cast <HtmlElement>()
                            .Where(q => q.GetAttribute("type") == "radio" && q.GetAttribute("data-parent-id") == parentValue);

                foreach (var element in level)
                {
                    //var elementValue = element.GetAttribute("value");
                    var node = new CategoryTree(element.GetAttribute("title"));
                    parentNode.AddChild(node);

                    element.InvokeMember("click");
                    Thread.Sleep(1000);
                    LoadCategoryTrees(node, null, parentValue);
                }
            });
        }