private void GMapControl1_OnMarkerEnter(GMapMarker item) { if (!_isMouseDown) { _currentMarker = item as GMapMarkerImage; _currentMarker.Selected = true; } }
private void GMapControl1_OnMarkerLeave(GMapMarker item) { if (!_isMouseDown && _currentMarker != null) { _currentMarker.Selected = false; _currentMarker = null; gMapControl1.Refresh(); } }
private void GMapControl1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { _isMouseDown = true; } if (e.Button == MouseButtons.Right) { var marker = new GMapMarkerImage(gMapControl1.FromLocalToLatLng(e.X, e.Y)); AddMarketToDb(marker); _markers.Markers.Add(marker); } }
private void UpdateMarker(GMapMarkerImage marker) { using (SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.ConnectionString)) { myConnection.Open(); using (SqlCommand myCommand = new SqlCommand("UPDATE Markers SET Lat=@lat, Lng=@Lng WHERE ID = @Id", myConnection)) { myCommand.Parameters.AddWithValue("@Id", marker.Tag); myCommand.Parameters.AddWithValue("@Lat", marker.Position.Lat); myCommand.Parameters.AddWithValue("@Lng", marker.Position.Lng); myCommand.ExecuteNonQuery(); } } }
private void AddMarketToDb(GMapMarkerImage marker) { using (SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.ConnectionString)) { myConnection.Open(); using (SqlCommand myCommand = new SqlCommand("INSERT INTO Markers(Lat, Lng) VALUES(@Lat, @Lng); SELECT SCOPE_IDENTITY()", myConnection)) { myCommand.Parameters.AddWithValue("@Lat", marker.Position.Lat); myCommand.Parameters.AddWithValue("@Lng", marker.Position.Lng); var id = Convert.ToInt32(myCommand.ExecuteScalar()); marker.Tag = id; } } }
private void LoadMarkers() { using (SqlConnection myConnection = new SqlConnection(Properties.Settings.Default.ConnectionString)) { myConnection.Open(); using (SqlCommand myCommand = new SqlCommand("SELECT Id, Lng, Lat FROM Markers", myConnection)) { SqlDataReader dataReader = myCommand.ExecuteReader(); while (dataReader.Read()) { var marker = new GMapMarkerImage( new PointLatLng( Convert.ToDouble(dataReader["Lat"]), Convert.ToDouble(dataReader["Lng"]))); marker.Tag = Convert.ToInt32(dataReader["Id"]); _markers.Markers.Add(marker); } } } }