Imports System.Security.Cryptography
Imports System.Net
Imports System.IO

Partial Class admin_Default
    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 xWidth As String = "width: 715px;"
    Protected xDisplay As String = "全体"
    '初期設定用変数の終わり

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        'プログラムの始まり
        If Not IsPostBack Then
            'PC or Mobile
            If Request.Browser.IsMobileDevice Then
                Response.Redirect("../NotAllowed.aspx?msg=スマホではなく、PC限定です")
                Response.End()
            Else
                
            End If


            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 "Admin"
                            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
                        Case "表示選択"
                            xDisplay = xFormat.Item(i).Row(2).ToString
                    End Select
                Next
            End If

            '認証
            Dim xCode As String() = IsStatus.Split(",") 'No,date,name,mail,IP,Status,cookie(No,name,date),sw(Level)
            LabelName.Text = xCode(2)
            LabelMail.Text = xCode(3)
            Dim n As Integer = 0
            Try
                n = Integer.Parse(xCode(xCode.Length - 1))
            Catch ex As Exception
                Response.Redirect("../NotAllowed.aspx?msg=認証されていません DBに無し")
                Response.End()
            End Try
            If n >= Integer.Parse(xApprove) And 7 Then '
            Else
                Response.Redirect("../NotAllowed.aspx?msg=認証されていません 資格が有りません")
                Response.End()
            End If

            '

            TextBoxLevel.Text = "0"
            LabelID.Text = "New"
            TextBoxDate.Text = Mid(Date.Now.ToString, 1, 10)
            makeList()
            TextBoxBody.Visible = True
            PanelUpload2.Visible = False
            Dim x As String() = xDisplay.Split(",")
            For i = 0 To x.Length - 1
                DropDownList1.Items.Add(x(i))
            Next
            DropDownList1.SelectedIndex = 0
        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 Sub makeList()
        'リストボックスのデータ作成
        Dim dt As Data.DataView = SqlDataSourceAll.Select(DataSourceSelectArguments.Empty)
        If dt IsNot Nothing And dt.Count <> 0 Then
            If Not LabelOrder.Text = "上に挿入" Then
                dt.Sort = "id ASC" 'Format sort for DESC or ASC
                ListViewSubjectList.DataSourceID = "SqlDataSourceSubjectList2"
            End If
            Dim n As Integer
            Dim sp As String = ""
            Dim j As Integer
            For i = 0 To dt.Count - 1
                n = Integer.Parse(dt.Item(i).Row(4).ToString) 'Level
                sp = ""
                j = 0
                While j < n
                    sp = sp & "⇒"
                    j = j + 1
                End While
                Dim x As String = Strings.Right("0000" & dt.Item(i).Row(0).ToString, 4)
            Next
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        '記事の書込み
        If IsPostBack Then
            'If CheckBoxTag.Checked Then
            If CheckBox4.Checked Then
                If PanelAjax.Visible = True Then
                    If Len(TextBoxBody.Text) = 0 Then LabelMsg.Text = "本文が有りません" : Exit Sub
                Else
                    If Len(FreeTextBox1.Text) = 0 Then LabelMsg.Text = "本文が有りません" : Exit Sub
                End If
                If Len(TextBoxSubject.Text) = 0 Then LabelMsg.Text = "サブジェクト有りません" : Exit Sub
                If Len(TextBoxDate.Text) = 0 Then LabelMsg.Text = "日付が有りません" : Exit Sub
                'If Button4.Text = "Text" Then LabelMsg.Text = "Textモードなので、書き込めません" : Exit Sub
            End If
            Try
                Dim xDate As Date
                xDate = Date.Parse(TextBoxDate.Text)
                TextBoxDate.Text = Mid(xDate.ToString, 1, 10)
            Catch ex As Exception
                LabelMsg.Text = "日付フォーマットが違います" : Exit Sub
            End Try
            Session("date") = TextBoxDate.Text
            Session("subject") = HttpUtility.HtmlEncode(TextBoxSubject.Text)
            If Len(TextBoxBody.Text) = 0 Then TextBoxBody.Text = " "
            If Len(FreeTextBox1.Text) = 0 Then FreeTextBox1.Text = " "
            Session("body") = plusWidth()

            Session("level") = Integer.Parse(TextBoxLevel.Text)
            If CheckBox1.Checked Then
                Session("button") = 1 '表示
            Else
                Session("button") = 0
            End If
            Session("new") = CheckBox2.Checked.ToString
            Session("menu") = DropDownList1.SelectedItem.ToString 'CheckBox3.Checked.ToString
            Session("backcolor") = CheckBox4.Checked.ToString
            If CheckBox3.Checked Then
                Session("proxy") = LabelProxy.Text
            Else
                Session("proxy") = LabelCookie.Text
            End If
            If LabelID.Text = "New" Then '新規挿入
                Session("myid") = Format(Now, "yyyyMMddhhmmss").ToString
                SqlDataSourceAll.Insert()
            Else '修正
                Session("id") = LabelID.Text
                Session("myid") = LabelMyid.Text
                SqlDataSourceAll.Update()
            End If
            makeList()
            LabelMsg.Text = "書込みが完了しました"
            RadioButtonList1.SelectedIndex = 0
            Image1.Visible = False
            ListViewSubjectList.DataBind()
        End If
    End Sub

    Protected Function plusWidth() As String
        Dim n1, n2 As Integer
        Dim m1, m2 As String
        Dim xBody As String = ""
        If PanelAjax.Visible = True Then
            xBody = TextBoxBody.Text
        Else
            xBody = FreeTextBox1.Text
        End If
        If Len(TextBoxBody.Text) <> 0 Then
            For i = 1 To Len(TextBoxBody.Text)
                n1 = InStr(i, xBody, "<img")
                n2 = InStr(n1 + 1, xBody, ">")
                If n1 = 0 Then Exit For
                If InStr(Mid(xBody, n1 + 1, n2 - n1 - 1), "width=") = 0 Then
                    m1 = Mid(xBody, 1, n2 - 1)
                    m2 = Mid(xBody, n2 + 1, Len(xBody) - n2)
                    xBody = m1 & " class='width1'>" & m2
                End If
                i = i + n2 - n1 + 1
            Next
            If PanelAjax.Visible = True Then
                TextBoxBody.Text = xBody
            Else
                FreeTextBox1.Text = xBody
            End If
        End If
        Return xBody
    End Function

    Protected Sub idou(ByVal xFrom As Integer, ByVal xTo As Integer)
        'リストボックスの移動
        If LabelOrder.Text = "上に挿入" Then
            If xFrom > xTo Then 'リスト上の項目を下に移動
                Session("xEnd") = xFrom
                Session("xStart") = xTo
                Dim dt As Data.DataView = SqlDataSourceFromTo.Select(DataSourceSelectArguments.Empty)
                If dt IsNot Nothing AndAlso dt.Count <> 0 Then
                    Dim xID As String = dt.Item(0).Row(0).ToString
                    Dim xDate As String = dt.Item(0).Row(1).ToString
                    Dim xSubject As String = dt.Item(0).Row(2).ToString
                    Dim xBody As String = dt.Item(0).Row(3).ToString
                    Dim xLevel As String = dt.Item(0).Row(4).ToString
                    Dim xButton As String = dt.Item(0).Row(5).ToString
                    Dim xNew As String = dt.Item(0).Row(6).ToString
                    Dim xMenu As String = dt.Item(0).Row(7).ToString
                    Dim xBcolor As String = dt.Item(0).Row(8).ToString
                    Dim xMyid As String = dt.Item(0).Row(9).ToString
                    Dim xProxy As String = dt.Item(0).Row("proxy").ToString
                    For i = 0 To dt.Count - 2
                        Session("id") = dt.Item(i).Row(0).ToString
                        Session("date") = dt.Item(i + 1).Row(1).ToString
                        Session("subject") = dt.Item(i + 1).Row(2).ToString
                        Session("body") = dt.Item(i + 1).Row(3).ToString
                        Session("level") = dt.Item(i + 1).Row(4).ToString
                        Session("button") = dt.Item(i + 1).Row(5).ToString
                        Session("new") = dt.Item(i + 1).Row(6).ToString
                        Session("menu") = dt.Item(i + 1).Row(7).ToString
                        Session("backcolor") = dt.Item(i + 1).Row(8).ToString
                        Session("myid") = dt.Item(i + 1).Row(9).ToString
                        Session("proxy") = dt.Item(i + 1).Row("proxy").ToString
                        SqlDataSourceAll.Update()
                    Next
                    Session("id") = dt.Item(dt.Count - 1).Row(0).ToString
                    Session("date") = xDate
                    Session("subject") = xSubject
                    Session("body") = xBody
                    Session("level") = xLevel
                    Session("button") = xButton
                    Session("new") = xNew
                    Session("menu") = xMenu
                    Session("backcolor") = xBcolor
                    Session("myid") = xMyid
                    Session("proxy") = xProxy
                    SqlDataSourceAll.Update()
                End If
            Else
                Session("xEnd") = xTo
                Session("xStart") = xFrom
                Dim dt As Data.DataView = SqlDataSourceFromTo.Select(DataSourceSelectArguments.Empty)
                If dt IsNot Nothing AndAlso dt.Count <> 0 Then
                    Dim xID As String = dt.Item(dt.Count - 1).Row(0).ToString
                    Dim xDate As String = dt.Item(dt.Count - 1).Row(1).ToString
                    Dim xSubject As String = dt.Item(dt.Count - 1).Row(2).ToString
                    Dim xBody As String = dt.Item(dt.Count - 1).Row(3).ToString
                    Dim xLevel As String = dt.Item(dt.Count - 1).Row(4).ToString
                    Dim xButton As String = dt.Item(dt.Count - 1).Row(5).ToString
                    Dim xNew As String = dt.Item(dt.Count - 1).Row(6).ToString
                    Dim xMenu As String = dt.Item(dt.Count - 1).Row(7).ToString
                    Dim xBcolor As String = dt.Item(dt.Count - 1).Row(8).ToString
                    Dim xMyid As String = dt.Item(dt.Count - 1).Row(9).ToString
                    Dim xProxy As String = dt.Item(dt.Count - 1).Row("proxy").ToString
                    For i = dt.Count - 1 To 1 Step -1
                        Session("id") = dt.Item(i).Row(0).ToString
                        Session("date") = dt.Item(i - 1).Row(1).ToString
                        Session("subject") = dt.Item(i - 1).Row(2).ToString
                        Session("body") = dt.Item(i - 1).Row(3).ToString
                        Session("level") = dt.Item(i - 1).Row(4).ToString
                        Session("button") = dt.Item(i - 1).Row(5).ToString
                        Session("new") = dt.Item(i - 1).Row(6).ToString
                        Session("menu") = dt.Item(i - 1).Row(7).ToString
                        Session("backcolor") = dt.Item(i - 1).Row(8).ToString
                        Session("myid") = dt.Item(i - 1).Row(9).ToString
                        Session("proxy") = dt.Item(i - 1).Row("proxy").ToString
                        SqlDataSourceAll.Update()
                    Next
                    Session("id") = dt.Item(0).Row(0).ToString
                    Session("date") = xDate
                    Session("subject") = xSubject
                    Session("body") = xBody
                    Session("level") = xLevel
                    Session("button") = xButton
                    Session("new") = xNew
                    Session("menu") = xMenu
                    Session("backcolor") = xBcolor
                    Session("myid") = xMyid
                    Session("proxy") = xProxy
                    SqlDataSourceAll.Update()
                End If
            End If
        Else
            If xFrom > xTo Then 'リスト上の項目を上に移動
                Session("xEnd") = xFrom
                Session("xStart") = xTo
                Dim dt As Data.DataView = SqlDataSourceFromTo2.Select(DataSourceSelectArguments.Empty)
                If dt IsNot Nothing AndAlso dt.Count <> 0 Then
                    Dim xID As String = dt.Item(dt.Count - 1).Row(0).ToString
                    Dim xDate As String = dt.Item(dt.Count - 1).Row(1).ToString
                    Dim xSubject As String = dt.Item(dt.Count - 1).Row(2).ToString
                    Dim xBody As String = dt.Item(dt.Count - 1).Row(3).ToString
                    Dim xLevel As String = dt.Item(dt.Count - 1).Row(4).ToString
                    Dim xButton As String = dt.Item(dt.Count - 1).Row(5).ToString
                    Dim xNew As String = dt.Item(dt.Count - 1).Row(6).ToString
                    Dim xMenu As String = dt.Item(dt.Count - 1).Row(7).ToString
                    Dim xBcolor As String = dt.Item(dt.Count - 1).Row(8).ToString
                    Dim xMyid As String = dt.Item(dt.Count - 1).Row(9).ToString
                    Dim xProxy As String = dt.Item(dt.Count - 1).Row("proxy").ToString
                    For i = dt.Count - 1 To 1 Step -1
                        Session("id") = dt.Item(i).Row(0).ToString
                        Session("date") = dt.Item(i - 1).Row(1).ToString
                        Session("subject") = dt.Item(i - 1).Row(2).ToString
                        Session("body") = dt.Item(i - 1).Row(3).ToString
                        Session("level") = dt.Item(i - 1).Row(4).ToString
                        Session("button") = dt.Item(i - 1).Row(5).ToString
                        Session("new") = dt.Item(i - 1).Row(6).ToString
                        Session("menu") = dt.Item(i - 1).Row(7).ToString
                        Session("backcolor") = dt.Item(i - 1).Row(8).ToString
                        Session("myid") = dt.Item(i - 1).Row(9).ToString
                        Session("proxy") = dt.Item(i - 1).Row("proxy").ToString
                        SqlDataSourceAll.Update()
                    Next
                    Session("id") = dt.Item(0).Row(0).ToString
                    Session("date") = xDate
                    Session("subject") = xSubject
                    Session("body") = xBody
                    Session("level") = xLevel
                    Session("button") = xButton
                    Session("new") = xNew
                    Session("menu") = xMenu
                    Session("backcolor") = xBcolor
                    Session("myid") = xMyid
                    Session("proxy") = xProxy
                    SqlDataSourceAll.Update()
                End If
            Else
                Session("xEnd") = xTo
                Session("xStart") = xFrom
                Dim dt As Data.DataView = SqlDataSourceFromTo2.Select(DataSourceSelectArguments.Empty)
                If dt IsNot Nothing AndAlso dt.Count <> 0 Then
                    Dim xID As String = dt.Item(0).Row(0).ToString
                    Dim xDate As String = dt.Item(0).Row(1).ToString
                    Dim xSubject As String = dt.Item(0).Row(2).ToString
                    Dim xBody As String = dt.Item(0).Row(3).ToString
                    Dim xLevel As String = dt.Item(0).Row(4).ToString
                    Dim xButton As String = dt.Item(0).Row(5).ToString
                    Dim xNew As String = dt.Item(0).Row(6).ToString
                    Dim xMenu As String = dt.Item(0).Row(7).ToString
                    Dim xBcolor As String = dt.Item(0).Row(8).ToString
                    Dim xMyid As String = dt.Item(0).Row(9).ToString
                    Dim xProxy As String = dt.Item(0).Row("proxy").ToString
                    For i = 0 To dt.Count - 2
                        Session("id") = dt.Item(i).Row(0).ToString
                        Session("date") = dt.Item(i + 1).Row(1).ToString
                        Session("subject") = dt.Item(i + 1).Row(2).ToString
                        Session("body") = dt.Item(i + 1).Row(3).ToString
                        Session("level") = dt.Item(i + 1).Row(4).ToString
                        Session("button") = dt.Item(i + 1).Row(5).ToString
                        Session("new") = dt.Item(i + 1).Row(6).ToString
                        Session("menu") = dt.Item(i + 1).Row(7).ToString
                        Session("backcolor") = dt.Item(i + 1).Row(8).ToString
                        Session("myid") = dt.Item(i + 1).Row(9).ToString
                        Session("proxy") = dt.Item(i + 1).Row("proxy").ToString
                        SqlDataSourceAll.Update()
                    Next
                    Session("id") = dt.Item(dt.Count - 1).Row(0).ToString
                    Session("date") = xDate
                    Session("subject") = xSubject
                    Session("body") = xBody
                    Session("level") = xLevel
                    Session("button") = xButton
                    Session("new") = xNew
                    Session("menu") = xMenu
                    Session("backcolor") = xBcolor
                    Session("myid") = xMyid
                    Session("proxy") = xProxy
                    SqlDataSourceAll.Update()
                End If
            End If
        End If
        RadioButtonList1.SelectedIndex = 0
        LabelFrom.Text = ""
    End Sub

    Protected Sub ButtonDown_Click(sender As Object, e As System.EventArgs) Handles ButtonDown.Click
        If IsPostBack Then
            Dim n As Integer = Integer.Parse(TextBoxLevel.Text) - 1
            If n < 0 Then n = 0
            TextBoxLevel.Text = n.ToString
        End If
    End Sub

    Protected Sub ButtonUp_Click(sender As Object, e As System.EventArgs) Handles ButtonUp.Click
        If IsPostBack Then
            Dim n As Integer = Integer.Parse(TextBoxLevel.Text) + 1
            TextBoxLevel.Text = n.ToString
        End If
    End Sub

    Protected Function levelChar(ByVal x As String) As String
        'リストの繰り下げ表示
        levelChar = ""
        Dim n As Integer = Integer.Parse(x)
        Dim y As String = ""
        Select Case n
            Case 0
                levelChar = ""
            Case 1
                levelChar = "　：… "
            Case Else
                y = "　：… "
                For i = 0 To n - 1
                    y = "　" & y
                Next
                levelChar = y
        End Select
    End Function

    Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
        '新規ボタン
        If IsPostBack Then
            TextBoxLevel.Text = "0"
            LabelID.Text = "New"
            TextBoxDate.Text = Mid(Date.Now.ToString, 1, 10)
            TextBoxSubject.Text = ""
            'LiteralSubject.Text = ""
            TextBoxBody.Text = ""
            FreeTextBox1.Text = ""
            LabelMsg.Text = ""
            CheckBox2.Checked = False
            CheckBox4.Checked = True
            LabelMyid.Text = ""
            makeList()
            ListViewSubjectList.DataBind()
            TextBoxBody.Text = ""
            FreeTextBox1.Text = ""
            LabelProxy.Text = ""
            TextBoxName.Text = ""
            TextBoxMail.Text = ""
        End If
    End Sub

    Protected Sub RadioButtonList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
        '移動の選択
        If IsPostBack Then
            If RadioButtonList1.SelectedIndex = 0 Then
                Image1.Visible = False
                LabelFrom.Text = ""
                LabelIdou.Text = ""
            Else
                Image1.Visible = True
                LabelIdou.Text = "移動対象を選択"
            End If
        End If
    End Sub

    'Protected Sub AjaxFileUpload1_UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete
    '    If Not IsPostBack Then 'files
    '        PanelUpload.Visible = True
    '        Dim xName As String = e.FileName & ""
    '        Dim xDate As String = Date.Now.ToString
    '        AjaxFileUpload1.SaveAs(Server.MapPath("../files/" & xName))
    '        e.PostedUrl = Page.ResolveUrl("~/files/" & e.FileName)
    '    End If
    'End Sub

    'Protected Sub AjaxFileUpload2_UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles AjaxFileUpload2.UploadComplete
    '    If Not IsPostBack Then 'img
    '        PanelUpload.Visible = True
    '        Dim xName As String = e.FileName & ""
    '        Dim xDate As String = Date.Now.ToString
    '        AjaxFileUpload2.SaveAs(Server.MapPath("../img/" & xName))
    '        e.PostedUrl = Page.ResolveUrl("~/img/" & e.FileName)
    '    End If
    'End Sub

    Protected Sub ListViewSubjectList_ItemCommand(sender As Object, e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListViewSubjectList.ItemCommand
        If IsPostBack Then
            Dim xName As String = e.CommandName
            Dim xComm As String = e.CommandArgument
            If xName = "Sel" Then
                Session("id") = xComm
                If RadioButtonList1.SelectedIndex = 0 Then '編集モード
                    Dim dt As Data.DataView = SqlDataSourceID.Select(DataSourceSelectArguments.Empty)
                    If dt IsNot Nothing And dt.Count <> 0 Then
                        LabelID.Text = dt.Item(0).Row(0).ToString
                        TextBoxDate.Text = Mid(dt.Item(0).Row(1).ToString, 1, 10)
                        TextBoxSubject.Text = HttpUtility.HtmlDecode(dt.Item(0).Row(2).ToString)
                        'LiteralSubject.Text = TextBoxSubject.Text
                        If PanelAjax.Visible = True Then
                            TextBoxBody.Text = HttpUtility.HtmlDecode(dt.Item(0).Row(3).ToString)
                        Else
                            FreeTextBox1.Text = HttpUtility.HtmlDecode(dt.Item(0).Row(3).ToString)
                        End If

                        TextBoxLevel.Text = dt.Item(0).Row(4).ToString
                        If dt.Item(0).Row(5).ToString = "1" Then '表示
                            CheckBox1.Checked = True
                        Else
                            CheckBox1.Checked = False
                        End If
                        If UCase(dt.Item(0).Row(6).ToString) = "TRUE" Then
                            CheckBox2.Checked = True
                        Else
                            CheckBox2.Checked = False
                        End If
                        If UCase(dt.Item(0).Row(8).ToString) = "TRUE" Then
                            CheckBox4.Checked = True
                        Else
                            CheckBox4.Checked = False
                        End If
                        LabelMyid.Text = dt.Item(0).Row(9).ToString
                        LabelProxy.Text = dt.Item(0).Row("proxy").ToString
                    End If
                Else
                    '移動モード
                    If Len(LabelFrom.Text) = 0 Then 'Fromの指定
                        LabelFrom.Text = xComm 'x(0).ToString
                        Image1.Visible = True
                        LabelIdou.Text = "次に移動先を指定"

                    Else
                        'Toの指定
                        idou(Integer.Parse(LabelFrom.Text), Integer.Parse(xComm))
                        makeList()
                        LabelIdou.Text = ""
                        Image1.Visible = False
                        TextBoxSubject.Text = ""
                        'LiteralSubject.Text = ""
                        TextBoxDate.Text = Mid(Date.Now.ToString, 1, 10)
                        TextBoxBody.Text = ""
                        FreeTextBox1.Text = ""
                        LabelID.Text = "New"
                        LabelMsg.Text = ""
                        CheckBox2.Checked = False
                        'CheckBox3.Checked = True
                        CheckBox4.Checked = True
                        LabelMyid.Text = ""
                        LabelProxy.Text = ""
                    End If
                End If
                ListViewSubjectList.DataBind()
            End If
        End If
    End Sub

    'Protected Sub Button7_Click(sender As Object, e As System.EventArgs) Handles Button7.Click
    '    If IsPostBack Then
    '        If Len(TextBoxSubject.Text) = 0 Then Exit Sub
    '        If TextBoxSubject.Visible = True Then
    '            LiteralSubject.Text = TextBoxSubject.Text
    '            TextBoxSubject.Visible = False
    '            LiteralSubject.Visible = True
    '            Button7.Text = "タグ"
    '        Else
    '            TextBoxSubject.Visible = True
    '            LiteralSubject.Visible = False
    '            Button7.Text = "表示"
    '        End If
    '    End If
    'End Sub

    Protected Sub Button5_Click(sender As Object, e As System.EventArgs) Handles Button5.Click
        'Delボタン
        If IsPostBack Then
            If LabelID.Text = "New" Then
                LabelMsg.Text = ""
                Exit Sub
            End If
            Session("id") = LabelID.Text
            SqlDataSourceAll.Delete()
            TextBoxLevel.Text = "0"
            LabelID.Text = "New"
            TextBoxDate.Text = Mid(Date.Now.ToString, 1, 10)
            TextBoxSubject.Text = ""
            'LiteralSubject.Text = ""
            TextBoxBody.Text = ""
            FreeTextBox1.Text = ""
            LabelMsg.Text = ""
            CheckBox2.Checked = False
            CheckBox3.Checked = False
            CheckBox4.Checked = True
            LabelMyid.Text = ""
            LabelProxy.Text = ""
            TextBoxName.Text = ""
            TextBoxMail.Text = ""
            makeList()
            ListViewSubjectList.DataBind()
        End If
    End Sub

    Protected Sub CheckBoxUpload_CheckedChanged(sender As Object, e As System.EventArgs) Handles CheckBoxUpload.CheckedChanged
        If IsPostBack Then
            If CheckBoxUpload.Checked Then
                PanelUpload2.Visible = True
            Else
                PanelUpload2.Visible = False
            End If
        End If
    End Sub


    Protected Sub HtmlEditorExtender1_ImageUploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles HtmlEditorExtender1.ImageUploadComplete
        If Not IsPostBack Then
            Dim xName As String = e.FileName & ""
            Dim xFile As String = Format(Now, "yyyyMMddhhmmss").ToString & "_" 'Replace(Replace(Replace(xDate, "/", ""), ":", ""), " ", "") & "_"
            HtmlEditorExtender1.AjaxFileUpload.SaveAs(Server.MapPath("../files/" & xFile & xName))
            e.PostedUrl = Page.ResolveUrl("../files/" & xFile & e.FileName)
        End If
    End Sub

    Protected Sub ButtonOpen_Click(sender As Object, e As System.EventArgs) Handles ButtonOpen.Click
        If IsPostBack Then
            If ButtonOpen.Text = "+" Then
                PanelOpen.Visible = True
                ButtonOpen.Text = "-"
            Else
                PanelOpen.Visible = False
                ButtonOpen.Text = "+"
            End If
        End If
    End Sub

    Protected Sub Button6_Click(sender As Object, e As System.EventArgs) Handles Button6.Click
        If IsPostBack Then
            TextBoxBody.Text = Regex.Replace(TextBoxBody.Text, "<[^>]*>", "")
            FreeTextBox1.Text = Regex.Replace(FreeTextBox1.Text, "<[^>]*>", "")
        End If
    End Sub

    Protected Sub CheckBox3_CheckedChanged(sender As Object, e As System.EventArgs) Handles CheckBox3.CheckedChanged
        If IsPostBack Then
            If CheckBox3.Checked Then
                PanelProxy.Visible = True
            Else
                PanelProxy.Visible = False
            End If
        End If
    End Sub

    Protected Sub Button3_Click(sender As Object, e As System.EventArgs) Handles Button3.Click
        If IsPostBack Then
            '名簿へ問合せから
            LabelMsg.Text = ""
            If String.IsNullOrEmpty(TextBoxName.Text) Then LabelMsg.Text = "名前が有りません" : Exit Sub
            Dim xNow As String = Format(Now, "hhmmss")
            Dim enc As Encoding = Encoding.GetEncoding("UTF-8")
            Dim wc As WebClient = New WebClient()
            Dim xPath As String = "https://3myuuyuu.club"
            Dim st As Stream = wc.OpenRead(xPath & "/meibo/whois.aspx?Code=" & xNow & "," & "3" & "," & TextBoxName.Text)
            Dim sr As StreamReader = New StreamReader(st, enc)
            Dim html As String = sr.ReadToEnd()
            sr.Close()
            st.Close()
            Dim x As String() = html.Split(",")
            LabelName.Text = x(3)
            LabelMail.Text = x(11)
            TextBoxMail.Text = x(11)
            LabelProxy.Text = x(0) & "," & x(3) & "," & x(12)

        End If
    End Sub

    Protected Sub Button4_Click(sender As Object, e As System.EventArgs) Handles Button4.Click
        If IsPostBack Then
            '名簿へ問合せから
            LabelMsg.Text = ""
            If String.IsNullOrEmpty(TextBoxMail.Text) Then LabelMsg.Text = "メールが有りません" : Exit Sub
            Dim xNow As String = Format(Now, "hhmmss")
            Dim enc As Encoding = Encoding.GetEncoding("UTF-8")
            Dim wc As WebClient = New WebClient()
            Dim xPath As String = "https://3myuuyuu.club"
            Dim st As Stream = wc.OpenRead(xPath & "/meibo/whois.aspx?Code=" & xNow & "," & "11" & "," & TextBoxMail.Text)
            Dim sr As StreamReader = New StreamReader(st, enc)
            Dim html As String = sr.ReadToEnd()
            sr.Close()
            st.Close()
            Dim x As String() = html.Split(",")
            LabelName.Text = x(3)
            TextBoxName.Text = x(3)
            LabelMail.Text = x(11)
            LabelProxy.Text = x(0) & "," & x(3) & "," & x(12)

        End If
    End Sub

    Protected Sub Button7_Click(sender As Object, e As System.EventArgs) Handles Button7.Click
        If IsPostBack Then
            If PanelAjax.Visible = True Then
                PanelSpc.Visible = True
                PanelAjax.Visible = False
            Else
                PanelSpc.Visible = False
                PanelAjax.Visible = True
            End If
        End If
    End Sub
End Class
