Imports System.Data
Imports AppCommon
Imports AppInfo
Imports AppVariable

Partial Class InfoPublic
    Inherits System.Web.UI.Page

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

    '一覧
    Private Const SESSION_LIST_SELECTED_INDEX As String = "InfoPublic_SelectedIndex"     '選択行の位置

#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")

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

        If Not IsPostBack Then
            dd_対象検索.DataSource = GetData()
            dd_対象検索.DataBind()
        End If

        '---------------------------------------------------------------
        '検索項目に値をセット
        '---------------------------------------------------------------
        If Not IsPostBack Then
            If Request.QueryString("m") IsNot Nothing AndAlso Request.QueryString("m").ToString = "1" Then
                cb_自分宛て検索.Checked = True
            Else
                cb_自分宛て検索.Checked = False
            End If

            '2018/05/25 M.Okabe MOD Start
            'Try '※外すと落ちる
            '    dd_対象検索.Text = HttpUtility.UrlDecode(Request.QueryString("t").ToString)
            '    tb_WORD検索.Text = HttpUtility.UrlDecode(Request.QueryString("w").ToString)
            'Catch ex As Exception
            'End Try
            If Not String.IsNullOrEmpty(Request.QueryString("t")) Then
                dd_対象検索.Text = HttpUtility.UrlDecode(Request.QueryString("t").ToString)
            End If

            If Not String.IsNullOrEmpty(Request.QueryString("w")) Then
                tb_WORD検索.Text = HttpUtility.UrlDecode(Request.QueryString("w").ToString)
            End If
            '2018/05/25 M.Okabe MOD End
        End If
    End Sub

#End Region

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

    Protected Sub gv_info_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv_info_public.SelectedIndexChanged
        '未読既読処理
        If Read_Command = "read" Then
            Info_既読処理(gv_info_public.SelectedDataKey.Item(0).ToString, Session(S_COM_PortalID))
            'ユーザコントロールを開く
            Com_UC1_Visible("slideopen")
        Else
            Info_未読処理(gv_info_public.SelectedDataKey.Item(0).ToString, Session(S_COM_PortalID))
        End If

        Session(SESSION_LIST_SELECTED_INDEX) = 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_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_public_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv_info_public.RowCommand
        Read_Command = e.CommandArgument
    End Sub

    Protected Sub btn_検索_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_検索.Click
        Dim strSearch As String

        strSearch = "?"

        If cb_自分宛て検索.Checked = True Then
            strSearch = strSearch & "m=1"
        End If

        If Len(tb_WORD検索.Text) > 0 Then
            If strSearch <> "?" Then
                strSearch = strSearch & "&"
            End If

            strSearch = strSearch & "w=" & HttpUtility.UrlEncode(tb_WORD検索.Text)
        End If

        If Len(dd_対象検索.SelectedValue.ToString) > 0 Then
            If strSearch <> "?" Then
                strSearch = strSearch & "&"
            End If

            strSearch = strSearch & "t=" & HttpUtility.UrlEncode(dd_対象検索.SelectedValue.ToString)
        End If

        Response.Redirect(Request.FilePath.ToString & strSearch)
    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

#End Region

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

    Private 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

    Private Function GetData() As DataSet
        Using spm As New StoredProcedureManager("掲示_掲示所属_CMB_SELECT")
            spm.Fill()

            Return spm.ds
        End Using
    End Function

#End Region

End Class
