/// <summary> /// Create the view for InsertInfoPage class. /// </summary> /// <param name="placeID">the place id</param> /// <param name="fenceType">the fence type</param> /// <param name="sender">Specifies the sender of this event</param> private void CreatePage(int placeID, FenceType fenceType, object sender) { // Set the title of this page Title = ((Button)sender).Text; // Create an entry var FirstEntry = new Entry { BackgroundColor = Color.White, VerticalOptions = LayoutOptions.Center }; // Set the guide text for the entry if (sender == ButtonList[0] || sender == ButtonList[6]) { FirstEntry.Placeholder = "Place Name"; } else if (sender == ButtonList[2]) { if (fenceType == FenceType.GeoPoint) { FirstEntry.Placeholder = "Latitude"; } else { FirstEntry.Placeholder = "BSSID"; } } // Create a second entry var SecondEntry = new Entry { // Set the guide text Placeholder = "Longitude", // Set the background color BackgroundColor = Color.White, VerticalOptions = LayoutOptions.Center }; // Create a cancel button var cancelButton = new Button { Text = "Cancel" }; // Move to the main page when cancel button is selected cancelButton.Clicked += async(o, e) => await Navigation.PopToRootAsync(); // Create a done button var doneButton = new Button { Text = "Done" }; // Run the function about inserted information doneButton.Clicked += async(o, e) => { try { // Check the value of the first entry if (string.IsNullOrEmpty(FirstEntry.Text)) { // Throw an argument exception with message throw new ArgumentException("Content cannot be null or empty"); } if (sender == ButtonList[0]) { // Add place with inserted name perimeter.AddPlaceName(FirstEntry.Text); } else if (sender == ButtonList[2]) { Fence fence = null; switch (fenceType) { case FenceType.GeoPoint: // Check the value of the second entry if (string.IsNullOrEmpty(SecondEntry.Text)) { // Throw an argument exception with message throw new ArgumentException("Content cannot be null or empty"); } // Create a gps fence with inserted information fence = Fence.CreateGPSFence(placeID, double.Parse(FirstEntry.Text), double.Parse(SecondEntry.Text), 100, "TestAddress"); break; case FenceType.Wifi: // Create a wifi fence with inserted information fence = Fence.CreateWifiFence(placeID, FirstEntry.Text, "TestAddress"); break; case FenceType.Bluetooth: // Create a bt fence with inserted information fence = Fence.CreateBTFence(placeID, FirstEntry.Text, "TestAddress"); break; default: break; } if (fence != null) { // Add the fence perimeter.AddGeofence(fence); } } else if (sender == ButtonList[6]) { // Update the place name perimeter.UpdatePlace(placeID, FirstEntry.Text); } } catch (Exception exception) { // Display the exception message await DisplayAlert("Alert", exception.Message, "OK"); } // Move to the main page await Navigation.PopToRootAsync(); }; // Create a layout for buttons var ButtonGridLayout = new Grid { RowDefinitions = { new RowDefinition { Height = GridLength.Star }, }, ColumnDefinitions = { new ColumnDefinition { Width = GridLength.Star }, new ColumnDefinition { Width = GridLength.Star }, }, VerticalOptions = LayoutOptions.End }; ButtonGridLayout.Children.Add(cancelButton, 0, 0); ButtonGridLayout.Children.Add(doneButton, 1, 0); // Create a layout for this page StackLayout parent = new StackLayout { Margin = 10 }; parent.Children.Add(FirstEntry); if (sender == ButtonList[2] && fenceType == FenceType.GeoPoint) { parent.Children.Add(SecondEntry); } parent.Children.Add(ButtonGridLayout); Content = parent; }