예제 #1
0
        void RefreshForm(DataAccessLevel.Forecast forecast)
        {
            //try
            //{

            //// проверка заполненности списков
            if (forecast.dailyList.Count > 0 && forecast.hourlyList.Count > 0 && forecast.tenDaysList.Count > 0)
            {
                CurWeather(forecast);
                //NoData();
                GridView(forecast);
                GridView2(forecast.hourlyList[0].periodDate);
                GroupTag(forecast);
            }
            else
            {
                MessageBox.Show("Извините, нет данных. Требуется подключение к интернету");
                NoData();
            }

            label7.Text = "Последнее обновление: \r\n" + CurData.ToString();
            label6.Text = CurCity;
            //}
            //catch (Exception ex)
            //{

            //}
        }
예제 #2
0
        void CurWeather(DataAccessLevel.Forecast forecast)
        {
            // картинки
            string pic = forecast.curWeather.symbol.Replace('-', '0');

            pic = pic.Replace('+', '1');

            Image myIcon = (Image)TheTime.Properties.Resources.ResourceManager.GetObject(pic);

            pictureBox1.Image = myIcon;

            label1.Text  = forecast.curWeather.description;
            label2.Text  = "Температура воздуха " + forecast.curWeather.temperature + " С";
            label3.Text  = "Скорость ветра " + forecast.curWeather.windSpeed + " м/с";
            label8.Text  = "Направление ветра " + forecast.curWeather.windDirection;
            label9.Text  = "Влажность воздуха " + forecast.curWeather.hummidity + "%";
            label10.Text = "Атм. давление " + forecast.curWeather.pressure + "мм рт. ст.";

            // сохраняем текущие данные для трея
            CurIcon = pic;
            CurTemp = forecast.curWeather.temperature;
            CurDesc = forecast.curWeather.description;

            // Название ссылки, откр Календарь
            linkLabel2.Text = DateTime.Parse(Convert.ToString(forecast.hourlyList[0].periodDate)).ToLongDateString();
            // Сегодняшняя Дата календаря = информации из яндекса или owm
            monthCalendar1.TodayDate = forecast.hourlyList[0].periodDate;
        }
예제 #3
0
        void GridView(DataAccessLevel.Forecast tag1)
        {
            label4.Visible        = false;
            label5.Visible        = false;
            label11.Visible       = false;
            dataGridView1.Visible = true;
            pictureBox1.Visible   = true;
            //this.Invoke (new Action (dataGridView1.Rows.Clear));
            dataGridView1.Rows.Clear();
            dataGridView1.RowCount = tag1.hourlyList.Count;
            for (int i = 0; i < tag1.hourlyList.Count; i++)
            {
                //if (i != tag1.hourlyList.Count - 1)
                //dataGridView1.Rows.Add();
                dataGridView1.Rows[i].Cells[0].Value = tag1.hourlyList[i].periodTime + ":00";
                dataGridView1.Rows[i].Cells[1].Value = tag1.hourlyList[i].temperature;
                string buf    = tag1.hourlyList[i].symbol.Replace("-", "0").Replace("+", "1");
                Image  myIcon = (Image)TheTime.Properties.Resources.ResourceManager.GetObject(buf);

                dataGridView1.Rows[i].Cells[2].Value = myIcon;
                dataGridView1.Rows[i].Cells[3].Value = tag1.hourlyList[i].windSpeed;
                dataGridView1.Rows[i].Cells[4].Value = tag1.hourlyList[i].pressure;
                dataGridView1.Rows[i].Cells[5].Value = tag1.hourlyList[i].hummidity;

                if (i == 7)
                {
                    break;
                }
            }
            int total_height = 22 * 8 + 47;

            dataGridView1.Height = total_height;
        }
예제 #4
0
        private void button5_Click(object sender, EventArgs e)
        {
            SQLiteDatabaseWorker worker = new SQLiteDatabaseWorker();

            worker.SetConnect(Program.DBName);

            Forecast f = new Forecast();

            f.hourlyList.Add(new HourlyForecastsDataContext {
                description   = "описание",
                hummidity     = "75",
                periodDate    = DateTime.Parse("12.02.2015 0:00:00"),
                periodTime    = 20,
                pressure      = "755",
                settingID     = 1,
                symbol        = "1d",
                temperature   = "-21",
                windDirection = "СЗ",
                windSpeed     = "5"
            });

            f.dailyList.Add(new DailyForecastsDataContext {
                description   = "поиссисми",
                hummidity     = "75",
                periodDate    = DateTime.Parse("12.02.2015 0:00:00"),
                pressure      = "155",
                settingID     = 1,
                symbol        = "1",
                temperature   = "-39",
                windDirection = "CP",
                windSpeed     = "5",
                timeOfDay     = "ночь"
            });

            f.tenDaysList.Add(new TenDaysForecastsDataContext {
                periodDate  = DateTime.Parse("12.02.2015 0:00:00"),
                settingID   = 1,
                symbol      = "1",
                temperature = "-123",
                timeOfDay   = "ночь"
            });

            worker.SaveForecast(f);

            worker.CloseConnect();
        }
예제 #5
0
        private void linkLabel3_Click(object sender, EventArgs e)
        {
            this.Size            = new System.Drawing.Size(749, 91);
            progressBar1.Visible = true;
            tabControl1.Visible  = false;
            groupBox1.Visible    = false;
            this.ControlBox      = false;
            forecast             = GetForecat(Program.DBName, progressBar1);

            RefreshForm(forecast);

            this.Size            = new System.Drawing.Size(749, 356);
            progressBar1.Visible = false;
            tabControl1.Visible  = true;
            groupBox1.Visible    = true;
            this.ControlBox      = true;
        }
예제 #6
0
        void GridView2(DateTime Select_day)
        {
            dataGridView2.Visible = true;
            DataAccessLevel.Forecast tag1 = forecast;

            int day = Select_day.DayOfYear - tag1.hourlyList[0].periodDate.DayOfYear;

            if (day < 0)
            {
                if (tag1.hourlyList[0].periodDate.Year % 4 == 0)
                {
                    day = (366 - tag1.hourlyList[0].periodDate.DayOfYear) + Select_day.DayOfYear;
                }
                else
                {
                    day = (365 - tag1.hourlyList[0].periodDate.DayOfYear) + Select_day.DayOfYear;
                }
            }
            dataGridView2.RowCount = 4;
            monthCalendar1.MaxDate = monthCalendar1.TodayDate.AddDays(tag1.tenDaysList.Count() / 2 - 1);
            //MessageBox.Show(Convert.ToString(day));
            for (int i = 0; i < 4; i++)
            {
                //if (i != tag1.dailyList.Count-1)
                //dataGridView2.Rows.Add();

                dataGridView2.Rows[i].Height         = 34;
                dataGridView2.Rows[i].Cells[0].Value = tag1.dailyList[i + day * 4].timeOfDay;
                dataGridView2.Rows[i].Cells[1].Value = tag1.dailyList[i + day * 4].temperature;
                string buf    = tag1.dailyList[i + day * 4].symbol.Replace("-", "0").Replace("+", "1");
                Image  myIcon = (Image)TheTime.Properties.Resources.ResourceManager.GetObject(buf);
                dataGridView2.Rows[i].Cells[2].Value = myIcon;
                dataGridView2.Rows[i].Cells[3].Value = tag1.dailyList[i + day * 4].windSpeed;
                dataGridView2.Rows[i].Cells[4].Value = tag1.dailyList[i + day * 4].pressure;
                dataGridView2.Rows[i].Cells[5].Value = tag1.dailyList[i + day * 4].hummidity;
                if (i == tag1.dailyList.Count - 1)
                {
                    break;
                }
            }

            int total_height = 34 * 4 + 62; // высота dataGrubview

            dataGridView2.Height = total_height;
        }
예제 #7
0
        private void linkLabel1_Click(object sender, EventArgs e)
        {
            Settings form = new Settings();

            if (form.ShowDialog() == DialogResult.OK)

            {
                this.Size            = new System.Drawing.Size(749, 91);
                progressBar1.Visible = true;
                tabControl1.Visible  = false;
                groupBox1.Visible    = false;
                this.ControlBox      = false;
                forecast             = GetForecat(Program.DBName, progressBar1);

                RefreshForm(forecast);

                this.Size            = new System.Drawing.Size(749, 356);
                progressBar1.Visible = false;
                tabControl1.Visible  = true;
                groupBox1.Visible    = true;
                this.ControlBox      = true;
            }
        }
예제 #8
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            forecast = GetForecat(Program.DBName, progressBar1);

            this.Size            = new System.Drawing.Size(749, 356);
            progressBar1.Visible = false;
            tabControl1.Visible  = true;
            groupBox1.Visible    = true;
            this.ControlBox      = true;


            RefreshForm(forecast);

            //-----Сворачиваем форму при запуске в трей----
            this.WindowState = FormWindowState.Minimized;
            DeactivateForm();


            //------------вешаем ТАЙМЕР-------------
            timer1.Enabled = true;
            ////TimerCallback tm = new TimerCallback(Count);
            // раз в час
            //System.Threading.Timer timer = new System.Threading.Timer(tm, num, 0, 3600000);
        }
예제 #9
0
        /// <summary>
        /// Получаем прогноз из базы данных
        /// </summary>
        /// <param name="Current">Текущие дата/время в формате DateTime</param>
        /// <returns>объект класса Forecast</returns>
        public Forecast GetForecast(DateTime Current)
        {
            SettingsDataContext sdc = GetSettings(); // получили текущие настройки

            List <string> setID = new List <string>();

            // получаем id всех настроек с похожими параметрами
            string           sql     = "SELECT * FROM 'settings' WHERE cityID = '" + sdc.cityID + "' AND sourseID = '" + sdc.sourceID + "';";
            SQLiteCommand    command = new SQLiteCommand(sql, m_dbConnection);
            SQLiteDataReader reader  = command.ExecuteReader();

            foreach (DbDataRecord record in reader)
            {
                setID.Add(record["ID"].ToString());
            }


            Forecast f = new Forecast();

            // вычисляем "текущий час"
            int CurHour = Current.Hour;

            switch (Current.Hour)
            {
            case 1:
            case 2:
                CurHour = 0;
                break;

            case 4:
            case 5:
                CurHour = 3;
                break;

            case 7:
            case 8:
                CurHour = 6;
                break;

            case 10:
            case 11:
                CurHour = 9;
                break;

            case 13:
            case 14:
                CurHour = 12;
                break;

            case 16:
            case 17:
                CurHour = 15;
                break;

            case 19:
            case 20:
                CurHour = 18;
                break;

            case 22:
            case 23:
                CurHour = 21;
                break;
            }



            // получаем прогноз на текущий момент
            sql     = "SELECT * FROM 'hourly_forecasts' WHERE settingId = '" + sdc.ID + "' AND periodDate = '" + Current.Date.ToString() + "' AND periodTime = '" + CurHour + "' LIMIT 1;";
            command = new SQLiteCommand(sql, m_dbConnection);
            reader  = command.ExecuteReader();

            foreach (DbDataRecord record in reader)
            {
                f.curWeather.description   = record["description"].ToString();
                f.curWeather.hummidity     = record["hummidity"].ToString();
                f.curWeather.pressure      = record["pressure"].ToString();
                f.curWeather.symbol        = record["symbol"].ToString();
                f.curWeather.temperature   = record["temperature"].ToString();
                f.curWeather.windDirection = record["windDirection"].ToString();
                f.curWeather.windSpeed     = record["windSpeed"].ToString();
            }

            // получаем прогноз на день


            sql = "SELECT * FROM 'daily_forecasts' WHERE settingId = '" + sdc.ID + "' AND (periodDate = '" + Current.Date.ToString() + "' OR periodDate = '" + Current.AddDays(1).Date.ToString() + "' OR periodDate = '" + Current.AddDays(2).Date.ToString() + "' OR periodDate = '" + Current.AddDays(3).Date.ToString() + "' OR periodDate = '" + Current.AddDays(4).Date.ToString() + "' OR periodDate = '" + Current.AddDays(5).Date.ToString() + "' OR periodDate = '" + Current.AddDays(6).Date.ToString() + "' OR periodDate = '" + Current.AddDays(7).Date.ToString() + "' OR periodDate = '" + Current.AddDays(8).Date.ToString() + "' OR periodDate = '" + Current.AddDays(9).Date.ToString() + "' );";
            // должны получить 4 записи
            command = new SQLiteCommand(sql, m_dbConnection);
            reader  = command.ExecuteReader();

            foreach (DbDataRecord record in reader)
            {
                DailyForecastsDataContext context = new DailyForecastsDataContext();
                context.description   = record["description"].ToString();
                context.hummidity     = record["hummidity"].ToString();
                context.periodDate    = DateTime.Parse(record["periodDate"].ToString());
                context.pressure      = record["pressure"].ToString();
                context.settingID     = int.Parse(record["settingID"].ToString());
                context.symbol        = record["symbol"].ToString();
                context.temperature   = record["temperature"].ToString();
                context.timeOfDay     = record["timeOfDay"].ToString();
                context.windDirection = record["windDirection"].ToString();
                context.windSpeed     = record["windSpeed"].ToString();
                f.dailyList.Add(context);
            }

            // получаем прогноз на 10 дней -> 10*2 = 20 записей
            sql     = "SELECT * FROM 'ten_days_forecasts' WHERE settingId = '" + sdc.ID + "' AND (periodDate = '" + Current.Date.ToString() + "' OR periodDate = '" + Current.AddDays(1).Date.ToString() + "' OR periodDate = '" + Current.AddDays(2).Date.ToString() + "' OR periodDate = '" + Current.AddDays(3).Date.ToString() + "' OR periodDate = '" + Current.AddDays(4).Date.ToString() + "' OR periodDate = '" + Current.AddDays(5).Date.ToString() + "' OR periodDate = '" + Current.AddDays(6).Date.ToString() + "' OR periodDate = '" + Current.AddDays(7).Date.ToString() + "' OR periodDate = '" + Current.AddDays(8).Date.ToString() + "' OR periodDate = '" + Current.AddDays(9).Date.ToString() + "' );";
            command = new SQLiteCommand(sql, m_dbConnection);
            reader  = command.ExecuteReader();
            foreach (DbDataRecord record in reader)
            {
                TenDaysForecastsDataContext context = new TenDaysForecastsDataContext();
                context.periodDate  = DateTime.Parse(record["periodDate"].ToString());
                context.settingID   = int.Parse(record["settingID"].ToString());
                context.symbol      = record["symbol"].ToString();
                context.temperature = record["temperature"].ToString();
                context.timeOfDay   = record["timeOfDay"].ToString();
                f.tenDaysList.Add(context);
            }

            // получаем почасовой прогноз на день - должны получить 9 записей
            sql     = "SELECT * FROM 'hourly_forecasts' WHERE settingId = '" + sdc.ID + "' AND periodDate = '" + Current.Date.ToString() + "';";
            command = new SQLiteCommand(sql, m_dbConnection);
            reader  = command.ExecuteReader();

            foreach (DbDataRecord record in reader)
            {
                HourlyForecastsDataContext context = new HourlyForecastsDataContext();
                context.description   = record["description"].ToString();
                context.hummidity     = record["hummidity"].ToString();
                context.periodDate    = Current;
                context.pressure      = record["pressure"].ToString();
                context.settingID     = int.Parse(record["settingID"].ToString());
                context.symbol        = record["symbol"].ToString();
                context.temperature   = record["temperature"].ToString();
                context.periodTime    = int.Parse(record["periodTime"].ToString());
                context.windDirection = record["windDirection"].ToString();
                context.windSpeed     = record["windSpeed"].ToString();
                f.hourlyList.Add(context);
            }

            return(f);
        }
예제 #10
0
        /// <summary>
        /// Сохраняет / обновляет прогнозы в трех таблицах
        /// </summary>
        /// <param name="forecast">объект класса Forecast</param>
        public void SaveForecast(Forecast forecast)
        {
            // получаем текущий SettingID
            SettingsDataContext set = GetSettings();

            // для каждого  public List<HourlyForecastsDataContext> hourlyList { get; set; } - проверяем и обновляем / переписываем
            #region
            for (int i = 0; i < forecast.hourlyList.Count; i++)
            {
                // проверить наличие такой строки в базе
                string           sql     = "SELECT * FROM 'hourly_forecasts' WHERE settingId = '" + set.ID + "' AND periodDate = '" + forecast.hourlyList[i].periodDate.Date.ToString() + "' AND periodTime = '" + forecast.hourlyList[i].periodTime + "';";
                SQLiteCommand    command = new SQLiteCommand(sql, m_dbConnection);
                SQLiteDataReader reader  = command.ExecuteReader();

                // считаем
                int count = 0;
                foreach (DbDataRecord record in reader)
                {
                    count++;
                }

                if (count > 0)
                {
                    // делаем update
                    sql     = @"UPDATE 'hourly_forecasts' SET
                            description = '" + forecast.hourlyList[i].description + "', temperature = '" + forecast.hourlyList[i].temperature + "', windSpeed = '" + forecast.hourlyList[i].windSpeed + "', windDirection = '" + forecast.hourlyList[i].windDirection + "', pressure = '" + forecast.hourlyList[i].pressure + "', hummidity = '" + forecast.hourlyList[i].hummidity + "', symbol ='" + forecast.hourlyList[i].symbol + "' WHERE settingId = '" + set.ID + "' AND periodDate = '" + forecast.hourlyList[i].periodDate.Date.ToString() + "' AND periodTime = '" + forecast.hourlyList[i].periodTime + "';";
                    command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                }
                else
                {
                    // сохраняем
                    sql     = @"INSERT INTO hourly_forecasts
                                (settingID, periodDate, periodTime, description, temperature, windSpeed, windDirection, pressure, hummidity, symbol)
                          VALUES ('" + set.ID + "', '" + forecast.hourlyList[i].periodDate.Date.ToString() + "', '" + forecast.hourlyList[i].periodTime + "', '" + forecast.hourlyList[i].description + "', '" + forecast.hourlyList[i].temperature + "', '" + forecast.hourlyList[i].windSpeed + "', '" + forecast.hourlyList[i].windDirection + "', '" + forecast.hourlyList[i].pressure + "', '" + forecast.hourlyList[i].hummidity + "', '" + forecast.hourlyList[i].symbol + "')";
                    command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                }
            }
            #endregion

            // для каждого public List<DailyForecastsDataContext> dailyList { get; set; } - проверяем и обновляем / переписываем
            #region
            for (int i = 0; i < forecast.dailyList.Count; i++)
            {
                // проверить наличие такой строки в базе
                string           sql     = "SELECT * FROM 'daily_forecasts' WHERE settingId = '" + set.ID + "' AND periodDate = '" + forecast.dailyList[i].periodDate.Date.ToString() + "' AND timeOfDay = '" + forecast.dailyList[i].timeOfDay + "';";
                SQLiteCommand    command = new SQLiteCommand(sql, m_dbConnection);
                SQLiteDataReader reader  = command.ExecuteReader();

                // считаем
                int count = 0;
                foreach (DbDataRecord record in reader)
                {
                    count++;
                }

                if (count > 0)
                {
                    // делаем update
                    sql     = @"UPDATE 'daily_forecasts' SET
                            description = '" + forecast.dailyList[i].description + "', temperature = '" + forecast.dailyList[i].temperature + "', windSpeed = '" + forecast.dailyList[i].windSpeed + "', windDirection = '" + forecast.dailyList[i].windDirection + "', pressure = '" + forecast.dailyList[i].pressure + "', hummidity = '" + forecast.dailyList[i].hummidity + "', symbol ='" + forecast.dailyList[i].symbol + "' WHERE settingId = '" + set.ID + "' AND periodDate = '" + forecast.dailyList[i].periodDate.Date.ToString() + "' AND timeOfDay = '" + forecast.dailyList[i].timeOfDay + "';";
                    command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                }
                else
                {
                    // сохраняем
                    sql     = @"INSERT INTO daily_forecasts
                                (settingID, periodDate, timeOfDay, description, temperature, windSpeed, windDirection, pressure, hummidity, symbol)
                          VALUES ('" + set.ID + "', '" + forecast.dailyList[i].periodDate.Date.ToString() + "', '" + forecast.dailyList[i].timeOfDay + "', '" + forecast.dailyList[i].description + "', '" + forecast.dailyList[i].temperature + "', '" + forecast.dailyList[i].windSpeed + "', '" + forecast.dailyList[i].windDirection + "', '" + forecast.dailyList[i].pressure + "', '" + forecast.dailyList[i].hummidity + "', '" + forecast.dailyList[i].symbol + "')";
                    command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                }
            }
            #endregion

            // для каждого public List<TenDaysForecastsDataContext> tenDaysList { get; set; } - проверяем и обновляем / переписываем
            #region
            for (int i = 0; i < forecast.tenDaysList.Count; i++)
            {
                // проверить наличие такой строки в базе
                string           sql     = "SELECT * FROM 'ten_days_forecasts' WHERE settingId = '" + set.ID + "' AND periodDate = '" + forecast.tenDaysList[i].periodDate.Date.ToString() + "' AND timeOfDay = '" + forecast.tenDaysList[i].timeOfDay + "';";
                SQLiteCommand    command = new SQLiteCommand(sql, m_dbConnection);
                SQLiteDataReader reader  = command.ExecuteReader();

                // считаем
                int count = 0;
                foreach (DbDataRecord record in reader)
                {
                    count++;
                }

                if (count > 0)
                {
                    // делаем update
                    sql     = @"UPDATE 'ten_days_forecasts' SET
                            temperature = '" + forecast.tenDaysList[i].temperature + "',  symbol ='" + forecast.tenDaysList[i].symbol + "' WHERE settingId = '" + set.ID + "' AND periodDate = '" + forecast.tenDaysList[i].periodDate.Date.ToString() + "' AND timeOfDay = '" + forecast.tenDaysList[i].timeOfDay + "';";
                    command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                }
                else
                {
                    // сохраняем
                    sql     = @"INSERT INTO ten_days_forecasts
                                (settingID, periodDate, timeOfDay, temperature, symbol)
                          VALUES ('" + set.ID + "', '" + forecast.tenDaysList[i].periodDate.Date.ToString() + "', '" + forecast.tenDaysList[i].timeOfDay + "', '" + forecast.tenDaysList[i].temperature + "', '" + forecast.tenDaysList[i].symbol + "')";
                    command = new SQLiteCommand(sql, m_dbConnection);
                    command.ExecuteNonQuery();
                }
            }
            #endregion
        }
예제 #11
0
        public DataAccessLevel.Forecast GetForecat(string path, ProgressBar pb)
        {
            DataAccessLevel.SQLiteDatabaseWorker worker   = new DataAccessLevel.SQLiteDatabaseWorker();
            DataAccessLevel.Forecast             forecast = new DataAccessLevel.Forecast();

            // получаем текущий город из настроек

            worker.SetConnect(path);
            DataAccessLevel.SettingsDataContext sdc    = worker.GetSettings(); // текущие настройки
            DataAccessLevel.SettingsDataContext altSet = worker.GetAltSetStr(sdc);
            CurCity = worker.GetCurCityName(sdc.cityID.ToString());
            worker.CloseConnect();

            // CurCity


            // sdc.cityID - id выбранного города
            // sdc.ID - id настройки

            try
            {
                HttpWebRequest reqFP = (HttpWebRequest)HttpWebRequest.Create("http://www.google.com");

                HttpWebResponse rspFP = (HttpWebResponse)reqFP.GetResponse();
                if (HttpStatusCode.OK == rspFP.StatusCode)
                {
                    // HTTP = 200 - Интернет безусловно есть!
                    rspFP.Close();

                    DataAccessLevel.Forecast yandexForecast = new DataAccessLevel.Forecast();
                    DataAccessLevel.Forecast owmForecast    = new DataAccessLevel.Forecast();

                    // DataAccessLevel.CurrentWeather yaCurWeather = new DataAccessLevel.CurrentWeather();
                    // получаем текущее время - нужен id текущий города на яндексе
                    Date_Time.GetTime getter  = new Date_Time.GetTime();
                    DateTime          CurDate = getter.Yandex_Time(sdc.cityID);

                    CurData = CurDate;

                    // получаем город по ид яндекса GetCityByYaId
                    worker.SetConnect(path);
                    DataAccessLevel.CitiesDataContext city = worker.GetCityByYaId(sdc.cityID.ToString());
                    worker.CloseConnect();

                    // получаем прогнозы
                    // получаем прогноз с яндекса
                    Yandex.YandexMethods yaworker2 = new Yandex.YandexMethods();
                    yaworker2.GetYandexForecast(sdc.cityID.ToString(), yandexForecast);
                    // с owm
                    OpenWeatherMap.APIWorker owmworker = new APIWorker();
                    owmForecast = owmworker.GetWeather(city.name, city.owmID);

                    switch (sdc.sourceID)
                    {
                    case 1:
                        // owm
                        worker.SetConnect(path);
                        worker.SaveForecast(owmForecast, pb, sdc);
                        worker.SaveForecast(yandexForecast, pb, altSet);
                        worker.CloseConnect();
                        break;

                    case 2:
                        // ya
                        worker.SetConnect(path);
                        worker.SaveForecast(owmForecast, pb, altSet);
                        worker.SaveForecast(yandexForecast, pb, sdc);
                        worker.CloseConnect();
                        return(yandexForecast);
                    }

                    worker.SetConnect(path);
                    forecast = worker.GetForecast(CurDate);
                    worker.CloseConnect();

                    // if (sdc.sourceID == 2)
                    //    forecast.curWeather = yaCurWeather;

                    return(forecast);


                    // switch (sdc.sourceID)
                    // {
                    //     case 1: // owm
                    //         // получаем город по ид яндекса GetCityByYaId
                    //         worker.SetConnect(path);
                    //         DataAccessLevel.CitiesDataContext city = worker.GetCityByYaId(sdc.cityID.ToString());
                    //         worker.CloseConnect();
                    //         // получаем прогноз owm по названию или owmid
                    //         OpenWeatherMap.APIWorker owmworker = new APIWorker();
                    //         DataAccessLevel.Forecast owmForecast = owmworker.GetWeather(city.name, city.owmID);

                    //         // получаем прогноз с яндекса
                    //         Yandex.YandexMethods yaworker2 = new Yandex.YandexMethods();
                    //         yaworker2.GetYandexForecast(sdc.cityID.ToString(), yandexForecast);

                    //         // сохраняем в базу
                    //         worker.SetConnect(path);
                    //         worker.SaveForecast(yandexForecast, pb, altSet);
                    //         worker.CloseConnect();

                    //         // сохраняем в базу
                    //         worker.SetConnect(path);
                    //         worker.SaveForecast(owmForecast, pb);
                    //         worker.CloseConnect();

                    //         break;
                    //     case 2: // яндекс
                    //         // получаем прогноз с яндекса (по ID города яндекса)
                    //         Yandex.YandexMethods yaworker = new Yandex.YandexMethods();
                    //         yaworker.GetYandexForecast(sdc.cityID.ToString(), yandexForecast);

                    //         // сохраняем в базу
                    //         worker.SetConnect(path);
                    //         worker.SaveForecast(yandexForecast, pb);
                    //         worker.CloseConnect();
                    //         //break;
                    //         //yaCurWeather = yandexForecast.curWeather;
                    //         return yandexForecast;
                    //         //break;
                    //     default:
                    //         break;
                    // }


                    // // получаем прогноз из базы по установленному в настройках серверу

                    // worker.SetConnect(path);
                    // forecast = worker.GetForecast(CurDate);
                    // worker.CloseConnect();

                    //// if (sdc.sourceID == 2)
                    // //    forecast.curWeather = yaCurWeather;

                    // return forecast;
                }


                else
                {
                    CurData = DateTime.Now;
                    // сервер вернул отрицательный ответ, возможно что инета нет
                    rspFP.Close();
                    MessageBox.Show("Подключение к интернету ограничено, данные могут быть неточными");

                    // получаем прогноз из базы по установленному в настройках серверу

                    worker.SetConnect(path);
                    forecast = worker.GetForecast(DateTime.Now);
                    worker.CloseConnect();

                    return(forecast);
                }
            }
            catch (WebException)
            {
                CurData = DateTime.Now;
                // Ошибка, значит интернета у нас нет. Плачем :'(
                MessageBox.Show("Невозможно подключиться к интернету, данные могут быть неточными");

                // получаем прогноз из базы по установленному в настройках серверу

                worker.SetConnect(path);
                forecast = worker.GetForecast(DateTime.Now);
                worker.CloseConnect();

                return(forecast);
            }
        }
예제 #12
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     forecast = GetForecat(Program.DBName);
     RefreshForm(forecast);
     timer1.Enabled = true;
 }
예제 #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tag1"></param>
        void GroupTag(DataAccessLevel.Forecast tag1)
        {
            //this.Invoke(new Action(tabPage3.Controls.Clear));
            tabPage3.Controls.Clear();
            int Kol = tag1.tenDaysList.Count / 2;

            GroupBox[]   tb  = new GroupBox[Kol];
            PictureBox[] tb1 = new PictureBox[Kol];
            Label[]      mor = new Label[Kol * 2];
            Label[]      tem = new Label[Kol * 2];
            for (int i = 0; i < Kol; i++)
            {
                tb[i]          = new System.Windows.Forms.GroupBox();
                mor[i * 2]     = new System.Windows.Forms.Label();
                mor[i * 2 + 1] = new System.Windows.Forms.Label();
                tem[i * 2]     = new System.Windows.Forms.Label();
                tem[i * 2 + 1] = new System.Windows.Forms.Label();
                if (Kol <= 5)
                {
                    tb[i].Location = new System.Drawing.Point(10 + 80 * i, 80);
                }
                else
                {
                    if (i < 5)
                    {
                        tb[i].Location = new System.Drawing.Point(10 + 80 * i, 30);
                    }
                    else
                    {
                        tb[i].Location = new System.Drawing.Point((10 + 80 * i) - 400, 132);
                    }
                }
                tb[i].Name     = "groupboxes" + i.ToString();
                tb[i].Size     = new System.Drawing.Size(75, 77);
                tb[i].TabIndex = i;
                tb[i].Text     = DateTime.Parse(Convert.ToString(tag1.tenDaysList[i * 2].periodDate)).ToShortDateString();
                tb[i].Click   += new EventHandler(groupBox2_Enter); //RoutedEventHandler(groupBox2_Enter);
                tb[i].Cursor   = Cursors.Hand;

                mor[i * 2].Text     = "День";
                mor[i * 2].Location = new System.Drawing.Point(30, 16);
                mor[i * 2].Size     = new System.Drawing.Size(34, 13);

                mor[i * 2 + 1].Text     = "Ночь";
                mor[i * 2 + 1].Location = new System.Drawing.Point(32, 43);
                mor[i * 2 + 1].Size     = new System.Drawing.Size(32, 13);

                tem[i * 2].Text     = tag1.tenDaysList[i].temperature;
                tem[i * 2].Location = new System.Drawing.Point(36, 29);
                tem[i * 2].Size     = new System.Drawing.Size(30, 13);
                tem[i * 2].Font     = new Font("Modern No. 20", (float)10);

                tem[i * 2 + 1].Text     = tag1.tenDaysList[i + 1].temperature;
                tem[i * 2 + 1].Location = new System.Drawing.Point(36, 59);
                tem[i * 2 + 1].Size     = new System.Drawing.Size(30, 13);
                tem[i * 2 + 1].Font     = new Font("Modern No. 20", (float)10);

                tb1[i] = new System.Windows.Forms.PictureBox();

                tb1[i].Location = new System.Drawing.Point(2, 28);
                tb1[i].Name     = "pictureboxes" + i.ToString();
                tb1[i].Size     = new System.Drawing.Size(28, 40);
                string buf    = tag1.tenDaysList[i].symbol.Replace("-", "0").Replace("+", "1");
                Image  myIcon = (Image)TheTime.Properties.Resources.ResourceManager.GetObject(buf);
                tb1[i].Image    = myIcon;
                tb1[i].SizeMode = PictureBoxSizeMode.StretchImage;

                /*    tb1[i].Click += new EventHandler(groupBox2_Enter);
                 *  tem[i*2].Click += new EventHandler(groupBox2_Enter);
                 *  tem[i*2+1].Click += new EventHandler(groupBox2_Enter);
                 *  mor[i*2].Click += new EventHandler(groupBox2_Enter);
                 *  mor[i*2+1].Click += new EventHandler(groupBox2_Enter);
                 */
                tabPage3.Controls.Add(tb[i]);
                tb[i].Controls.Add(tem[i * 2]);
                tb[i].Controls.Add(tem[i * 2 + 1]);
                tb[i].Controls.Add(mor[i * 2]);
                tb[i].Controls.Add(mor[i * 2 + 1]);
                tb[i].Controls.Add(tb1[i]);
            }
        }