public void InsertAuctionBids(AuctionBids auctionBids) { if (!this.OpenConnection()) { throw new DBConnectionException(); } try { string query = "INSERT INTO `auctionbids` " + "(`position`,`bid`,`price`,`forecastInfo_id`,`created_at`, `updated_at`) VALUES " + "(@position,@bid,@price,@forecastInfo_id,@created_at, @updated_at)"; long pos = 0; switch (auctionBids.Position.ToUpper()) { case "P11": pos = 1; break; case "P12": pos = 2; break; case "P13": pos = 3; break; case "P14": pos = 4; break; case "P21": pos = 5; break; case "P22": pos = 6; break; case "P23": pos = 7; break; case "P24": pos = 8; break; } Console.WriteLine("auctionBids=>" + auctionBids.ToString()); MySqlCommand cmd = new MySqlCommand(query, conn); cmd.Parameters.AddWithValue("@position", pos); cmd.Parameters.AddWithValue("@bid", auctionBids.Bid); cmd.Parameters.AddWithValue("@price", auctionBids.Price); cmd.Parameters.AddWithValue("@forecastInfo_id", auctionBids.forecastInfo_id); cmd.Parameters.AddWithValue("@created_at", DateTime.Now); cmd.Parameters.AddWithValue("@updated_at", DateTime.Now); cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine("Ошибочка InsertAuctionBids:" + e); } this.CloseConnection(); }
private void getReport(int reportId) { ForecastInfo fi = _yds.GetForecast(reportId); Console.WriteLine("Получаем отчет с айди {0}", reportId); fi.Phrases.ToList().ForEach(_fbpi => { Console.WriteLine("Глянем что в AuctionBids, а там {0}", _fbpi.AuctionBids == null?"пусто":"что-то есть"); Forecastinfo fc = new Forecastinfo(); fc.Clicks = _fbpi.Clicks; fc.ContextPrice = _fbpi.ContextPrice; fc.FirstPlaceClicks = _fbpi.FirstPlaceClicks; fc.FirstPlaceCtr = _fbpi.FirstPlaceCtr; fc.PremiumClicks = _fbpi.PremiumClicks; fc.PremiumCtr = _fbpi.PremiumCtr; fc.PremiumMax = _fbpi.PremiumMax; fc.PremiumMin = _fbpi.PremiumMin; fc.CTR = fc.CTR; fc.Shows = _fbpi.Shows; fc.is_preceded = _fbpi.Phrase.IndexOf("!") != -1 ? true : false; fc.Keyword_id = this.isKeywordExist(_fbpi.Phrase.restoringPrecede()) ? this.getKeywordId(_fbpi.Phrase.restoringPrecede()) : -1; long addedId = this.InsertForecast(fc); Console.WriteLine("Добавлен ForecastInfo c id=> " + addedId); if (addedId != -1 && _fbpi.AuctionBids != null) { _fbpi .AuctionBids .ToList() .ForEach(_ab_item => { AuctionBids ab = new AuctionBids(); ab.Position = _ab_item.Position; ab.Bid = _ab_item.Bid; ab.Price = _ab_item.Price; ab.forecastInfo_id = addedId; this.InsertAuctionBids(ab); }); Console.WriteLine("Добавление AuctionBids для фразы=> " + _fbpi.Phrase); } }); removeReport(reportId); }