This question might sound a lot vague. What I'm looking for is a way to generate a html <table></table>
.
I need to build this table:
Actually the top row is a header and the first two columns are headers too.
For every cell starting from (3,2), I execute a 'count' query.
Now I'm doing a very ugly loop to build a 2D-array. I've got the feeling that has to be nicer. In the near future I have to put a link below every 'counted' integer which links to another table to present the rows related to the integer.
This is how I do it now:
I'm just looping trough various Dictionaries(Of String,String)
to generate the 2D array. To build the arrays I use two variables to know where in the table I am: Dim lv_TRow As Integer = 0
and Dim lv_TCol As Integer = 0
.
There must be a better way. Maybe converting these to objects or something I don't know yet.
Can you help to make this nicer?
Public Function build2DArray() As String(,)
Dim lv_Tabel(15, 4) As String
Dim riskLevels As New Dictionary(Of String, String) ' Kan gebruikt worden in WHERE
riskLevels.Add("Extreem", 5)
riskLevels.Add("Hoog", 4)
riskLevels.Add("Normaal", 3)
riskLevels.Add("Laag", 2)
riskLevels.Add("Gering", 1)
Dim algStss As New Dictionary(Of String, String)
algStss.Add("Gestart", 0)
algStss.Add("Geanalyseerd", 0)
algStss.Add("Opgelost", 0)
Dim incStss As New Dictionary(Of String, String) ' Kan gebruikt worden in WHERE
incStss.Add("Gestart", "L14_IncSts IN (1,2)")
incStss.Add("Geanalyseerd", "L14_IncSts IN (3,4,5,6,7)")
incStss.Add("Opgelost", "L14_IncSts IN (8)")
Dim prmStss As New Dictionary(Of String, String) ' Kan gebruikt worden in WHERE
prmStss.Add("Gestart", "L24_StsIdt IN (1)")
prmStss.Add("Geanalyseerd", "L24_StsIdt IN (2,3,4,5,6)")
prmStss.Add("Opgelost", "L24_StsIdt IN (7)")
Dim wzgStss As New Dictionary(Of String, String) ' Kan gebruikt worden in WHERE
wzgStss.Add("Gestart", "L38_StsIdt IN (1,2)")
wzgStss.Add("Geanalyseerd", "L38_StsIdt IN (3,4,5,6,7)")
wzgStss.Add("Opgelost", "L38_StsIdt IN (8,9,10,11)")
Dim headers As New Dictionary(Of String, String) ' Kan gebruikt worden in FROM
headers.Add("Risiconiveau", 0)
headers.Add("Status", 0)
headers.Add("Incident", "Inc")
headers.Add("Probleem", "Prm")
headers.Add("Wijziging", "Wzg")
Dim lv_Dtb As New Database
'lv_Dtb.ExecuteQuery("SELECT * FROM Ris")
Dim lv_TRow As Integer = 0
Dim lv_TCol As Integer = 0
For Each header As KeyValuePair(Of String, String) In headers
lv_Tabel(lv_TRow, lv_TCol) = header.Key
lv_TCol += 1
Next
lv_TCol = 0
lv_TRow = 1
For Each riskLevel As KeyValuePair(Of String, String) In riskLevels
lv_Tabel(lv_TRow + 1, lv_TCol) = riskLevel.Key
lv_TCol += 1
For Each algSts As KeyValuePair(Of String, String) In algStss
lv_Tabel(lv_TRow, lv_TCol) = algSts.Key
lv_TRow += 1
Next
lv_TRow -= 3
lv_TCol += 1
For Each incSts As KeyValuePair(Of String, String) In incStss
Try
Dim dataset As DataSet = lv_Dtb.ExecuteQuery(QryString(1, incSts.Value, riskLevel.Value))
lv_Tabel(lv_TRow, lv_TCol) = dataset.Tables(0).Rows(0).Item(0) 'eerste query
Catch err As SqlException
Logger.Log(err.Message)
lv_Tabel(lv_TRow, lv_TCol) = "err"
End Try
lv_TRow += 1
Next
lv_TRow -= 3
lv_TCol += 1
For Each prmSts As KeyValuePair(Of String, String) In prmStss
Try
Dim dataset As DataSet = lv_Dtb.ExecuteQuery(QryString(2, prmSts.Value, riskLevel.Value))
lv_Tabel(lv_TRow, lv_TCol) = dataset.Tables(0).Rows(0).Item(0) 'eerste query
Catch err As SqlException
Logger.Log(err.Message)
lv_Tabel(lv_TRow, lv_TCol) = "err"
End Try
lv_TRow += 1
Next
lv_TRow -= 3
lv_TCol += 1
For Each wzgSts As KeyValuePair(Of String, String) In wzgStss
Try
Dim dataset As DataSet = lv_Dtb.ExecuteQuery(QryString(3, wzgSts.Value, riskLevel.Value))
lv_Tabel(lv_TRow, lv_TCol) = dataset.Tables(0).Rows(0).Item(0) 'eerste query
Catch err As SqlException
Logger.Log(err.Message)
lv_Tabel(lv_TRow, lv_TCol) = "err"
End Try
lv_TRow += 1
Next
lv_TCol -= 4
Next
lv_Dtb.CloseConnection()
Return lv_Tabel
End Function