示例#1
0
        async void OnViewInMapButtonClicked(object sender, EventArgs e)
        {
            if (!await LocationDetails.ValidateCoordinates(latitudeEntry.Text, longitudeEntry.Text))
            {
                return;
            }

            Location         location = new Location(double.Parse(latitudeEntry.Text), double.Parse(longitudeEntry.Text));
            MapLaunchOptions options  = new MapLaunchOptions {
                Name = nameEntry.Text
            };

            try
            {
                await Map.OpenAsync(location, options);
            }
            catch
            {
                // No map application available to open
                await DisplayAlert("View On Map Failure", "There is no map application available to open.", "OK");
            }
        }
示例#2
0
        async void OnAddButtonClicked(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(nameEntry.Text))
            {
                await DisplayAlert("Incomplete Name Entry", "A name entry is required.", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(latitudeEntry.Text) || string.IsNullOrWhiteSpace(longitudeEntry.Text))
            {
                await DisplayAlert("Incomplete Latitude or Longitude Entry", "Both a Latitude and Longitude entry is required.", "OK");

                return;
            }

            if (!await LocationDetails.ValidateCoordinates(latitudeEntry.Text, longitudeEntry.Text))
            {
                return;
            }

            // radius
            if (string.IsNullOrWhiteSpace(radiusEntry.Text))
            {
                await DisplayAlert("Incomplete Radius Entry", "A radius entry is required.", "OK");

                return;
            }

            try
            {
                int.Parse(radiusEntry.Text);
            }
            catch
            {
                await DisplayAlert("Invalid Radius Entry", "The radius entry must be a whole number.", "OK");

                return;
            }

            //seconds

            /*if (string.IsNullOrWhiteSpace(secondsEntry.Text))
             * {
             *  await DisplayAlert("Incomplete Seconds Entry", "A seconds entry is required.", "OK");
             *  return;
             * }
             *
             * try
             * {
             *  int.Parse(secondsEntry.Text);
             * }
             * catch
             * {
             *  await DisplayAlert("Invalid Seconds Entry", "The seconds entry must be a whole number.", "OK");
             *  return;
             * }*/

            // reminders
            if (onEnterPicker.SelectedIndex == -1 && onExitPicker.SelectedIndex == -1)
            {
                await DisplayAlert("Incomplete Reminders", "At least one reminder needs to be chosen.", "OK");

                return;
            }

            string onEnterReminder = "";

            if (onEnterPicker.SelectedIndex != -1)
            {
                onEnterReminder = onEnterPicker.SelectedItem.ToString();
            }

            string onExitReminder = "";

            if (onExitPicker.SelectedIndex != -1)
            {
                onExitReminder = onExitPicker.SelectedItem.ToString();
            }

            try
            {
                if (editingItem != null)
                {
                    editingItem.Name      = nameEntry.Text;
                    editingItem.Latitude  = double.Parse(latitudeEntry.Text);
                    editingItem.Longitude = double.Parse(longitudeEntry.Text);
                    editingItem.Radius    = int.Parse(radiusEntry.Text);
                    //editingItem.Seconds = int.Parse(secondsEntry.Text);
                    editingItem.OnEnter         = onEnterPicker.SelectedIndex != -1;
                    editingItem.OnExit          = onExitPicker.SelectedIndex != -1;
                    editingItem.OnEnterReminder = onEnterReminder;
                    editingItem.OnExitReminder  = onExitReminder;
                }
                else
                {
                    editingItem = new CoordinateItem
                    {
                        Name      = nameEntry.Text,
                        Latitude  = double.Parse(latitudeEntry.Text),
                        Longitude = double.Parse(longitudeEntry.Text),
                        Radius    = int.Parse(radiusEntry.Text),
                        //Seconds = int.Parse(secondsEntry.Text),
                        Seconds         = 0,
                        OnEnter         = onEnterPicker.SelectedIndex != -1,
                        OnExit          = onExitPicker.SelectedIndex != -1,
                        OnEnterReminder = onEnterReminder,
                        OnExitReminder  = onExitReminder,
                        IsOn            = false
                    };
                }
            }
            catch
            {
                await DisplayAlert("Invalid Entry", "An entry field contains invalid characters.", "OK");

                return;
            }

            await App.Database.SaveCoordinateAsync(editingItem);

            await Navigation.PopAsync();
        }