//Update the result box private void UpdateUpdateBox() { editBox.Items.Clear(); for (int i = 0; i < Weather.GetCityNameCount(); i++) { editBox.Items.Add(Weather.GetCityName(i) + " - " + Weather.GetWeatherDate(i)); } }
// //Code for Report section // //Populate the report city selection combo box private void PopulateCityComboBox() { cityComboBox.Items.Clear(); for (int i = 0; i < (Weather.GetCityNameCount()); i++) { if (cityComboBox.Items.Contains(Weather.GetCityName(i))) { } else { cityComboBox.Items.Add(Weather.GetCityName(i)); } } }
//Retrieve and compare the results for the weather report private void PopulateReportTable() { int lowMinTemp = 0; int highMinTemp = 0; int lowMaxTemp = 0; int highMaxTemp = 0; int lowPrecip = 0; int highPrecip = 0; int lowHumid = 0; int highHumid = 0; int lowSpeed = 0; int highSpeed = 0; reportTable.Rows.Clear(); if (citiesSelected.Count != 0) { for (int i = 0; i < citiesSelected.Count; i++) { for (int j = 0; j < Weather.GetCityNameCount(); j++) { if (Weather.GetCityName(j) == Convert.ToString(citiesSelected[i])) { if (Weather.GetWeatherDate(j) >= startDateBox.Value && Weather.GetWeatherDate(j) <= endDateBox.Value) { if (reportTable.Rows.Count == 0) { //Initiate values in the lowest and highest section lowMinTemp = Convert.ToInt32(Weather.GetMinTemp(j)); highMinTemp = Convert.ToInt32(Weather.GetMinTemp(j)); lowMaxTemp = Convert.ToInt32(Weather.GetMaxTemp(j)); highMaxTemp = Convert.ToInt32(Weather.GetMaxTemp(j)); lowPrecip = Convert.ToInt32(Weather.GetPrecipitation(j)); highPrecip = Convert.ToInt32(Weather.GetPrecipitation(j)); lowHumid = Convert.ToInt32(Weather.GetHumidity(j)); highHumid = Convert.ToInt32(Weather.GetHumidity(j)); lowSpeed = Convert.ToInt32(Weather.GetWindSpeed(j)); highSpeed = Convert.ToInt32(Weather.GetWindSpeed(j)); } else { //Update values if lowest and highest section not empty if (Convert.ToInt32(Weather.GetMinTemp(j)) < lowMinTemp) { lowMinTemp = Convert.ToInt32(Weather.GetMinTemp(j)); } if (Convert.ToInt32(Weather.GetMinTemp(j)) > highMinTemp) { highMinTemp = Convert.ToInt32(Weather.GetMinTemp(j)); } if (Convert.ToInt32(Weather.GetMaxTemp(j)) < lowMaxTemp) { lowMaxTemp = Convert.ToInt32(Weather.GetMaxTemp(j)); } if (Convert.ToInt32(Weather.GetMaxTemp(j)) > highMaxTemp) { highMaxTemp = Convert.ToInt32(Weather.GetMaxTemp(j)); } if (Convert.ToInt32(Weather.GetPrecipitation(j)) < lowPrecip) { lowPrecip = Convert.ToInt32(Weather.GetPrecipitation(j)); } if (Convert.ToInt32(Weather.GetPrecipitation(j)) > highPrecip) { highPrecip = Convert.ToInt32(Weather.GetPrecipitation(j)); } if (Convert.ToInt32(Weather.GetHumidity(j)) < lowHumid) { lowHumid = Convert.ToInt32(Weather.GetHumidity(j)); } if (Convert.ToInt32(Weather.GetHumidity(j)) > highHumid) { highHumid = Convert.ToInt32(Weather.GetHumidity(j)); } if (Convert.ToInt32(Weather.GetWindSpeed(j)) < lowSpeed) { lowSpeed = Convert.ToInt32(Weather.GetWindSpeed(j)); } if (Convert.ToInt32(Weather.GetWindSpeed(j)) > highSpeed) { highSpeed = Convert.ToInt32(Weather.GetWindSpeed(j)); } } //Populate the table with the report reportTable.Rows.Add(Weather.GetCityName(j), Weather.GetWeatherDate(j).ToShortDateString(), Weather.GetMinTemp(j) + "°C", Weather.GetMaxTemp(j) + "°C", Weather.GetPrecipitation(j) + "%", Weather.GetHumidity(j) + "%", Weather.GetWindSpeed(j) + "km/h"); lowestMinTemp.Text = Convert.ToString(lowMinTemp) + " °C"; highestMinTemp.Text = Convert.ToString(highMinTemp) + " °C"; lowestMaxTemp.Text = Convert.ToString(lowMaxTemp) + " °C"; highestMaxTemp.Text = Convert.ToString(highMaxTemp) + " °C"; lowestPrecip.Text = Convert.ToString(lowPrecip) + " %"; highestPrecip.Text = Convert.ToString(highPrecip) + " %"; lowestHumid.Text = Convert.ToString(lowHumid) + " %"; highestHumid.Text = Convert.ToString(highHumid) + " %"; lowestWind.Text = Convert.ToString(lowSpeed) + " km/h"; highestWind.Text = Convert.ToString(highSpeed) + " km/h"; } } } } //Reset report and display error if (reportTable.Rows.Count == 0) { lowestMinTemp.Text = ""; highestMinTemp.Text = ""; lowestMaxTemp.Text = ""; highestMaxTemp.Text = ""; lowestPrecip.Text = ""; highestPrecip.Text = ""; lowestHumid.Text = ""; highestHumid.Text = ""; lowestWind.Text = ""; highestWind.Text = ""; MessageBox.Show("No Results Found."); } } else { MessageBox.Show("You have not selected any cities. \nTo obtain results, please select one or more cities."); } }