#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
' These global variables will be declared once when the application starts.
' These variables can be accessed from all modules.
DimCurrentIndex = -1AsInt ' index of the current entry
DimRowNumber = 0AsInt ' number of rows
DimIDListAsList ' list containing the IDs of the database
'we need it because the IDs can be different from the List indexes
'If we delete an entry its ID Is lost
End Sub
Sub Globals
'These global variables will be redeclared Each time the Activity Is created.
'These variables can only be accessed from this module.
'Declare views
Privatewv_ScoringTableAsWebView
Privatelbl_ScoringIDAsLabel
Privatebtn_ScoringDelAsButton, btn_ScoringFilterAsButton, btn_ScoringDelAllAsButton
' Used In ExecuteHtml
DimHtmlCSSAsString
HtmlCSS = "table {width: 100%;border: 1px solid #cef;text-align: left; }" _
& " th { font-weight: bold; background-color: #acf; border-bottom: 1px solid #cef; }" _
& "td,th { padding: 4px 5px; }" _
& ".odd {background-color: #def; } .odd td {border-bottom: 1px solid #cef; }" _
& "a { text-decoration:none; color: #000;}"
End Sub
Sub Activity_Create(FirstTime AsBoolean)
'Load Layout
Activity.LoadLayout("lay_Scoring_Table")
Activity.Title = "Scoring Records"
ShowTable
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed AsBoolean)
End Sub
Sub ShowTable
'Shows the scoring stats In a table In a WebView
Dim SEL_ScoringTable AsString
SEL_ScoringTable = "SELECT ID, Visits As [Visits], Ave As [3 Dart Ave], Points As [Points] FROM scoring"
'displays the database In a table
wv_ScoringTable.LoadHtml(ExecuteHtml(Main.DS_SQL1, SEL_ScoringTable, Null, 0, True))
ReadDataBaseIDs
UpdateScoringID
End Sub
Sub ReadDataBaseIDs
'Reads the database IDs In IDList
Dim Row AsInt
Dim Cursor1 AsCursor
IDList.Initialize 'initialize the ID list
'We read only the ID column AND put them In a List
Cursor1 = Main.DS_SQL1.ExecQuery("SELECT ID FROM scoring")
If Cursor1.RowCount > 0Then 'check if entries exist
RowNumber = Cursor1.RowCount 'set the row count variable
IDList.Initialize 'initialize the ID list
For Row = 0To RowNumber - 1
Cursor1.Position = Row 'set the Cursor to each row
IDList.Add(Cursor1.GetInt("ID")) 'add the ID's to the ID list
Next
CurrentIndex = 0 'set the current index to 0
Else
CurrentIndex = -1 'set the current index to -1, no selected item
ToastMessageShow("No items found", False)
EndIf
Cursor1.Close 'close the cursor, we don't need it anymore
End Sub
Sub UpdateScoringID
Dim Query AsString
Dim Curs AsCursor
Query = "SELECT ID FROM scoring WHERE ID = " & IDList.Get(CurrentIndex)
Curs = Main.DS_SQL1.ExecQuery(Query)
Curs.Position = 0
lbl_ScoringID.Text = Curs.GetString("ID")
Curs.Close
End Sub
Sub ExecuteHtml(SQLAsSQL, Query AsString, StringArgs() AsString, Limit AsInt, Clickable AsBoolean) AsString
'This routine is extracted from the DBUtils code module
'Creates a html text that displays the data in a table.
'The style of the table can be changed by modifying HtmlCSS variable.
Dim cur AsCursor
If StringArgs <> NullThen
cur = SQL.ExecQuery2(Query, StringArgs)
Else
cur = SQL.ExecQuery(Query)
EndIf
Log("ExecuteHtml: " & Query)
If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
Dim sb AsStringBuilder
sb.Initialize
sb.Append("<html><body>").Append(CRLF)
sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
sb.Append("<table><tr>").Append(CRLF)
For i = 0To cur.ColumnCount - 1
sb.Append("<th>").Append(cur.GetColumnName(i)).Append("</th>")
Next
sb.Append("</tr>").Append(CRLF)
For row = 0To Limit - 1
cur.Position = row
If row Mod2 = 0Then
sb.Append("<tr>")
Else
sb.Append("<tr class='odd'>")
EndIf
For i = 0To cur.ColumnCount - 1
sb.Append("<td>")
If Clickable Then
sb.Append("<a href='http://").Append(i).Append(".")
sb.Append(row)
sb.Append(".com'>").Append(cur.GetString2(i)).Append("</a>")
Else
sb.Append(cur.GetString2(i))
EndIf
sb.Append("</td>")
Next
sb.Append("</tr>").Append(CRLF)
Next
cur.Close
sb.Append("</table></body></html>")
Return sb.ToString
End Sub
Sub wbvTable_OverrideUrl (Url AsString) AsBoolean
'parse the row and column numbers from the URL
Dim values() AsString
values = Regex.Split("[.]", Url.SubString(7))
Dim col, row AsInt
col = values(0)
row = values(1)
CurrentIndex = row
UpdateScoringID
ReturnTrue 'Don't try to navigate to this URL
End Sub