-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmSelectTrack.vb
152 lines (120 loc) · 4.31 KB
/
frmSelectTrack.vb
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Imports System.Xml
Imports System.Xml.XPath
Public Class frmSelectTrack
Public Enum FirstLast
First
Last
End Enum
Public Enum RecDateTimeType
RecDate
RecTime
End Enum
Private xmlDoc As XmlDocument
Public Property gpx() As XmlDocument
Get
Return xmlDoc
End Get
Set(ByVal value As XmlDocument)
xmlDoc = value
End Set
End Property
Private ndeTrkSeg As XmlNode
Public ReadOnly Property TrackSegment() As XmlNode
Get
Return ndeTrkSeg
End Get
End Property
Dim ndes As XmlNodeList
Public Sub InitialiseList()
Dim nde As XmlNode
Dim ndesTrkPt As XmlNodeList
Dim strStart As String
Dim strEnd As String
Dim iValidTrack As Integer = 0
ndes = gpx.GetElementsByTagName("trkseg")
Dim li As ListViewItem
Dim iTrackSeg As Integer
Dim str(4) As String
lvTracks.Items.Clear()
For iTrackSeg = 0 To ndes.Count - 1
nde = ndes(iTrackSeg)
ndesTrkPt = nde.SelectNodes("*[contains(name(), 'trkpt')]")
strStart = FormatDateTime(ndesTrkPt, FirstLast.First)
strEnd = FormatDateTime(ndesTrkPt, FirstLast.Last)
'We only consider track segments where there is more than one point and which
'have time elements associated with them.
If strStart.Length > 0 And strEnd.Length > 0 And ndesTrkPt.Count > 1 Then
iValidTrack += 1
str(0) = iValidTrack
str(1) = strStart
str(2) = strEnd
str(3) = ndesTrkPt.Count.ToString
str(4) = iTrackSeg
li = New ListViewItem(str)
lvTracks.Items.Add(li)
End If
Next
If lvTracks.Items.Count = 1 Then
ndeTrkSeg = ndes(CInt(lvTracks.Items(0).SubItems(4).Text))
Me.Close()
ElseIf lvTracks.Items.Count = 0 Then
ndeTrkSeg = Nothing
Me.Close()
Else
'Do nothing (i.e. show this dialog)
End If
End Sub
Private Function FormatDateTime(ByVal ndesTrkPt As XmlNodeList, ByVal fl As FirstLast) As String
Dim iPnt As Integer
Dim strTime As String = ""
Dim ndeTrkPt As XmlNode
Dim ndeTime As XmlNode
Dim dtmThis As DateTime
If fl = FirstLast.First Then
iPnt = 0
Else
iPnt = ndesTrkPt.Count - 1
End If
If ndesTrkPt.Count > 0 Then
ndeTrkPt = ndesTrkPt(iPnt)
If Not ndeTrkPt Is Nothing Then
ndeTime = ndeTrkPt.SelectSingleNode("*[contains(name(), 'time')]")
If Not ndeTime Is Nothing Then
strTime = ndeTime.InnerText
dtmThis = DateTime.Parse(strTime)
End If
End If
End If
If strTime = "" Then
Return ""
Else
Return UTC2LocalTime(dtmThis, RecDateTimeType.RecDate) & " " & UTC2LocalTime(dtmThis, RecDateTimeType.RecTime)
End If
End Function
Private Function UTC2LocalTime(ByVal utcDateTime As DateTime, ByVal dtType As RecDateTimeType) As String
Dim localDateTime As DateTime = utcDateTime.ToLocalTime()
If dtType = RecDateTimeType.RecDate Then
Return (Format(localDateTime, "dd/MM/yyyy"))
Else
Return (Format(localDateTime, "HH:mm:ss"))
End If
End Function
Private Sub butOkay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butOkay.Click
If lvTracks.SelectedItems.Count = 0 Then
MessageBox.Show("First select a track segment to use.")
Else
ndeTrkSeg = ndes(CInt(lvTracks.SelectedItems(0).SubItems(4).Text))
Me.Close()
End If
End Sub
Private Sub butCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butCancel.Click
ndeTrkSeg = Nothing
Me.Close()
End Sub
Private Sub frmSelectTrack_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
InitialiseList()
lvTracks.Columns(0).Width = 70
lvTracks.Columns(1).Width = 150
lvTracks.Columns(2).Width = 150
End Sub
End Class