这个问题听起来可能很模糊。我正在寻找的是一种生成 html 的方法<table></table>
。
我需要建立这个表:
实际上顶行是标题,前两列也是标题。
对于从 (3,2) 开始的每个单元格,我执行一个“计数”查询。
现在我正在做一个非常丑陋的循环来构建一个二维数组。我有一种必须更好的感觉。在不久的将来,我必须在每个“计数”整数下方放置一个链接,该链接链接到另一个表以显示与整数相关的行。
这就是我现在的做法:我只是通过各种循环Dictionaries(Of String,String)
来生成二维数组。为了构建数组,我使用两个变量来知道我在表中的位置:Dim lv_TRow As Integer = 0
和Dim lv_TCol As Integer = 0
.
一定会有更好的办法。也许将这些转换为对象或我还不知道的东西。
你能帮忙把它做得更好吗?
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