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

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

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Contact.aspx無効化のため、アドレス直入力防止用にリダイレクト 20250326 S.Iguchi
        Response.Redirect("~/login.aspx")
        Return

        'ヘッダの左領域を設定
        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)

        If Not IsPostBack() Then

            CreateScreenList()
            AddHandler uc_SearchCityCd.CitySelected, AddressOf Me.CitySelected
        End If
    End Sub

#End Region

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

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

        '連絡先
        Dim cityCd As String = txtCityCd.Text
        Dim orgName As String = txtOrgName.Text
        Dim deptName As String = txtDeptName.Text
        Dim userName As String = txtUserName.Text
        Dim userKana As String = txtKana.Text
        Dim tel As String = txtTel.Text
        Dim email As String = txtEmail.Text

        '画面名
        Dim screen As String = ddl_screen.SelectedItem.Text
        Dim screenName As String = txtOtherInput.Text

        '問合せ内容
        Dim content As String = txtContent.Text

        If screen = "その他" AndAlso txtOtherInput.Text = "" Then
            lbl_errorMsg.Text = "画面名に「その他」を選択された場合は、画面名を入力してください。"
            Exit Sub
        End If

        Dim contactData As New Dictionary(Of String, String) From {
            {"CityCd", cityCd},
            {"OrgName", orgName},
            {"DeptName", deptName},
            {"UserName", userName},
            {"UserKana", userKana},
            {"Tel", tel},
            {"Email", email},
            {"Screen", screen},
            {"ScreenOther", screenName},
            {"Content", content}
        }

        'システム問い合わせメール送信
        Dim sucFlg = AppMail.SendSystemContactMail(contactData)

        If sucFlg Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().GetHashCode().ToString, "javascript:alert('問い合わせメールを送信しました。\nシステム担当からの回答までしばらくお待ちください。'); window.location='Login.aspx';", True)
            lbl_errorMsg.Text = ""

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

    Protected Sub CitySelected(sender As Object, e As uc_SearchCityCd.CitySelectedEventArgs)
        ' 親画面の入力フィールドに値を設定します
        txtCityCd.Text = e.CityCd
        txtOrgName.Text = e.CityName

        ' モーダルを閉じる
        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "closeModal", "closeModal();", True)
    End Sub

    Protected Sub ModalClosed(sender As Object, e As uc_SearchCityCd.CitySelectedEventArgs)
        ' モーダルを閉じる
        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "closeModal", "closeModal();", True)
    End Sub

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


#End Region

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

    Private Sub CreateScreenList()

        Using spm As New StoredProcedureManager("共通_変数_DDL")
            spm.AddPrmIn("@変数", Data.SqlDbType.VarChar, 50, "PT_SCREEN_NAME")
            spm.Fill()

            ddl_screen.DataSource = spm.ds.Tables(0)
            ddl_screen.DataValueField = "CD"
            ddl_screen.DataTextField = "内容"

            ddl_screen.DataBind()

            'デフォルト項目
            ddl_screen.Items.Insert(0, New ListItem("選択してください", ""))

        End Using
    End Sub
#End Region


End Class