private void SetToolTips(Settings.Settings set) { ToolTip tool = new ToolTip(); if (set.General.Language == "English") { tool.SetToolTip(this.pictureBox1, "Temperature"); tool.SetToolTip(this.pictureBox2, "Wind"); tool.SetToolTip(this.pictureBox3, "Cloudiness"); tool.SetToolTip(this.pictureBox4, "Humidity"); tool.SetToolTip(this.pictureBox5, "Pressure"); tool.SetToolTip(this.pictureBox6, "Sunrise"); tool.SetToolTip(this.pictureBox7, "Sunset"); tool.SetToolTip(this.city_label, "Your city"); } else { tool.SetToolTip(this.pictureBox1, "Температура воздуха"); tool.SetToolTip(this.pictureBox2, "Ветер"); tool.SetToolTip(this.pictureBox3, "Облачность"); tool.SetToolTip(this.pictureBox4, "Влажность"); tool.SetToolTip(this.pictureBox5, "Давление"); tool.SetToolTip(this.pictureBox6, "Восход"); tool.SetToolTip(this.pictureBox7, "Закат"); tool.SetToolTip(this.city_label, "Ваш город"); } }
private async void GetWeatherFiveDays(Settings.Settings set) { string req = String.Format("http://api.openweathermap.org/data/2.5/forecast?id={0}&lang={3}&units={1}&APPID={2}", set.City.Id, set.Weather.Units, APPID, Settings.SettingsHelper.GetLanguage(set)); WebRequest request = WebRequest.Create(req); request.Method = "POST"; request.ContentType = "application/x-www-urlencoded"; WebResponse response = await request.GetResponseAsync(); string answer = ""; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { answer = await sr.ReadToEndAsync(); } } response.Close(); Weather.OpenWeatherFiveDays OWFD = JsonConvert.DeserializeObject <Weather.OpenWeatherFiveDays>(answer); Point p = this.Location; FiveDayWeather FDW = new FiveDayWeather(OWFD, set, answer, p); FDW.Owner = this; this.Hide(); FDW.Show(); }
//save all changes private void OK_button_Click(object sender, EventArgs e) { Settings.Settings set = new Settings.Settings(); Settings.City city = new Settings.City(); Settings.General general = new Settings.General(); Settings.Weather weather = new Settings.Weather(); //default city if (cities_dataGridView.SelectedRows.Count == 0) { city.Id = 524901; city.Name = "Moscow"; city.Country = "RU"; } else { city.Id = Convert.ToInt64(cities_dataGridView.SelectedRows[0].Cells["Id"].Value); city.Name = cities_dataGridView.SelectedRows[0].Cells["City"].Value.ToString(); city.Country = cities_dataGridView.SelectedRows[0].Cells["Country"].Value.ToString(); } weather.Units = dataFormat_comboBox.Text; weather.PressureValue = pressureValue_comboBox.Text; weather.MinMaxTemp = minMaxTemp_checkBox.Checked; general.Language = language_listBox.SelectedItem.ToString(); general.WinAutostart = autoStart_checkBox.Checked; if (updTimeEng.Count > 0) { general.UpdateTime = updTimeEng[weatherUpdTime_comboBox.Text]; } else { general.UpdateTime = updTimeRu[weatherUpdTime_comboBox.Text]; } set.City = city; set.General = general; set.Weather = weather; if (autoStart_checkBox.Enabled) { set.WinAutoStart(); } set.SaveSettings(); changeUpdTimeDeleg(general.UpdateTime); getWeatherDeleg(set); if (general.Language == "English") { ChangeFormLanguage(Localizations.English); changeFormLangDeleg(Localizations.English); } else { ChangeFormLanguage(Localizations.Russian); changeFormLangDeleg(Localizations.Russian); } this.Close(); }
private void SetSettings(Settings.Settings set) { foreach (DataGridViewRow row in cities_dataGridView.Rows) { if (Convert.ToInt32(row.Cells["id"].Value) == set.City.Id) { cities_dataGridView.ClearSelection(); cities_dataGridView.Rows[row.Index].Selected = true; cities_dataGridView.CurrentCell = cities_dataGridView.Rows[row.Index].Cells[1]; break; } } if (set.General.Language == "English") { weatherUpdTime_comboBox.Text = GetKeyWeatheUpd(set.General.UpdateTime, updTimeEng); } else { weatherUpdTime_comboBox.Text = GetKeyWeatheUpd(set.General.UpdateTime, updTimeRu); } dataFormat_comboBox.Text = set.Weather.Units; pressureValue_comboBox.Text = set.Weather.PressureValue; minMaxTemp_checkBox.Checked = set.Weather.MinMaxTemp; autoStart_checkBox.Checked = set.General.WinAutostart; for (int i = 0; i < language_listBox.Items.Count; i++) { if (language_listBox.Items[i].ToString() == set.General.Language) { language_listBox.SelectedIndex = i; } } }
private void settings_pictureBox_Click(object sender, EventArgs e) { SettingsForm SF = new SettingsForm(new GetWeatherDel(GetWeatherNow), new ChangeFormLanguageDel(ChangeFormLanguage), new ChangeUpdTimeDel(ChengeUpdTime)); SF.ShowDialog(); Settings.Settings set = JsonConvert.DeserializeObject <Settings.Settings>(File.ReadAllText(System.Environment.CurrentDirectory + @"\settings.json")); short_radioButton.Checked = true; SetToolTips(set); }
private async void GetWeatherNow(Settings.Settings set) { // WebRequest request = WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=Syktyvkar&lang=en&units=metric&APPID=284736d7aa6652238e2598fa8ce6dd15"); string req1 = String.Format("http://api.openweathermap.org/data/2.5/weather?id={0}&lang={3}&units={1}&APPID={2}", set.City.Id, set.Weather.Units, APPID, Settings.SettingsHelper.GetLanguage(set)); string req2 = String.Format("http://api.openweathermap.org/data/2.5/forecast?id={0}&lang={3}&units={1}&APPID={2}", set.City.Id, set.Weather.Units, APPID, Settings.SettingsHelper.GetLanguage(set)); WebRequest request = WebRequest.Create(req1); request.Method = "POST"; request.ContentType = "application/x-www-urlencoded"; try { WebResponse response = await request.GetResponseAsync(); string answer = ""; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { answer = await sr.ReadToEndAsync(); } } response.Close(); Weather.OpenWeatherNow OWN = JsonConvert.DeserializeObject <Weather.OpenWeatherNow>(answer); request = WebRequest.Create(req2); response = await request.GetResponseAsync(); answer = ""; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { answer = await sr.ReadToEndAsync(); } } response.Close(); Weather.OpenWeatherFiveDays OWFD = JsonConvert.DeserializeObject <Weather.OpenWeatherFiveDays>(answer); SetWeatherParams(OWN, OWFD, set); } catch { if (set.General.Language == "English") { SetWeatherParams("Сonnection problemю. No data", set); } else { SetWeatherParams("Проблемы с подключением. Нет данных", set); } } }
ChangeUpdTimeDel changeUpdTimeDeleg; //делегат для изменения таймера обновления public SettingsForm(GetWeatherDel sender_I, ChangeFormLanguageDel sender_II, ChangeUpdTimeDel sender_III) { InitializeComponent(); if (SettingsHelper.IsAdministrator()) { autoStart_checkBox.Enabled = true; } Settings.Settings set = JsonConvert.DeserializeObject <Settings.Settings>(File.ReadAllText(System.Environment.CurrentDirectory + @"\settings.json")); if (set.General.Language == "English") { ChangeFormLanguage(Localizations.English); updTimeEng.Add("5m", 5); updTimeEng.Add("10m", 10); updTimeEng.Add("15m", 15); updTimeEng.Add("20m", 20); updTimeEng.Add("30m", 30); updTimeEng.Add("45m", 45); updTimeEng.Add("1h", 60); updTimeEng.Add("1h 30m", 90); updTimeEng.Add("2h", 120); updTimeEng.Add("3h", 180); weatherUpdTime_comboBox.DataSource = updTimeEng.Keys.ToList <string>(); } else { ChangeFormLanguage(Localizations.Russian); updTimeRu.Add("5м", 5); updTimeRu.Add("10м", 10); updTimeRu.Add("15м", 15); updTimeRu.Add("20м", 20); updTimeRu.Add("30м", 30); updTimeRu.Add("45м", 45); updTimeRu.Add("1ч", 60); updTimeRu.Add("1ч 30м", 90); updTimeRu.Add("2ч", 120); updTimeRu.Add("3ч", 180); weatherUpdTime_comboBox.DataSource = updTimeRu.Keys.ToList <string>(); } getWeatherDeleg = sender_I; changeFormLangDeleg = sender_II; changeUpdTimeDeleg = sender_III; SetToolTips(set); // устанавливаю описание для всех параметров FillCitiesTable(); //заполняю таблицу городов SetSettings(set); //устанавливаю все парметры приложения из settings.json }
private void SetWeatherParams(string str, Settings.Settings set) { city_label.Text = set.City.Name; description_label.Text = str; temp_label.Text = String.Empty; pressure_label.Text = String.Empty; wind_label.Text = String.Empty; dateNow_label.Text = String.Empty; humidity_label.Text = String.Empty; cloudiness_label.Text = String.Empty; sunrise_label.Text = String.Empty; sunset_label.Text = String.Empty; }
private void SetToolTips(Settings.Settings set) { ToolTip tool = new ToolTip(); if (set.General.Language == "English") { tool.SetToolTip(this.label6, "Metric (°C, meter/sec)\r\nImperial (°F, miles/hour)"); tool.SetToolTip(this.label7, "mmHg - millimeters of mercury\r\nhPa - hectopascal"); tool.SetToolTip(this.question_label, "For adding the programm to Windows autostart,\r\nyou need start the programm with administrator mode"); } else { tool.SetToolTip(this.label6, "Metric (°C, метр/сек)\r\nImperial (°F, миль/час)"); tool.SetToolTip(this.label7, "mmHg - миллиметров ртутного столба\r\nhPa - гектопаскаль"); tool.SetToolTip(this.question_label, "Для добавления программы в автозагрузку,\r\nнеобходимо запустить её от имени администратора"); } }
public Main() { InitializeComponent(); this.ShowInTaskbar = false; notifyIcon1.Visible = false; this.notifyIcon1.MouseClick += NotifyIcon1_MouseClick; this.Resize += Main_Resize; Settings.Settings set = JsonConvert.DeserializeObject <Settings.Settings>(File.ReadAllText(System.Environment.CurrentDirectory + @"\settings.json")); ChengeUpdTime(set.General.UpdateTime); //обновляю время таймера обновления if (set.General.Language == "English") { ChangeFormLanguage(Localizations.English); } else { ChangeFormLanguage(Localizations.Russian); } GetWeatherNow(set); SetToolTips(set); }
public FiveDayWeather(Weather.OpenWeatherFiveDays OWFD, Settings.Settings set, string str, Point p) { InitializeComponent(); this.Location = p; Settings.SettingsHelper.GetWeatherParams(set, ref temp, ref wind, ref pressure); wind_label_1.Text += " " + wind; wind_label_2.Text += " " + wind; wind_label_3.Text += " " + wind; int start = GetFirstTomorrow(OWFD); //date if (set.General.Language == "English") { this.Text = "Next 3 days weather"; first_date_label.Text = String.Format("{0}, {1}", OWFD.List[start].Date.DayOfWeek.ToString().ToUpper(), OWFD.List[start].Date.ToString("d MMM yyyy", new CultureInfo("en-US"))); second_date_label.Text = String.Format("{0}, {1}", OWFD.List[start + 8].Date.DayOfWeek.ToString().ToUpper(), OWFD.List[start + 8].Date.ToString("d MMM yyyy", new CultureInfo("en-US"))); third_date_label.Text = String.Format("{0}, {1}", OWFD.List[start + 16].Date.DayOfWeek.ToString().ToUpper(), OWFD.List[start + 16].Date.ToString("d MMM yyyy", new CultureInfo("en-US"))); } else { this.Text = "Погода на следующие 3 дня"; first_date_label.Text = String.Format("{0}, {1}", OWFD.List[start].Date.ToString("dddd", new CultureInfo("ru-RU")).ToUpper(), OWFD.List[start].Date.ToString("d MMM yyyy", new CultureInfo("ru-RU"))); second_date_label.Text = String.Format("{0}, {1}", OWFD.List[start + 8].Date.ToString("dddd", new CultureInfo("ru-RU")).ToUpper(), OWFD.List[start + 8].Date.ToString("d MMM yyyy", new CultureInfo("ru-RU"))); third_date_label.Text = String.Format("{0}, {1}", OWFD.List[start + 16].Date.ToString("dddd", new CultureInfo("ru-RU")).ToUpper(), OWFD.List[start + 16].Date.ToString("d MMM yyyy", new CultureInfo("ru-RU"))); } //icon first_icon_n.Image = OWFD.List[start].Weather[0].IconPath; first_icon_m.Image = OWFD.List[start + 2].Weather[0].IconPath; first_icon_a.Image = OWFD.List[start + 4].Weather[0].IconPath; first_icon_e.Image = OWFD.List[start + 6].Weather[0].IconPath; second_icon_n.Image = OWFD.List[start + 8].Weather[0].IconPath; second_icon_m.Image = OWFD.List[start + 10].Weather[0].IconPath; second_icon_a.Image = OWFD.List[start + 12].Weather[0].IconPath; second_icon_e.Image = OWFD.List[start + 14].Weather[0].IconPath; third_icon_n.Image = OWFD.List[start + 16].Weather[0].IconPath; third_icon_m.Image = OWFD.List[start + 18].Weather[0].IconPath; third_icon_a.Image = OWFD.List[start + 20].Weather[0].IconPath; third_icon_e.Image = OWFD.List[start + 22].Weather[0].IconPath; //temp first_temp_n.Text = Math.Round(OWFD.List[start].Main.Temp, 0) + temp; first_temp_m.Text = Math.Round(OWFD.List[start + 2].Main.Temp, 0) + temp; first_temp_a.Text = Math.Round(OWFD.List[start + 4].Main.Temp, 0) + temp; first_temp_e.Text = Math.Round(OWFD.List[start + 6].Main.Temp, 0) + temp; second_temp_n.Text = Math.Round(OWFD.List[start + 8].Main.Temp, 0) + temp; second_temp_m.Text = Math.Round(OWFD.List[start + 10].Main.Temp, 0) + temp; second_temp_a.Text = Math.Round(OWFD.List[start + 12].Main.Temp, 0) + temp; second_temp_e.Text = Math.Round(OWFD.List[start + 14].Main.Temp, 0) + temp; third_temp_n.Text = Math.Round(OWFD.List[start + 16].Main.Temp, 0) + temp; third_temp_m.Text = Math.Round(OWFD.List[start + 18].Main.Temp, 0) + temp; third_temp_a.Text = Math.Round(OWFD.List[start + 20].Main.Temp, 0) + temp; third_temp_e.Text = Math.Round(OWFD.List[start + 22].Main.Temp, 0) + temp; //wind first_wind_n.Text = Math.Round(OWFD.List[start].Wind.Speed, 0).ToString(); first_wind_m.Text = Math.Round(OWFD.List[start + 2].Wind.Speed, 0).ToString(); first_wind_a.Text = Math.Round(OWFD.List[start + 4].Wind.Speed, 0).ToString(); first_wind_e.Text = Math.Round(OWFD.List[start + 6].Wind.Speed, 0).ToString(); second_wind_n.Text = Math.Round(OWFD.List[start + 8].Wind.Speed, 0).ToString(); second_wind_m.Text = Math.Round(OWFD.List[start + 10].Wind.Speed, 0).ToString(); second_wind_a.Text = Math.Round(OWFD.List[start + 12].Wind.Speed, 0).ToString(); second_wind_e.Text = Math.Round(OWFD.List[start + 14].Wind.Speed, 0).ToString(); third_wind_n.Text = Math.Round(OWFD.List[start + 16].Wind.Speed, 0).ToString(); third_wind_m.Text = Math.Round(OWFD.List[start + 18].Wind.Speed, 0).ToString(); third_wind_a.Text = Math.Round(OWFD.List[start + 20].Wind.Speed, 0).ToString(); third_wind_e.Text = Math.Round(OWFD.List[start + 22].Wind.Speed, 0).ToString(); //humidity first_humidity_n.Text = OWFD.List[start].Main.Humidity.ToString(); first_humidity_m.Text = OWFD.List[start + 2].Main.Humidity.ToString(); first_humidity_a.Text = OWFD.List[start + 4].Main.Humidity.ToString(); first_humidity_e.Text = OWFD.List[start + 6].Main.Humidity.ToString(); second_humidity_n.Text = OWFD.List[start + 8].Main.Humidity.ToString(); second_humidity_m.Text = OWFD.List[start + 10].Main.Humidity.ToString(); second_humidity_a.Text = OWFD.List[start + 12].Main.Humidity.ToString(); second_humidity_e.Text = OWFD.List[start + 14].Main.Humidity.ToString(); third_humidity_n.Text = OWFD.List[start + 16].Main.Humidity.ToString(); third_humidity_m.Text = OWFD.List[start + 18].Main.Humidity.ToString(); third_humidity_a.Text = OWFD.List[start + 20].Main.Humidity.ToString(); third_humidity_e.Text = OWFD.List[start + 22].Main.Humidity.ToString(); //cloudeness first_cloudiness_n.Text = OWFD.List[start].Clouds.All.ToString(); first_cloudiness_m.Text = OWFD.List[start + 2].Clouds.All.ToString(); first_cloudiness_a.Text = OWFD.List[start + 4].Clouds.All.ToString(); first_cloudiness_e.Text = OWFD.List[start + 6].Clouds.All.ToString(); second_cloudiness_n.Text = OWFD.List[start + 8].Clouds.All.ToString(); second_cloudiness_m.Text = OWFD.List[start + 10].Clouds.All.ToString(); second_cloudiness_a.Text = OWFD.List[start + 12].Clouds.All.ToString(); second_cloudiness_e.Text = OWFD.List[start + 14].Clouds.All.ToString(); third_cloudiness_n.Text = OWFD.List[start + 16].Clouds.All.ToString(); third_cloudiness_m.Text = OWFD.List[start + 18].Clouds.All.ToString(); third_cloudiness_a.Text = OWFD.List[start + 20].Clouds.All.ToString(); third_cloudiness_e.Text = OWFD.List[start + 22].Clouds.All.ToString(); }
private void threedays_pictureBox_Click(object sender, EventArgs e) { Settings.Settings set = JsonConvert.DeserializeObject <Settings.Settings>(File.ReadAllText(System.Environment.CurrentDirectory + @"\settings.json")); GetWeatherFiveDays(set); }
private void updateWeather_timer_Tick(object sender, EventArgs e) { Settings.Settings set = JsonConvert.DeserializeObject <Settings.Settings>(File.ReadAllText(System.Environment.CurrentDirectory + @"\settings.json")); GetWeatherNow(set); }
private void SetWeatherParams(Weather.OpenWeatherNow OWN, Weather.OpenWeatherFiveDays OWFD, Settings.Settings set) { //OWN VALUES string tempValue = ""; string windValue = ""; string pressureValue = ""; Settings.SettingsHelper.GetWeatherParams(set, ref tempValue, ref windValue, ref pressureValue); if (set.General.Language == "English") { if (set.Weather.MinMaxTemp) { temp_label.Text = String.Format("{0}{3} (Min temp {1}{3}, Max temp {2}{3})", Math.Round(OWN.Main.Temp, 0), OWN.Main.TempMin, OWN.Main.TempMax, tempValue); } else { temp_label.Text = String.Format("{0}{1}", Math.Round(OWN.Main.Temp, 0), tempValue); } wind_label.Text = String.Format("{0}, speed: {1} {2}", OWN.Wind.DegStrEng, OWN.Wind.Speed, windValue); wind_label_1.Text = "Wind speed, " + windValue; dateNow_label.Text = DateTime.Now.ToString("d MMM yyyy", new CultureInfo("en-US")); } else { if (set.Weather.MinMaxTemp) { temp_label.Text = String.Format("{0}{3} (Мин. темп. {1}{3}, Макс. темп. {2}{3})", OWN.Main.Temp, OWN.Main.TempMin, OWN.Main.TempMax, tempValue); } else { temp_label.Text = String.Format("{0}{1}", OWN.Main.Temp, tempValue); } wind_label.Text = String.Format("{0}, скорость: {1} {2}", OWN.Wind.DegStrRu, OWN.Wind.Speed, windValue); wind_label_1.Text = "Скорость ветра, " + windValue; dateNow_label.Text = DateTime.Now.ToString("D", new CultureInfo("ru-RU")); } city_label.Text = OWN.Name; humidity_label.Text = OWN.Main.Humidity.ToString() + "%"; pressure_label.Text = String.Format("{0} {1}", Math.Round(OWN.Main.Pressure, 0), pressureValue); description_label.Text = FirstUpper(OWN.Weather[0].Description); icon_pictureBox.Image = OWN.Weather[0].IconPath; cloudiness_label.Text = OWN.Clouds.All + "%"; wind_pictureBox.Image = OWN.Wind.Img; sunrise_label.Text = OWN.Sys.SunriseLocal.ToString("t"); sunset_label.Text = OWN.Sys.SunsetLocal.ToString("t"); //OWFD VALUES //time time1_label.Text = OWFD.List[1].Date.ToString("t"); time2_label.Text = OWFD.List[2].Date.ToString("t"); time3_label.Text = OWFD.List[3].Date.ToString("t"); time4_label.Text = OWFD.List[4].Date.ToString("t"); time5_label.Text = OWFD.List[5].Date.ToString("t"); time6_label.Text = OWFD.List[6].Date.ToString("t"); //icons icon1.Image = OWFD.List[1].Weather[0].IconPath; icon2.Image = OWFD.List[2].Weather[0].IconPath; icon3.Image = OWFD.List[3].Weather[0].IconPath; icon4.Image = OWFD.List[4].Weather[0].IconPath; icon5.Image = OWFD.List[5].Weather[0].IconPath; icon6.Image = OWFD.List[6].Weather[0].IconPath; //temp temp1.Text = Math.Round(OWFD.List[1].Main.Temp, 0) + tempValue; temp2.Text = Math.Round(OWFD.List[2].Main.Temp, 0) + tempValue; temp3.Text = Math.Round(OWFD.List[3].Main.Temp, 0) + tempValue; temp4.Text = Math.Round(OWFD.List[4].Main.Temp, 0) + tempValue; temp5.Text = Math.Round(OWFD.List[5].Main.Temp, 0) + tempValue; temp6.Text = Math.Round(OWFD.List[6].Main.Temp, 0) + tempValue; //wind wind1.Text = Math.Round(OWFD.List[1].Wind.Speed, 0).ToString(); wind2.Text = Math.Round(OWFD.List[2].Wind.Speed, 0).ToString(); wind3.Text = Math.Round(OWFD.List[3].Wind.Speed, 0).ToString(); wind4.Text = Math.Round(OWFD.List[4].Wind.Speed, 0).ToString(); wind5.Text = Math.Round(OWFD.List[5].Wind.Speed, 0).ToString(); wind6.Text = Math.Round(OWFD.List[6].Wind.Speed, 0).ToString(); }