Imports System.Data.SqlClient

Public Class GoogleAnalytics
    Inherits System.Web.UI.UserControl

    Property GTag As String
        Get
            Return _GTag
        End Get
        Set(value As String)
            _GTag = value
            phContent.Visible = Not String.IsNullOrEmpty(_GTag)
        End Set
    End Property
    Private _GTag As String = ""

    Sub LoadByAppId(appId As String)
        Using connection As New SqlConnection(Logic.Database.connectionString)
            connection.Open()
            Dim cmd As New SqlCommand(
                "SELECT ISNULL(sc.GoogleAnalyticsTag, '')
                FROM web_DriverApplication app LEFT JOIN ServiceContract sc ON sc.ID=app.clientId
                WHERE app.id=@appId", connection)
            cmd.Parameters.AddWithValue("appId", appId)
            GTag = cmd.ExecuteScalar()
        End Using
    End Sub

    Sub LoadByContractId(contractId As String)
        Using connection As New SqlConnection(Logic.Database.connectionString)
            connection.Open()
            Dim cmd As New SqlCommand(
                "SELECT ISNULL(sc.GoogleAnalyticsTag, '')
                FROM ServiceContract sc
                WHERE sc.id=@contractId", connection)
            cmd.Parameters.AddWithValue("contractId", contractId)
            GTag = cmd.ExecuteScalar()
        End Using
    End Sub

End Class