public void UpdateCoordinates(string longitude, string latitude)
        {
            if (string.IsNullOrWhiteSpace(longitude))
            {
                throw new ArgumentException("Cannot be empty", "longitude");
            }
            if (string.IsNullOrWhiteSpace(latitude))
            {
                throw new ArgumentException("Cannot be empty", "latitude");
            }

            //if there is letter we need to convert to coords
            foreach (var c in longitude)
            {
                if (char.IsLetter(c))
                {
                    calculatedPoint = StringToCoordinateConverter.ConvertToCoordinate(Longitude, Latitude);
                    Longitude       = longitude;
                    Latitude        = latitude;
                    return;
                }
            }
            //otherwise it was passed already converted coords and just use those
            calculatedPoint = new PointLatLng(Convert.ToDouble(latitude), Convert.ToDouble(longitude));
            Longitude       = StringToCoordinateConverter.ConvertBackFromLongitude(calculatedPoint.Lng);
            Latitude        = StringToCoordinateConverter.ConvertBackFromLatitude(calculatedPoint.Lat);
        }
Beispiel #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var latitudeString  = "08.50S";
            var longitudeString = "13.15E";
            StringToCoordinateConverter converter = new StringToCoordinateConverter();

            (double lat, double lon) = converter.Convert(latitudeString, longitudeString);
            outputText.Text          = $"{lat}, {lon}";
        }
        // add marker
        void MainMap_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (CurrentSelectedMarker != null && CurrentSelectedMarker.Type == newMarkerStyle)
            {
                // Do well detail filling in here
                // if marker is blue_dot to add to database and change to green
                string longitude = StringToCoordinateConverter.ConvertBackFromLongitude(CurrentSelectedMarker.Position.Lng);
                string latitude  = StringToCoordinateConverter.ConvertBackFromLatitude(CurrentSelectedMarker.Position.Lat);

                string majorName = GetMajorAddressNameFromMarker(CurrentSelectedMarker);

                try
                {
                    databaseLoader.AddLocationData(majorName, string.Empty, string.Empty, string.Empty);
                }
                catch (NpgsqlException)
                {
                    databaseLoader.UpdateLocationData(majorName, string.Empty, string.Empty, string.Empty);
                }

                var wellId = databaseLoader.InsertWellData(longitude, latitude, majorName);
                if (wellId == -1)
                {
                    MessageBox.Show("No well added, likely no internet connection\n" +
                                    "If application was started with no internet connection\n" +
                                    "it was run with read-only mode and must be restarted to login");
                    return;
                }
                var newWell = new Well(wellId.ToString(), longitude, latitude, null);
                CurrentSelectedMarker.Tag = newWell.WellId;
                objects.Markers.Remove(CurrentSelectedMarker);
                objects.Markers.AddDefaultGoogleMarker(CurrentSelectedMarker.Position, loadedMarkerStyle, newWell.WellId);
                CurrentSelectedMarker = objects.Markers[objects.Markers.Count - 1] as GMarkerGoogle;
                wellsLoaded.Add(newWell);
                reloadMap_Click(null, EventArgs.Empty);
            }
            else
            {
                var cc = new GMarkerGoogle(MainMap.FromLocalToLatLng(e.X, e.Y), newMarkerStyle);
                objects.Markers.Add(cc);
                CurrentSelectedMarker = cc;
            }
        }
        private void Edit_Click(object sender, EventArgs e)
        {
            editErrorLbl.Text = string.Empty;
            var button = sender as Button;

            if (button.Text == "Edit")
            {
                latEditBackup = editLngBox.Text;
                lngEditBackup = editLatBox.Text;
                //open edit window or better allow editing in same open space
                //let browse new image
                editLngBox.Enabled   = true;
                editLatBox.Enabled   = true;
                editImageBtn.Visible = true;
                button.Text          = "Save";
                closeBtn.Text        = "Cancel";
            }
            else if (button.Text == "Save")
            {
                if (string.IsNullOrWhiteSpace(editLngBox.Text))
                {
                    editErrorLbl.Text = "Latitude cannot be empty";
                }
                else if (string.IsNullOrWhiteSpace(editLatBox.Text))
                {
                    editErrorLbl.Text = "Longitude cannot be empty";
                }
                else
                {
                    editLngBox.Enabled   = false;
                    editLatBox.Enabled   = false;
                    editImageBtn.Visible = false;
                    try
                    {
                        var testPoint = StringToCoordinateConverter.ConvertToCoordinate(editLngBox.Text, editLatBox.Text);
                    }
                    catch (ArgumentException)
                    {
                        editErrorLbl.Text    = "Lat/Long not in L DD MM.MMM";
                        editLngBox.Enabled   = true;
                        editLatBox.Enabled   = true;
                        editImageBtn.Visible = true;
                        return;
                    }

                    //send all to database
                    var db = new DatabaseLoader(connectionString, NetworkChecker.LastStatus);
                    well.UpdateCoordinates(editLatBox.Text, editLngBox.Text);
                    try
                    {
                        db.UpdateWellData(well);
                    }
                    catch (NpgsqlException ex)
                    {
                        editErrorLbl.Text = ex.Message;
                        RestoreFromBackup();
                    }
                    updateMarkerPositionAction(well);
                    button.Text   = "Edit";
                    closeBtn.Text = "Close";
                }
            }
            else
            {
                throw new NotSupportedException("Button can only be Edit or Save");
            }
        }