public ResultType_enum FillWinners(Order order, InternetRequestEngine internetRequestEngine, LotSearched_delegate lotSearched_delegate, out string winnerMessage) { isWinner = false; winnerMessage = ""; HtmlAgilityPack.HtmlNode nodeTmp = null; try { switch (order.LawType.Name.Trim().ToLower()) { #region 44 Закон case ("44"): // Параметры лота string _44lotName = order.Name; long _44lotPrice = order.Price; string _44lotPriceTypeName = order.OrderPriceType.Name; string _44lotOrderHref = @"http://zakupki.gov.ru/epz/order/notice/zp44/view/common-info.html?regNumber=" + order.HrefId; long _44lotDocumentPrice = 0; string _44lotDocumentDateTime = ""; // Параметры победителя string winnerName = ""; string winnerPhone = ""; string winnerEmail = ""; // Закупка string numRegistr = ""; doc = internetRequestEngine.GetHtmlDoc(@"http://zakupki.gov.ru/epz/order/notice/ea44/view/supplier-results.html?regNumber=" + order.HrefId); string checkMessage = ""; ResultType_enum resultTypeCheck = Globals.CheckDocResult(doc, out checkMessage); if (resultTypeCheck != ResultType_enum.Done) { winnerMessage = checkMessage; return resultTypeCheck; } text = "//div[@class=\"cardWrapper\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainBox\"]"; text += "/div[@class=\"noticeTabBox\"]"; text += "/div[@class=\"noticeTabBoxWrapper\"]"; text += "/table"; text += "/tr"; text += "/td"; text += "/table[@class=\"noticeCardTableInBlock contractTable\"]"; text += "/tr"; text += "/td"; text += "/table[@class=\"contractTable displaytagTable\"]"; text += "/tbody"; text += "/tr"; text += "/td"; HtmlAgilityPack.HtmlNodeCollection atrCollection = doc.DocumentNode.SelectNodes(text); // Возможно : Сведения о контракте из реестра контрактов отсутствуют if ((atrCollection == null)/* && (doc.DocumentNode.InnerText.IndexOf("Сведения о контракте из реестра контрактов отсутствуют") > 0)*/) { return ResultType_enum.NotSearch; } int num = 1; foreach (HtmlAgilityPack.HtmlNode atrNode in atrCollection) { switch (num) { case (1): numRegistr = ConvertNum(atrNode.InnerText.Trim()); break; case (4): if (atrNode.InnerText.Trim() != "") { string lotPriceStr = atrNode.InnerText.Trim().Replace(" ", "").ToLower(); try { if (lotPriceStr.IndexOf(',') > -1) { _44lotDocumentPrice = Convert.ToInt64(lotPriceStr.Substring(0, lotPriceStr.IndexOf(','))); } else { if (lotPriceStr.IndexOf(' ') > -1) { _44lotDocumentPrice = Convert.ToInt64(lotPriceStr.Substring(0, lotPriceStr.IndexOf(' '))); } else { _44lotDocumentPrice = Convert.ToInt64(lotPriceStr); } } } catch { string sss = "ывавы"; } } break; case (5): if (atrNode.InnerText.Trim() != "") { _44lotDocumentDateTime = atrNode.InnerText.Trim(); break; } break; default: break; } num++; } // Номер реестровой записи text = @"http://zakupki.gov.ru/epz/contract/contractCard/common-info.html?reestrNumber=" + numRegistr; doc = internetRequestEngine.GetHtmlDoc(text); resultTypeCheck = Globals.CheckDocResult(doc, out checkMessage); if (resultTypeCheck != ResultType_enum.Done) { winnerMessage = checkMessage; return resultTypeCheck; } text = "//div[@class=\"cardWrapper\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainBox\"]"; text += "/div[@class=\"noticeTabBox\"]"; text += "/div[@class=\"noticeTabBoxWrapper\"]"; text += "/table[@class=\"cTdCenter\"]"; text += "/tbody"; text += "/tr"; HtmlAgilityPack.HtmlNodeCollection trCollection = doc.DocumentNode.SelectNodes(text); if (trCollection == null) { return ResultType_enum.NotSearch; } num = 1; int numTd = 1; foreach (HtmlAgilityPack.HtmlNode trNode in trCollection) { if (num == 2) { foreach (HtmlAgilityPack.HtmlNode tdNode in trNode.ChildNodes) { if (tdNode.Name == "td") { switch (numTd) { case (1): // Наименование организации winnerName = Globals.DecodeInternetSymbs(tdNode.InnerHtml.Trim().Replace("<br>", " ")); isWinner = true; break; case (6): // Телефон, электронная почта string emailPhone = tdNode.InnerText.Trim(); if (emailPhone.IndexOf('\n') > -1) { winnerPhone = Globals.DecodeInternetSymbs(emailPhone.Substring(0, emailPhone.IndexOf('\n')).Trim()); winnerEmail = Globals.DecodeInternetSymbs(emailPhone.Substring(emailPhone.IndexOf('\n'), emailPhone.Length - emailPhone.IndexOf('\n')).Trim()); } else { winnerPhone = emailPhone; } break; default: break; } numTd++; } } } num++; } if ((_44lotName != "") && (_44lotPrice != 0) && (_44lotPriceTypeName != "")) { Lot _44lot = new Lot(); _44lot.Order = order; _44lot.Name = _44lotName; if (_44lot.Name.Length > 400) { _44lot.Name = _44lot.Name.Substring(0, 398) + ".."; } _44lot.Price = _44lotPrice; // LotPriceType LotPriceType lotPriceType = mvm.wc.LotPriceTypes.FirstOrDefault(m => m.Name.ToLower().Trim() == _44lotPriceTypeName.ToLower()); if (lotPriceType == null) { lotPriceType = new LotPriceType(); lotPriceType.Name = _44lotPriceTypeName; mvm.wc.LotPriceTypes.Add(lotPriceType); mvm.wc.SaveChanges(); } _44lot.LotPriceType = lotPriceType; _44lot.OrderHref = _44lotOrderHref; _44lot.DocumentPrice = _44lotDocumentPrice; _44lot.CreateDateTime = DateTime.Now; try { if (_44lotDocumentDateTime.IndexOf('(') > -1) { _44lot.DocumentDateTime = Convert.ToDateTime(_44lotDocumentDateTime.Substring(0, _44lotDocumentDateTime.IndexOf('(')).Trim()); } else { _44lot.DocumentDateTime = Convert.ToDateTime(_44lotDocumentDateTime.Trim()); } } catch { string sss = "аыв"; } if (winnerName != "") { mvm.wc.Lots.Add(_44lot); mvm.wc.SaveChanges(); Winner winner = new Winner(); winner.Name = winnerName; winner.Phone = winnerPhone; winner.Email = winnerEmail; winner.Lot = _44lot; mvm.wc.Winners.Add(winner); mvm.wc.SaveChanges(); lotSearched_delegate(winner); } } break; #endregion #region 223 Закон case ("223"): doc = internetRequestEngine.GetHtmlDoc(@"http://zakupki.gov.ru/223/purchase/public/purchase/info/protocols.html?noticeId=" + order.HrefId + @"&epz=true"); resultTypeCheck = Globals.CheckDocResult(doc, out checkMessage); if (resultTypeCheck != ResultType_enum.Done) { winnerMessage = checkMessage; return resultTypeCheck; } // Поиск протоколов text = "//div[@class=\"cardWrapper\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainbox\"]"; text += "/div[@class=\"contentTabBox\"]"; text += "/div[@class=\"contentTabBoxBlock\"]"; text += "/div[@class=\"noticeTabBox \"]"; text += "/div[@class=\"noticeTabBoxWrapper\"]"; text += "/table"; text += "/tbody"; text += "/tr"; HtmlAgilityPack.HtmlNodeCollection trColl = doc.DocumentNode.SelectNodes(text); // Страница не найдена if (trColl == null) return ResultType_enum.NotSearch; // Параметры победителя winnerName = ""; winnerPhone = ""; winnerEmail = ""; // Поиск протоколов с победителем foreach (HtmlAgilityPack.HtmlNode protocolNode in trColl) { text = ".//td[@class=\"descriptTenderTd\"]"; text += "/dl"; text += "/dt"; text += "/a"; HtmlAgilityPack.HtmlNode winnerProtocolNode = protocolNode.SelectSingleNode(text); if (winnerProtocolNode == null) continue; #region Решение комиссии if ((winnerProtocolNode.InnerText.Trim().ToLower().IndexOf("протокол подведения итогов") > -1) || (winnerProtocolNode.InnerText.Trim().ToLower().IndexOf("подведению итогов") > -1) || (winnerProtocolNode.InnerText.Trim().ToLower().IndexOf("оценки и сопоставления заявок") > -1) || (winnerProtocolNode.InnerText.Trim().ToLower().IndexOf("победител") > -1) || (winnerProtocolNode.InnerText.Trim().ToLower().IndexOf("протокол основного этапа закупки") > -1) || (winnerProtocolNode.InnerText.Trim().ToLower().IndexOf("запрос предложений о цене договора") > -1)) { string commissionDecisionMessage = ""; _223commissionDecision.Work(order, internetRequestEngine, winnerProtocolNode, lotSearched_delegate, out commissionDecisionMessage, out isWinner); } #endregion #region Выбор победителя if (winnerProtocolNode.InnerText.Trim().ToLower().IndexOf("протокол запроса котировок") > -1) { string winnerChoiceMessage = ""; // Доделать _223winnerChoice.Work(order, internetRequestEngine, winnerProtocolNode, lotSearched_delegate, out winnerChoiceMessage, out isWinner); } #endregion } break; #endregion default: return ResultType_enum.Done; // !!! Необходимо добавить 94 закон } if (!isWinner) return ResultType_enum.NotSearch; else return ResultType_enum.Done; } catch (Exception ex) { winnerMessage = ex.Message + '\n' + ex.StackTrace; return ResultType_enum.Error; } }
private void SearchCustomers_proc() { try { customers = new ObservableCollection<Customer>(); InternetRequestEngine internetRequestEngine = new InternetRequestEngine(); if (customerName == "") { customersSearchDone_delegate(customers, ResultType_enum.NullSearchText, ""); return; } string lawTypeStr = ""; switch (lawType_enum) { case (LawType_enum._44_94): lawTypeStr = "FZ_44"; break; case (LawType_enum._223): lawTypeStr = "FZ_223"; break; case (LawType_enum._44_94_223): lawTypeStr = "EVERYWHERE"; break; } string customerTypeStr = ""; switch (customerType_enum) { case (CustomerType_enum.Customer): customerTypeStr = "CUSTOMER"; break; case (CustomerType_enum.Organization): customerTypeStr = "REPRESENTATIVE_ORGANIZATION"; break; } text = @"http://zakupki.gov.ru/epz/organization/organization/extended/search/result.html?sortDirection=true&"; text += @"organizationSimpleSorting=PO_NAZVANIYU&recordsPerPage=_100&pageNumber=1&searchText=" + customerName + "&"; text += @"strictEqual=false&morphology=false&placeOfSearch=" + lawTypeStr + "®istrationStatusType=ANY&"; text += @"kpp=&custLev=F%2CS%2CM%2CNOT_FSM&organizationRoleList=" + customerTypeStr + "&"; text += @"okvedCode=&okvedWithSubElements=false&districtIds=®ionIds=&cityIds=&organizationTypeList=&"; text += @"spz=&withBlocked=false&customerIdentifyCode=&headAgencyCode=&headAgencyWithSubElements=false&"; text += @"organizationsWithBranches=false&legalEntitiesTypeList=&ppoWithSubElements=false&ppoCode=&"; text += @"address=" + town + "&town=&publishedOrderClause=true&unpublishedOrderClause=true&bik=&bankRegNum=&"; text += @"bankIdCode="; #region Получение заказчиков, заполнение их параметров doc = internetRequestEngine.GetHtmlDoc(text); string checkMessage = ""; ResultType_enum resultTypeCheck = Globals.CheckDocResult(doc, out checkMessage); if (resultTypeCheck != ResultType_enum.Done) { customersSearchDone_delegate(customers, resultTypeCheck, checkMessage); return; } // Если заказчики не найдены text = "//div[@class=\"outerWrapper mainPage\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainBox\"]"; text += "/div[@class=\"rightCol\"]"; text += "/div[@class=\"content\"]"; text += "/div[@class=\"paginator\"]"; HtmlAgilityPack.HtmlNode htmlNode = doc.DocumentNode.SelectSingleNode(text); if (htmlNode == null) { customersSearchDone_delegate(customers, ResultType_enum.ErrorNetwork, ""); return; } if (htmlNode.InnerText.Trim() == "Поиск не дал результатов") { customersSearchDone_delegate(customers, ResultType_enum.NotSearch, ""); return; } // Определение количества страниц заказчиков int pageCustomersCount = 0; text = "//div[@class=\"outerWrapper mainPage\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainBox\"]"; text += "/div[@class=\"rightCol\"]"; text += "/div[@class=\"content\"]"; text += "/div[@class=\"paginator\"]"; text += "/ul[@class=\"paging\"]/li"; HtmlAgilityPack.HtmlNodeCollection liCollection = doc.DocumentNode.SelectNodes(text); if (liCollection == null) { pageCustomersCount = 1; } else { bool nextTagIsCount = false; foreach (HtmlAgilityPack.HtmlNode node in liCollection) { if (nextTagIsCount) { pageCustomersCount = Convert.ToInt32(node.InnerText); break; } if (node.InnerText.ToLower() == "из") { nextTagIsCount = true; } } } text = "//div[@class=\"outerWrapper mainPage\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainBox\"]"; text += "/div[@class=\"rightCol\"]"; text += "/div[@class=\"content\"]"; text += "/div[@id=\"exceedSphinxPageSizeDiv\"]"; text += "/div[@class=\"registerBox\"]"; HtmlAgilityPack.HtmlNodeCollection customerCollection = doc.DocumentNode.SelectNodes(text); if ((customerCollection == null) || (customerCollection.Count == 0)) { customersSearchDone_delegate(customers, ResultType_enum.NotSearch, ""); return; } // Получение параметров заказчиков int customerNum = 1; Customer customer = null; foreach (HtmlAgilityPack.HtmlNode node in customerCollection) { string customerMessage = ""; customer = new Customer(); ResultType_enum customerResult = FillCustomer(customer, node, internetRequestEngine, out customerMessage); switch (customerResult) { case (ResultType_enum.Error): customersSearchDone_delegate(customers, ResultType_enum.Error, customerMessage); return; default: break; } // Проверить на повтор и записать в БД Customer repeatCustomer = mvm.wc.Customers.FirstOrDefault(m => (m.Name == customer.Name && m.Vatin == customer.Vatin)); if (repeatCustomer != null) { if (repeatCustomer.CustomerTypes.FirstOrDefault(m => m.CustomerTypeCode.Trim().ToLower() == customerType_enum.ToString().ToLower()) == null) { repeatCustomer.CustomerTypes.Add(mvm.wc.CustomerTypes.FirstOrDefault(m => m.CustomerTypeCode.ToLower() == customerType_enum.ToString().ToLower())); } customer = repeatCustomer; } else { customer.CustomerTypes.Add(mvm.wc.CustomerTypes.FirstOrDefault(m => m.CustomerTypeCode.ToLower() == customerType_enum.ToString().ToLower())); customer.CreateDateTime = DateTime.Now; mvm.wc.Customers.Add(customer); mvm.wc.SaveChanges(); } customers.Add(customer); customerNum++; } #endregion //return ResultType.Done; customersSearchDone_delegate(customers, ResultType_enum.Done, ""); } catch (Exception ex) { customersSearchDone_delegate(customers, ResultType_enum.Error, ex.Message + '\n' + ex.StackTrace); return; } }
public ResultType_enum FillCustomer(Customer customer, HtmlAgilityPack.HtmlNode customerNode, InternetRequestEngine internetRequestEngine, out string message) { try { message = ""; HtmlAgilityPack.HtmlNode nodeTmp = null; #region Определение параметров text = ".//table"; //text += "/tbody"; !!!newBrowser text += "/tr"; text += "/td[@class=\"descriptTenderTd\"]"; text += "/dl"; text += "/dt"; text += "/a"; nodeTmp = customerNode.SelectSingleNode(text); // Название заказчика if (nodeTmp.Attributes.Contains("title")) customer.Name = Globals.DecodeInternetSymbs(nodeTmp.Attributes["title"].Value.Trim()); // Определение ID 94 и 223 законов // Есди существует атрибут <href>, значит указана одна ссылка на один закон LawType_enum lawType = LawType_enum.None; Regex regex = new Regex(@"http://.*?Id=\d*"); MatchCollection matchColl = null; if (nodeTmp.Attributes.Contains("href")) { matchColl = regex.Matches(nodeTmp.Attributes["href"].Value); } else { matchColl = regex.Matches(nodeTmp.Attributes["onclick"].Value); } foreach (Match match in matchColl) { string lawID = GetIDLaw(match.Value, out lawType); switch (lawType) { case (LawType_enum._44_94): customer.Law_44_94_ID = lawID; break; case (LawType_enum._223): customer.Law_223_ID = lawID; break; default: break; } //break; } // Уровень организации text = ".//table"; //text += "/tbody"; !!!newBrowser text += "/tr"; text += "/td[@class=\"tenderTd\"]"; text += "/dl"; text += "/dt"; nodeTmp = customerNode.SelectSingleNode(text); CustomerLevel_enum customerLevel = CustomerLevel_enum.None; if (nodeTmp != null) { switch(nodeTmp.InnerText.ToLower().Trim()) { case ("федеральный уровень"): customerLevel = CustomerLevel_enum.Federal; break; case ("уровень субъекта рф"): customerLevel = CustomerLevel_enum.Subject; break; case ("муниципальный уровень"): customerLevel = CustomerLevel_enum.Municipal; break; case ("иное"): customerLevel = CustomerLevel_enum.Other; break; } } customer.CustomerLevel = mvm.wc.CustomerLevels.FirstOrDefault(m => m.CustomerLevelCode == customerLevel.ToString()); // ИНН (VATIN) text = ".//table"; //text += "/tbody"; !!!newBrowser text += "/tr"; text += "/td[@class=\"descriptTenderTd\"]"; text += "/dl"; text += "/dd[@class=\"nameOrganization\"]"; text += "/span"; HtmlAgilityPack.HtmlNodeCollection collectionVatin = customerNode.SelectNodes(text); foreach (HtmlAgilityPack.HtmlNode nodeVatin in collectionVatin) { int vatinIntPos = nodeVatin.InnerText.IndexOf("ИНН:"); if (vatinIntPos > -1) { customer.Vatin = nodeVatin.InnerText.Substring(vatinIntPos + 4, nodeVatin.InnerText.Length - (vatinIntPos + 4)).Trim(); break; } } // Адрес text = ".//table"; //text += "/tbody"; !!!newBrowser text += "/tr"; text += "/td[@class=\"descriptTenderTd\"]"; text += "/dl"; text += "/dd"; HtmlAgilityPack.HtmlNodeCollection adressDDColl = customerNode.SelectNodes(text); if (adressDDColl.Count == 3) { customer.Address = Globals.CutAddress(adressDDColl[2].InnerText.Trim()); } #endregion return ResultType_enum.Done; } catch (Exception ex) { message = ex.Message + "\n\n" + ex.StackTrace; return ResultType_enum.Error; } }
public ResultType_enum Work(Order order, InternetRequestEngine internetRequestEngine, HtmlAgilityPack.HtmlNode winnerProtocolNode, LotSearched_delegate lotSearched_delegate, out string commissionDecisionMessage, out bool isWinner) { try { isWinner = false; commissionDecisionMessage = ""; List<Lot> lotsTemp = new List<Lot>(); List<Winner> winnersTemp = new List<Winner>(); // Получаем ID протокола string protocolHref = winnerProtocolNode.Attributes["onclick"].Value; string protocolID = protocolHref.Substring(protocolHref.IndexOf("protocolInfoId=") + 15, protocolHref.IndexOf("&purchaseId=") - (protocolHref.IndexOf("protocolInfoId=") + 15)); text = @"http://zakupki.gov.ru/223/purchase/public/purchase/protocol/ip/application/comission-decision.html?noticeInfoId=&protocolInfoId=" + protocolID + "&mode=view"; //text = @"http://zakupki.gov.ru/223/purchase/public/purchase/protocol/ip/application/comission-decision.html?noticeInfoId=716491&protocolInfoId=692914&mode=view"; doc = internetRequestEngine.GetHtmlDoc(text); string checkMessage = ""; ResultType_enum resultTypeCheck = Globals.CheckDocResult(doc, out checkMessage); if (resultTypeCheck != ResultType_enum.Done) { commissionDecisionMessage = checkMessage; return resultTypeCheck; } // Поиск лотов text = "//div[@class=\"cardWrapper\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainbox\"]"; text += "/div[@class=\"contentTabBoxBlock\"]"; text += "/div[@class=\"noticeTabBox\"]"; text += "/div[@class=\"noticeTabBoxWrapper\"]"; text += "/div[@class=\"blue-border rootOfLot\"]"; HtmlAgilityPack.HtmlNodeCollection lotsColl = doc.DocumentNode.SelectNodes(text); if (lotsColl == null) return ResultType_enum.NotSearch; string _223lotName = ""; long _223lotPrice = 0; string _223lotPriceTypeName = ""; long _223lotDocumentPrice = 0; string _223lotDocumentDate = ""; Lot _223lot = null; Winner _223winner = null; int num = 1; // Обработка лотов int lotNum = 0; foreach (HtmlAgilityPack.HtmlNode lotNode in lotsColl) { // Заполняем цену и валюту лота _223lotName = ""; _223lotPrice = 0; _223lotPriceTypeName = ""; _223lotDocumentPrice = 0; _223lotDocumentDate = ""; _223lot = new Lot(); _223winner = new Winner(); _223winner.Lot = _223lot; _223lot.Order = order; _223lot.CreateDateTime = DateTime.Now; _223lot.OrderHref = @"http://zakupki.gov.ru/223/purchase/public/purchase/info/common-info.html?noticeId=" + order.HrefId + "&epz=true"; lotsTemp.Add(_223lot); // Получаем цену и валюту лота text = ".//table"; text += "/tr[@class=\"mainExpand\"]"; text += "/td"; text += "/table[@class=\"outertable\"]"; text += "/tr"; HtmlAgilityPack.HtmlNodeCollection lotParamsColl = lotNode.SelectNodes(text); if (lotParamsColl != null) { HtmlAgilityPack.HtmlNode lotParamPriceNode = lotParamsColl[1]; num = 1; foreach (HtmlAgilityPack.HtmlNode tdNode in lotParamPriceNode.ChildNodes) { if (tdNode.Name != "td") continue; if (num == 2) { string priceTypePriceLot = tdNode.InnerText.Trim(); if (priceTypePriceLot.IndexOf(' ') > -1) { string _223lotPriceStr = Globals.DecodeInternetSymbs(priceTypePriceLot.Substring(0, priceTypePriceLot.IndexOf(' ')).Trim()); if (_223lotPriceStr.IndexOf(',') > -1) { _223lotPrice = Convert.ToInt64(_223lotPriceStr.Substring(0, _223lotPriceStr.IndexOf(','))); } else { _223lotPrice = Convert.ToInt64(_223lotPriceStr); } //_223lotPrice = Convert.ToInt64(Globals.DecodeInternetSymbs(priceTypePriceLot.Substring(0, priceTypePriceLot.IndexOf(' ')).Trim())); _223lotPriceTypeName = Globals.DecodeInternetSymbs(priceTypePriceLot.Substring(priceTypePriceLot.IndexOf(' '), priceTypePriceLot.Length - priceTypePriceLot.IndexOf(' ')).Trim()); } break; } num++; } } else { text = ".//table[@class=\"outertable\"]"; text += "/tr"; lotParamsColl = lotNode.SelectNodes(text); if (lotParamsColl != null) { int numTr = 1; foreach (HtmlAgilityPack.HtmlNode trNode in lotParamsColl) { if (trNode.Name != "tr") continue; int numTdParam = 1; switch (numTr) { case (1): numTdParam = 1; foreach (HtmlAgilityPack.HtmlNode tdNode in trNode.ChildNodes) { if (tdNode.Name != "td") continue; if (numTdParam == 1) { _223lotName = Globals.CutLotName(tdNode.InnerText.Trim()); break; } numTdParam++; } break; case (2): numTdParam = 1; foreach (HtmlAgilityPack.HtmlNode tdNode in trNode.ChildNodes) { if (tdNode.Name != "td") continue; if (numTdParam == 2) { string priceTypePriceLot = tdNode.InnerText.Trim(); if (priceTypePriceLot.IndexOf(' ') > -1) { string _223lotPriceStr = Globals.DecodeInternetSymbs(priceTypePriceLot.Substring(0, priceTypePriceLot.IndexOf(' ')).Trim()); if (_223lotPriceStr.IndexOf(',') > -1) { _223lotPrice = Convert.ToInt64(_223lotPriceStr.Substring(0, _223lotPriceStr.IndexOf(','))); } else { _223lotPrice = Convert.ToInt64(_223lotPriceStr); } //_223lotPrice = Convert.ToInt64(Globals.DecodeInternetSymbs(priceTypePriceLot.Substring(0, priceTypePriceLot.IndexOf(' ')).Trim())); _223lotPriceTypeName = Globals.DecodeInternetSymbs(priceTypePriceLot.Substring(priceTypePriceLot.IndexOf(' '), priceTypePriceLot.Length - priceTypePriceLot.IndexOf(' ')).Trim()); break; } } numTdParam++; } break; default: break; } numTr++; } } else { return ResultType_enum.NotSearch; } } if (_223lotName != "") { _223lot.Name = _223lotName; if (_223lot.Name.Length > 400) { _223lot.Name = _223lot.Name.Substring(0, 398) + ".."; } } if ((_223lotPrice != 0) && (_223lotPriceTypeName != "")) { _223lot.Price = _223lotPrice; LotPriceType lotPriceType = mvm.wc.LotPriceTypes.FirstOrDefault(m => m.Name.ToLower().Trim() == _223lotPriceTypeName.ToLower()); if (lotPriceType == null) { lotPriceType = new LotPriceType(); lotPriceType.Name = _223lotPriceTypeName; mvm.wc.LotPriceTypes.Add(lotPriceType); mvm.wc.SaveChanges(); } _223lot.LotPriceType = lotPriceType; } else { // Не указана цена, берем следующий лот continue; } // Получаем список участников text = ".//table"; text += "/tr[@class=\"expandable-row\"]"; text += "/td"; text += "/div[@class=\"clientDemandWrapper\"]"; text += "/table[@class=\"outertable clientDemandTbl\"]"; text += "/tr"; HtmlAgilityPack.HtmlNodeCollection partnerWithHeaderColl = lotNode.SelectNodes(text); // Поиск победителя среди участников int tdnum = 1; isWinner = false; foreach (HtmlAgilityPack.HtmlNode partnerNode in partnerWithHeaderColl) { if (partnerNode.Attributes.Count > 0) continue; tdnum = 1; string nameTmp = ""; foreach (HtmlAgilityPack.HtmlNode tdNode in partnerNode.ChildNodes) { if (tdNode.Name != "td") continue; if (tdnum == 2) { nameTmp = Globals.DecodeInternetSymbs(tdNode.InnerText.Trim()); nameTmp = Globals.CleanSpaces(nameTmp.Replace('\n', ' ').Replace('\t', ' ')); } if (tdnum == 4) { if (tdNode.InnerText.Trim().ToLower() == "победитель") { _223winner.Name = nameTmp; winnersTemp.Add(_223winner); isWinner = true; } break; } tdnum++; } if (isWinner) break; } lotNum++; } // Если лоты уже с заполненным именем, то не ищем имена bool allHasName = true; foreach (Lot lot in lotsTemp) { if (lot.Name == "") { allHasName = false; break; } } // Если нет победителей, то не заполняем имена лотов bool hasWinners = false; foreach (Winner winner in winnersTemp) { if (winner.Name != "") { hasWinners = true; break; } } // Заполняем имена лотов /*if ((!allHasName) && (hasWinners)) { if (lotsTemp.Count > 0) { text = @"http://zakupki.gov.ru/223/purchase/public/purchase/protocol/ip/application/list.html?noticeInfoId=&protocolInfoId=" + protocolID + @"&mode=view"; //text = @"http://zakupki.gov.ru/223/purchase/public/purchase/protocol/rkz/application/list.html?noticeInfoId=&protocolInfoId=1698215&mode=view"; doc = internetRequestEngine.GetHtmlDoc(text); if (doc.DocumentNode.InnerText.IndexOf("Запрашиваемая страница временно недоступна") > -1) { //text = @"http://zakupki.gov.ru/223/purchase/public/purchase/protocol/ip/application/list.html?noticeInfoId=&protocolInfoId=" + protocolID + @"&mode=view"; text = @"http://zakupki.gov.ru/223/purchase/public/purchase/protocol/rkz/application/list.html?noticeInfoId=&protocolInfoId=1698215&mode=view"; doc = internetRequestEngine.GetHtmlDoc(text); } resultTypeCheck = Globals.CheckDocResult(doc, out checkMessage); if (resultTypeCheck != ResultType_enum.Done) { commissionDecisionMessage = checkMessage; return resultTypeCheck; } // Поиск имен лотов text = "//div[@class=\"cardWrapper\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainbox\"]"; text += "/div[@class=\"contentTabBoxBlock\"]"; text += "/div[@class=\"noticeTabBox\"]"; text += "/div[@class=\"clientDemandWrapper\"]"; text += "/table"; text += "/tr[@class=\"mainExpand\"]"; text += "/td[@class=\"descriptTenderTd\"]"; text += "/dt"; HtmlAgilityPack.HtmlNodeCollection lotNamesColl = doc.DocumentNode.SelectNodes(text); if (lotNamesColl == null) { // Поиск имен лотов text = "//div[@class=\"cardWrapper\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainbox\"]"; text += "/div[@class=\"contentTabBox\"]"; text += "/div[@class=\"contentTabBoxBlock\"]"; text += "/div[@class=\"noticeTabBox\"]"; text += "/div[@class=\"noticeTabBoxWrapper\"]"; text += "/div[@class=\"clientDemandWrapper\"]"; text += "/table"; text += "/tr"; text += "/td"; text += "/table"; text += "/tr[@class=\"mainExpand\"]"; text += "/td[@class=\"descriptTenderTd\"]"; lotNamesColl = doc.DocumentNode.SelectNodes(text); if (lotNamesColl == null) return ResultType_enum.NotSearch; } // Перебираем имена лотов int lotNameNum = 0; foreach (HtmlAgilityPack.HtmlNode lotNameNode in lotNamesColl) { try { lotsTemp[lotNameNum].Name = Globals.DecodeInternetSymbs(lotNameNode.InnerText.Trim()); } catch { continue; } lotNameNum++; } // Поиск цены контракта и даты // Перебираем лоты text = "//div[@class=\"cardWrapper\"]"; text += "/div[@class=\"wrapper\"]"; text += "/div[@class=\"mainbox\"]"; text += "/div[@class=\"contentTabBoxBlock\"]"; text += "/div[@class=\"noticeTabBox\"]"; text += "/div[@class=\"clientDemandWrapper\"]"; text += "/table"; text += "/tr[@class=\"expandRow\"]"; HtmlAgilityPack.HtmlNodeCollection lotsPriceDateColl = doc.DocumentNode.SelectNodes(text); if ((lotsPriceDateColl != null) && (lotsPriceDateColl.Count > 0)) { int lotPriceDateNum = 0; foreach (HtmlAgilityPack.HtmlNode lotPriceDateNode in lotsPriceDateColl) { text = ".//td"; text += "/div"; text += "/table"; text += "/tr"; HtmlAgilityPack.HtmlNodeCollection customersColl = lotPriceDateNode.SelectNodes(text); if (customersColl != null) { // Перебираем участников и ищем победителя bool itsWinner = false; foreach (HtmlAgilityPack.HtmlNode customerNode in customersColl) { if (customerNode.Attributes.Count > 0) continue; HtmlAgilityPack.HtmlNodeCollection customerAttributesColl = customerNode.SelectNodes(".//td"); int attrNum = 1; foreach (HtmlAgilityPack.HtmlNode customerAttributeNode in customerAttributesColl) { if (customerAttributeNode.Name != "td") continue; switch (attrNum) { case (2): string nameTmp = Globals.DecodeInternetSymbs(customerAttributeNode.InnerText.Trim()); if (nameTmp.IndexOf("Просмотреть заявку") > -1) { nameTmp = nameTmp.Substring(0, nameTmp.IndexOf("Просмотреть заявку")).Trim(); } if (nameTmp == lotsTemp[lotPriceDateNum].Winner.Name) { itsWinner = true; } break; case (3): if (customerAttributeNode.InnerText.Trim() != "") { _223lotDocumentDate = customerAttributeNode.InnerText.Trim(); break; } break; case (4): if (customerAttributeNode.InnerText.Trim() != "") { string priceTypePriceLot = Globals.DecodeInternetSymbs(customerAttributeNode.InnerText.Trim()); if (priceTypePriceLot.IndexOf(' ') > -1) { _223lotDocumentPrice = Convert.ToInt64(Globals.DecodeInternetSymbs(priceTypePriceLot.Substring(0, priceTypePriceLot.IndexOf(' ')).Trim())); } } break; } attrNum++; } if (itsWinner) { lotsTemp[lotPriceDateNum].DocumentPrice = _223lotDocumentPrice; if (_223lotDocumentDate.IndexOf('(') > -1) { lotsTemp[lotPriceDateNum].DocumentDateTime = Convert.ToDateTime(_223lotDocumentDate.Substring(0, _223lotDocumentDate.IndexOf('(')).Trim()); } else { lotsTemp[lotPriceDateNum].DocumentDateTime = Convert.ToDateTime(_223lotDocumentDate.Trim()); } break; } else { _223lotDocumentPrice = 0; _223lotDocumentDate = ""; } } } lotPriceDateNum++; } } // Заполняем заказ foreach (Lot lotTmp in lotsTemp) { if (lotTmp.Name != "") { mvm.wc.Winners.Add(lotTmp.Winner); mvm.wc.SaveChanges(); mvm.wc.Lots.Add(lotTmp); mvm.wc.SaveChanges(); lotSearched_delegate(lotTmp); } } } } else {*/ if (hasWinners) { foreach (Winner winnerTmp in winnersTemp) { if ((winnerTmp.Name != "") && (winnerTmp.Lot.Name != "")) { mvm.wc.Lots.Add(winnerTmp.Lot); mvm.wc.SaveChanges(); mvm.wc.Winners.Add(winnerTmp); mvm.wc.SaveChanges(); lotSearched_delegate(winnerTmp); } } } //} return ResultType_enum.Done; } catch (Exception ex) { isWinner = false; commissionDecisionMessage = ex.Message + '\n' + ex.StackTrace; return ResultType_enum.Error; } }