Imports System.Net
Imports System.IO

Partial Class user_OnePage
    Inherits System.Web.UI.Page
    '初期設定用変数の初まり
    Protected xApprove As String = "管理者認証"
    Protected xTitle As String = "小説フォーマット"
    Protected xTab As String = "小説フォーマット"
    Protected xListTitle As String = "タイトルのリスト"
    Protected xPageTitle As String = "ページのタイトル"
    '初期設定用変数の終わり

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        'スマホ or PC
        If Request.Browser.IsMobileDevice Then
            PanelMenuPC.Visible = False
            PanelMenuMobile.Visible = True
        Else
            PanelMenuPC.Visible = True
            PanelMenuMobile.Visible = False
        End If

        If Not IsPostBack Then
            Dim xFormat As Data.DataView = SqlDataSourceFormat.Select(DataSourceSelectArguments.Empty)
            If xFormat IsNot Nothing AndAlso xFormat.Count <> 0 Then
                For i = 0 To xFormat.Count - 1
                    Select Case xFormat.Item(i).Row(1).ToString
                        Case "User"
                            xApprove = xFormat.Item(i).Row(2).ToString
                        Case "タイトル"
                            xTitle = xFormat.Item(i).Row(2).ToString
                        Case "タブ"
                            xTab = xFormat.Item(i).Row(2).ToString
                        Case "並び"
                            LabelOrder.Text = xFormat.Item(i).Row(2).ToString
                        Case "リストのタイトル"
                            xListTitle = xFormat.Item(i).Row(2).ToString
                        Case "ページのタイトル"
                            xPageTitle = xFormat.Item(i).Row(2).ToString
                    End Select
                Next
            End If

            '認証
            Dim xCode As String() = IsStatus.Split(",")
            Dim n As Integer = Integer.Parse(xCode(xCode.Length - 1))
            If n >= Integer.Parse(xApprove) Then
            Else
                Response.Redirect("../NotAllowed.aspx?msg=認証されていません DBに無し")
                Response.End()
            End If

            '
            Dim myid As String = Page.Request.QueryString.Get("myid")
            myid = HttpUtility.HtmlEncode(myid)
            If IsNumeric(myid) Then
            Else
                Response.Redirect("../NotAllowed.aspx?msg=ページが指定されていません")
                Response.End()
            End If
            Session("myid") = myid
            Dim ds As Data.DataView = SqlDataSourcePages.Select(DataSourceSelectArguments.Empty)
            If ds IsNot Nothing AndAlso ds.Count <> 0 Then
                For i = 0 To ds.Count - 1
                    If ds.Item(i).Row("myid").ToString = myid Then
                        DataPager2.SetPageProperties(i, DataPager2.MaximumRows, False)
                        Exit For
                    End If
                Next
            End If
            Session("button") = "1"

        End If
    End Sub

    Protected Function IsStatus() As String
        '管理者確認の問合せ
        Dim xCookie As String = ""
        If Request.Cookies("Local") IsNot Nothing Then
            xCookie = Request.Cookies("Local").Value
            Dim xTime As String = Format(Now, "hhmmss").ToString
            Dim x As String() = xCookie.Split(",")
            Dim enc As Encoding = Encoding.GetEncoding("UTF-8")
            Dim wc As WebClient = New WebClient()
            Dim host As String = System.Net.Dns.GetHostName
            Dim xPath As String = "http://" & host
            Dim st As Stream = wc.OpenRead(xPath & "/Approve/IsStatus.aspx?code=" & xTime & "," & xCookie)
            Dim sr As StreamReader = New StreamReader(st, enc)
            Dim html As String = sr.ReadToEnd()
            sr.Close()
            st.Close()
            Return html
        Else
            Return "不明,0,0,0,0,0,0,0,0,0,0"
        End If
    End Function

    Protected Function xBackColor(ByVal xBcolor As String) As String
        If xBcolor = "True" Then
            xBackColor = "background-color: #F7F6F3; color: #7C6F57; overflow: auto;"
        Else
            xBackColor = "background-color: Transparent; color:white; overflow: auto;"
        End If
    End Function

    Protected Function xBackColor2(ByVal xBcolor As String) As String
        If xBcolor = "True" Then
            xBackColor2 = "background-color: #F7F6F3; color: #7C6F57; overflow: auto;"
        Else
            xBackColor2 = "background-color: Transparent; color:Red; overflow: auto;"
        End If
    End Function

    'Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
    '    'スマホへ
    '    If IsPostBack Then

    '        Dim myHtmlLinkMobile As New HtmlLink()
    '        myHtmlLinkMobile.Href = "../StyleSheetMobile.css"
    '        myHtmlLinkMobile.Attributes.Add("rel", "stylesheet")
    '        myHtmlLinkMobile.Attributes.Add("type", "text/css")
    '        Page.Header.Controls.Add(myHtmlLinkMobile)

    '        PanelMenuPC.Visible = False
    '        PanelMenuMobile.Visible = True
    '    End If

    'End Sub

    'Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
    '    'PCへ
    '    If IsPostBack Then

    '        Dim myHtmlLinkPC As New HtmlLink()
    '        myHtmlLinkPC.Href = "../StyleSheetPC.css"
    '        myHtmlLinkPC.Attributes.Add("rel", "stylesheet")
    '        myHtmlLinkPC.Attributes.Add("type", "text/css")
    '        Page.Header.Controls.Add(myHtmlLinkPC)

    '        'vPage.Style.Add("width", "980px")
    '        PanelMenuPC.Visible = True
    '        PanelMenuMobile.Visible = False
    '    End If

    'End Sub

End Class
