Imports System.Data
Namespace LYB.VB
    Public Class Display
        Public Function MakeTableCell(ByVal text As String, _
                                        ByVal fontFamily As String, _
                                        ByVal fontSize As String) As TableCell
            Dim tbcell As New TableCell
            If fontFamily <> "" Then
                tbcell.Style.Add("font-family", fontFamily)
            End If
            If fontSize <> "" Then
                tbcell.Style.Add("font-size", fontSize & "em")
            End If
            tbcell.Text = text
            Return tbcell
        End Function
        Public Function MakeTableCell(ByVal text As String, _
                                        ByVal fontFamily As String, _
                                        ByVal fontSize As String, _
                                        ByVal fontWeight As String) As TableCell
            Dim tbcell As New TableCell
            If fontFamily <> "" Then
                tbcell.Style.Add("font-family", fontFamily)
            End If
            If fontSize <> "" Then
                tbcell.Style.Add("font-size", fontSize & "em")
            End If
            tbcell.Style.Add("font-weight", fontWeight)
            tbcell.Text = text
            Return tbcell
        End Function
        Public Function MakeTableCell(ByVal text As String, _
                                        ByVal fontFamily As String, _
                                        ByVal fontSize As String, _
                                        ByVal columnSpan As Integer) As TableCell
            Dim tbcell As New TableCell
            If fontFamily <> "" Then
                tbcell.Style.Add("font-family", fontFamily)
            End If
            If fontSize <> "" Then
                tbcell.Style.Add("font-size", fontSize & "em")
            End If
            tbcell.ColumnSpan = CStr(columnSpan)
            tbcell.Text = text
            Return tbcell
        End Function
        Public Function MakeTableCell(ByVal text As String, _
                                        ByVal fontFamily As String, _
                                        ByVal fontSize As String, _
                                        ByVal cssclass As Boolean, _
                                        ByVal cssclassID As String) As TableCell
            Dim tbcell As New TableCell
            If cssclass = True Then
                tbcell.CssClass = cssclassID
            Else
                tbcell.Style.Add(Left(cssclassID, InStr(cssclassID, ":") - 1), Mid(cssclassID, InStr(cssclassID, ":") + 1))
            End If
            If fontFamily <> "" Then
                tbcell.Style.Add("font-family", fontFamily)
            End If
            If fontSize <> "" Then
                tbcell.Style.Add("font-size", fontSize & "em")
            End If
            tbcell.Text = text
            Return tbcell

        End Function
        Public Function MakeTableCell(ByVal text As String, _
                                        ByVal fontFamily As String, _
                                        ByVal fontSize As String, _
                                        ByVal fontWeight As String, _
                                        ByVal columnSpan As Integer) As TableCell
            Dim tbcell As New TableCell
            If fontFamily <> "" Then
                tbcell.Style.Add("font-family", fontFamily)
            End If
            If fontSize <> "" Then
                tbcell.Style.Add("font-size", fontSize & "em")
            End If
            tbcell.ColumnSpan = CStr(columnSpan)
            tbcell.Text = text
            Return tbcell
        End Function
        Public Function MakeTableHeaderCell(ByVal text As String, _
                                            ByVal fontFamily As String, _
                                            ByVal fontSize As String, _
                                            Optional ByVal columnSpan As Integer = 1) As TableHeaderCell
            Dim tbheadercell As New TableHeaderCell
            If fontFamily <> "" Then
                tbheadercell.Style.Add("font-family", fontFamily)
            End If
            tbheadercell.Text = text
            tbheadercell.ColumnSpan = CStr(columnSpan)
            Return tbheadercell
        End Function
        Public Sub ShowDefaultPagePictures(ByVal page As System.Web.UI.Page, ByVal tbGlobalConfig As DataTable, ByVal userID As String)
            Dim dataUtils As New DataUtils
            Dim r As Integer
            Dim r1 As Integer
            Dim r2 As Integer
            Dim tbDynamicPicture As DataTable
            Dim rndMin As Integer
            Dim rndMax As Integer
            Dim pictureGroupRN As Integer
            Dim currentRow As DataRow
            Dim countL As Integer
            Dim countR As Integer

            For r = 0 To page.Controls.Count - 1
                If page.Controls(r).ID = "pnlHead" Then
                    Dim pnlControl As System.Web.UI.WebControls.Panel = page.Controls(r)
                    pnlControl.CssClass = "head_surface"
                End If
                If page.Controls(r).ID = "pnlMain" Then
                    Dim pnlControl As System.Web.UI.WebControls.Panel = page.Controls(r)
                    pnlControl.CssClass = "main_surface"
                    For r1 = 0 To page.Controls(r).Controls.Count - 1
                        If page.Controls(r).Controls(r1).ID = "Form1" Then
                            For r2 = 0 To page.Controls(r).Controls(r1).Controls.Count - 1
                                If page.Controls(r).Controls(r1).Controls(r2).ID = "lblWelcome" Then
                                    page.Controls(r).Controls(r1).Controls(r2).Visible = False
                                End If
                                If page.Controls(r).Controls(r1).Controls(r2).ID = "lblOut1" Then
                                    page.Controls(r).Controls(r1).Controls(r2).Visible = False
                                End If
                            Next
                        End If
                    Next
                End If
            Next
            Randomize()
            rndMin = tbGlobalConfig.Rows(0).Item("RandomPictureGroupMin")
            rndMax = tbGlobalConfig.Rows(0).Item("RandomPictureGroupMax")
            pictureGroupRN = CInt(Int((rndMax * Rnd()) + rndMin))

            tbDynamicPicture = dataUtils.RetrievePictureData(pictureGroupRN)
            For Each currentRow In tbDynamicPicture.Rows
                If currentRow.Item("Placement") = "L" Then
                    countL = countL + 1
                    Dim img As Control = page.Controls(3).Controls(1).FindControl("imgL" + CStr(countL))
                    Dim imgL As System.Web.UI.WebControls.Image = img
                    imgL.ImageUrl = "images/" + currentRow.Item("PictureName")
                    imgL.Style.Add("position", "absolute")
                    Randomize()
                    ' CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound))
                    Dim pxLeft As Integer = CInt(Int((tbGlobalConfig.Rows(0).Item("PictureLeftX2") - tbGlobalConfig.Rows(0).Item("PictureLeftX1") + 1) * Rnd()) + tbGlobalConfig.Rows(0).Item("PictureLeftX1"))
                    imgL.Style.Add("left", CStr(pxLeft) + "px")
                    Dim pxTop As Integer = CInt(Int((tbGlobalConfig.Rows(0).Item("PictureLeftY2") - tbGlobalConfig.Rows(0).Item("PictureLeftY1") + 1) * Rnd()) + tbGlobalConfig.Rows(0).Item("PictureLeftY1"))
                    imgL.Style.Add("top", CStr(pxTop) + "px")
                    imgL.ToolTip = currentRow.Item("PictureComment")
                    '                imgL.ToolTip = "L:" + CStr(pxLeft) + " T:" + CStr(pxTop)
                    If currentRow.Item("Private") = True Then
                        If userID = tbGlobalConfig.Rows(0).Item("PrivateID") Or userID = "127.0.0.1" Then
                            imgL.Visible = True
                        Else
                            imgL.Visible = False
                        End If
                    Else
                        imgL.Visible = True
                    End If
                Else
                    countR = countR + 1
                    Dim img As Control = page.Controls(3).Controls(1).FindControl("imgR" + CStr(countL))
                    Dim imgR As System.Web.UI.WebControls.Image = img
                    imgR.ImageUrl = "images/" + currentRow.Item("PictureName")
                    imgR.Style.Add("position", "absolute")
                    Randomize()
                    Dim pxLeft As Integer = CInt(Int((tbGlobalConfig.Rows(0).Item("PictureRightX2") - tbGlobalConfig.Rows(0).Item("PictureRightX1") + 1) * Rnd()) + tbGlobalConfig.Rows(0).Item("PictureRightX1"))
                    imgR.Style.Add("left", CStr(pxLeft) + "px")
                    Dim pxTop As Integer = CInt(Int((tbGlobalConfig.Rows(0).Item("PictureRightY2") - tbGlobalConfig.Rows(0).Item("PictureRightY1") + 1) * Rnd()) + tbGlobalConfig.Rows(0).Item("PictureRightY1"))
                    imgR.Style.Add("top", CStr(pxTop) + "px")
                    imgR.ToolTip = currentRow.Item("PictureComment")
                    'imgR.ToolTip = "L:" + CStr(pxLeft) + " T:" + CStr(pxTop)
                    If currentRow.Item("Private") = True Then
                        If userID = tbGlobalConfig.Rows(0).Item("PrivateID") Or userID = "127.0.0.1" Then
                            imgR.Visible = True
                        Else
                            imgR.Visible = False
                        End If
                    Else
                        imgR.Visible = True
                    End If
                End If
            Next

        End Sub
    End Class
End Namespace
