//Click event to return the user to the landing page private void btnReturn_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("You are about to go back to the starter page. Are you sure you want to quit?", "confirm Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) //If the user confirms that they would like to return to the landing page open it and close the current { Landing ld = new Landing(); ld.Show(); this.Hide(); } }
//begin Landing page event private void btnReturn_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("You are about to go back to the starter page. Are you sure you want to quit?", "confirm Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { Landing ld = new Landing(); ld.Show(); this.Hide(); } }
//If the signout icon is clicked sign the user out if they choose to private void signOutToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Are you sure you would like to sign out?", "Sign out", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) //If yes sign the user oput and send back to the landing page { Landing ld = new Landing(); ld.Show(); this.Hide(); } else { return; } }
//Begin helper methods //--------------------------------- //method to set information according to the users preffered city public void PreferedData(UserModel gUser, bool nextCity = false) { JSONconnection js = new JSONconnection(); //Create a connection to the JSON class weath = js.readWeatherFile(); //Get all the forecasts and store them in a list of weather models if (weath != null) //if the weather file is not empty attempt to populate the user's preffered information { if (gUser != null) //If the user is not found is not a null value attempt to populate the display with correct info { // Variable to store the weatehr values string city; double min; double max; double precip; double humidity; int cloud; string userCity = ""; if (nextCity == false) //If the user wants to see thy're home city { userCity = gUser._homeCity; } else //If the user has not specified that they want to see the next stored city { foreach (string item in gUser.prefferedCities) { if (!currentCity.Equals(item) && !previousCity.Equals(item)) { userCity = item;//store the user's city as the next extra city previousCity = currentCity; currentCity = item; break; } } } //Check the user's preferred temperature unit if (gUser.IsCelsius) { unit = "C"; } else { unit = "F"; } foreach (WeatherModel w in weath) { if (w.City.Equals(userCity) && w.Date == DateTime.Today) { w.convertUnit(gUser.IsCelsius); //Convert the unit of emasure if they user's and the weather file do not correspond city = w.City; max = w.Max; min = w.Min; precip = w.Precipitation; humidity = w.Humidity; cloud = w.CloudCover; //set the display based on the corresponding values found in the weather file lblCity.Text = "Weather in " + city + " today"; lblMax.Text = Convert.ToString(max) + "°" + unit; lblMin.Text = Convert.ToString(min) + "°" + unit; lblPrecip.Text = Convert.ToString(precip) + "%"; lblHumidity.Text = Convert.ToString(humidity) + "%"; //set the picture box based on the value that i9s found in the weather file if (cloud == 1) { pBoxSunny.Visible = true; pBoxPartlyCloudy.Visible = false; pBoxCloudy.Visible = false; pBoxStormy.Visible = false; lblCloudCover.Text = "Sunny"; } else if (cloud == 2) { pBoxSunny.Visible = false; pBoxPartlyCloudy.Visible = true; pBoxCloudy.Visible = false; pBoxStormy.Visible = false; lblCloudCover.Text = "Partly Cloud"; } else if (cloud == 3) { pBoxSunny.Visible = false; pBoxPartlyCloudy.Visible = false; pBoxCloudy.Visible = true; pBoxStormy.Visible = false; lblCloudCover.Text = "Full Cloud Cover"; } else if (cloud == 4) { pBoxSunny.Visible = false; pBoxPartlyCloudy.Visible = false; pBoxCloudy.Visible = false; pBoxStormy.Visible = true; lblCloudCover.Text = "Thunder Showers"; } } } } } else //If there is no weather data send the user back to the landing page { MessageBox.Show("There is no weather data to display. Please create weather data if you are a forecaster. If you are not please contact/" + "send an email to the developer", "Weather Data error", MessageBoxButtons.OK, MessageBoxIcon.Error); Landing ld = new Landing(); ld.Show(); this.Close(); } }