Imports System.Data
Imports System.Data.SqlClient
Imports AppVariable
Imports AppAuth
Imports AppCommon

Partial Public Class Reminder
    Inherits System.Web.UI.Page

#Region "******************** ページイベント ********************"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'ヘッダの左領域を設定
        SetHeaderLeft(lb_user, lb_title)

        '---------------------------------------------------------------
        'HTMLタグを追加
        '---------------------------------------------------------------
        Dim ctl As Control = Page.FindControl("login_header")
        'JS
        SetTagJs(ctl, "common.js")
        SetTagJs(ctl, "jquery-1.8.3.min.js")
        SetTagJs(ctl, "login.js")
        'CSS
        SetTagCss(ctl, "login.css?20230605")
        SetTagCss(ctl, "master.css")
        SetTagCss(ctl, "common.css")
        'ファビコン
        SetTagFavicon(ctl)

    End Sub

#End Region

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

    Protected Sub btn送信_Click(sender As Object, e As EventArgs) Handles btn送信.Click

        Dim strEmail As String = txtEmail.Text
        Dim strCityCd As String = txtCityCd.Text
        Dim strUserName As String = txtUserName.Text

        'メールアドレスと市区町村CDが登録されているかをチェック
        Dim strOutputArr As String() = CHKアカウント(strEmail, strCityCd, strUserName)
        Dim errMsg As String = strOutputArr(0)
        Dim portalId As String = strOutputArr(1)

        If Not String.IsNullOrEmpty(errMsg) Then
            lbl_errorMsg.Text = errMsg
            Exit Sub
        End If

        If String.IsNullOrEmpty(portalId) Then
            lbl_errorMsg.Text = errMsg
            Exit Sub
        End If

        'アカウント通知メール送信
        Dim sucFlg = AppMail.SendUserCdReminderMail(strEmail, portalId)

        If sucFlg Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().GetHashCode().ToString, "javascript:alert('メールを送信しました。'); window.location='Login.aspx';", True)
            lbl_errorMsg.Text = ""

        Else
            lbl_errorMsg.Text = "エラーが発生しました。"
        End If
    End Sub

    Protected Sub btnBackToLogin_Click(sender As Object, e As EventArgs)
        ' ログイン画面にリダイレクト
        Response.Redirect("Login.aspx")
    End Sub


#End Region

#Region "******************* Sub及びFunction ********************"
    Private Function CHKアカウント(strEmail As String,
                                  strCityCd As String, userName As String) As String()

        Using spm As New StoredProcedureManager("PT_認証_USER_OUTPUT")
            spm.AddPrmIn("@EMAIL", Data.SqlDbType.NVarChar, 100, strEmail)
            spm.AddPrmIn("@市区町村CD", Data.SqlDbType.VarChar, 20, strCityCd)
            spm.AddPrmIn("@氏名", Data.SqlDbType.NVarChar, 200, userName)
            spm.AddPrmOut("@out_PORTALID", Data.SqlDbType.VarChar, 200)
            spm.AddPrmOut("@ERRMSG", Data.SqlDbType.VarChar, 200)

            spm.Exec()

            Dim errMsg = spm.GetValue("@ERRMSG")
            Dim userCd = spm.GetValue("@out_PORTALID")
            Return {errMsg, userCd}
        End Using
    End Function
#End Region


End Class