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

Partial Class Top
    Inherits System.Web.UI.Page

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

    '一覧
    Private Const SESSION_LIST_SELECTED_INDEX_PERSONAL As String = "Top_SelectedIndex_Personal" '選択行の位置(個人へのお知らせ)
    Private Const SESSION_LIST_SELECTED_INDEX_PUBLIC As String = "Top_SelectedIndex_Public" '選択行の位置(連絡事項)
    Private Const SESSION_LIST_SELECTED_INDEX_QA As String = "Top_SelectedIndex_Qa" '選択行の位置(問合せ事項)

#End Region

#Region "******************** ページイベント ********************"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '2020/6/19 ADD START モバイル対応のため、ユーザコントロールの幅調整 /Liu
        '---------------------------------------------------------------
        'HTMLタグを追加
        '---------------------------------------------------------------
        Dim ctl As Control = Page.Master.FindControl("msp_header")
        'CSS
        SetTagCss(ctl, "info.css")
        '2020/6/19 ADD END /Liu

        'アカウントが講師の場合は新着のお知らせを表示しない
        If Session(S_COM_PortalKbn) IsNot Nothing AndAlso
            Session(S_COM_PortalKbn).ToString().Equals("教員") Then
            div_info_title.Visible = False
            div_info.Visible = False
        End If

        '---------------------------------------------------------------
        '指定した個人へのお知らせを選択状態にする
        '---------------------------------------------------------------
        If Not Session(SESSION_LIST_SELECTED_INDEX_PERSONAL) Is Nothing Then
            gv_info.SelectedIndex = Session(SESSION_LIST_SELECTED_INDEX_PERSONAL)
        End If

        '---------------------------------------------------------------
        '指定した連絡事項を選択状態にする
        '---------------------------------------------------------------
        If Not Session(SESSION_LIST_SELECTED_INDEX_PUBLIC) Is Nothing Then
            gv_info_public.SelectedIndex = Session(SESSION_LIST_SELECTED_INDEX_PUBLIC)
        End If

        '---------------------------------------------------------------
        '指定した問い合わせ事項を選択状態にする
        '---------------------------------------------------------------
        If Not Session(SESSION_LIST_SELECTED_INDEX_QA) Is Nothing Then
            gv_info_public.SelectedIndex = Session(SESSION_LIST_SELECTED_INDEX_QA)
        End If

    End Sub
#End Region

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

    Protected Sub gv_info_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv_info.SelectedIndexChanged
        Info_既読処理(gv_info.SelectedDataKey.Item(0).ToString, Session(S_COM_PortalID))
        'ユーザコントロールを開く
        Com_UC1_Visible("slideopen")
        Com_Change_UC1("menu_kj_001")

        Session(SESSION_LIST_SELECTED_INDEX_PERSONAL) = gv_info.SelectedIndex
        Session(S_Info_Selected_No) = gv_info.SelectedDataKey.Item(0).ToString
        Response.Redirect(Request.RawUrl.ToString)
    End Sub

    Protected Sub gv_info_public_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv_info_public.SelectedIndexChanged
        Info_既読処理(gv_info_public.SelectedDataKey.Item(0).ToString, Session(S_COM_PortalID))
        'ユーザコントロールを開く
        Com_UC1_Visible("slideopen")
        Com_Change_UC1("menu_kj_002")

        Session(SESSION_LIST_SELECTED_INDEX_PUBLIC) = gv_info_public.SelectedIndex
        Session(S_Info_Selected_No) = gv_info_public.SelectedDataKey.Item(0).ToString
        Response.Redirect(Request.RawUrl.ToString)
    End Sub

    Protected Sub gv_info_qa_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv_info_qa.SelectedIndexChanged
        'Info_既読処理(gv_info_public.SelectedDataKey.Item(0).ToString, Session(S_COM_PortalID))
        ''ユーザコントロールを開く
        'Com_UC1_Visible("slideopen")
        'Com_Change_UC1("menu_kj_002")

        Session(SESSION_LIST_SELECTED_INDEX_QA) = gv_info_qa.SelectedIndex
        Session(S_Info_Selected_No) = gv_info_qa.SelectedDataKey.Item(0).ToString
        Response.Redirect(Request.RawUrl.ToString)

        'IDをセッションに保存
        Session(S_QA_Selected_ID) = gv_info_qa.SelectedDataKey.Item(0).ToString()

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

    End Sub

    Protected Sub TitleClick(sender As Object, e As EventArgs)
        Dim btn As LinkButton = DirectCast(sender, LinkButton)
        Session(S_QA_Selected_ID) = btn.CommandArgument
        '詳細画面へ
        Response.Redirect(Com_Get_Content("menu_kj_qa02"))
    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_public_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_info_public.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_qa_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_info_qa.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
        End If
    End Sub


#End Region

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

    Protected Sub sql_info_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles sql_info.Init
        sql_info_select()
    End Sub

    Protected Sub sql_info_public_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles sql_info_public.Init
        sql_info_public_select()
    End Sub

    Protected Sub sql_info_qa_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles sql_info_qa.Init
        sql_info_qa_select()
    End Sub

    'SqlDataSourceパラメータ設定
    Protected Sub sql_info_select()
        Dim n As String

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

        Dim sds As SqlDataSource = sql_info
        WebControlsUtil.DeclareSP(sds, "掲示_掲示一覧_個人_SELECT")
        With sds
            .SelectParameters.Add("PORTALID", DbType.String, Session(S_COM_PortalID))
            .SelectParameters.Add("新着", DbType.Int32, n.ToString)
        End With
    End Sub

    'SqlDataSourceパラメータ設定
    Protected Sub sql_info_public_select()
        Dim m As String
        Dim w As String
        Dim n As String
        Dim t As String

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

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

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

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

        Dim sds As SqlDataSource = sql_info_public
        WebControlsUtil.DeclareSP(sds, "掲示_掲示一覧_連絡_SELECT")
        With sds
            .SelectParameters.Add("PORTALID", DbType.String, Session(S_COM_PortalID))
            .SelectParameters.Add("自分宛て", DbType.String, m.ToString)
            .SelectParameters.Add("WORD", DbType.String, w.ToString)
            .SelectParameters.Add("掲示対象CD", DbType.String, t.ToString)
            .SelectParameters.Add("新着", DbType.Int32, n.ToString)
        End With
    End Sub

    'SqlDataSourceパラメータ設定
    Protected Sub sql_info_qa_select()
        Dim m As String
        Dim w As String
        Dim n As String
        Dim t As String

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

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

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

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

        Dim sds As SqlDataSource = sql_info_qa
        WebControlsUtil.DeclareSP(sds, "掲示_掲示一覧_問合せ_SELECT")
        With sds
            .SelectParameters.Add("PORTALID", DbType.String, Session(S_COM_PortalID))
            .SelectParameters.Add("新着", DbType.Int32, n.ToString)
        End With
    End Sub


#End Region

End Class
