﻿Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.MasterPage
Imports AjaxControlToolkit
Public Class Fourms
    Inherits System.Web.UI.Page
    Dim SqlConn As SqlConnection
    Dim SqlCommand As SqlCommand
    Dim SqlDataReader, SqlItemDataReader As SqlDataReader
    Dim SqlQuery As String
    Dim Sql_CommuntyDataAdapter, Sql_SurveyItemsDataAdapter As SqlDataAdapter
    Dim Sql_CommuntyDataTable, Sql_SurveyItemsDataTable As DataTable
    Dim MdlPop As ModalPopupExtender
    Dim StrDataTableFilter, StrDataTableSort, StrStudentCode As String
    Dim IntItemCount, IntItemNo, IntItemAnwser, IntStudentCode As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session("Messege") = ""
        SqlConn = New SqlConnection(Session("Connection"))
        SqlConn.Open()
        SqlCommand = New SqlCommand()
        SqlCommand.Connection = SqlConn
        LblCommentWriteDate.Text = Date.UtcNow.Date.ToString
        LBlStudentName.Text = Session("Studentname")
        SqlQuery = "SELECT        dbo.StudentID.StudentName, dbo.StudentCommunty.Comment, dbo.StudentCommunty.CommentDate"
        SqlQuery = SqlQuery & " FROM            dbo.StudentID INNER JOIN"
        SqlQuery = SqlQuery & " dbo.StudentCommunty ON dbo.StudentID.StudentCode = dbo.StudentCommunty.StudentCode"
        SqlQuery = SqlQuery & " ORDER BY dbo.StudentCommunty.CommentDate"
        SqlCommand.CommandText = SqlQuery
        Sql_CommuntyDataAdapter = New SqlDataAdapter()
        Sql_CommuntyDataTable = New DataTable()
        Sql_CommuntyDataAdapter.SelectCommand = SqlCommand
        Sql_CommuntyDataAdapter.Fill(Sql_CommuntyDataTable)
        If Sql_CommuntyDataTable.Rows.Count <> 0 Then
            Session("Fourms") = ""
            Dim RowIndex As Integer = 0
            For Each Row As DataRow In Sql_CommuntyDataTable.Rows
                Session("Fourms") = Session("Fourms") & "<table style='width:650px; border-color:#CCCCCC; border-width:1; border-style:solid;' >"
                Session("Fourms") = Session("Fourms") & "<tr>"
                Session("Fourms") = Session("Fourms") & " <td rowspan =3 >  </td>"
                ''For Each column As DataColumn In Sql_CommuntyDataTable.Columns

                'Select Case column.ColumnName
                '    Case "StudentName"
                Session("Fourms") = Session("Fourms") & "<td style= text-align:right;'> <p>" & Sql_CommuntyDataTable.Rows(RowIndex).Item("StudentName") & "</p></td>"
                'Case "CommentDate"
                Session("Fourms") = Session("Fourms") & "<td style= text-align:left;'>  <p>" & Sql_CommuntyDataTable.Rows(RowIndex).Item("CommentDate") & "</p></td></tr>"
                'Case "Comment"
                'Session("Fourms") = Session("Fourms") & "<tr><td  colspan=2 style='width:650px; text-align:right;'> <p>" & Sql_CommuntyDataTable.Rows(RowIndex).Item(column.ColumnName) & "</p></td>"
                Session("Fourms") = Session("Fourms") & "<tr><td  colspan=2 style='width:650px; text-align:right;'> <p>" & Sql_CommuntyDataTable.Rows(RowIndex).Item("Comment") & "</p></td>"

                '    End Select


                'Next
                Session("Fourms") = Session("Fourms") & "</tr></table><br/>"
                RowIndex = RowIndex + 1
            Next
        End If

    End Sub

    Private Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click

        Try

            If TxtComment.Text <> "" Then
                SqlQuery = "Insert into StudentCommunty (StudentCode, Comment, CommentDate) Values (" & Session("StudentCode") & ",'" & TxtComment.Text & "','" & DateTime.Parse(LblCommentWriteDate.Text) & "')"

                SqlCommand.CommandText = SqlQuery
                SqlCommand.ExecuteNonQuery()
                SqlCommand.Cancel()
                SqlCommand.Dispose()
                TxtComment.Text = ""
            Else
                Dim LblMessege As Label = CType(Master.FindControl("Label1"), Label)
                Session("Messege") = "لم يتم أدخال تعليقك لعدم كتابة أى تعليق"
                ShowPanel("Label4", "Panel8", "Button3")

            End If
        Catch ex As Exception
            ShowPanel("Label1", "Panel5", "Button1")

        End Try

    End Sub

    Sub ShowPanel(ByVal StrTargetControlID As String, ByVal StrPopupControlID As String, ByVal StrOkControlID As String)
        MdlPop = CType(Master.FindControl("mdlpopup"), ModalPopupExtender)
        With MdlPop
            .DropShadow = "True"
            .TargetControlID = StrTargetControlID
            .PopupControlID = StrPopupControlID
            .OkControlID = StrOkControlID
            .X = "400"
            .Y = "250"
            .Show()
            .Focus()
            .Enabled() = True
        End With


    End Sub
End Class