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


Partial Class mobile_info_PersonalSP
    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, "mobile_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掲示NO As String = gv_info.SelectedDataKey.Item(0).ToString

        Session(S_Info_Selected_Index) = gv_info.SelectedIndex

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

            'ページ遷移
            Session(S_Info_Selected_No) = str掲示NO
            Session(S_Info_遷移元) = "個人へのお知らせ"
            Com_Change_UC1("menu_kj_001_mb")
            Response.Redirect("~/mobile/info/DetailSP.aspx")

        Else
            Info_未読処理(gv_info.SelectedDataKey.Item(0).ToString, Session(S_COM_PortalID))

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

            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
