private void AddAttachments(MySqlConnection connect, int idTender) { var tenderId = _tn.Href.GetDataFromRegex("&requestId=(\\d+)"); var docString = CurlLoaderFederal.DownL( $"https://t2.federal1.ru/includes/Auction/ajax/viewFiles.php?table=request&typeId=1&id={tenderId}", ParserFederal.Cookie.Value); if (!docString.Contains("viewLinkDoc")) { docString = CurlLoaderFederal.DownL( $"https://t2.federal1.ru/ajax/zQuotation/ajaxViewFilesQuotation.php?table=request&typeId=1&id={tenderId}", ParserFederal.Cookie.Value); } var attDoc = new HtmlDocument(); attDoc.LoadHtml(docString); var docs = attDoc.DocumentNode.SelectNodes( "//a[contains(@class, 'viewLinkDoc')]") ?? new HtmlNodeCollection(null); foreach (var dd in docs) { var urlAttT = (dd?.Attributes["href"]?.Value ?? "").Trim(); var fName = (dd?.InnerText ?? "").Trim(); var urlAtt = $"https://t2.federal1.ru/{urlAttT}"; if (string.IsNullOrEmpty(fName)) { continue; } var insertAttach = $"INSERT INTO {AppBuilder.Prefix}attachment SET id_tender = @id_tender, file_name = @file_name, url = @url"; var cmd10 = new MySqlCommand(insertAttach, connect); cmd10.Prepare(); cmd10.Parameters.AddWithValue("@id_tender", idTender); cmd10.Parameters.AddWithValue("@file_name", fName); cmd10.Parameters.AddWithValue("@url", urlAtt); cmd10.ExecuteNonQuery(); } }
private void AddLots(HtmlDocument htmlDoc, MySqlConnection connect, int idTender, int customerId) { var lots = htmlDoc.DocumentNode.SelectNodes( "//td[@lotid]") ?? new HtmlNodeCollection(null); var lotNum = 1; foreach (var l in lots) { var lotNumber = l.Attributes["lotid"]?.Value ?? ""; if (lotNumber == "") { continue; } var docString = CurlLoaderFederal.DownL( $"https://t2.federal1.ru/includes/Auction/ajax/viewLot.php?id={lotNumber}", ParserFederal.Cookie.Value); if (!docString.Contains("<table")) { docString = CurlLoaderFederal.DownL( $"https://t2.federal1.ru/ajax/zQuotation/ajaxViewLotQuotation.php?id={lotNumber}", ParserFederal.Cookie.Value); } if (string.IsNullOrEmpty(docString)) { Log.Logger( $"Empty string lots in {GetType().Name}.{System.Reflection.MethodBase.GetCurrentMethod().Name}", _tn.Href); continue; } var attDoc = new HtmlDocument(); attDoc.LoadHtml(docString); var navLot = (HtmlNodeNavigator)attDoc.CreateNavigator(); var nmck = navLot.SelectSingleNode( "//td[contains(., 'Начальная (максимальная)')]/following-sibling::td")?.Value?.Trim() ?.Replace(" ", "")?.DelAllWhitespace() ?? _tn.Nmck; var lotName = navLot.SelectSingleNode( "//td[contains(., 'Предмет договора')]/following-sibling::td")?.Value?.Trim() ?? _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", _tn.Currency); cmd18.Parameters.AddWithValue("@finance_source", ""); cmd18.Parameters.AddWithValue("@lot_name", lotName); cmd18.ExecuteNonQuery(); var idLot = (int)cmd18.LastInsertedId; lotNum++; var insertLotitem = $"INSERT INTO {AppBuilder.Prefix}purchase_object SET id_lot = @id_lot, id_customer = @id_customer, name = @name, sum = @sum"; 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", nmck); cmd19.ExecuteNonQuery(); var delivPlace = navLot.SelectSingleNode( "//td[contains(., 'Место поставки (адрес)')]/following-sibling::td")?.Value ?.Trim() ?? ""; if (!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", ""); cmd16.ExecuteNonQuery(); } } }