-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEVCStatConfig.vb
624 lines (554 loc) · 26.1 KB
/
EVCStatConfig.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
Imports System.Text
Imports System.Web
Imports System.Threading
Imports Scheduler
Imports System.Data
Imports HomeSeerAPI
Public Class EVCSTATConfig
Inherits clsPageBuilder
Dim i As Integer
Dim pi As HSPI
Dim s As String = ""
Dim j As Integer
Dim poll As Boolean = True
Dim dd As New clsJQuery.jqDropList("dd0", PageName, False)
Dim tb As New clsJQuery.jqTextBox("tb0", "", "", PageName, 0, True)
Dim lb As New clsJQuery.jqListBox("lb0", PageName)
Dim cb As New clsJQuery.jqCheckBox("cb0", "", PageName, True, True)
Dim b As New clsJQuery.jqButton("b0", "", PageName, True)
Dim colObjectValues As New hsCollection
Public Sub New(ByVal PageName As String)
MyBase.New(PageName)
End Sub
Public Overrides Function postBackProc(page As String, data As String, user As String, userRights As Integer) As String
Dim parts As Collections.Specialized.NameValueCollection
Dim sKey As String = ""
parts = HttpUtility.ParseQueryString(data)
Dim CurrentStat As Thermostat
Select Case parts("id")
Case "oButSave"
ButSave_Click(data)
Case "oButAddStat"
ButAddStat_Click(data)
Case "oButUpdateStat"
ButUpdateStat_Click(data)
Case "oButDeleteStat"
ButDeleteStat_Click(data)
Case "oListBoxStats"
If parts("ListBoxStats") = "" Then
BuildOptions()
Else
CurrentStat = arrThermostats(parts("ListBoxStats"))
BuildOptions(CurrentStat, True)
End If
End Select
Return MyBase.postBackProc(page, data, user, userRights)
End Function
' build and return the actual page
Public Function GetPagePlugin(ByVal pageName As String, ByVal user As String, ByVal userRights As Integer, ByVal queryString As String) As String
Dim stb As New StringBuilder
pi = plugin
Try
Me.reset()
' handle any queries like mode=something
Dim parts As Collections.Specialized.NameValueCollection = Nothing
' add the normal title
Me.AddHeader(hs.GetPageHeader(pageName, "EVC MQTTT Configuration", "", "", False, False))
stb.Append(clsPageBuilder.DivStart("pluginpage", ""))
' a message area for error messages from jquery ajax postback (optional, only needed if using AJAX calls to get data)
stb.Append(clsPageBuilder.DivStart("errormessage", "class='errormessage'"))
stb.Append(clsPageBuilder.DivEnd)
'Me.RefreshIntervalMilliSeconds = 5000 ' # of seconds between callbacks
'' add a callback post string, this is what will be posted when the page timer expires
'stb.Append(Me.AddAjaxHandlerPost("id=timer", pageName))
' specific page code is here
stb.Append(BuildWebPageBody())
stb.Append(clsPageBuilder.DivEnd)
' add the body html to the page
Me.AddBody(stb.ToString)
Me.AddFooter(hs.GetPageFooter)
Me.suppressDefaultFooter = True
' return the full page
Return Me.BuildPage()
Catch ex As Exception
Log("Error - Building page: " & ex.Message, LogLevel.Normal)
Return "error"
End Try
End Function
Private Sub LoadItems()
Try
BuildDropList("ListBoxStats", True)
BuildTextBox("TextBoxPoll", True)
BuildCheckBox("CheckBoxDebug", True)
BuildDropList("DropDownListEditStatID", True)
Catch ex As Exception
Log("Error in LoadItems: " & ex.Message)
End Try
End Sub
Protected Sub ButSave_Click(ByVal data As String)
Dim sKey As String
Dim parts As Collections.Specialized.NameValueCollection
'Dim BaudRate As Integer
parts = HttpUtility.ParseQueryString(data)
Try
'reset checkbox values first
gDebug = False
For Each sKey In parts.Keys
If sKey Is Nothing Then Continue For
If String.IsNullOrEmpty(sKey.Trim) Then Continue For
Select Case True
Case InStr(sKey, "TextBoxPoll") > 0
ComThread.SetPolling(CInt(parts(sKey)))
Case InStr(sKey, "TextBoxSend") > 0
ComThread.SetSendTopic(CStr(parts(sKey)))
Case InStr(sKey, "TextBoxRecv") > 0
ComThread.SetRecvTopic(CStr(parts(sKey)))
Case InStr(sKey, "TextBoxHost") > 0
ComThread.SetMQTTHost(CStr(parts(sKey)))
Case InStr(sKey, "DropDownList") > 0
'BaudRate = CInt(DDText("DropDownList", parts(sKey)))
'If ComThread.BaudRate <> BaudRate Then
'ComThread.BaudRate = BaudRate
'ComThread.Restart()
'End If
Case InStr(sKey, "CheckBoxDebug") > 0
gDebug = CheckBoxValue(parts(sKey))
End Select
Next
SaveData(data)
Catch ex As Exception
Log("Error In Save: " & ex.Message)
End Try
End Sub
Function BuildStatList() As Pair()
Dim Thermostat As Thermostat
Dim i As Integer = 0
Dim DataPairs() As Pair = Nothing
For Each Thermostat In arrThermostats.Values
ReDim Preserve DataPairs(i)
DataPairs(i).Name = Thermostat.Name
DataPairs(i).Value = Thermostat.RefID
i += 1
Next
Return DataPairs
End Function
Protected Sub ButUpdateStat_Click(ByVal data As String)
Dim parts As Collections.Specialized.NameValueCollection
'Dim Name As String
Dim Address As String
Dim RefID As Integer
Dim oThermostat As Thermostat
parts = HttpUtility.ParseQueryString(data)
RefID = parts("RefID")
'If parts("TextBoxName") = "" Then
' Name = parts("TextBoxNew")
'Else
' Name = parts("TextBoxName")
'End If
If parts("DropDownListEditStatID") = "" Then
Address = parts("DropDownListNewStatID")
Else
Address = parts("DropDownListEditStatID")
End If
Try
'pi.UpdateStatObj(CurrentStat.RefID, TextBoxName & vbTab & parts("TextBoxLocation") & vbTab & DropDownListStatID & vbTab & DDText("DropDownListEditStatType", DropDownListStatType) & vbTab & CheckBoxValue(parts("CheckSingleSetpoint")).ToString, poll)
oThermostat = arrThermostats(RefID.ToString)
'oThermostat.Name = Name
oThermostat.Address = Address
'oThermostat.Location = parts("TextBoxLocation")
'oThermostat.Location2 = parts("TextBoxLocation2")
BuildOptions()
BuildDropList("ListBoxStats", True)
BuildDropList("DropDownListNewStatID", True)
Catch ex As Exception
Log("Error in UpdateStat: " & ex.Message & ex.TargetSite.ToString & ex.StackTrace)
End Try
End Sub
Protected Sub ButAddStat_Click(ByVal data As String)
Dim parts As Collections.Specialized.NameValueCollection
Dim stat As Thermostat
parts = HttpUtility.ParseQueryString(data)
Try
If parts("TextBoxNew") = "" Then Exit Sub
stat = AddThermostat(parts("TextBoxNew"), parts("DropDownListNewStatID"))
stat.Address = parts("DropDownListNewStatID")
stat.Location = parts("TextBoxLocation")
stat.Location2 = parts("TextBoxLocation2")
' Clear out the old stat
BuildTextBox("TextBoxNew", True)
BuildTextBox("TextBoxLocation", True)
BuildTextBox("TextBoxLocation2", True)
BuildDropList("DropDownListNewStatID", True)
BuildDropList("ListBoxStats", True, stat.Address)
Catch ex As Exception
Log("Error in ButAddStat_Click: " & ex.Message)
End Try
End Sub
Private Sub LoadDefaultStatVals()
BuildTextBox("TextBoxLocation", True, "")
End Sub
Private Function BuildUsedStatAddressList() As String
Dim Thermostat As Thermostat
Dim StatList As String = "|"
For Each Thermostat In arrThermostats.Values
StatList &= Thermostat.Address & "|"
Next
Return StatList
End Function
Protected Sub ButDeleteStat_Click(ByVal data As String)
Dim parts As Collections.Specialized.NameValueCollection
parts = HttpUtility.ParseQueryString(data)
Try
RemoveThermostat(parts("RefID"))
BuildButton("ButEditStat", True, False)
LoadItems()
BuildDropList("ListBoxStats", True)
BuildDropList("DropDownListNewStatID", True)
BuildOptions()
Catch ex As Exception
Log("Error in ButDeleteStat_Click: " & ex.Message)
End Try
End Sub
Function BuildWebPageBody() As String
Dim stb As New StringBuilder
Try
stb.Append("<table width='1000' cellpadding='0' cellspacing='0' border='0'>")
stb.Append(" <tr>")
stb.Append(" <td></td>")
stb.Append(" <td align='right'>")
stb.Append(" <a href='EVC%20Help%20File\EVCSerial-Help.htm'>Help Page</a>")
stb.Append(" </td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td colspan='2'>")
stb.Append(clsPageBuilder.FormStart("frmStatsData", "StatsData", "Post"))
stb.Append(" <table width='1000' cellpadding='0' cellspacing='0' style='border-right: black thin solid; border-top: black thin solid; border-left: black thin solid; border-bottom: black thin solid;'>")
stb.Append(" <tr>")
stb.Append(" <td colspan='3' style='background-color: #Cdcdcd; text-align: center'><br /></td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td style='width: 394px; background-color: #f5f5f5;'><strong>Poll Interval </strong></td>")
stb.Append(" <td style='background-color: #f5f5f5;' width='100'>" & BuildTextBox("TextBoxPoll") & "</td>")
stb.Append(" <td style='background-color: #f5f5f5;'> seconds</td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td style='width: 394px; background-color: #f5f5f5;'><strong>MQTTT Host Address </strong></td>")
stb.Append(" <td style='background-color: #f5f5f5;' width='100'>" & BuildTextBox("TextBoxHost") & "</td>")
stb.Append(" <td style='background-color: #f5f5f5;'></td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td style='width: 394px; background-color: #f5f5f5;'><strong>MQTTT Send Topic </strong></td>")
stb.Append(" <td style='background-color: #f5f5f5;' width='100'>" & BuildTextBox("TextBoxSend") & "</td>")
stb.Append(" <td style='background-color: #f5f5f5;'></td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td style='width: 394px; background-color: #f5f5f5;'><strong>MQTTT Receive Topic </strong></td>")
stb.Append(" <td style='background-color: #f5f5f5;' width='100'>" & BuildTextBox("TextBoxRecv") & "</td>")
stb.Append(" <td style='background-color: #f5f5f5;'></td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td style='width: 394px; background-color: #f5f5f5; height: 19px;'><strong>Enable Debug Messages</strong></td>")
stb.Append(" <td style='background-color: #f5f5f5; height: 19px;' colspan='2'>" & BuildCheckBox("CheckBoxDebug") & "</td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td colspan='3' style='background-color: #f5f5f5; text-align: center'><br>" & BuildButton("ButSave") & "<br></td>")
stb.Append(" </tr>")
stb.Append(" </table>")
stb.Append(clsPageBuilder.FormEnd)
stb.Append(" </td>")
stb.Append(" </tr>")
'############################################################################################
stb.Append(" <tr>")
stb.Append(" <td colspan='2'>")
stb.Append(clsPageBuilder.FormStart("frmStatAdd", "AddStat", "Post"))
stb.Append(" <table width='1000' cellpadding='0' cellspacing='0' style='border-right: black thin solid; border-top: none; border-left: black thin solid; border-bottom: black thin solid;'>")
stb.Append(" <tr>")
stb.Append(" <td style='background-color: #Cdcdcd; text-align: center'><br /></td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td style='background-color: #f5f5f5; text-align: center'>")
stb.Append(" <table width='100%'>")
stb.Append(" <tr><td colspan='3'><strong>Add new thermostat</strong></td></tr>")
stb.Append(" <tr>")
stb.Append(" <td>Name:</td>")
stb.Append(" <td>" & BuildTextBox("TextBoxNew") & "</td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td>Location1:</td>")
stb.Append(" <td>" & BuildTextBox("TextBoxLocation") & "</td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td>Location2:</td>")
stb.Append(" <td>" & BuildTextBox("TextBoxLocation2") & "</td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td>Address:</td>")
stb.Append(" <td>" & BuildDropList("DropDownListNewStatID") & "</td>")
stb.Append(" </tr>")
stb.Append(" </table>")
stb.Append(BuildButton("ButAddStat") & "<br>")
stb.Append(" </td>")
stb.Append(" </tr>")
stb.Append(" </table>")
stb.Append(clsPageBuilder.FormEnd)
stb.Append(" </td>")
stb.Append(" </tr>")
'#############################################################################################
stb.Append(" <tr>")
stb.Append(" <td colspan='2'>")
stb.Append(" <table width='1000' cellpadding='0' cellspacing='0' style='border-right: black thin solid; border-top: none; border-left: black thin solid; border-bottom: black thin solid;'>")
stb.Append(" <tr><td style='background-color: #Cdcdcd; text-align: center;'><br /></td></tr>")
stb.Append(" <tr>")
stb.Append(" <td align='center' style='background-color: #f5f5f5;'>")
stb.Append(" <table width='100%'>")
stb.Append(" <tr><td><strong>Select Thermostat to Edit</strong></td></tr>")
stb.Append(" <tr>")
stb.Append(" <td align='center'>" & BuildDropList("ListBoxStats") & "</td>")
stb.Append(" </tr>")
stb.Append(" </table>")
stb.Append(" </td>")
stb.Append(" </tr>")
stb.Append(" </table>")
stb.Append(" </td>")
stb.Append(" </tr>")
stb.Append(" <tr><td colspan='2'><div id='ViewOptions'></div></td></tr>")
'#############################################################################################
stb.Append("</table>")
Return stb.ToString
Catch ex As Exception
Log("Error in BuildWebPageBody: " & ex.Message)
End Try
Return Nothing
End Function
Sub BuildOptions(Optional stat As Thermostat = Nothing, Optional ByVal Visible As Boolean = False)
Dim stb As New StringBuilder
If Visible Then
stb.Append(clsPageBuilder.FormStart("frmStatEdit", "EditStat", "Post"))
stb.Append(" <table width='1000' cellpadding='0' cellspacing='0' style='border-right: black thin solid; border-top: none; border-left: black thin solid; border-bottom: black thin solid;'>")
stb.Append(" <tr>")
stb.Append(" <td colspan='3' style='background-color: #Cdcdcd; text-align: center'><br /><input id='oRefID' name='RefID' type='hidden' value='" & stat.RefID & "'></td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td colspan='2'>Name:</td>")
stb.Append(" <td colspan='2'>" & BuildLabel("LabelName", False, stat.Name) & "</td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td colspan='2'>Location1:</td>")
stb.Append(" <td colspan='2'>" & BuildLabel("LabelLocation", False, stat.Location) & "</td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td colspan='2'>Location2:</td>")
stb.Append(" <td colspan='2'>" & BuildLabel("LabelLocation2", False, stat.Location2) & "</td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td colspan='2'>Thermostat Address:</td>")
stb.Append(" <td colspan='2' nowrap>" & BuildDropList("DropDownListEditStatID", False, , , stat.Address) & "</td>")
stb.Append(" </tr>")
stb.Append(" <tr>")
stb.Append(" <td colspan='4' align='Center'>")
stb.Append(BuildButton("ButUpdateStat"))
stb.Append(BuildButton("ButDeleteStat"))
stb.Append(" <br />")
stb.Append(" </td>")
stb.Append(" </tr>")
stb.Append(" </table>")
stb.Append(clsPageBuilder.FormEnd)
End If
Me.divToUpdate.Add("ViewOptions", stb.ToString)
End Sub
Function BuildButton(ByVal Name As String, Optional ByVal Rebuilding As Boolean = False, Optional ByVal Enabled As Boolean = True, Optional ByVal Visible As Boolean = True) As String
Dim Content As String = ""
Dim ButtonText As String = "Submit"
Select Case Name
Case "ButSave"
ButtonText = "Save Settings"
Case "ButAddStat"
ButtonText = "Add Thermostat"
Case "ButEditStat"
ButtonText = "Edit Thermostat"
Case "ButUpdateStat"
ButtonText = "Update Thermostat"
Case "ButDeleteStat"
ButtonText = "Delete Thermostat"
End Select
If Visible Then
If Rebuilding Then
Me.divToUpdate.Add(Name & "_div", FormButton(b, Name, ButtonText, True, , , , Enabled))
Else
Content = "<div id='" & Name & "_div'>" & FormButton(b, Name, ButtonText, True, , , , Enabled) & "</div>"
End If
Else
Me.divToUpdate.Add(Name & "_div", "")
End If
Return Content
End Function
Function BuildLabel(ByVal Name As String, Optional ByVal Rebuilding As Boolean = False, Optional ByVal Msg As String = "", Optional ByVal Visible As Boolean = True) As String
Dim Content As String = ""
If Msg <> "" Then
If colObjectValues.ContainsKey(Name) Then
colObjectValues(Name) = Msg
Else
colObjectValues.Add(CObj(Msg), Name)
End If
End If
If Visible Then
If colObjectValues.ContainsKey(Name) Then Msg = colObjectValues(Name)
If Rebuilding Then
Me.divToUpdate.Add(Name & "_div", FormLabel(Name, Msg))
Else
Content = "<div id='" & Name & "_div'>" & FormLabel(Name, Msg) & "</div>"
End If
Else
Me.divToUpdate.Add(Name & "_div", "")
End If
Return Content
End Function
Function BuildTextBox(ByVal Name As String, Optional ByVal Rebuilding As Boolean = False, Optional ByVal Text As String = "", Optional ByVal Visible As Boolean = True) As String
Dim Content As String = ""
Select Case Name
Case "TextBoxPoll"
Text = ComThread.PollInterval.ToString
Case "TextBoxSend"
Text = ComThread.MQTT_SendTopic
Case "TextBoxRecv"
Text = ComThread.MQTT_RecvTopic
Case "TextBoxHost"
Text = ComThread.MQTT_HostAddr
End Select
If Text <> "" Then
If colObjectValues.ContainsKey(Name) Then
colObjectValues(Name) = Text
Else
colObjectValues.Add(CObj(Text), Name)
End If
End If
If Visible Then
If Rebuilding Then
Me.divToUpdate.Add(Name & "_div", HTMLTextBox(Name, Text, 20))
Else
Content = "<div id='" & Name & "_div'>" & HTMLTextBox(Name, Text, 20) & "</div>"
End If
Else
Me.divToUpdate.Add(Name & "_div", "")
End If
Return Content
End Function
Function BuildCheckBox(ByVal Name As String, Optional ByVal Rebuilding As Boolean = False, Optional ByVal Checked As Integer = -1, Optional ByVal Visible As Boolean = True) As String
Dim Content As String = ""
Select Case Name
Case "CheckBoxDebug"
Checked = Math.Abs(CInt(gDebug))
End Select
If Checked >= 0 Then
If colObjectValues.ContainsKey(Name) Then
colObjectValues(Name) = Checked
Else
colObjectValues.Add(Checked, Name)
End If
End If
If Visible Then
If colObjectValues.ContainsKey(Name) Then
Checked = colObjectValues(Name)
Else
Checked = 0
End If
If Rebuilding Then
Me.divToUpdate.Add(Name & "_div", FormCheckBox(cb, Name, Checked, True, True))
Else
Content = "<div id='" & Name & "_div'>" & FormCheckBox(cb, Name, Checked, True, True) & "</div>"
End If
Else
Me.divToUpdate.Add(Name & "_div", "")
End If
Return Content
End Function
Function BuildListBox(ByVal Name As String, Optional ByVal Rebuilding As Boolean = False, Optional ByVal Selected As Integer = -1, Optional ByVal Visible As Boolean = True) As String
Dim Content As String = ""
Dim DataPairs() As Pair = Nothing
Select Case Name
Case "ListBoxStats"
DataPairs = BuildStatList()
End Select
If Selected >= 0 Then
If colObjectValues.ContainsKey(Name) Then
colObjectValues(Name) = Selected
Else
colObjectValues.Add(Selected, Name)
End If
End If
If Visible Then
If colObjectValues.ContainsKey(Name) Then Selected = colObjectValues(Name)
If Rebuilding Then
Me.divToUpdate.Add(Name & "_div", FormListBox(lb, Name, DataPairs))
Else
Content = "<div id='" & Name & "_div'>" & FormListBox(lb, Name, DataPairs) & "</div>"
End If
Else
Me.divToUpdate.Add(Name & "_div", "")
End If
Return Content
End Function
Function BuildDropList(ByVal Name As String, Optional ByVal Rebuilding As Boolean = False, Optional ByVal Selected As Integer = -1, Optional ByVal Visible As Boolean = True, Optional ByVal SelectedValue As String = "") As String
Dim Content As String = ""
Dim DataPairs() As Pair = Nothing
Dim i As Integer
Dim x As Integer = 0
Dim EnumArray() As String
Dim Msg As String = ""
Dim AddBlank As Boolean = False
Dim UsedAddressList As String = ""
Dim AutoSubmit As Boolean = True
Select Case Name
Case "DropDownList"
ReDim EnumArray(1)
EnumArray(0) = "9600"
EnumArray(1) = "19200"
For i = 0 To 1
ReDim Preserve DataPairs(i)
DataPairs(i).Name = EnumArray(i)
DataPairs(i).Value = i.ToString
Next
' Select Case ComThread.BaudRate
' Case 9600
' Selected = 0
' Case 19200
' Selected = 1
' End Select
AddBlank = True
Msg = "Please Select"
Case "ListBoxStats"
DataPairs = BuildStatList()
AddBlank = True
Msg = "Select Thermostat"
AutoSubmit = False
Case "DropDownListNewStatID", "DropDownListEditStatID"
UsedAddressList = BuildUsedStatAddressList()
For i = 1 To 15
If InStr(UsedAddressList, "|" & i.ToString & "|") = 0 Or SelectedValue <> "" Then
ReDim Preserve DataPairs(x)
DataPairs(x).Name = i.ToString
DataPairs(x).Value = i.ToString
x += 1
End If
Next
End Select
If Selected >= 0 Then
If colObjectValues.ContainsKey(Name) Then
colObjectValues(Name) = Selected
Else
colObjectValues.Add(Selected, Name)
End If
End If
If Visible Then
If colObjectValues.ContainsKey(Name) Then Selected = colObjectValues(Name)
If Rebuilding Then
Me.divToUpdate.Add(Name & "_div", FormDropDown(dd, Name, DataPairs, Selected, , AutoSubmit, AddBlank, , , , Msg, SelectedValue))
Else
Content = "<div id='" & Name & "_div'>" & FormDropDown(dd, Name, DataPairs, Selected, , AutoSubmit, AddBlank, , , , Msg, SelectedValue) & "</div>"
End If
Else
Me.divToUpdate.Add(Name & "_div", "")
End If
Return Content
End Function
End Class