private async void ButtonAdd_Click(object sender, RoutedEventArgs e) { try { add.IsEnabled = false; cancel.IsEnabled = false; if (DatePicker.Date.Date < DateTime.Now.Date) { throw new ArgumentException("If you aren't a time traveler I think it is impossible to travel in the past"); } TravelList travelList = new TravelList { Destination = TxtDestination.Text, Day = DatePicker.Date.DateTime }; dc.addTravelDestination(travelList); TxtDestination.Text = ""; StandardPopup.IsOpen = false; } catch (ArgumentException ex) { MessageDialog msgbox = new MessageDialog(ex.Message); await msgbox.ShowAsync(); } finally { add.IsEnabled = true; cancel.IsEnabled = true; } }
public void addTravelDestination(TravelList travelList) { user.addTravelList(travelList); }
public void removeTravelList(TravelList travelList) { user.removeTravelList(travelList); }
public async void fillContext() { MobileServiceCollection<TravelList, TravelList> list = await dc.GetUserDestinations(); Char[] friendDest= dc.destinationFriend.Destination.ToCharArray(); int teller; int noemer; foreach (TravelList destination in list) { teller = 0; noemer = 0; Char[] dest = destination.Destination.ToCharArray(); if (dest.Length > friendDest.Length) { for (int i = 0; i < friendDest.Length; i++) { noemer++; if (friendDest[i] == dest[i]) { teller++; } } } else { for (int i = 0; i < dest.Length; i++) { noemer++; if (friendDest[i] == dest[i]) { teller++; } } } if ((teller / noemer) >= ratio) { double lengthRatioCurrent= (double)dest.Length / (double)friendDest.Length; Debug.WriteLine(destination.Destination); Debug.WriteLine(lengthRatioCurrent); Debug.WriteLine(lengthRatio); Debug.WriteLine((lengthRatioCurrent <= 1 && lengthRatioCurrent > lengthRatio)); Debug.WriteLine((lengthRatioCurrent > 1 && lengthRatioCurrent < lengthRatio)); Debug.WriteLine((lengthRatioCurrent < 1 && lengthRatioCurrent > lengthRatio) || (lengthRatioCurrent > 1 && lengthRatioCurrent < lengthRatio)); if ((dest.Length / friendDest.Length <= 1 && dest.Length / friendDest.Length > lengthRatio) || (dest.Length / friendDest.Length > 1 && dest.Length / friendDest.Length < lengthRatio)) { lengthRatio = dest.Length / friendDest.Length; bestFit = destination; ratio = teller / noemer; } } } this.DataContext = new CollectionViewSource { Source = await dc.getFriendPAckingItems() }; DestCombo.DataContext= new CollectionViewSource { Source = list }; if(bestFit!=null) DestCombo.SelectedItem = bestFit; TravelList selected= (TravelList) DestCombo.SelectedItem; dc.destination = selected; CatCombo.DataContext = new CollectionViewSource { Source = await selected.getTravelLists() }; }