1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| ''' <summary>
''' Calculate the distances between actual position and the selected points
''' </summary>
''' <param name="querySelected">The query corresponding to the selected points.</param>
Private Sub CalculateDistance(ByVal querySelected As String)
' get the points and set it to a dataadapter
Dim query As String = "select * from Point where idProject=" & idProject & querySelected & " ;"
Dim adapter As New SQLiteDataAdapter(query, db)
Dim pointsSet As New DataSet
adapter.Fill(pointsSet, "Point")
' calculate the distance
Dim pointsRow As DataRow
For i As Integer = 0 To pointsSet.Tables("Point").Rows.Count - 1
pointsRow = pointsSet.Tables("Point").Rows(i)
pointsRow("calcDistance") = CalcDistance(CDbl(pointsRow("x")), CDbl(pointsRow("y")), gpsPos.Easting, gpsPos.Northing)
Next
pointsRow = Nothing
' define the update command for calculated distance
Dim cmdUpdate As SQLiteCommand = New SQLiteCommand("update point set calcDistance=? where idProject=? and idPoint =?", db)
With cmdUpdate.Parameters.Add("@p1", DbType.Decimal)
.SourceColumn = "calcDistance"
.SourceVersion = DataRowVersion.Current
End With
With cmdUpdate.Parameters.Add("@p2", DbType.Int32)
.SourceColumn = "idProject"
.SourceVersion = DataRowVersion.Original
End With
With cmdUpdate.Parameters.Add("@p3", DbType.Int32)
.SourceColumn = "idPoint"
.SourceVersion = DataRowVersion.Original
End With
adapter.UpdateCommand = cmdUpdate
' update the distance to the database
Try
adapter.Update(pointsSet, "Point")
Catch ex As DBConcurrencyException
MessageBox.Show(ex.Message, "Distance calculation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
Exit Sub
Finally
pointsSet = Nothing
adapter = Nothing
End Try
End Sub |
Partager