#Region "asp2dotnet converter header"
' Source file: "file://c:\inetpub\wwwroot\MM\gethint.asp"
' Source MD5: 4d57f4ef7f5217b684bfc39170021f05
' Original Modified: 2017-07-14T13:46:44.000Z
' Date Converted: 2017-07-26T20:36:40.424Z
' File Protected: false
#End Region

Imports System.Data.SqlClient

Public Class pageGethint

    Inherits AspPage

#Region "Used Modules"
    Private ReadOnly Property _clsMessageVAR As clsMessageVAR
        Get
            If __clsMessageVAR Is Nothing Then
                __clsMessageVAR = createInstance(GetType(clsMessageVAR))
            End If
            Return __clsMessageVAR
        End Get
    End Property
#End Region

#Region "Global Variables"
    Private __clsMessageVAR As clsMessageVAR = Nothing

    Public Property Keywords As Object
    Public Property KeywordsCmd As Object
    Public Property Output As Object
    Public Property FirstItem As Object
    Public Property HomeUrl As Object

    ' now read the Recordset into a 2nd array
    Public Property ATable1Values As Object
    Private IRowLoop As Integer
    Public Property IColLoop As Object
#End Region

#Region "Used Modules"
    Private __Vb6 As Vb6 = Nothing
    Private q As String
    Private r As String
    Private s As String
    Private param1 As String
    Private param2 As String
    Private param3 As String
    Private param4 As String
    Private param5 As String
    Private param6 As String
    Private param7 As String
    Private param8 As String
    Private param9 As String

    Private ReadOnly Property _Vb6 As Vb6
        Get
            If __Vb6 Is Nothing Then
                __Vb6 = createInstance(GetType(Vb6))
            End If
            Return __Vb6
        End Get
    End Property
#End Region



    '************************************************
    '
    ' Sub: Page_Load
    ' Sub is called on each page load
    '
    '************************************************
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim MyConnection As New SqlConnection
        Dim strConn As String
        Dim sqlDataReader As SqlDataReader
        Dim strOutput As String

        strConn = ConfigurationManager.ConnectionStrings("MMConnectionString").ToString

        'get home url parameter
        Me.HomeUrl = System.Web.HttpContext.Current.Session("webURL")

        'get the q parameter from URL which represents Lookup string
        q = UCase(Request.QueryString("q").ToString())

        'get the r parameter from URL which represents radio button selection
        r = UCase(Request.QueryString("r").ToString())

        'get the s parameter from URL which represents Site
        s = UCase(Request.QueryString("s").ToString())

        MyConnection = New SqlConnection(strConn)
        Dim MyCommand As New SqlCommand()
        MyCommand.Connection = MyConnection
        MyCommand.CommandType = CommandType.Text

        Response.Expires = -1

        If q = "OVERRIDE" Then
            param1 = Request.QueryString("p1").ToString() ' Patient Last Name field tab_Globals.Gl_overrideLName
            param2 = Request.QueryString("p2").ToString() ' Patient First Name field tab_Globals.Gl_overrideFName
            param3 = Request.QueryString("p3").ToString() ' Patient Last Four SSN field tab_Globals.Gl_overrideL4
            param4 = Request.QueryString("p4").ToString() ' Patient Phone Number field tab_Globals.Gl_overridePhone
            param5 = Request.QueryString("p5").ToString() ' Patient Return Call field tab_Globals.Gl_overrideRCall
            param6 = Request.QueryString("p6").ToString() ' Patient Reason field tab_Globals.Gl_overrideReason
            param7 = Request.QueryString("p7").ToString() ' Patient Comment field tab_Globals.Gl_overrideComment
            param8 = Request.QueryString("p8").ToString() ' Patient Date of Birth field tab_Globals.Gl_overrideDOB
            param9 = Request.QueryString("p9").ToString() ' Team Colorize field tab_Globals.Gl_overrideTeamColorize

            MyCommand.CommandText = "UPDATE tab_Globals SET Gl_overrideLName= '" & param1 & "', Gl_overrideFName= '" & param2 & "', Gl_overrideL4= '" & param3 & "', Gl_overridePhone= '" & param4 & "', Gl_overrideRCall= '" & param5 & "', Gl_overrideReason= '" & param6 & "', Gl_overrideComment= '" & param7 & "', Gl_overrideDOB= '" & param8 & "', Gl_overrideTeamColorize= '" & param9 & "' ;"

            Try
                If MyConnection.State = ConnectionState.Closed Then
                    MyConnection.Open()
                End If

                sqlDataReader = MyCommand.ExecuteReader
                sqlDataReader.Close()

            Catch ex As Exception
                System.Web.HttpContext.Current.Session(“Oops”) = ex.Message
                Response.Redirect("oops.aspx")
            End Try

            strOutput = "Field Overrides update success!"
            Response.Write(strOutput)
        ElseIf r = "TEAM" Then ' Lookup by Team Name

            MyCommand.CommandText = "Select tab_Teams.Te_Name As TeamName, tab_Sites.Si_SiteNum As SiteNum, " &
            "tab_Sites.Si_Name As SiteName, tab_Locations.Lo_Index As LocIndex, tab_Locations.Lo_Name As LocName, " &
            "tab_Teams.Te_Index As TeamIndex From tab_Teams " &
            "INNER Join tab_Locations On tab_Locations.Lo_Index = tab_Teams.Te_LocationIndex " &
            "INNER Join tab_Sites On tab_Sites.Si_SiteNum = tab_Locations.Lo_SiteNum " &
            "WHERE Te_Name Like '%" & q & "%'" & " AND tab_Teams.Te_Active = 'Yes' AND tab_Locations.Lo_Active = 'Yes' AND tab_Sites.Si_Active = 'Yes'"

            If s <> "0" Then
                MyCommand.CommandText = MyCommand.CommandText & " AND tab_Sites.Si_SiteNum = " & "'" & s & "'"
            End If

            MyCommand.CommandText = MyCommand.CommandText & " ORDER BY tab_Teams.Te_Name;"

            Try
                If MyConnection.State = ConnectionState.Closed Then
                    MyConnection.Open()
                End If

                sqlDataReader = MyCommand.ExecuteReader

                If Not sqlDataReader.HasRows Then
                    sqlDataReader.Close()
                    Response.Write("no team names found. Please refine search critera.")
                Else
                    'lookup hints from array if length of q>2
                    If Len(q) > 2 Then
                        strOutput = "Click To enter New Message for selected Team Name:<br><br>"
                        While sqlDataReader.Read = True
                            strOutput = strOutput & "<a href=" & HomeUrl & "?S=" & sqlDataReader.Item("SiteNum") & "&L=" & sqlDataReader.Item("LocIndex") & "&T=" & sqlDataReader.Item("TeamIndex") & ">" & sqlDataReader.Item("TeamName") & " - Site: " & sqlDataReader.Item("SiteName") & " - Location: " & sqlDataReader.Item("LocName") & "</a><br>"
                        End While
                        Response.Write(strOutput)
                    Else
                        Response.Write("")
                    End If
                End If
                sqlDataReader.Close()

            Catch ex As Exception
                System.Web.HttpContext.Current.Session(“Oops”) = ex.Message
                Response.Redirect("oops.aspx")
            End Try
        Else ' Lookup by Team Member

            MyCommand.CommandText = "Select tab_Members.Me_Name As MemberName, tab_Members.Me_Title As Title, tab_Sites.Si_SiteNum As SiteNum, tab_Sites.Si_Name As SiteName, tab_Locations.Lo_Index As LocIndex, " &
            "tab_Locations.Lo_Name As LocName, tab_Teams.Te_Index As TeamIndex, tab_Teams.Te_Name As TeamName FROM tab_Members " &
            "INNER JOIN tab_Teams On tab_Teams.Te_Index = tab_Members.Me_TeamIndex " &
            "INNER JOIN tab_Locations On tab_Locations.Lo_Index = tab_Teams.Te_LocationIndex " &
            "INNER JOIN tab_Sites On tab_Sites.Si_SiteNum = tab_Locations.Lo_SiteNum "

            If s = "0" Then
                MyCommand.CommandText = MyCommand.CommandText & " WHERE Me_Name Like '%" & q & "%'" & " AND tab_Members.Me_Active = 'Yes' AND tab_Teams.Te_Active = 'Yes' AND tab_Locations.Lo_Active = 'Yes' AND tab_Sites.Si_Active = 'Yes' AND tab_Members.Me_ShowOn = 'Yes' ORDER BY tab_Members.Me_Name;"
            Else
                MyCommand.CommandText = MyCommand.CommandText & " WHERE tab_Sites.Si_SiteNum = '" & s & "' AND Me_Name Like '%" & q & "%'" & " AND tab_Members.Me_Active = 'Yes' AND tab_Teams.Te_Active = 'Yes' AND tab_Locations.Lo_Active = 'Yes' AND tab_Sites.Si_Active = 'Yes' AND tab_Members.Me_ShowOn = 'Yes' ORDER BY tab_Members.Me_Name;"
            End If

            Try
                If MyConnection.State = ConnectionState.Closed Then
                    MyConnection.Open()
                End If

                sqlDataReader = MyCommand.ExecuteReader

                If Not sqlDataReader.HasRows Then
                    sqlDataReader.Close()
                    Response.Write("no team members found. Please refine search critera.")
                Else
                    'lookup hints from array if length of q>2
                    If Len(q) > 2 Then
                        strOutput = "Click to enter new Message for selected Team Member:<br><br>"
                        While sqlDataReader.Read = True
                            strOutput = strOutput & "<a href=" & HomeUrl & "?S=" & sqlDataReader.Item("SiteNum") & "&L=" & sqlDataReader.Item("LocIndex") & "&T=" & sqlDataReader.Item("TeamIndex") & ">" & sqlDataReader.Item("MemberName") & " " & sqlDataReader.Item("Title") & " - Site: " & sqlDataReader.Item("SiteName") & " - Location: " & sqlDataReader.Item("LocName") & " - Team: " & sqlDataReader.Item("TeamName") & "</a><br>"
                        End While
                        Response.Write(strOutput)
                    Else
                        Response.Write("")
                    End If
                End If
                sqlDataReader.Close()

            Catch ex As Exception
                System.Web.HttpContext.Current.Session(“Oops”) = ex.Message
                Response.Redirect("oops.aspx")
            End Try
        End If

    End Sub

    Protected Overrides Sub Finalize()
    End Sub

End Class
