private void AddNewTimeButton_Click(object sender, System.Windows.RoutedEventArgs e) { Random rand = new Random(); string selectedCity = this.acBox.Text; int foundIndex = -1; for (int i = 0; i < dataSource.Count; i++) { if (dataSource[i].City.Equals(selectedCity, StringComparison.InvariantCultureIgnoreCase)) { foundIndex = i; break; } } if (foundIndex >= 0) { SavedTimeInstance timeInstance = new SavedTimeInstance(); timeInstance.Location = selectedCity; timeInstance.Description = this.CustomTagTextBox.Text; timeInstance.Hearted = (bool) heartCheckBox.IsChecked; timeInstance.Military = (bool) militaryTimeCheckBox.IsChecked; timeInstance.UTCOffset = dataSource[foundIndex].Offset; timeInstance.Id = Guid.NewGuid(); IsolatedStorageHelper.AddToTimeZoneFile(timeInstance); NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } else { MessageBox.Show("Must Select a Valid or Known City!"); } }
/// <summary> /// Add an additional time zone instance to isolated storage /// </summary> /// <param name="timeInstance">time instance to add</param> public static void AddToTimeZoneFile(SavedTimeInstance timeInstance) { List<SavedTimeInstance> readInstances = ReadFromTimeZoneFile(); if (readInstances == null) { readInstances = new List<SavedTimeInstance>(); } if (timeInstance.Hearted) { readInstances.Insert(0, timeInstance); } else { readInstances.Add(timeInstance); } WriteTimeZoneFile(readInstances); }
public void CreateUI(object sender, EventArgs e) { if (IsolatedStorageHelper.ReadFromTimeZoneFile() == null) { SavedTimeInstance defaultInstance2 = new SavedTimeInstance(); defaultInstance2.Description = "The Big Apple & Bob lives here."; defaultInstance2.Location = "New York City, NY, US"; defaultInstance2.UTCOffset = -5; defaultInstance2.Id = Guid.NewGuid(); SavedTimeInstance defaultInstance = new SavedTimeInstance(); defaultInstance.Description = "Asakusa Shrine & Jiro's Sushi!"; defaultInstance.Location = "Tokyo, JP"; defaultInstance.UTCOffset = 9; defaultInstance.Hearted = true; defaultInstance.Id = Guid.NewGuid(); IsolatedStorageHelper.AddToTimeZoneFile(defaultInstance); IsolatedStorageHelper.AddToTimeZoneFile(defaultInstance2); } this.instances = IsolatedStorageHelper.ReadFromTimeZoneFile(); // clean out children while (this.ListOfZones.Items.Count > 0) { this.ListOfZones.Items.RemoveAt(0); } // add new children for (int i = 0; i < this.instances.Count; i++) { TimeInstance timeInstance = new TimeInstance(); timeInstance.SetTimerTime( (Style)this.Resources["TimerTimeStyle"], "12:34 PM"); timeInstance.SetTimerDate( (Style)this.Resources["TimerDateStyle"], "12/12/12"); timeInstance.SetTimerLabel( (Style)this.Resources["TimerLabelStyle"], this.instances[i].Description); timeInstance.SetTimerLabelLoc( (Style)this.Resources["TimerLabelLocStyle"], this.instances[i].Location); timeInstance.SetDividerStyles( (Style)this.Resources["DividerStyle"], (Style)this.Resources["DividerTopStyle"]); timeInstance.SetGridStyles( (Style)this.Resources["DayNightGridStyle"], (Style)this.Resources["HeartGridStyle"]); timeInstance.EnableHeart(this.instances[i].Hearted); timeInstance.militaryTime = this.instances[i].Military; timeInstance.Id = this.instances[i].Id; Thickness prevThick = timeInstance.Margin; prevThick.Bottom = 25; timeInstance.Margin = prevThick; timeInstance.UTCOffset = this.instances[i].UTCOffset; ContextMenu contextMenu = new ContextMenu(); MenuItem removeMenuItem = new MenuItem() { Header = "Remove", Tag = "Remove"}; removeMenuItem.Click += new RoutedEventHandler(ConMenuRemove_Click); contextMenu.Items.Add(removeMenuItem); contextMenu.Tag = timeInstance.Id; ContextMenuService.SetContextMenu(timeInstance,contextMenu); this.ListOfZones.Items.Add(timeInstance); } RefreshUI(this, null); }