Beispiel #1
0
        public long InsertForecast(Forecastinfo forecast)
        {
            //return;
            if (!this.OpenConnection())
            {
                throw new DBConnectionException();
            }

            string query = "INSERT INTO `forecastinfo` " +
                           "(`min`,`max`,`premium_min`,`premium_max`,`shows`,`clicks`,`first_place_clicks`,`premium_clicks`,`ctr`,`first_place_ctr`,`premium_ctr`,`currency`,`Keywords_id`,`is_preceded` ,`created_at`, `updated_at`) VALUES " +
                           "(@min,@max,@premium_min,@premium_max,@shows,@clicks,@first_place_clicks,@premium_clicks,@ctr,@first_place_ctr,@premium_ctr,@currency,@Keywords_id,@is_preceded ,@created_at, @updated_at)";


            try
            {
                MySqlCommand cmd = new MySqlCommand(query, conn);
                cmd.Parameters.AddWithValue("@min", forecast.Min);
                cmd.Parameters.AddWithValue("@max", forecast.Max);
                cmd.Parameters.AddWithValue("@premium_min", forecast.PremiumMin);
                cmd.Parameters.AddWithValue("@premium_max", forecast.PremiumMax);
                cmd.Parameters.AddWithValue("@shows", forecast.Shows);
                cmd.Parameters.AddWithValue("@clicks", forecast.Shows);
                cmd.Parameters.AddWithValue("@first_place_clicks", forecast.FirstPlaceClicks);
                cmd.Parameters.AddWithValue("@premium_clicks", forecast.PremiumClicks);
                cmd.Parameters.AddWithValue("@ctr", forecast.CTR);
                cmd.Parameters.AddWithValue("@first_place_ctr", forecast.FirstPlaceCtr);
                cmd.Parameters.AddWithValue("@premium_ctr", forecast.PremiumCtr);
                cmd.Parameters.AddWithValue("@currency", forecast.Currency);
                cmd.Parameters.AddWithValue("@Keywords_id", forecast.Keyword_id);
                cmd.Parameters.AddWithValue("@is_preceded", forecast.is_preceded);
                cmd.Parameters.AddWithValue("@created_at", DateTime.Now);
                cmd.Parameters.AddWithValue("@updated_at", DateTime.Now);
                cmd.ExecuteNonQuery();
                long lastId = (long)cmd.LastInsertedId;
                this.CloseConnection();
                return(lastId);
            }
            catch (Exception e)
            {
                Console.WriteLine("Ошибочка InsertForecast:" + e);
            }
            this.CloseConnection();
            return(-1);
        }
Beispiel #2
0
        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);
        }