Imports System.Net
Imports System.IO

Partial Class SQCode
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim xSQCode As String = Page.Request.QueryString.Get("sqcode") 'No
            Dim xIP As String = System.Web.HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
            If String.IsNullOrEmpty(xSQCode) Then Exit Sub
            'SQコードで確認
            'xSQCode = System.Text.RegularExpressions.Regex.Replace(xSQCode, "[^0-9]", "")
            Session("status") = xSQCode
            Dim dt As Data.DataView = SqlDataSourceSQCode.Select(DataSourceSelectArguments.Empty)
            If dt IsNot Nothing AndAlso dt.Count <> 0 Then
                Dim xCookie As String = "Class_1" & ":" & dt.Item(0).Row("mail").ToString
                Session("id") = dt.Item(0).Row("id").ToString
                Session("date") = Now.ToString
                Session("name") = dt.Item(0).Row("name").ToString
                Session("mail") = dt.Item(0).Row("mail").ToString
                Session("IP") = xIP
                Session("status") = "認証済み"
                Session("cookie") = xCookie
                SqlDataSourceSQCode.Update()

                'クッキーの消込
                Response.Cookies("Local").Value = ""
                Response.Cookies("Local").Expires = DateTime.Now.AddDays(-3)
                Response.Cookies("AccessDateTime").Value = DateTime.Now.ToString()
                'クッキーへの書込み
                Response.Cookies("Local").Value = xCookie
                Response.Cookies("Local").Expires = DateTime.Now.AddDays(365)
                Response.Cookies("AccessDateTime").Value = DateTime.Now.ToString()
                Response.Redirect("Default.aspx")
                Response.End()
            Else
                Response.Redirect("NotAllowed.aspx?msg=承認できませんでした")
            End If
        End If
    End Sub

End Class
