Imports System.Data
Imports System.IO
Imports AppCommon
Imports AppInfo
Imports AppVariable
Imports AppVariable_QA

Partial Class InfoPersonal
    Inherits System.Web.UI.Page

#Region "************************* 定数 *************************"
    'SORT
    Public Const S_LIST_SORT_COLUMN As String = "InfoPersonal_SORT_COLUMN"
    Public Const S_LIST_SORT_DIR As String = "InfoPersonal_SORT_DIR"
    'ページインデックス
    Public Const S_LIST_PAGE_INDEX As String = "InfoPersonal_PAGE_INDEX"
#End Region

#Region "********************** メンバ変数 **********************"

    Private Read_Command As String '既読処理 OR 未読処理の判別フラグ

#End Region

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '---------------------------------------------------------------
        'HTMLタグを追加
        '---------------------------------------------------------------
        Dim ctl As Control = Page.Master.FindControl("msp_header")
        'CSS
        SetTagCss(ctl, "info.css")
        
        If IsPostBack = False Then
            gv_info.DataSource = GetData()
            gv_info.DataBind()

            'ページインデックスを復元
            If Not Session(S_LIST_PAGE_INDEX) Is Nothing Then
                gv_info.SetPageIndex(Session(S_LIST_PAGE_INDEX))
            End If

            '---------------------------------------------------------------
            '指定したinfoをセレクト状態にする
            '---------------------------------------------------------------
            If Not Session(S_Info_Selected_Index) Is Nothing Then
                gv_info.SelectedIndex = Session(S_Info_Selected_Index)
            End If
        End If

    End Sub

#End Region

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

    Protected Sub gv_info_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)
        gv_info.SelectedIndex = -1

        gv_info.PageIndex = e.NewPageIndex

        'ページの位置を保持
        Session(S_LIST_PAGE_INDEX) = gv_info.PageIndex.ToString

        gv_info.DataSource = GetData()
        gv_info.DataBind()
    End Sub


    Protected Sub gv_info_Sorting(sender As Object, e As GridViewSortEventArgs)
        If Session(S_LIST_SORT_COLUMN) Is Nothing Then
            Session(S_LIST_SORT_COLUMN) = e.SortExpression

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

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

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

                        Session(S_LIST_SORT_COLUMN) = "既定SORT順"
                        Session(S_LIST_SORT_DIR) = "ASC"

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

                End Select
            Else
                Session(S_LIST_SORT_COLUMN) = e.SortExpression

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

            End If
        End If

        gv_info.DataSource = GetData()
        gv_info.DataBind()

    End Sub

    Protected Sub gv_info_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv_info.SelectedIndexChanged

        Dim strページ遷移_PATH As String = CType(gv_info.SelectedRow.FindControl("lb_ページ遷移_PATH"), Label).Text
        Dim strページ遷移_機能CD As String = CType(gv_info.SelectedRow.FindControl("lb_ページ遷移_機能CD"), Label).Text
        Dim strページ遷移_KEYCD As String = CType(gv_info.SelectedRow.FindControl("lb_ページ遷移_KEYCD"), Label).Text
        Dim str掲示種別CD As String = CType(gv_info.SelectedRow.FindControl("lbl_掲示種別CD"), Label).Text
        Dim arrayKEYCD As String() = strページ遷移_KEYCD.Split("/")
        Dim str掲示NO As String = gv_info.SelectedDataKey.Item(0).ToString
        Dim portal区分 As String = Session(S_COM_PortalKbn)

        '未読既読処理
        If Read_Command = "read" Then
            Info_既読処理(gv_info.SelectedDataKey.Item(0).ToString, Session(S_COM_PortalID))

            'ページ遷移
            If AppInfo.掲示_遷移チェック(str掲示NO) = True Then

                'If str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_レポート") Then
                '    'Session設定
                '    '・学籍NO
                '    Session(S_Rpt_Selected_Gakuseki_NO) = arrayKEYCD(0).ToString
                '    '・履修年度
                '    Session(S_Rpt_Selected_Risyu_Nendo) = arrayKEYCD(1).ToString
                '    '・成績年度
                '    Session(S_Rpt_Selected_Seiseki_Nendo) = arrayKEYCD(2).ToString
                '    '・分野CD
                '    Session(S_Rpt_Selected_Bunya_CD) = arrayKEYCD(3).ToString
                '    '・科目CD
                '    Session(S_Rpt_Selected_Kamoku_CD) = arrayKEYCD(4).ToString
                '    '・設題番号
                '    Session(S_Rpt_Selected_Report_NO) = arrayKEYCD(5).ToString
                '    '・回数
                '    Session(S_Rpt_Selected_Report_Kai) = arrayKEYCD(6).ToString

                '    '遷移元保存
                '    '2018.06.27 ADD START /Liu
                '    Select Case portal区分
                '        Case "職員"
                '            If strページ遷移_機能CD = "menu_km_rpt03" Then
                '                Session(S_Rpt_ReportSend_RedirectFrom) = "個人へのお知らせ"

                '            ElseIf strページ遷移_機能CD = "menu_km_rpt05" Then
                '                Session(S_Rpt_ReportResult_RedirectFrom) = "個人へのお知らせ"
                '            End If
                '        Case "学生"
                '            If strページ遷移_機能CD = "menu_km_rpt04" Then
                '                Session(S_Rpt_ReportResult_RedirectFrom) = "個人へのお知らせ"
                '            End If
                '        Case "教員"
                '            If strページ遷移_機能CD = "menu_km_rpt03" Then
                '                Session(S_Rpt_ReportScore_RedirectFrom) = "個人へのお知らせ"
                '            End If
                '    End Select
                '2018.06.27 ADD END /Liu

                If str掲示種別CD = AppInfo.GetInfoKindCd("問い合わせ") Then
                    'Session設定
                    '・問合せID
                    Session(S_QA_Selected_ID) = strページ遷移_KEYCD

                    '遷移元保存
                    Session(S_QA_Detail_RedirectFrom) = "個人へのお知らせ"   '2018.06.27 ADD /Liu

                    'ElseIf str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_住所変更届") Then
                    '    'Session設定
                    '    '・学籍NO
                    '    Session(S_APL_JS_GakusekiNO) = arrayKEYCD(0).ToString
                    '    '・申請CNT
                    '    Session(S_APL_JS_ShinseiCNT) = arrayKEYCD(1).ToString

                    '    '遷移元保存
                    '    Session(S_APL_JS_RedirectFrom) = "個人へのお知らせ"    '2018.06.27 ADD /Liu

                    'ElseIf str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_スクーリング欠席届") Then
                    '    'Session設定
                    '    '・学籍NO
                    '    Session(S_APL_KS_GakusekiNO) = arrayKEYCD(0).ToString
                    '    '・申請CNT
                    '    Session(S_APL_KS_ShinseiCNT) = arrayKEYCD(1).ToString

                    '    '遷移元保存
                    '    Session(S_APL_KS_RedirectFrom) = "個人へのお知らせ"    '2018.06.27 ADD /Liu

                    'ElseIf str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_購入届") Then
                    '    'Session設定
                    '    '・学籍NO
                    '    Session(S_APL_KN_GakusekiNO) = arrayKEYCD(0).ToString
                    '    '・申請CNT
                    '    Session(S_APL_KN_ShinseiCNT) = arrayKEYCD(1).ToString

                    '    '遷移元保存
                    '    Session(S_APL_KN_RedirectFrom) = "個人へのお知らせ"    '2018.06.27 ADD /Liu

                    'ElseIf str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_学生カルテ_成績") Then
                    '    'Session設定
                    '    '選択中のタブ設定
                    '    Session(SESSION_TAB_SELECTED) = "成績状況"

                    'ElseIf str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_スクーリング") Then
                    '    '2022.06.22 ADD START /Liu
                    '    Select Case portal区分
                    '        Case "職員"
                    '            'Session設定
                    '            '・学籍NO
                    '            Session(S_Sch_Selected_Gakuseki_NO) = arrayKEYCD(0).ToString
                    '            '・履修年度
                    '            Session(S_Sch_Selected_Risyu_Nendo) = arrayKEYCD(1).ToString
                    '            '・成績年度
                    '            Session(S_Sch_Selected_Seiseki_Nendo) = arrayKEYCD(2).ToString
                    '            '・分野CD
                    '            Session(S_Sch_Selected_Bunya_CD) = arrayKEYCD(3).ToString
                    '            '・科目CD
                    '            Session(S_Sch_Selected_Kamoku_CD) = arrayKEYCD(4).ToString
                    '            '・講座CD
                    '            Session(S_Sch_Selected_Kouza_CD) = arrayKEYCD(5).ToString
                    '            '・回数
                    '            Session(S_Sch_Selected_Kaisuu) = arrayKEYCD(6).ToString
                    '            '遷移元保存
                    '            Session(S_Sch_DetailPage_RedirectFrom) = "個人へのお知らせ"
                    '    End Select
                    '    '2022.06.22 ADD END /Liu
                End If

                Session(S_Info_Selected_Index) = gv_info.SelectedIndex  '2018.3.26 ADD /Liu
                'Response.Redirect(Com_Get_Content(strページ遷移_機能CD))

                Com_UC1_Visible("slideopen")

                    Session(S_Info_Selected_Index) = gv_info.SelectedIndex
                    Session(S_Info_Selected_No) = gv_info.SelectedDataKey.Item(0).ToString

                    Response.Redirect(Request.FilePath.ToString)

                Else
                    'ユーザコントロールを開く
                    Com_UC1_Visible("slideopen")

                Session(S_Info_Selected_Index) = gv_info.SelectedIndex
                Session(S_Info_Selected_No) = gv_info.SelectedDataKey.Item(0).ToString

                Response.Redirect(Request.FilePath.ToString)
            End If
        Else
            Info_未読処理(gv_info.SelectedDataKey.Item(0).ToString, Session(S_COM_PortalID))

            'If str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_レポート") Or
            '    str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_問合せ") Or
            '     str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_住所変更届") Or
            '      str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_スクーリング欠席届") Or
            '       str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_購入届") Or
            '        str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_学生カルテ_成績") Or
            '         str掲示種別CD = AppCommon.Com_Get_変数("掲示種別_スクーリング") Then
            '    'ページ遷移する掲示は掲示NOをセッションに保存しない
            'Else
            '    Session(S_Info_Selected_No) = gv_info.SelectedDataKey.Item(0).ToString
            'End If

            If str掲示種別CD = AppInfo.GetInfoKindCd("問い合わせ") Then
                'ページ遷移する掲示は掲示NOをセッションに保存しない
            Else
                Session(S_Info_Selected_No) = gv_info.SelectedDataKey.Item(0).ToString
            End If

            Session(S_Info_Selected_Index) = gv_info.SelectedIndex

            Response.Redirect(Request.FilePath.ToString)
        End If

    End Sub

    Protected Sub gv_info_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_info.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If CType(e.Row.FindControl("lb_添付"), Label).Text = "添付" Then
                CType(e.Row.FindControl("img_添付"), Image).Visible = True
            Else
                CType(e.Row.FindControl("img_添付"), Image).Visible = False
            End If

            If CType(e.Row.FindControl("lb_new"), Label).Text = "新着" Then
                CType(e.Row.FindControl("img_new"), Image).Visible = True
            Else
                CType(e.Row.FindControl("img_new"), Image).Visible = False
            End If

            If CType(e.Row.FindControl("lb_未読"), Label).Text = "既読" Then
                CType(e.Row.FindControl("img_未読"), Image).Visible = False
            Else
                CType(e.Row.FindControl("img_未読"), Image).Visible = True
            End If

            If CType(e.Row.FindControl("lb_レベル"), Label).Text = "通常" Then
                CType(e.Row.FindControl("lb_レベル"), Label).Visible = False
            Else
                CType(e.Row.FindControl("lb_レベル"), Label).Visible = True
            End If

            If CType(e.Row.FindControl("lb_レベル"), Label).Text = "重要" Then
                CType(e.Row.FindControl("lb_レベル"), Label).ForeColor = Drawing.Color.FromName("#ff0000")
            Else
                CType(e.Row.FindControl("lb_レベル"), Label).ForeColor = Drawing.Color.FromName("#0000ff")
            End If
        End If
    End Sub

    Protected Sub gv_info_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv_info.RowCommand
        Read_Command = e.CommandArgument
    End Sub

#End Region

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

    Private Function GetData() As DataTable
        Using spm As New StoredProcedureManager("掲示_掲示一覧_個人_SELECT")
            Dim n As String

            If Request.QueryString("n") Is Nothing Then
                n = ""
            Else
                n = Request.QueryString("n").ToString
            End If

            spm.AddPrmIn("@PORTALID", Data.SqlDbType.VarChar, 200, Session(S_COM_PortalID))
            spm.AddPrmIn("@新着", Data.SqlDbType.Int, n.ToString)

            spm.Fill("Personal")

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

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

            Return dt.DefaultView.ToTable

        End Using
    End Function
#End Region



End Class
