Exemplo n.º 1
0
        private void OnAddPersonClick(object sender, RoutedEventArgs args)
        {
            var dialog = new PersonDialog();

            dialog.Owner = this;
            dialog.ShowDialog();
            if (dialog.DialogResult == false)
            {
                return;
            }

            string city         = dialog.AddressCity;
            string country      = dialog.AddressCountry;
            string streetName   = dialog.AddressStreetName;
            int    streetNumber = dialog.AddressStreetNumber;
            // Add person to map and database here.
            var pin = AddPin(latestClickLocation, "Person", Colors.Blue);

            pin.MouseDown += (s, a) =>
            {
                // Handle click on person pin here.
                MessageBox.Show("You clicked a person");
                UpdateMap();

                // Prevent click from being triggered on map.
                a.Handled = true;
            };
        }
        private void OnAddPersonClick(object sender, RoutedEventArgs args)
        {
            var dialog = new PersonDialog();

            dialog.Owner = this;
            dialog.ShowDialog();
            if (dialog.DialogResult == false)
            {
                return;
            }

            string firstName    = dialog.PersonFirstName;
            string lastName     = dialog.PersonLastName;
            string city         = dialog.AddressCity;
            string country      = dialog.AddressCountry;
            string streetName   = dialog.AddressStreetName;
            int    streetNumber = dialog.AddressStreetNumber;

            // Add person to map and database here.
            Person person = AddPersonToDatabase(dialog, latestClickLocation);

            var pin = AddPin(latestClickLocation, HooverOnPersonPinShowTooltip(person), Colors.Blue, person);

            pin.MouseDown += (s, a) =>
            {
                // Handle click on person pin here.
                activePerson = db.Person.First(p => p.ID == person.ID);
                UpdateMap();

                // Prevent click from being triggered on map.
                a.Handled = true;
            };
        }
        private void OnAddPersonClick(object sender, RoutedEventArgs args)
        {
            var dialog = new PersonDialog();

            dialog.Owner = this;
            dialog.ShowDialog();
            if (dialog.DialogResult == false)
            {
                return;
            }

            string firstName    = dialog.PersonFirstName;
            string lastName     = dialog.PersonLastName;
            string city         = dialog.AddressCity;
            string country      = dialog.AddressCountry;
            string streetName   = dialog.AddressStreetName;
            int    streetNumber = dialog.AddressStreetNumber;

            // Add person to map and database here.
            var    person    = new Person();
            string streetNum = streetNumber.ToString();

            person.FirstName    = firstName;
            person.LastName     = lastName;
            person.Latitude     = latestClickLocation.Latitude;
            person.Longitude    = latestClickLocation.Longitude;
            person.Country      = country;
            person.City         = city;
            person.StreetName   = streetName;
            person.StreetNumber = byte.Parse(streetNum);
            db.Add(person);
            db.SaveChanges();
            OnMapLeftClick();
        }
Exemplo n.º 4
0
        private async void OnAddPersonClickAsync(object sender, RoutedEventArgs args)
        {
            var dialog = new PersonDialog
            {
                Owner = this
            };

            dialog.ShowDialog();
            if (dialog.DialogResult == false)
            {
                return;
            }

            string city         = dialog.AddressCity;
            string country      = dialog.AddressCountry;
            string streetName   = dialog.AddressStreetName;
            byte   streetNumber = dialog.AddressStreetNumber;

            string tooltip = $"Latitude:\t\t{latestClickLocation.Latitude}\r\nLongitude:\t{latestClickLocation.Longitude}\r\n" +
                             $"Name:\t\t{dialog.PersonFirstName + " " + dialog.PersonLastName}\r\nStreet address:\t{streetName + " " + streetNumber}";

            Pushpin pin = AddPin(latestClickLocation, tooltip, Colors.Blue);

            pin.MouseLeftButtonDown += OnPersonPinClick;
            personPins.Add(pin);

            Person person = new Person()
            {
                FirstName    = dialog.PersonFirstName,
                LastName     = dialog.PersonLastName,
                City         = city,
                Country      = country,
                StreetName   = streetName,
                StreetNumber = streetNumber,
                Coordinates  = latestClickLocation
            };
            await _db.AddPersonAsync(person);

            pin.Tag         = person;
            activePinPerson = person;

            foreach (var personPin in personPins)
            {
                if (personPin == pin)
                {
                    personPin.Opacity = 1;
                }
                else
                {
                    personPin.Opacity = 0.5;
                }
            }

            foreach (var cachePin in cachePins)
            {
                cachePin.Background = colors["Red"];
            }
        }
Exemplo n.º 5
0
        // Here the person object and pin is created and saved to database on map right-click.
        private async void BeginOnAddPersonClick(object sender, RoutedEventArgs args)
        {
            using (var database = new AppDbContext())
            {
                var dialog = new PersonDialog();
                dialog.Owner = this;
                dialog.ShowDialog();
                if (dialog.DialogResult == false)
                {
                    return;
                }

                string firstName    = dialog.PersonFirstName;
                string lastName     = dialog.PersonLastName;
                string city         = dialog.AddressCity;
                string country      = dialog.AddressCountry;
                string streetName   = dialog.AddressStreetName;
                int    streetNumber = dialog.AddressStreetNumber;

                person.Coordinates    = coordinates;
                person.FirstName      = firstName;
                person.LastName       = lastName;
                person.Country        = country;
                person.City           = city;
                person.StreetName     = streetName;
                person.StreetNumber   = (byte)streetNumber;
                coordinates.Longitude = latestClickLocation.Longitude;
                coordinates.Latitude  = latestClickLocation.Latitude;

                string personToolTip = person.FirstName + " " + person.LastName + "\n" + person.StreetName + " " + person.StreetNumber + "\n" + person.City + "\n" + person.Country;
                var    pin           = AddPin(latestClickLocation, personToolTip, Colors.Blue);

                var task = Task.Run(() =>
                {
                    database.Add(person);
                    database.SaveChanges();
                });
                await(task);

                ActivePersonID = person.ID;
                person.ID      = 0;
                UpdateMap();
            }
        }
        private void OnAddPersonClick(object sender, RoutedEventArgs args)
        {
            var dialog = new PersonDialog();

            dialog.Owner = this;
            dialog.ShowDialog();
            if (dialog.DialogResult == false)
            {
                return;
            }
            string firstName    = dialog.PersonFirstName;
            string lastName     = dialog.PersonLastName;
            double latitude     = latestClickLocation.Latitude;
            double longitude    = latestClickLocation.Longitude;
            string city         = dialog.AddressCity;
            string country      = dialog.AddressCountry;
            string streetName   = dialog.AddressStreetName;
            int    streetNumber = dialog.AddressStreetNumber;

            Person person = new Person
            {
                FirstName    = firstName,
                LastName     = lastName,
                Latitude     = latitude,
                Longitude    = longitude,
                City         = city,
                Country      = country,
                StreetName   = streetName,
                StreetNumber = (short)streetNumber
            };

            db.Add(person);
            db.SaveChanges();

            string   message  = TooltipMessagePer(person);
            Location location = new Location(person.Latitude, person.Longitude);
            var      pinGeo   = AddPersonPin(location, message, color: Colors.Blue, 1, person);

            CurrentPerID  = person.ID;
            currentPerson = person;
            UpdateMap();
        }
        private Person AddPersonToDatabase(PersonDialog dialog, Location latestClickLocation)
        {
            Person person = new Person();

            person.FirstName = dialog.PersonFirstName;
            person.LastName  = dialog.PersonLastName;
            person.Address   = new Address()
            {
                City         = dialog.AddressCity,
                StreetName   = dialog.AddressStreetName,
                StreetNumber = dialog.AddressStreetNumber,
                Country      = dialog.AddressCountry
            };
            person.GeoCoordinate = new Coordinate()
            {
                Longitude = latestClickLocation.Longitude,
                Latitude  = latestClickLocation.Latitude
            };
            db.Add(person);
            db.SaveChanges();

            return(person);
        }