locked
code behind html to form on button click RRS feed

  • Question

  • User1985577645 posted

    I thought I had this all figured out. But I cannot seem to get this going. Forgive my verbiage as I'm still catching on here. I have a simple form (inherited from Master). On a button push I would like my function, that builds html.ToString, to be displayed. I've tried a Panel and a Placeholder but am still missing how to get the data to display. Here is the code behind function:

        Private Function BuildOffline(ByVal Node As String)
            Dim PublicCity As String
            Dim PublicCount As Integer = 0
            Try
                Dim client As MongoClient
                Dim server As MongoServer
                Dim db As MongoDatabase
                Dim Mac, AccountNum, AccountType, StreetName, StreetNum, Apt, AptNum, Area, City, CmtsName, ModemType, FirstName, LastName, ModemStatus, Card As String
                Dim ModemUpdateDate As DateTime
                Dim html As New System.Text.StringBuilder
                Dim online As Integer
                Dim offline As Integer
                Dim other As Integer
                Dim StartQueryDate As DateTime
    
                Dim NodeTable As New DataTable
                NodeTable.Columns.Add("_id", GetType(String))
                NodeTable.Columns.Add("AccountNum", GetType(String))
                NodeTable.Columns.Add("AccountType", GetType(String))
                NodeTable.Columns.Add("StreetNum", GetType(String))
                NodeTable.Columns.Add("StreetName", GetType(String))
                NodeTable.Columns.Add("Apt", GetType(String))
                NodeTable.Columns.Add("AptNum", GetType(String))
                NodeTable.Columns.Add("Area", GetType(String))
                NodeTable.Columns.Add("City", GetType(String))
                NodeTable.Columns.Add("CmtsName", GetType(String))
                NodeTable.Columns.Add("ModemType", GetType(String))
                NodeTable.Columns.Add("FirstName", GetType(String))
                NodeTable.Columns.Add("LastNam", GetType(String))
                NodeTable.Columns.Add("ModemUpdateDate", GetType(DateTime))
                NodeTable.Columns.Add("ModemStatus", GetType(String))
                NodeTable.Columns.Add("CmtsInterface", GetType(String))
    
                Node = Node.Substring(0, 6)
    
                client = New MongoClient("mongodb:xxxxxxxxxxxxxxxxxxxxxinventory")
                server = client.GetServer()
                db = server.GetDatabase("inventory")
                Dim collection = db.GetCollection(Of BsonDocument)("custdata")
    
                StartQueryDate = DateAdd(DateInterval.Hour, -25, TimeZoneInfo.ConvertTimeToUtc(Now))
                Debug.Print("Now: " & Now())
                Debug.Print("UTC: " & TimeZoneInfo.ConvertTimeToUtc(Now))
                Debug.Print("UTC - 24 Hours: " & StartQueryDate)
    
    
                html.Append("<TABLE style=""border:1px solid black;"">")
                
    
    
                Dim qry = Query.And(Query.EQ("NodeName", Node), Query.GT("ModemUpdateDate", StartQueryDate), Query.EQ("AccountStatus", "Active")) 'Query.NE("ModemStatus", "NFOS")
    
                 
    
                html.Append("<TH style=""border:1px solid black;"">Mac</TH>")
                html.Append("<TH style=""border:1px solid black;"">Status</TH>")
                html.Append("<TH style=""border:1px solid black;"">Modem Type</TH>")
                html.Append("<TH style=""border:1px solid black;"">ST#</TH>")
                html.Append("<TH style=""border:1px solid black;"">Street</TH>")
                html.Append("<TH style=""border:1px solid black;"">Apt</TH>")
                html.Append("<TH style=""border:1px solid black;"">Apt#</TH>")
                html.Append("<TH style=""border:1px solid black;"">City</TH>")
                html.Append("<TH style=""border:1px solid black;"">AccountNum</TH>")
                html.Append("<TH style=""border:1px solid black;"">AccountType</TH>")
                html.Append("<TH style=""border:1px solid black;"">Area</TH>")
                html.Append("<TH style=""border:1px solid black;"">Cmts Name</TH>")
                html.Append("<TH style=""border:1px solid black;"">First</TH>")
                html.Append("<TH style=""border:1px solid black;"">Last</TH>")
                html.Append("<TH style=""border:1px solid black;"">Time</TH>")
                html.Append("<TH style=""border:1px solid black;"">Interface</TH>")
    
                Dim count As Integer = 0
                online = 0
                offline = 0
                other = 0
                For Each item As BsonDocument In collection.Find(qry).SetSortOrder(SortBy.Ascending("ModemStatus").Ascending("StreetName").Ascending("StreetNum"))
    
                    Mac = item.GetElement("_id").Value
                    AccountNum = item.GetElement("AccountNum").Value
                    AccountType = item.GetElement("AccountType").Value
                    StreetNum = item.GetElement("StreetNum").Value
                    StreetName = item.GetElement("StreetName").Value
                    Apt = item.GetElement("Apt").Value
                    AptNum = item.GetElement("AptNum").Value
                    Area = item.GetElement("Area").Value
                    City = item.GetElement("City").Value
                    PublicCity = City
                    CmtsName = item.GetElement("CmtsName").Value
                    ModemType = item.GetElement("ModemType").Value
                    FirstName = item.GetElement("FirstName").Value
                    LastName = item.GetElement("LastName").Value
                    ModemUpdateDate = item.GetElement("ModemUpdateDate").Value
                    ModemUpdateDate = ModemUpdateDate.ToLocalTime
                    ModemStatus = item.GetElement("ModemStatus").Value
                    Card = item.GetElement("CmtsInterface").Value
    
                    NodeTable.Rows.Add(Mac, AccountNum, AccountType, StreetNum, StreetName, Apt, AptNum, Area, City, CmtsName, ModemType, FirstName, LastName, ModemUpdateDate, ModemStatus, Card)
    
                    If LCase(ModemStatus) Like "*online*" Or LCase(ModemStatus) Like "*operational*" Then
                        online = online + 1
                    ElseIf LCase(ModemStatus) Like "*offline*" Or LCase(ModemStatus) Like "*nfos*" Then
                        html.Append("<TR style=""border:1px solid black;"">")
                        html.Append("<TD style=""border:1px solid black;"">" & Mac & "</TD>")
                        html.Append("<TD bgcolor=""#FF4500""style=""border:1px solid black;"">" & ModemStatus & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & ModemType & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & StreetNum & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & StreetName & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & Apt & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & AptNum & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & City & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & AccountNum & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & AccountType & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & Area & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & CmtsName & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & FirstName & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & LastName & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & ModemUpdateDate & "</TD>")
                        html.Append("<TD style=""border:1px solid black;"">" & Card & "</TD>")
                        html.Append("</tr>")
                        offline = offline + 1
                    Else
                        other = other + 1
                    End If
    
                    count = count + 1
                     
                Next
                server.Disconnect()
                html.Append("</TABLE>")
                DevicesOffline.Text = html.ToString
                html.Clear()
                Dim Cards = From row In NodeTable.AsEnumerable()
                            Select row.Field(Of String)("CmtsInterface") Distinct
    
    
                Dim ModemCount As New DataTable
                ModemCount.Columns.Add("Card", GetType(String))
                ModemCount.Columns.Add("Total", GetType(Integer))
                ModemCount.Columns.Add("Online", GetType(Integer))
                ModemCount.Columns.Add("Offline", GetType(Integer))
                ModemCount.Columns.Add("Other", GetType(Integer))
                ModemCount.Columns.Add("PercentOnline", GetType(String))
    
                Dim CountOnline, CountOffline, CountOther As Integer
                CountOnline = 0
                CountOffline = 0
                CountOther = 0
    
                NodeTable.CaseSensitive = False
    
                For X = 0 To Cards.Count - 1
                    CountOnline = NodeTable.Select("CmtsInterface = '" & Cards(X) & "' AND (ModemStatus LIKE '%operational%' OR ModemStatus LIKE '%online%')").Count
                    CountOffline = NodeTable.Select("CmtsInterface = '" & Cards(X) & "' AND (ModemStatus LIKE '%offline%' OR ModemStatus LIKE '%nfo%')").Count
                    CountOther = NodeTable.Select("CmtsInterface = '" & Cards(X) & "' AND ModemStatus NOT LIKE '%offline%' AND ModemStatus NOT LIKE '%nfo%' AND ModemStatus NOT LIKE '%operational%' AND ModemStatus NOT LIKE '%online%'").Count
                    ModemCount.Rows.Add(Cards(X), CountOnline + CountOffline + CountOther, CountOnline, CountOffline, CountOther, FormatPercent(CountOnline / (CountOffline + CountOnline + CountOther)))
                    CountOnline = 0
                    CountOffline = 0
                    CountOther = 0
                Next
    
                ModemCount.DefaultView.Sort = "Card ASC"
    
                html.Append("<TR style=""border:1px solid black;""><TD style=""border:1px solid black;"">Card:</TD><TD style=""border:1px solid black;"">Total:</TD><TD style=""border:1px solid black;"">Online:</TD><TD style=""border:1px solid black;"">Offline:</TD><TD style=""border:1px solid black;"">Other:</TD><TD style=""border:1px solid black;"">% Online:</TD><TD style=""border:1px solid black;"" COLSPAN=""8""></TD></TR>")
                For Each row As DataRow In ModemCount.Rows
                     
                    html.Append("<TR style=""border:1px solid black;""><TD style=""border:1px solid black;"">" & row(0) & "</TD><TD style=""border:1px solid black;"">" & row(1) & "</TD><TD style=""border:1px solid black;"">" & row(2) & "</TD><TD style=""border:1px solid black;"">" & row(3) & "</TD><TD style=""border:1px solid black;"">" & row(4) & "</TD><TD style=""border:1px solid black;"">" & row(5) & "</TD><TD style=""border:1px solid black;"" COLSPAN=""8""></TD></TR>")
                Next
    
    
                Return html.ToString
    
            Catch ex As Exception
                Return ""
            End Try
    
        End Function

     On a button push I have: (edited out some other stuff)

    Offline.Text = BuildOffline(Node.Text) On aspx I have: <div> </div>


     All I get is the table structure with column names, but no data gets filled. Thank you in advance.

    Mac Status Modem Type ST# Street Apt Apt# City AccountNum AccountType Area Cmts Name First Last Time Interface
    " & Mac & " " & ModemStatus & " " & ModemType & " " & StreetNum & " " & StreetName & " " & Apt & " " & AptNum & " " & City & " " & AccountNum & " " & AccountType & " " & Area & " " & CmtsName & " " & FirstName & " " & LastName & " " & ModemUpdateDate & " " & Card & "
    Card: Total: Online: Offline: Other: % Online:
    " & row(0) & " " & row(1) & " " & row(2) & " " & row(3) & " " & row(4) & " " & row(5) & "
    Monday, September 24, 2018 7:55 PM

All replies

  • User1985577645 posted
    Damn I guess I need to learn how to post code to a forum 1st. Sorry.
    Monday, September 24, 2018 8:00 PM
  • User409696431 posted

    Edit your post and try again.  Look at the menu of the editing area, and hover over the icons to see what they do.  Specifically, over toward the right, {i} is for inserting code.

    Monday, September 24, 2018 10:01 PM