private void GetCusRequirements(HtmlNodeNavigator lotNav, MySqlConnection connect, int idLot, int customerId)
        {
            var delivPlace = (lotNav
                              .SelectSingleNode(
                                  "./following-sibling::tr/th[contains(text(), 'Место поставки товара, выполнения работ, оказания услуг')]/following-sibling::td/div")
                              ?.Value ?? "").ReplaceHtmlEntyty().Trim();
            var delivTerm = (lotNav
                             .SelectSingleNode(
                                 "./following-sibling::tr/th[contains(text(), 'Срок поставки')]/following-sibling::td")
                             ?.Value ?? "").Trim();

            if (!string.IsNullOrEmpty(delivTerm) || !string.IsNullOrEmpty(delivPlace))
            {
                var insertCustomerRequirement =
                    $"INSERT INTO {AppBuilder.Prefix}customer_requirement SET id_lot = @id_lot, id_customer = @id_customer, delivery_place = @delivery_place, max_price = @max_price, delivery_term = @delivery_term";
                var cmd16 = new MySqlCommand(insertCustomerRequirement, connect);
                cmd16.Prepare();
                cmd16.Parameters.AddWithValue("@id_lot", idLot);
                cmd16.Parameters.AddWithValue("@id_customer", customerId);
                cmd16.Parameters.AddWithValue("@delivery_place", delivPlace);
                cmd16.Parameters.AddWithValue("@max_price", "");
                cmd16.Parameters.AddWithValue("@delivery_term", delivTerm);
                cmd16.ExecuteNonQuery();
            }
        }
Exemple #2
0
 private void AddOrganizer(MySqlConnection connect, HtmlNodeNavigator navigator, out int organiserId)
 {
     organiserId = 0;
     if (!string.IsNullOrEmpty(_tn.OrgName))
     {
         var selectOrg =
             $"SELECT id_organizer FROM {AppBuilder.Prefix}organizer WHERE full_name = @full_name";
         var cmd3 = new MySqlCommand(selectOrg, connect);
         cmd3.Prepare();
         cmd3.Parameters.AddWithValue("@full_name", _tn.OrgName);
         var dt3      = new DataTable();
         var adapter3 = new MySqlDataAdapter {
             SelectCommand = cmd3
         };
         adapter3.Fill(dt3);
         if (dt3.Rows.Count > 0)
         {
             organiserId = (int)dt3.Rows[0].ItemArray[0];
         }
         else
         {
             var phone = navigator.SelectSingleNode(
                 "//td[contains(., 'Номер контактного телефона заказчика')]/following-sibling::td")
                         ?.Value?.Trim() ??
                         "";
             var email = navigator.SelectSingleNode(
                 "//td[contains(., 'Контактный адрес e-mail:')]/following-sibling::td")
                         ?.Value
                         ?.Trim() ??
                         "";
             var contactPerson = navigator.SelectSingleNode(
                 "//td[contains(., 'Контактное лицо:') or contains(., 'Ответственное лицо:')]/following-sibling::td")
                                 ?.Value?.Trim() ??
                                 "";
             var postAddr = navigator.SelectSingleNode(
                 "//td[contains(., 'Почтовый адрес заказчика:')]/following-sibling::td")
                            ?.Value?.Trim() ??
                            "";
             var address = navigator.SelectSingleNode(
                 "//td[contains(., 'Местонахождение заказчика:')]/following-sibling::td")
                           ?.Value?.Trim() ?? "";
             var addOrganizer =
                 $"INSERT INTO {AppBuilder.Prefix}organizer SET full_name = @full_name, contact_phone = @contact_phone, contact_person = @contact_person, contact_email = @contact_email, post_address = @post_address, fact_address = @fact_address";
             var cmd4 = new MySqlCommand(addOrganizer, connect);
             cmd4.Prepare();
             cmd4.Parameters.AddWithValue("@full_name", _tn.OrgName);
             cmd4.Parameters.AddWithValue("@contact_phone", phone);
             cmd4.Parameters.AddWithValue("@contact_person", contactPerson);
             cmd4.Parameters.AddWithValue("@contact_email", email);
             cmd4.Parameters.AddWithValue("@post_address", postAddr);
             cmd4.Parameters.AddWithValue("@fact_address", address);
             cmd4.ExecuteNonQuery();
             organiserId = (int)cmd4.LastInsertedId;
         }
     }
 }
Exemple #3
0
        private void FillNoticeVer(HtmlNodeNavigator navigator, out string noticeVer)
        {
            var comments = navigator.SelectSingleNode(
                "//td[b[. = 'Комментарии:']]")
                           ?.Value?.Trim() ??
                           "";
            var providingDocumentation = navigator.SelectSingleNode(
                "//td[contains(., 'Порядок предоставления документации по закупке:')]/following-sibling::td")
                                         ?.Value?.Trim() ??
                                         "";

            noticeVer = $"{comments}\nПорядок предоставления документации по закупке: {providingDocumentation}".Trim();
        }
        protected bool RunHtmlPathSearch()
        {
            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(htmlText);
            HtmlNodeNavigator navigator = (HtmlNodeNavigator)document.CreateNavigator();

            //https://stackoverflow.com/questions/1390568/how-can-i-match-on-an-attribute-that-contains-a-certain-string
            //sample htmlPath to get download link: @"//a[contains(@class, 'ModDetails_hidden')]//@href"
            //HtmlNodeCollection clientVersionNode = node.SelectNodes(@"//div[contains(@class, 'ModDetails_label')]");
            Logging.Debug(LogOptions.ClassName, "Searching using html path: {0}", HtmlPath);
            try
            {
                ResultNode = navigator.SelectSingleNode(HtmlPath) as HtmlNodeNavigator;
            }
            catch (XPathException ex)
            {
                Logging.Exception(ex.ToString());
                return(false);
            }

            if (ResultNode == null)
            {
                Logging.Info(LogOptions.ClassName, "Result was not found");
                return(false);
            }
            else
            {
                Logging.Info(LogOptions.ClassName, "HtmlPath results in node value '{0}' of type '{1}'", ResultNode.InnerXml, ResultNode.NodeType.ToString());
                Logging.Info(LogOptions.ClassName, "Result value as text: {0}\nResult inner html: {1}\nResult outer html: {2}", ResultNode.Value, ResultNode.InnerXml, ResultNode.OuterXml);
                ResultString = ResultNode.ToString();
                return(true);
            }
        }
        private void GetPurchaseObjects(HtmlNodeNavigator lotNav, MySqlConnection connect,
                                        int idLot,
                                        int customerId)
        {
            var okpd2 = (lotNav
                         .SelectSingleNode(
                             "./following-sibling::tr/th[.contains(text(), 'Код ОКРБ')]/following-sibling::td")
                         ?.Value ?? "").Trim();
            var purObjects = lotNav.Select(
                "./td[2]/text()");

            if (purObjects is null)
            {
                return;
            }
            foreach (XPathNavigator po in purObjects)
            {
                var namePo        = po?.Value?.ReplaceHtmlEntyty()?.Trim() ?? "";
                var insertLotitem =
                    $"INSERT INTO {AppBuilder.Prefix}purchase_object SET id_lot = @id_lot, id_customer = @id_customer, name = @name, quantity_value = @quantity_value, okei = @okei, customer_quantity_value = @customer_quantity_value, price = @price, sum = @sum, okpd2_code = @okpd2_code";
                var cmd19 = new MySqlCommand(insertLotitem, connect);
                cmd19.Prepare();
                cmd19.Parameters.AddWithValue("@id_lot", idLot);
                cmd19.Parameters.AddWithValue("@id_customer", customerId);
                cmd19.Parameters.AddWithValue("@name", namePo);
                cmd19.Parameters.AddWithValue("@quantity_value", "");
                cmd19.Parameters.AddWithValue("@okei", "");
                cmd19.Parameters.AddWithValue("@customer_quantity_value", "");
                cmd19.Parameters.AddWithValue("@price", "");
                cmd19.Parameters.AddWithValue("@sum", "");
                cmd19.Parameters.AddWithValue("@okpd2_code", okpd2);
                cmd19.ExecuteNonQuery();
            }
        }
Exemple #6
0
        private static ScrapeInfo useXPath()
        {
            ScrapeInfo values = new ScrapeInfo();

            HtmlWeb           webClient          = new HtmlWeb();
            HtmlDocument      firstInventoryPage = webClient.Load(url);
            HtmlNodeNavigator navigator          = (HtmlNodeNavigator)firstInventoryPage.DocumentNode.SelectSingleNode("//div[contains(@class,\"hproduct\")][@data-index-position=\"1\"]").CreateNavigator();

            values.Vin      = navigator.SelectSingleNode("@data-vin").Value;
            values.Price    = navigator.SelectSingleNode("//span[contains(@class,\"internetPrice\")]//span[@class=\"value\"]/text()").Value;
            values.Make     = navigator.SelectSingleNode("@data-make").Value;
            values.Model    = navigator.SelectSingleNode("@data-model").Value;
            values.PhotoUrl = navigator.SelectSingleNode("//div[@class=\"media\"]//img/@src").Value;

            return(values);
        }
Exemple #7
0
        private void FillBidAndScorDates(HtmlNodeNavigator navigator, out DateTime scoringDate,
                                         out DateTime biddingDate)
        {
            var scoringDateT =
                navigator.SelectSingleNode(
                    "//td[contains(., 'Дата и время рассмотрения заявок:') or contains(., 'Дата рассмотрения заявок:')]/following-sibling::td")
                ?.Value?.Trim() ??
                "";

            scoringDate = scoringDateT.ParseDateUn("dd.MM.yyyy HH:mm");
            var biddingDateT =
                navigator.SelectSingleNode(
                    "//td[contains(., 'Дата начала аукциона')]/following-sibling::td")?.Value?.Trim() ??
                "";

            biddingDate = biddingDateT.ParseDateUn("dd.MM.yyyy HH:mm");
        }
Exemple #8
0
        private void AddPurObjectFirst(MySqlConnection connect, int customerId, HtmlNodeNavigator nav, int idLot,
                                       string lotName, string sum)
        {
            var okpd2 = nav.SelectSingleNode(
                "//td[contains(., 'Категория ОКПД2:')]/following-sibling::td/div/b")
                        ?.Value?.Trim() ??
                        "";
            var okpdName = nav.SelectSingleNode(
                "//td[contains(., 'Категория ОКПД2:')]/following-sibling::td/div")
                           ?.Value?.ReplaceHtmlEntyty().Trim() ??
                           "";

            if (!string.IsNullOrEmpty(okpd2))
            {
                okpdName = okpdName.Replace(okpd2, "");
            }

            if (okpdName.Contains("Показать все"))
            {
                okpdName = "";
            }

            var quantity = nav.SelectSingleNode(
                "//td[contains(., 'Количество:')]/following-sibling::td")
                           ?.Value?.Trim().ExtractPrice() ??
                           "";
            var insertLotitem =
                $"INSERT INTO {AppBuilder.Prefix}purchase_object SET id_lot = @id_lot, id_customer = @id_customer, name = @name, sum = @sum, okpd2_code = @okpd2_code, okpd2_group_code = @okpd2_group_code, okpd2_group_level1_code = @okpd2_group_level1_code, okpd_name = @okpd_name, quantity_value = @quantity_value, customer_quantity_value = @customer_quantity_value, okei = @okei, price = @price";
            var cmd19 = new MySqlCommand(insertLotitem, connect);

            cmd19.Prepare();
            cmd19.Parameters.AddWithValue("@id_lot", idLot);
            cmd19.Parameters.AddWithValue("@id_customer", customerId);
            cmd19.Parameters.AddWithValue("@name", lotName);
            cmd19.Parameters.AddWithValue("@sum", sum);
            cmd19.Parameters.AddWithValue("@okpd2_code", okpd2);
            cmd19.Parameters.AddWithValue("@okpd2_group_code", "");
            cmd19.Parameters.AddWithValue("@okpd2_group_level1_code", "");
            cmd19.Parameters.AddWithValue("@okpd_name", okpdName);
            cmd19.Parameters.AddWithValue("@quantity_value", quantity);
            cmd19.Parameters.AddWithValue("@customer_quantity_value", quantity);
            cmd19.Parameters.AddWithValue("@okei", "");
            cmd19.Parameters.AddWithValue("@price", "");
            cmd19.ExecuteNonQuery();
        }
Exemple #9
0
        /// <summary>
        /// 根据相对路径XPath从单一Item的BaseNode节点提取某一个字段的Node的InnerText
        /// </summary>
        /// <param name="BaseNode">一个Item的根节点</param>
        /// <param name="RelXPath">相对XPath路径</param>
        /// <param name="CleanConnectionMark">是否清洗文本</param>
        /// <returns></returns>
        internal static string ExtractInnerTextFromBaseNode(HtmlNode BaseNode, string RelXPath, int postion, bool CleanConnectionMark = true)
        {
            if (BaseNode == null)
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(RelXPath))
            {
                if (CleanConnectionMark)
                {
                    return(TextCleaner.FullClean(XPathUtility.InnerTextNonDescendants(BaseNode)));
                }
                else
                {
                    return(TextCleaner.FullClean(XPathUtility.InnerTextNonDescendants(BaseNode), true, true, true, false, true, false));
                }
            }

            string innerTextValue = "";

            try
            {
                HtmlNodeNavigator navigator = (HtmlNodeNavigator)BaseNode.CreateNavigator();
                var node = navigator.SelectSingleNode(RelXPath);
                innerTextValue = node.Value;
            }
            catch (Exception ex)
            { }

            if (string.IsNullOrWhiteSpace(innerTextValue))
            {
                IEnumerable <HtmlNode> MatchNodes = BaseNode.SelectNodes(RelXPath);
                if (MatchNodes != null)
                {
                    MatchNodes = MatchNodes.Where(n => !string.IsNullOrEmpty(XPathUtility.InnerTextNonDescendants(n)));
                }
                if (!string.IsNullOrWhiteSpace(RelXPath) && (MatchNodes == null || MatchNodes.Count() == 0))
                {
                    return(null);
                }

                innerTextValue = XPathUtility.InnerTextNonDescendants(MatchNodes.First());
            }

            if (CleanConnectionMark)
            {
                return(TextCleaner.FullClean(innerTextValue));
            }
            else
            {
                return(TextCleaner.FullClean(innerTextValue, true, true, true, false, true, false));
            }
        }
Exemple #10
0
 private void FillPurName(HtmlNodeNavigator navigator)
 {
     if (string.IsNullOrEmpty(_tn.PurName))
     {
         var firstPurName = navigator.SelectSingleNode(
             "//div[@class = 's2']")
                            ?.Value?.Trim() ??
                            "";
         _tn.PurName = $"{_tn.FullPw} {firstPurName}";
     }
 }
Exemple #11
0
        private void AddOneLot(HtmlNodeNavigator navigator, MySqlConnection connect, int idTender,
                               int customerId)
        {
            var currency = navigator.SelectSingleNode(
                "//td[contains(., 'Вид валюты:')]/following-sibling::td")
                           ?.Value?.Trim() ??
                           "руб.";
            var nmckT = navigator.SelectSingleNode(
                "//td[contains(., 'Начальная (максимальная) цена договора:' ) or contains(., 'Начальная цена всего лота:') or contains(., 'Общая стоимость')]/following-sibling::td/b")
                        ?.Value?.Trim() ??
                        "";
            var nmck    = nmckT.ExtractPrice();
            var lotName = navigator.SelectSingleNode(
                "//div[@class = 'expandable-text short' or @class = 'expandable-text full']/span")
                          ?.Value?.Trim() ??
                          "";

            if (string.IsNullOrEmpty(lotName.DelAllWhitespace()))
            {
                lotName = _tn.PurName;
            }

            var lotNum    = 1;
            var insertLot =
                $"INSERT INTO {AppBuilder.Prefix}lot SET id_tender = @id_tender, lot_number = @lot_number, max_price = @max_price, currency = @currency, finance_source = @finance_source, lot_name = @lot_name";
            var cmd18 = new MySqlCommand(insertLot, connect);

            cmd18.Prepare();
            cmd18.Parameters.AddWithValue("@id_tender", idTender);
            cmd18.Parameters.AddWithValue("@lot_number", lotNum);
            cmd18.Parameters.AddWithValue("@max_price", nmck);
            cmd18.Parameters.AddWithValue("@currency", currency);
            cmd18.Parameters.AddWithValue("@finance_source", "");
            cmd18.Parameters.AddWithValue("@lot_name", lotName);
            cmd18.ExecuteNonQuery();
            var idLot = (int)cmd18.LastInsertedId;

            AddPurObjectFirst(connect, customerId, navigator, idLot, lotName, nmck);
            AddFirstCustRequirements(connect, customerId, navigator, idLot, nmck);
        }
Exemple #12
0
        //private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        //{
        //    progressBar.Value = e.ProgressPercentage;
        //}
        //private void click_Click(object sender, EventArgs e)
        //{
        //    WebClient webClient = new WebClient();
        //    webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);
        //    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

        //    string sourceFile = $"http://openload.co/stream/Ki5y8-mPcoE~1558022792~95.108.0.0~mdmeUiAb?";
        //    webClient.DownloadFileAsync(new Uri(sourceFile), "test.mp4");
        //}
        //private void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
        //{
        //    MessageBox.Show("The download is completed!");
        //}

        private void button1_Click(object sender, EventArgs e)
        {
            using (var client = new WebClient())
            {
                string page = adres.Text;
                string html = client.DownloadString(page);

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);



                HtmlNodeNavigator navigator = (HtmlNodeNavigator)doc.CreateNavigator();
                string            xPath     = "//*[@id=\"olvideo_html5_api\"]";

                string val = navigator.SelectSingleNode(xPath).Value;
                adres.Text = val;
            }
        }
Exemple #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="storeNumber">the store number to lookup</param>
        /// <param name="rfiNumber">the rfi number to lookup</param>
        /// <param name="htmlDocumentStream">the raw html stream of the rfi if we found it</param>
        /// <returns><see cref="bool"/> true if the RFI was found otherwise false</returns>
        public bool TryNavigateStoreRfi(int storeNumber, int sequence, int rfiNumber, out System.IO.Stream htmlDocumentStream)
        {
            // we have to emulate the way the browser works.  Evoco uses javascript onload events for redirection
            // which means that the httpClient doesn't follow to redirects

            #region RfiSubsystemLogin

            //log into the rfi sub system
            var uri = @"http://www.bldgportal.com/RFI/loginDirect.aspx{0}";

            this.Navigate(String.Format(uri, this.GlobalEvocoId));
            #endregion

            #region Rfisearch
            // the values from the search box are sent as get parameters
            // here we are doing the same, the page that is returned contains a window.location javascript which
            // is fired at the onload event.  the window.location contians the evoco project ID which we need.
            var uriToStoreRfis = String.Format("http://www.bldgportal.com/RFI/Application/Projects/ProjectListGrid.aspx?VCP=true&SEARCH_TYPE=StoreNumber&SEARCH_VALUE={0}&SORT_BY=Store&SORT_DIR=ASC", storeNumber.ToString());

            var thisResponse = this.Navigate(uriToStoreRfis);

            //extract the evoco id
            var navigator = new HtmlNodeNavigator(thisResponse);

            var doc = navigator.CurrentDocument;
            doc.Save(String.Format(@"..\{0}-search.html", storeNumber.ToString()));

            Logger.LoggerAsync.InstanceOf.GeneralLogger.Trace("Attempting to find RFI attachments for {0}", storeNumber.ToString());

            string evocoId = "";

            var scriptNode = navigator.SelectSingleNode(".//script[@event='onload']");

            var regex = new System.Text.RegularExpressions.Regex(@"PROJECT_ID=(?<id>\d+)");

            var match = regex.Match(scriptNode.Value);

            // we initally assume that there is only one matching store
            // if that fails then there may be more than one match store
            if (match.Success)
            {
                var group = match.Groups;

                evocoId = group["id"].Value;
            }
            else // if there are more than one matching store, then we are returned a table with the stores.  we need to select the correct one
            // let's first move and test if we can get to the table with id "projectGrid"
            // if we are successful then we can select the correct store.  otherwise something else went wrong
            {
                if (navigator.MoveToId("projectGrid"))
                {
                    var headerRow = navigator.CurrentNode.SelectSingleNode(@".//tr[contains(concat(' ',@class,' '), ' DataGridFixedHeader ')]");

                    var gridRows = navigator.CurrentNode.SelectNodes(@".//tr[not(contains(concat(' ',@class,' '), ' DataGridFixedHeader '))]");

                    var storeIndexLocation = 0;

                    // loop over the header rows until we encounter the node that has the word "store".  save the index value so we can quickly jump to that location in the data rows.
                    while (!headerRow.ChildNodes[storeIndexLocation].InnerText.Contains("Store"))
                    {
                        storeIndexLocation++;
                    }

                    var storeNumberAndSequence = String.Format("{0}-{1}", storeNumber.ToString(), sequence.ToString("D3"));

                    foreach (var dataRow in gridRows)
                    {
                        if (dataRow.ChildNodes[storeIndexLocation].InnerText == storeNumberAndSequence)
                        {
                            match = regex.Match(dataRow.GetAttributeValue("onclick", ""));

                            evocoId = match.Groups["id"].Value;
                        }
                    }
                }
            }

            //use the evoco id to get the list of open RFIs
            var uriToRfiList = String.Format("http://www.bldgportal.com/RFI/Application/Project/RFI/RFIListGrid.aspx?PROJECT_ID={0}&FILTER_BY=OPEN", evocoId);
            #endregion

            #region GetRfiTable
            //find the rfi in the table
            //rfis live in a <table id="RFIGrid"><tr><td></td><td onClick="ShowModalDialog('RFIResponse.aspx?RID=XXXXX','650px','800px');" >XX</td></tr></table>
            //



            //if there are no open RFIs then there is a <span id="noRFISFound"></span> which says no RFI where found.

            thisResponse = this.Navigate(uriToRfiList);

            navigator = new HtmlNodeNavigator(thisResponse);
            #endregion

            #region ProcessRfiRequest
            #region NoOpenRfis
            var success = navigator.MoveToId("noRFISFound");

            if (success)
            {
                // no open Rfis where found
                htmlDocumentStream = new System.IO.MemoryStream();

                return(false);

                #endregion
                #region FoundOpenRfis
            }
            else
            {
                // found some open Rfis
                success = navigator.MoveToId("RFIGrid");

                doc = navigator.CurrentDocument;
                doc.Save(String.Format(@"..\{0}.html", storeNumber.ToString()));

                var rowNodes = navigator.CurrentNode.SelectNodes(".//tr[@id]");

                #region RfiIteration
                foreach (var row in rowNodes)
                {
                    // the rfi number is found in the third child node
                    var cell = row.ChildNodes[2];

                    #region RfiTestForNumberMatch
                    if (cell.InnerText == rfiNumber.ToString())
                    {
                        var onClickAttribute = cell.GetAttributeValue("onclick", "");

                        regex = new System.Text.RegularExpressions.Regex(@"RID=(?<id>\d+)");

                        match = regex.Match(onClickAttribute);

                        var group = match.Groups;

                        string rfiId = group["id"].Value;

                        // uri for rfi using rfi id http://www.bldgportal.com/RFI/Application/Project/RFI/RFIResponse.aspx?RID=194553
                        var uriToRfi = string.Format("http://www.bldgportal.com/RFI/Application/Project/RFI/RFIResponse.aspx?RID={0}", rfiId);

                        thisResponse = this.Navigate(uriToRfi);

                        navigator = new HtmlNodeNavigator(thisResponse);

                        // the attachments are located in an iframe.  We get the path to post data to from the src attribute of the ifram node
                        var iframeNode = navigator.CurrentNode.SelectSingleNode(@"//iframe");

                        var filePath = iframeNode.GetAttributeValue("src", "");

                        // here we need to trim off the path notation "../../"
                        filePath = filePath.Substring(5);

                        filePath = filePath.Replace("&amp;", "&");

                        // concat the file path with the base uri
                        var uriToFile = "http://www.bldgportal.com/RFI/Application/" + filePath;

                        htmlDocumentStream = this.Navigate(uriToFile);

                        return(true);
                    }
                    #endregion
                }
                #endregion
                // didn't find the RFI in the table
                htmlDocumentStream = new System.IO.MemoryStream();

                return(false);
            }
            #endregion
            #endregion
        }
Exemple #14
0
        private JToken GetValueForJTokenRecursively(NodeAttribute node, HtmlNode htmlNode) // TODO: see if it is possible to use the same HTMLNode/Htmldocument through out the extractions.
        {
            JToken jToken = "";

            if (node.GetMultipleFromPage)
            {
                JArray jArray = new JArray();
                if (node.Type == NodeType.String || node.Type == NodeType.Number || node.Type == NodeType.Boolean) // basic types
                {
                    HtmlNodeCollection elements = htmlNode.SelectNodes(node.Xpath);
                    if (elements != null)
                    {
                        foreach (var element in elements)
                        {
                            HtmlNodeNavigator navigator = (HtmlNodeNavigator)element.CreateNavigator();
                            if (navigator.Value.Trim() == "")
                            {
                                continue;
                            }
                            jArray.Add(navigator.Value.Trim());
                        }
                        jToken = jArray;
                    }
                }
                else if (node.Type == NodeType.Object && node.Attributes.Count > 0) // complex types
                {
                    JObject            jObject  = new JObject();
                    HtmlNodeCollection elements = htmlNode.SelectNodes(node.Xpath);
                    if (elements != null)
                    {
                        foreach (var element in elements)
                        {
                            foreach (var attribute in node.Attributes)
                            {
                                JToken value = GetValueForJTokenRecursively(attribute, element);
                                if (value.ToString() == "" && attribute.IsRequired)
                                {
                                    return(jToken);
                                }
                                jObject.Add(attribute.Name, value);
                            }
                            jArray.Add(jObject);
                        }
                        jToken = jArray;
                    }
                }
            }
            else
            {
                HtmlNodeNavigator navigator = (HtmlNodeNavigator)htmlNode.CreateNavigator();
                if (node.Type == NodeType.String || node.Type == NodeType.Number || node.Type == NodeType.Boolean) // basic types
                {
                    XPathNavigator nodeFound = navigator.SelectSingleNode(node.Xpath);
                    // Get as Type
                    if (nodeFound != null)
                    {
                        if (nodeFound.Value.Trim() == "")
                        {
                            return(jToken);
                        }
                        jToken = nodeFound.Value.Trim();
                    }
                }
                else if (node.Type == NodeType.Object && node.Attributes.Count > 0) // complex types
                {
                    HtmlNode element = htmlNode.SelectSingleNode(node.Xpath);
                    if (element != null)
                    {
                        JObject jObject = new JObject();
                        foreach (var attribute in node.Attributes)
                        {
                            JToken value = GetValueForJTokenRecursively(attribute, element);
                            if (value.ToString() == "" && attribute.IsRequired)
                            {
                                return(jToken);
                            }
                            jObject.Add(attribute.Name, value);
                        }
                        jToken = jObject;
                    }
                }
            }
            return(jToken);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ExportBuildString         = "{\"accountId\":212929151,\"itemSets\":";
            Button[,] skillOrderArray =
            {
                { Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18 },
                { W1, W2, W3, W4, W5, W6, W7, W8, W9, W10, W11, W12, W13, W14, W15, W16, W17, W18 },
                { E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E16, E17, E18 },
                { R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16, R17, R18 }
            };

            PictureBox[] Frequentbuild = new PictureBox[] { pictureBox2, pictureBox3, pictureBox4, pictureBox5, pictureBox6, pictureBox7 };

            HtmlWeb web = new HtmlWeb();

            HtmlAgilityPack.HtmlDocument doc;
            try
            {
                doc = web.Load("https://champion.gg/champion/" + champText.Text + "/" + positionText.Text);
            }
            catch
            {
                MessageBox.Show("That Champion Doesn't exist!");
                return;
            }

            HtmlNodeNavigator navigator = (HtmlAgilityPack.HtmlNodeNavigator)doc.CreateNavigator();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 18; j++)
                {
                    var test = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[3]/div[1]/div[2]/div[" + (i + 1) + "]/div[1]/div[" + (j + 1) + "]/div[1]/div");
                    if (test != null)
                    {
                        skillOrderArray[i, j].BackColor = Color.FromArgb(51, 255, 255);
                        skillOrderArray[i, j].Text      = "";
                    }
                    else
                    {
                        skillOrderArray[i, j].BackColor = Color.FromArgb(38, 51, 66);
                        skillOrderArray[i, j].Text      = "";
                    }
                }
            }
            //Frequentbuild[0].LoadAsync
            for (int i = 0; i < 6; i++)
            {
                var node = (navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[1]/div[3]/div/div/div[" + (i + 1) + "]/div[1]/img"));
                Frequentbuild[i].LoadAsync(node.GetAttribute("src", node.NamespaceURI));
                Frequentbuild[i].SizeMode = PictureBoxSizeMode.StretchImage;
            }

            string keyStoneTitle       = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[1]/div[4]/div/span").Value;
            var    keyStone1           = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[1]/div[5]/div/span").Value;
            string keyStone2           = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[1]/div[6]/div/span").Value;
            string keyStone3           = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[1]/div[7]/div/span").Value;
            string keyStone4           = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[1]/div[8]/div/span").Value;
            string secondaryStoneTitle = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[2]/div[2]/div/span").Value;
            string secondaryStone1     = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[2]/div[3]/div/span").Value;
            string secondaryStone2     = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[2]/div[4]/div/span").Value;
            string extra1 = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[2]/div[7]/div/span").Value;
            string extra2 = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[2]/div[8]/div/span").Value;
            string extra3 = navigator.SelectSingleNode("/html/body/div/div/div[2]/div[3]/div/div/div[1]/div/div[1]/div[3]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[2]/div[9]/div/span").Value;

            RuneTitle.Text          = keyStoneTitle;
            Rune1.Text              = keyStone1;
            Rune2.Text              = keyStone2;
            Rune3.Text              = keyStone3;
            Rune4.Text              = keyStone4;
            SecondaryPathTitle.Text = secondaryStoneTitle;
            SecondaryPath1.Text     = secondaryStone1;
            SecondaryPath2.Text     = secondaryStone2;
            extrarune1.Text         = extra1;
            extrarune2.Text         = extra2;
            extrarune3.Text         = extra3;
            string temp = champText.Text.ToLower();

            char[] tempChar = temp.ToCharArray();
            for (int i = 0; i < tempChar.Length; i++)
            {
                if (i - 1 > 0)
                {
                    if (tempChar[i - 1] == ' ')
                    {
                        tempChar[i] = char.ToUpper(tempChar[i]);
                    }
                }
                else if (i == 0)
                {
                    tempChar[i] = char.ToUpper(tempChar[i]);
                }
            }
            temp = new string(tempChar);
            temp = temp.Replace(" ", "");
            temp = temp.Replace("\'", "");
            pictureBox1.WaitOnLoad = false;
            pictureBox1.LoadAsync("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/champion/" + temp + ".png");
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        }
Exemple #16
0
        private void AddLot(HtmlNodeNavigator navigator, MySqlConnection connect, int idTender, int customerId,
                            HtmlNode lot, out bool lotWasAdded)
        {
            lotWasAdded = false;
            var lotNumT      = lot.InnerText?.Trim().GetDataFromRegex(@"Лот № (\d+)");
            var succesLotNum = int.TryParse(lotNumT, out var lotNum);

            if (!succesLotNum)
            {
                lotNum = 1;
            }
            var lotHref = lot.Attributes["href"]?.Value ?? "";

            if (!string.IsNullOrEmpty(lotHref))
            {
                return;
            }
            lotHref = $"https://www.b2b-center.ru{lotHref}";
            var sLot = DownloadString.DownLHttpPostWithCookiesB2b(lotHref, ParserB2BWeb.CookieCollection,
                                                                  useProxy: AppBuilder.UserProxy);

            if (string.IsNullOrEmpty(sLot))
            {
                Log.Logger("Empty string in lot ParsingTender()", lotHref);
                return;
            }

            var htmlLot = new HtmlDocument();

            htmlLot.LoadHtml(sLot);
            var navLot = (HtmlNodeNavigator)htmlLot.CreateNavigator();
            var priceT = navLot.SelectSingleNode(
                "//td[contains(., 'Цена за единицу продукции:')]/following-sibling::td/b")
                         ?.Value?.Trim() ??
                         "";
            var currency = navigator.SelectSingleNode(
                "//td[contains(., 'Вид валюты:')]/following-sibling::td")
                           ?.Value?.Trim() ??
                           "руб.";
            var price = priceT.ExtractPrice();
            var nmckT = navigator.SelectSingleNode(
                "//td[contains(., 'Начальная (максимальная) цена договора:' ) or contains(., 'Начальная цена всего лота:') or contains(., 'Общая стоимость')]/following-sibling::td/b")
                        ?.Value?.Trim() ??
                        "";
            var nmck    = nmckT.ExtractPrice();
            var lotName = navLot.SelectSingleNode(
                "//div[@class = 'expandable-text short']/span")
                          ?.Value?.Trim() ??
                          "";

            if (string.IsNullOrEmpty(lotName.DelAllWhitespace()))
            {
                lotName = _tn.PurName;
            }

            var insertLot =
                $"INSERT INTO {AppBuilder.Prefix}lot SET id_tender = @id_tender, lot_number = @lot_number, max_price = @max_price, currency = @currency, finance_source = @finance_source, lot_name = @lot_name";
            var cmd18 = new MySqlCommand(insertLot, connect);

            cmd18.Prepare();
            cmd18.Parameters.AddWithValue("@id_tender", idTender);
            cmd18.Parameters.AddWithValue("@lot_number", lotNum);
            cmd18.Parameters.AddWithValue("@max_price", nmck);
            cmd18.Parameters.AddWithValue("@currency", currency);
            cmd18.Parameters.AddWithValue("@finance_source", "");
            cmd18.Parameters.AddWithValue("@lot_name", lotName);
            cmd18.ExecuteNonQuery();
            var idLot = (int)cmd18.LastInsertedId;

            lotWasAdded = true;
            AddPurObject(connect, customerId, navLot, idLot, lotName, price);
            AddCustRequirements(connect, customerId, navLot, idLot, nmck);
        }
Exemple #17
0
        private void AddCustRequirements(MySqlConnection connect, int customerId, HtmlNodeNavigator navLot,
                                         int idLot,
                                         string nmck)
        {
            var delivPlace = navLot.SelectSingleNode(
                "//td[contains(., 'Адрес места поставки товара, проведения работ или оказания услуг:')]/following-sibling::td")
                             ?.Value?.Trim() ??
                             "";
            var delivTerm1 = navLot.SelectSingleNode(
                "//td[contains(., 'Условия поставки:')]/following-sibling::td")
                             ?.Value?.Trim() ??
                             "";
            var delivTerm2 = navLot.SelectSingleNode(
                "//td[contains(., 'Условия оплаты:')]/following-sibling::td")
                             ?.Value?.Trim() ??
                             "";
            var delivTerm3 = navLot.SelectSingleNode(
                "//td[contains(., 'При выборе победителя учитывается:')]/following-sibling::td")
                             ?.Value?.Trim() ??
                             "";
            var delivTerm4 = navLot.SelectSingleNode(
                "//td[contains(., 'Требуется обеспечение заявки:')]/following-sibling::td")
                             ?.Value?.Trim() ??
                             "";
            var delivTerm5 = navLot.SelectSingleNode(
                "//td[contains(., 'Банковская гарантия:')]/following-sibling::td")
                             ?.Value?.Trim() ??
                             "";
            var delivTerm6 = navLot.SelectSingleNode(
                "//td[contains(., 'Иной вид обеспечения:')]/following-sibling::td")
                             ?.Value?.Trim() ??
                             "";
            var delivTerm = "";

            if (!string.IsNullOrEmpty(delivTerm1))
            {
                delivTerm = $"{delivTerm}\nУсловия поставки: {delivTerm1}";
            }

            if (!string.IsNullOrEmpty(delivTerm2))
            {
                delivTerm = $"{delivTerm}\nУсловия оплаты: {delivTerm2}";
            }

            if (!string.IsNullOrEmpty(delivTerm3))
            {
                delivTerm = $"{delivTerm}\nПри выборе победителя учитывается: {delivTerm3}";
            }

            if (!string.IsNullOrEmpty(delivTerm4))
            {
                delivTerm = $"{delivTerm}\nТребуется обеспечение заявки: {delivTerm4}";
            }

            if (!string.IsNullOrEmpty(delivTerm5))
            {
                delivTerm = $"{delivTerm}\nБанковская гарантия: {delivTerm5}";
            }

            if (!string.IsNullOrEmpty(delivTerm6))
            {
                delivTerm = $"{delivTerm}\nИной вид обеспечения: {delivTerm6}";
            }

            if (!string.IsNullOrEmpty(delivPlace) || !string.IsNullOrEmpty(delivTerm))
            {
                var insertCustomerRequirement =
                    $"INSERT INTO {AppBuilder.Prefix}customer_requirement SET id_lot = @id_lot, id_customer = @id_customer, delivery_place = @delivery_place, max_price = @max_price, delivery_term = @delivery_term";
                var cmd16 = new MySqlCommand(insertCustomerRequirement, connect);
                cmd16.Prepare();
                cmd16.Parameters.AddWithValue("@id_lot", idLot);
                cmd16.Parameters.AddWithValue("@id_customer", customerId);
                cmd16.Parameters.AddWithValue("@delivery_place", delivPlace);
                cmd16.Parameters.AddWithValue("@max_price", nmck);
                cmd16.Parameters.AddWithValue("@delivery_term", delivTerm.ReplaceHtmlEntyty().Trim());
                cmd16.ExecuteNonQuery();
            }
        }