private void updateSettingsButton_Click(object sender, RoutedEventArgs e) { if (celciusRadioButton.IsChecked == true) { settings.TempChoice = "c"; } else { settings.TempChoice = "f"; } settings.Postcode = postCode.Text; settings.writeSettingsFile(); //List<String> searchCriteria = new List<string>(); //searchCriteria.Add(settings.Postcode); //settings.updateWOEID(searchCriteria); loc.updateLocation(xm); day.updateDay(xm); //day.Weather.updateForecastList(settings.WOEID); this.Close(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { // attempt to load data from .txt and .xml files try { // read settings from file set.readSettingsFile(); // load saved postcode searchCriteria.Add(set.Postcode); // get woeid using saved postcode set.updateWOEID(searchCriteria); // check if a woeid was found if (set.WOEID.Length <= 0) { // set a new valid postcode and save it to settings file set.Postcode = "ip333rl"; set.writeSettingsFile(); // use this default woeid to load program set.WOEID = "14714"; // notify user of invalid postcode displayError("Invalid saved postcode, reverted to system default location. Settings updated.\nPlease set a valid postcode in settings."); } // instantiate the Xml access object to be used for retrieving weather data xm = new XmlAccessManager(set.WOEID); // load todays info from saved postcode day = new Day(); day.updateDay(xm); // load location info from settings loc = new Location(); loc.updateLocation(xm); // load reusable forecast UI component UserControlLibrary.ForecastControl fc = new UserControlLibrary.ForecastControl(); rightStackPanel.Children.Add(fc); // set the data context for the various labels to display the correct data dayInfo.DataContext = day.Weather; lastBuildDateLabel.DataContext = day; townLabel.DataContext = loc; fc.Forecast1DC = day.Weather.ForecastList[0]; fc.Forecast2DC = day.Weather.ForecastList[1]; fc.Forecast3DC = day.Weather.ForecastList[2]; fc.Forecast4DC = day.Weather.ForecastList[3]; fc.Forecast5DC = day.Weather.ForecastList[4]; // set default location of map Microsoft.Maps.MapControl.WPF.Location l = new Microsoft.Maps.MapControl.WPF.Location(Convert.ToDouble(loc.Latitude), Convert.ToDouble(loc.Longitude)); Map.SetView(l, 11); } catch (Exception ex) { // display any errors in the error window Error errorWindow = new Error(); errorWindow.Show(); errorWindow.errorMessage.Text = ex.Message + "\n" + ex.StackTrace; } }