﻿Imports System.Data.SqlClient
Public Class Site
    Inherits System.Web.UI.MasterPage
    Dim SqlConn As SqlConnection
    Dim SqlCommand As SqlCommand
    Dim SqlDataReader, SqlItemDataReader As SqlDataReader
    Dim SqlQuery As String
    Dim StrWelcome As String
    Dim modalPop As New AjaxControlToolkit.ModalPopupExtender()

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.Cache.SetNoStore()
        Session.Timeout = 45

        StrWelcome = "مرحباً " & Session("StudentName")
        LblWelcome.Text = StrWelcome
        If Session("UserName") <> "" And Session("password") <> "" Then
            If Session("ItemFinished") = "Finished" Then
                PnlResult.Visible = "true"
                ModalPopUpProperty("True", "label2", "PnlResult", "LblResult", "400", "100")
                mdlpopup.Show()
                Session("ItemFinished") = ""
            End If

            Exit Sub
        End If
        If Session("StudentName") = "Guest" Then
            StrWelcome = "  مرحباً بك ضيفاً"
            Session("StudentName") = ""
        ElseIf Session("StudentName") = "" Then
            pnl.Visible = "true"
            mdlpopup.Show()
        End If
        LblWelcome.Text = StrWelcome
    End Sub

    Private Sub btnok_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnok.Click
        mdlpopup.Hide()
        pnl.Visible = "False"
        Response.Redirect("Default.aspx")
    End Sub

    Protected Sub ImgButtonGal1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgButtonGal1.Click
        Panel1.Visible = "True"
        ModalPopUpProperty("false", "ImgButtonGal1", "Panel1", "LblGal1", "400", "200")
    End Sub

    Protected Sub BtnGal1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnGal1.Click
        mdlpopup.Hide()
        Panel1.Visible = "False"
    End Sub

    Public Sub ModalPopUpProperty(ByVal StrDropShadow As String, ByVal StrTargetControlID As String, ByVal StrPopupControlID As String, ByVal StrOkControlID As String, ByVal StrX As String, ByVal StrY As String)
        With mdlpopup
            .DropShadow = StrDropShadow
            .TargetControlID = StrTargetControlID
            .PopupControlID = StrPopupControlID
            .OkControlID = StrOkControlID
            .CancelControlID = ""
            .X = StrX
            .Y = StrY
            .Show()
        End With
    End Sub

    Private Sub ImgButtonGal2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgButtonGal2.Click
        Panel2.Visible = "True"
        ModalPopUpProperty("false", "ImgButtonGal2", "Panel2", "LblGal2", "400", "200")
    End Sub

    Private Sub ImgButtonGal3_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgButtonGal3.Click
        Panel3.Visible = "True"
        ModalPopUpProperty("false", "ImgButtonGal3", "Panel3", "LblGal3", "400", "200")

    End Sub

    Private Sub BtnGal2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGal2.Click
        mdlpopup.Hide()
        Panel2.Visible = "False"
    End Sub

    Private Sub BtnGal3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGal3.Click
        mdlpopup.Hide()
        Panel3.Visible = "False"
    End Sub

    Private Sub BtnGal4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGal4.Click
        mdlpopup.Hide()
        Panel4.Visible = "False"
    End Sub

    'Private Sub BtnGal5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGal5.Click
    '    mdlpopup.Hide()
    '    Panel5.Visible = "False"
    'End Sub

    Private Sub BtnGal6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGal6.Click
        mdlpopup.Hide()
        Panel6.Visible = "False"
    End Sub

    Private Sub ImgButtonGal4_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgButtonGal4.Click
        Panel4.Visible = "True"
        ModalPopUpProperty("false", "ImgButtonGal4", "Panel4", "LblGal4", "400", "200")
    End Sub

    'Private Sub ImgButtonGal5_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgButtonGal5.Click
    '    Panel5.Visible = "True"
    '    ModalPopUpProperty("false", "ImgButtonGal5", "Panel5", "LblGal5", "400", "200")
    'End Sub

    Private Sub ImgButtonGal6_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgButtonGal6.Click
        Panel6.Visible = "True"
        ModalPopUpProperty("false", "ImgButtonGal6", "Panel6", "LblGal6", "400", "200")
    End Sub

    Private Sub BtnResultOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnResultOk.Click
        If RBLSurvey.SelectedValue = True Then
            'PnlResult.Visible = "False"
            Dim IntSurvey As Integer = RBLSurvey.SelectedValue

            SqlConn = New SqlConnection(Session("Connection"))
            SqlConn.Open()
            SqlCommand = New SqlCommand()
            SqlCommand.Connection = SqlConn
            SqlQuery = "Select * from EndSurveyResponse where (StudentCode= " & Session("StudentCode") & ")"
            SqlCommand.CommandText = SqlQuery
            SqlDataReader = SqlCommand.ExecuteReader()
            If SqlDataReader.HasRows Then
                SqlQuery = "update EndSurveyResponse set EndSurveyResponse = " & IntSurvey & " Where (StudentCode = " & Session("StudentCode") & ")"
            Else
                SqlQuery = "Insert into EndSurveyResponse (StudentCode, EndSurveyResponse) Values (" & Session("StudentCode") & "," & IntSurvey & ")"
            End If
            SqlDataReader.Close()
            SqlCommand.CommandText = SqlQuery
            SqlCommand.ExecuteNonQuery()
            SqlCommand.Cancel()
            SqlCommand.Dispose()
            SqlConn.Close()
            'mdlpopup.Hide()
            'For h As Integer = 0 To 100000
            Session("ItemWindowsFinished") = "True"
            Response.Redirect("mainPage.aspx")
        End If

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        mdlpopup.Hide()

        Response.Redirect("Default.aspx")
    End Sub

    Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        'Session("StudentName") = ""
        'Session("UserName") = ""
        'Session("Password") = ""
        'Session("StudentCode") = ""
    End Sub
End Class