Imports System.Data
Imports AppVariable
Imports AppVariable_QA
Imports AppCommon

Partial Class teacher_QAList
    Inherits System.Web.UI.Page

#Region "************************* 定数 *************************"


#End Region

#Region "******************** ページイベント ********************"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            gv_問合せ履歴.DataSource = GetData()
            gv_問合せ履歴.DataBind()

            'ページの位置を復元
            If Not Session(S_QA_PAGE_INDEX) Is Nothing Then
                gv_問合せ履歴.SetPageIndex(Session(S_QA_PAGE_INDEX))
            End If
        End If

    End Sub

#End Region

#Region "***************** コントロールイベント *****************"

    Protected Sub btn_ToInsertPage_Click(sender As Object, e As EventArgs) Handles btn_ToInsertPage.Click
        '遷移先でリストが残るため、遷移前にTMP宛先から削除
        AppQA.宛先削除(strTo区分:="",
                      strTo履修年度:="",
                      strTo成績年度:="",
                      strTo分野CD:="",
                      strTo科目CD:="",
                      strTo講座CD:="",
                      str処理区分:="一括")

        '新規登録画面のパラメータクリア
        If Session(S_QA_Uploaded_File_ID) IsNot Nothing Then
            Session.Remove(S_QA_Uploaded_File_ID)
            Session.Remove(S_QA_Uploaded_File_Path)
            Session.Remove(S_QA_Uploaded_File_Name)
        End If

        '問い合わせ入力フォームへ
        Response.Redirect(Com_Get_Content("menu_kj_qa03"))
    End Sub

    Protected Sub gv_問合せ履歴_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gv_問合せ履歴.RowCommand
        If e.CommandName = "詳細" Then
            'IDをセッションに保存
            Session(S_QA_Selected_ID) = e.CommandArgument.ToString() '問合せID
            '遷移元保存
            Session(S_QA_Detail_RedirectFrom) = "お問合せ一覧"

            '詳細画面へ
            Response.Redirect(Com_Get_Content("menu_kj_qa02"))
        End If
    End Sub

    Protected Sub gv_問合せ履歴_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles gv_問合せ履歴.PageIndexChanging
        gv_問合せ履歴.PageIndex = e.NewPageIndex

        'ページの位置を保持
        Session(S_QA_PAGE_INDEX) = gv_問合せ履歴.PageIndex.ToString

        gv_問合せ履歴.DataSource = GetData()
        gv_問合せ履歴.DataBind()

    End Sub

    Protected Sub gv_問合せ履歴_Sorting(sender As Object, e As GridViewSortEventArgs) Handles gv_問合せ履歴.Sorting
        If Session(S_QA_SORT_COLUMN) Is Nothing Then
            Session(S_QA_SORT_COLUMN) = e.SortExpression

            e.SortDirection = SortDirection.Ascending
            Session(S_QA_SORT_DIR) = "ASC"

        Else
            If e.SortExpression = Session(S_QA_SORT_COLUMN) Then
                Select Case Session(S_QA_SORT_DIR)
                    Case "ASC"
                        e.SortDirection = SortDirection.Descending
                        Session(S_QA_SORT_DIR) = "DESC"

                    Case "DESC"
                        Session(S_QA_SORT_DIR) = "Default"

                        Session(S_QA_SORT_COLUMN) = "既定SORT順"
                        Session(S_QA_SORT_DIR) = "ASC"

                    Case "Default"
                        e.SortDirection = SortDirection.Ascending
                        Session(S_QA_SORT_DIR) = "ASC"

                End Select
            Else
                Session(S_QA_SORT_COLUMN) = e.SortExpression

                e.SortDirection = SortDirection.Ascending
                Session(S_QA_SORT_DIR) = "ASC"

            End If
        End If

        gv_問合せ履歴.DataSource = GetData()
        gv_問合せ履歴.DataBind()

    End Sub

    Protected Sub gv_問合せ履歴_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles gv_問合せ履歴.RowCreated
        If e.Row.RowType = DataControlRowType.Header Then
            Dim strDir As String = ""
            If Not Session(S_QA_SORT_DIR) Is Nothing Then
                If Session(S_QA_SORT_DIR) = "Default" Then strDir = ""
                If Session(S_QA_SORT_DIR) = "ASC" Then strDir = " ▲"
                If Session(S_QA_SORT_DIR) = "DESC" Then strDir = " ▼"
            End If

            If Not Session(S_QA_SORT_COLUMN) Is Nothing Then
                If Session(S_QA_SORT_COLUMN) = "登録者名" Then
                    e.Row.Cells(0).Controls.Add(New LiteralControl(strDir))
                ElseIf Session(S_QA_SORT_COLUMN) = "問合せ日時" Then
                    e.Row.Cells(1).Controls.Add(New LiteralControl(strDir))

                ElseIf Session(S_QA_SORT_COLUMN) = "件名" Then
                    e.Row.Cells(2).Controls.Add(New LiteralControl(strDir))

                ElseIf Session(S_QA_SORT_COLUMN) = "宛先名前表示" Then
                    e.Row.Cells(3).Controls.Add(New LiteralControl(strDir))

                ElseIf Session(S_QA_SORT_COLUMN) = "最新返信日時" Then
                    e.Row.Cells(4).Controls.Add(New LiteralControl(strDir))

                End If
            End If

        End If
    End Sub

#End Region

#Region "******************* Sub及びFunction ********************"

    Function GetData() As DataTable
        Using spm As New StoredProcedureManager("QA_問合せ一覧_教員用_SELECT")

            spm.AddPrmIn("@問合せ区分", Data.SqlDbType.VarChar, 20, Session(S_QA_Search_kubun))
            spm.AddPrmIn("@問合せ者氏名", Data.SqlDbType.NVarChar, 100, Session(S_QA_Search_Name))
            spm.AddPrmIn("@問合せ日", Data.SqlDbType.VarChar, 20, Session(S_QA_Search_ContactDate))
            spm.AddPrmIn("@USERCD", Data.SqlDbType.VarChar, 20, Session(S_COM_UserCD))

            spm.Fill("Contact")

            Dim dt As DataTable = spm.ds.Tables("Contact")

            If Not Session(S_QA_SORT_COLUMN) Is Nothing And Not Session(S_QA_SORT_DIR) Is Nothing Then
                dt.DefaultView.Sort = String.Format("{0} {1}", Session(S_QA_SORT_COLUMN).ToString(), Session(S_QA_SORT_DIR).ToString())
            End If

            Return dt.DefaultView.ToTable

        End Using
    End Function

#End Region





End Class
