Imports System.Data
Imports System.Drawing
Imports AppVariable
Imports System.Net.Mail '20240322 Add /S.Iguchi

Public Class AppCommon
    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Change_UC1
    '機能説明:指定した機能CDからUC1を呼び出す
    '引数:
    '       FunctionCD As String        機能CD
    '
    '--------------------------------------------------------------------------------------------------
    Shared Sub Com_Change_UC1(ByVal FunctionCD As String)
        Dim dts As DataSet
        Dim row As DataRow

        '機能情報取得
        dts = Com_Get_機能情報(FunctionCD)

        If dts IsNot Nothing Then
            row = dts.Tables(0).Rows(0)

            HttpContext.Current.Session(S_MSP_Selected_UC1_Title) = row("UC1_TITLE").ToString()
            HttpContext.Current.Session(S_MSP_Selected_UC1_Path) = row("UC1_PATH").ToString()
        End If
    End Sub

    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Del_Cookies
    '機能説明:Cookieを削除
    '引数:
    '   
    '--------------------------------------------------------------------------------------------------
    Shared Sub Com_Del_Cookies()
        Dim i As Integer
        Dim Cookie As HttpCookie

        Dim limit As Integer = HttpContext.Current.Request.Cookies.Count - 1
        For i = 0 To limit
            HttpContext.Current.Request.Cookies(i).Path = HttpContext.Current.Request.ApplicationPath & "/"
            Cookie = HttpContext.Current.Request.Cookies(i)
            Cookie.Expires = DateTime.Now.AddDays(-1)
            HttpContext.Current.Response.Cookies.Add(Cookie)
        Next
    End Sub
    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_UC1_Visible
    '機能説明:UC1の開閉をコントロール
    '引数:
    '       value As String             open/slideopen/close/slideclose
    '--------------------------------------------------------------------------------------------------
    Shared Sub Com_UC1_Visible(ByVal value As String)
        Select Case value
            Case "open", "slideopen"
                If HttpContext.Current.Request.Cookies(C_MSP_UC1_OpenClose).Value = "close" Then
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Value = value
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Path = HttpContext.Current.Request.ApplicationPath & "/"
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Expires = DateTime.Now.AddDays(Cookie_Expires)
                End If
            Case "close", "slideclose"
                If HttpContext.Current.Request.Cookies(C_MSP_UC1_OpenClose).Value = "open" Then
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Value = value
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Path = HttpContext.Current.Request.ApplicationPath & "/"
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Expires = DateTime.Now.AddDays(Cookie_Expires)
                End If
        End Select
    End Sub

    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Get_Content_M
    '機能説明:指定したMenuCDからコンテンツを呼び出す
    '引数:
    '       MenuCD As String            MenuCD
    '       UC1_Default As String       ユーザコントロール既定の開閉(open/slideopen/close/slideclose)
    '
    '返り値: String型 (URL)
    '--------------------------------------------------------------------------------------------------
    Shared Function Com_Get_Content_M(ByVal MenuCD As String, _
                                      Optional ByVal UC1_Default As String = "") As String
        Dim dts As DataSet
        Dim row As DataRow

        Try
            '機能情報取得
            dts = Com_Get_MENU情報(MenuCD)

            If dts IsNot Nothing Then
                row = dts.Tables(0).Rows(0)

                'メニューコードの保持
                HttpContext.Current.Session(S_MSP_Selected_MenuCD) = row("MENUCD").ToString()

                'タイトル初期化
                HttpContext.Current.Session(S_MSP_Selected_Title) = ""

                'ユーザコントロールタイトルの保持
                HttpContext.Current.Session(S_MSP_Selected_UC1_Title) = row("UC1_TITLE").ToString()

                'ユーザコントロールパスの保持
                HttpContext.Current.Session(S_MSP_Selected_UC1_Path) = row("UC1_PATH").ToString()

                'ユーザコントロールの利用可不可を保持
                HttpContext.Current.Response.Cookies(C_MSP_UC1_Use).Value = row("UC1_USE").ToString()
                HttpContext.Current.Response.Cookies(C_MSP_UC1_Use).Path = HttpContext.Current.Request.ApplicationPath & "/"
                HttpContext.Current.Response.Cookies(C_MSP_UC1_Use).Expires = DateTime.Now.AddDays(Cookie_Expires)

                'ユーザコントロールの開閉
                If UC1_Default <> "" Then
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Value = UC1_Default
                Else
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Value = row("UC1_DEFAULT").ToString()
                End If
                HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Path = HttpContext.Current.Request.ApplicationPath & "/"
                HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Expires = DateTime.Now.AddDays(Cookie_Expires)


                'コンテンツページのスクロールTOP初期化
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Top).Value = 0
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Top).Path = HttpContext.Current.Request.ApplicationPath & "/"
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Top).Expires = DateTime.Now.AddDays(Cookie_Expires)

                'コンテンツページスクロールLEFT初期化
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Left).Value = 0
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Left).Path = HttpContext.Current.Request.ApplicationPath & "/"
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Left).Expires = DateTime.Now.AddDays(Cookie_Expires)

                'コンテンツURL
                Return HttpContext.Current.Request.ApplicationPath & row("CONTENT_PATH").ToString() & row("CONTENT_PARAM").ToString()
            Else
                Return ""
            End If
        Catch ex As Exception
            Return "Err_SVN:Get_Menu_Content()関数で予期せぬエラーが発生しました。"
        End Try
    End Function

    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Get_Content
    '機能説明:指定した機能CDからコンテンツを呼び出す
    '引数:
    '       FunctionCD As String        機能CD
    '       UC1_Default As String       ユーザコントロール既定の開閉(open/slideopen/close/slideclose)
    '
    '返り値: String型 (URL)
    '--------------------------------------------------------------------------------------------------
    Shared Function Com_Get_Content(ByVal FunctionCD As String, _
                                    Optional ByVal UC1_Default As String = "") As String

        Dim dts As DataSet
        Dim row As DataRow

        Try

            '機能情報取得
            dts = Com_Get_機能情報(FunctionCD)

            If dts IsNot Nothing Then

                'row = dts.Tables("FUNCTION").Rows(0)
                row = dts.Tables(0).Rows(0)

                '機能名の保持
                HttpContext.Current.Session(S_MSP_Selected_Title) = row("機能名").ToString()

                'ユーザコントロールのタイトル保持
                HttpContext.Current.Session(S_MSP_Selected_UC1_Title) = row("UC1_TITLE").ToString()

                'ユーザコントロールのファイルパス保持
                HttpContext.Current.Session(S_MSP_Selected_UC1_Path) = row("UC1_PATH").ToString()

                'ユーザコントロールの使用可、不可
                HttpContext.Current.Response.Cookies(C_MSP_UC1_Use).Value = row("UC1_USE").ToString()
                HttpContext.Current.Response.Cookies(C_MSP_UC1_Use).Path = HttpContext.Current.Request.ApplicationPath & "/"
                HttpContext.Current.Response.Cookies(C_MSP_UC1_Use).Expires = DateTime.Now.AddDays(Cookie_Expires)

                'ユーザコントロールの開閉
                If UC1_Default <> "" Then
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Value = UC1_Default
                Else
                    HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Value = row("UC1_DEFAULT").ToString()
                End If

                HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Path = HttpContext.Current.Request.ApplicationPath & "/"
                HttpContext.Current.Response.Cookies(C_MSP_UC1_OpenClose).Expires = DateTime.Now.AddDays(Cookie_Expires)

                'コンテンツページのスクロールTOP保持
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Top).Value = 0
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Top).Path = HttpContext.Current.Request.ApplicationPath & "/"
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Top).Expires = DateTime.Now.AddDays(Cookie_Expires)

                'コンテンツページのスクロールLEFT保持
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Left).Value = 0
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Left).Path = HttpContext.Current.Request.ApplicationPath & "/"
                HttpContext.Current.Response.Cookies(C_MSP_Content_Scroll_Left).Expires = DateTime.Now.AddDays(Cookie_Expires)

                'コンテンツのURL
                Return HttpContext.Current.Request.ApplicationPath & row("CONTENT_PATH").ToString() & row("CONTENT_PARAM").ToString()

            Else

                Return ""

            End If

        Catch ex As Exception

            Return "Err_SVN:Get_Function_Content()関数で予期せぬエラーが発生しました。"

        End Try


    End Function

    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Get_機能情報
    '機能説明:指定した機能CDから機能情報を取得
    '引数:
    '       FunctionCD As String        機能CD
    '
    '返り値: DataSet型
    '--------------------------------------------------------------------------------------------------
    Shared Function Com_Get_機能情報(ByVal FunctionCD As String) As DataSet
        Using spm As New StoredProcedureManager("PT_機能_GET")
            spm.AddPrmIn("@PORTALID", Data.SqlDbType.VarChar, 200, HttpContext.Current.Session(S_COM_PortalID))
            spm.AddPrmIn("@機能CD", Data.SqlDbType.VarChar, 50, FunctionCD)
            spm.Fill()

            Return spm.ds
        End Using
    End Function

    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Get_MENU情報
    '機能説明:指定したMENUCDからメニュー情報を取得
    '引数:
    '       MenuCD As String        MenuCD
    '
    '返り値: DataSet型
    '--------------------------------------------------------------------------------------------------
    Shared Function Com_Get_MENU情報(ByVal MenuCD As String) As DataSet
        Using spm As New StoredProcedureManager("PT_MENU_GET")
            spm.AddPrmIn("@PORTALID", Data.SqlDbType.VarChar, 200, HttpContext.Current.Session(S_COM_PortalID))
            spm.AddPrmIn("@MENUCD", Data.SqlDbType.VarChar, 50, MenuCD)
            spm.Fill()

            Return spm.ds
        End Using
    End Function

    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Get_既定授業年度
    '機能説明:授業マスタに登録されている授業年度のMAXを取得
    '引数:
    '      なし
    '
    '返り値: Integer型
    '--------------------------------------------------------------------------------------------------
    Shared Function Com_Get_既定授業年度() As Integer
        Dim ret As Integer

        Using spm As New StoredProcedureManager("共通_教務_既定授業年度_OUTPUT")
            spm.AddPrmOut("@既定授業年度", Data.SqlDbType.SmallInt)
            spm.Exec()
            ret = spm.GetValue("@既定授業年度")
        End Using

        Return ret
    End Function

    '2017/3/31 M.Okabe ADD Start
    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Get_既定授業年度_学生
    '機能説明:授業マスタに登録されている授業年度のMAXを取得(学生毎)
    '引数:
    '      なし
    '
    '返り値: Integer型
    '--------------------------------------------------------------------------------------------------
    Shared Function Com_Get_既定授業年度_学生(ByVal prm学籍NO As String) As Integer
        Dim ret As Integer

        Using spm As New StoredProcedureManager("共通_学生_既定授業年度_OUTPUT")
            spm.AddPrmIn("@学籍NO", Data.SqlDbType.VarChar, 20, prm学籍NO)
            spm.AddPrmOut("@既定授業年度", Data.SqlDbType.SmallInt)
            spm.Exec()
            ret = spm.GetValue("@既定授業年度")
        End Using

        Return ret
    End Function
    '2017/3/31 M.Okabe ADD End

    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Get_変数
    '機能説明:変数マスタ(CD変数)から任意の変数を取得
    '引数:
    '      変数
    '
    '返り値: String型
    '--------------------------------------------------------------------------------------------------
    Shared Function Com_Get_変数(変数 As String) As String
        Dim ret As String = ""

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

            If spm.ds IsNot Nothing Then
                ret = (spm.ds.Tables(0).Rows(0))("内容")
            End If
        End Using

        Return ret
    End Function

    '--------------------------------------------------------------------------------------------------
    'メソッド名：Com_Get_変数TABLE
    '機能説明:変数マスタ(CD変数)から任意の変数を取得
    '引数:
    '      変数
    '
    '返り値: Datatable型
    '--------------------------------------------------------------------------------------------------
    Shared Function Com_Get_変数TABLE(変数 As String) As DataTable
        Using spm As New StoredProcedureManager("共通_変数_DDL")
            spm.AddPrmIn("@変数", Data.SqlDbType.VarChar, 50, 変数)
            spm.Fill()

            Return spm.ds.Tables(0)
        End Using
    End Function

    Shared Function Info_FileFolder_Path() As String
        Return Com_Get_変数("PT_COMMON_DIRECTORY") & Com_Get_変数("FolderPath_添付FILE")
    End Function

    '-------------------------------------------------------------------------------------------------------
    '2014.4.28 スマートフォン専用/牧
    'ユーザエージェント文字列によって、metaタグのviewport値を書き分ける
    '-------------------------------------------------------------------------------------------------------
    Public Shared Function stringViewport(ByVal Str As String) As String
        If InStr(Str, "iPhone") > 0 Then
            Return "width=device-width, user-scalable=yes, initial-scale=0.5, maximum-scale=1"
        ElseIf InStr(Str, "ISW12HT") > 0 Or InStr(Str, "ISW11SC") > 0 Then
            Return "width=device-width, initial-scale=0.5625,minimum-scale=0.5625, maximum-scale=0.5625, user-scalable=yes"
        ElseIf InStr(Str, "IS11S") > 0 Then
            Return "width=device-width, initial-scale=0.5,minimum-scale=0.5, maximum-scale=0.5, user-scalable=yes"
        Else
            Return "width=device-width, initial-scale=0.5,minimum-scale=0.5, maximum-scale=0.5, user-scalable=yes"
        End If
    End Function

    '-------------------------------------------------------------------------------------------------------
    '2014.4.30 牧
    '文字列内のURLをaタグに変換
    '-------------------------------------------------------------------------------------------------------
    Public Shared Function URLChange(ByVal Str As String) As String
        Str = System.Text.RegularExpressions.Regex.Replace(Str, "s?https?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+", "<a href=""$&"" target=""_blank"">$&</a>")
        Return Str
    End Function


    ''' <summary>
    ''' 入力桁数(Byte)チェック処理
    ''' </summary>
    ''' <param name="str_check_value">入力文字列</param>
    ''' <param name="int_byte_size">Byte数</param>
    ''' <param name="enc">エンコード</param>
    ''' <returns>True:エラー False:エラーではない</returns>
    ''' <remarks></remarks>
    Public Shared Function IsErrOverByte(ByVal str_check_value As String, _
                                   ByVal int_byte_size As String, _
                                   Optional enc As Encoding = Nothing) As Boolean

        '指定がない場合はShift-jisでチェックする
        If IsNothing(enc) Then
            enc = Encoding.GetEncoding("Shift-jis")
        End If

        If enc.GetByteCount(str_check_value) > int_byte_size Then
            Return True
        End If

        Return False
    End Function

    Public Shared Function BlankToNull(ByVal value As Object) As Object
        Dim result As Object = value

        If IsNothing(value) Then
            result = DBNull.Value
        ElseIf TypeOf value Is String Then
            If String.IsNullOrEmpty(value) Then
                result = DBNull.Value
            End If
        End If

        Return result
    End Function

    Public Shared Function GetConStr() As String
        Return System.Configuration.ConfigurationManager.ConnectionStrings(DB_strCon).ConnectionString
    End Function

    Public Shared Sub SetTagFavicon(ByRef ctl As Control)
        If "1".Equals(ConfigurationManager.AppSettings("UseFavicon")) Then
            Dim literal As Literal = New Literal()
            literal.Text = "<link href=""" & HttpContext.Current.Request.ApplicationPath & "/favicon.ico"" rel=""shortcut icon"" type=""image/x-icon"" />"

            Dim head As HtmlHead = DirectCast(ctl, HtmlHead)
            head.Controls.Add(literal)
        End If
    End Sub

    Public Shared Sub SetTagJs(ByRef ctl As Control, ByVal file As String, Optional subDir As String = "/js")
        Dim literal As Literal = New Literal()
        literal.Text = "<script type=""text/javascript"" src=""" & HttpContext.Current.Request.ApplicationPath & subDir & "/" & file & """></script>"

        Dim head As HtmlHead = DirectCast(ctl, HtmlHead)
        head.Controls.Add(literal)
    End Sub

    Public Shared Sub SetTagCss(ByRef ctl As Control, ByVal file As String, Optional subDir As String = "/css")
        Dim literal As Literal = New Literal()
        literal.Text = "<link rel=""stylesheet"" type=""text/css"" href=""" & HttpContext.Current.Request.ApplicationPath & subDir & "/" & file & """ />"

        Dim head As HtmlHead = DirectCast(ctl, HtmlHead)
        head.Controls.Add(literal)
    End Sub

    Public Shared Sub SetHeaderLeft(ByRef user As Label, ByRef title As Label)
        user.Text = Com_Get_変数("PT_USER")
        title.Text = Com_Get_変数("PT_TITLE")

        Dim colorCode As String = ConfigurationManager.AppSettings("HeaderForeColorLeft")
        colorCode = Replace(colorCode, "#", "0x")
        user.ForeColor = ColorTranslator.FromHtml(colorCode)
        title.ForeColor = ColorTranslator.FromHtml(colorCode)
    End Sub

    Public Shared Sub SetHeaderRight(ByRef loginuser_label As Label, ByRef loginuser_name As Label)
        loginuser_name.Text = HttpContext.Current.Session(S_COM_User_Name)

        Dim colorCode As String = ConfigurationManager.AppSettings("HeaderForeColorRight")
        colorCode = Replace(colorCode, "#", "0x")
        loginuser_label.ForeColor = ColorTranslator.FromHtml(colorCode)
        loginuser_name.ForeColor = ColorTranslator.FromHtml(colorCode)
    End Sub
    
    '2018/8/24 ADD START /Liu
    Public Shared Sub SetDropDown都道府県(ByRef cmb As DropDownList)
        Dim table As DataTable
        Using spm As New StoredProcedureManager("AS_共通_CMB_県")
            spm.AddPrmIn("@住所01", SqlDbType.NVarChar, "")
            spm.Fill()
            table = spm.ds.Tables(0)
        End Using

        For Each row As DataRow In table.Rows
            Dim cd As String = Convert.ToString(row("県CD"))
            Dim content As String = Convert.ToString(row("名前"))
            Dim item As New ListItem
            item.Text = content
            item.Value = cd
            cmb.Items.Add(item)
        Next
    End Sub

    Public Shared Sub SetDropDown学校訪問(ByRef cmb As DropDownList)
        Dim table As DataTable = Com_Get_変数TABLE("学校分類")
        For Each row As DataRow In table.Rows
            Dim content As String = Convert.ToString(row("内容"))
            Dim cd As String = Convert.ToString(row("CD"))
            Dim item As New ListItem
            item.Text = cd & ":" & content
            item.Value = cd
            cmb.Items.Add(item)
        Next
    End Sub

    Public Shared Sub SetDropDown学校訪問資料(ByRef cmb As DropDownList)
        Dim table As DataTable
        Using spm As New StoredProcedureManager("学校_訪問資料_SELECT")
            spm.Fill()
            table = spm.ds.Tables(0)
        End Using

        For Each row As DataRow In table.Rows
            Dim cd As String = Convert.ToString(row("送付CD"))
            Dim content As String = Convert.ToString(row("送付物"))
            Dim item As New ListItem
            item.Text = cd & ":" & content
            item.Value = cd
            cmb.Items.Add(item)
        Next
    End Sub

    Public Shared Sub SetDropDown訪問担当(ByRef cmb As DropDownList, Optional ByVal selectLoginUser As Boolean = False)
        Dim table As DataTable
        Using spm As New StoredProcedureManager("HM_訪問入力_CMB_担当")
            spm.Fill()
            table = spm.ds.Tables(0)
        End Using

        For Each row As DataRow In table.Rows
            Dim cd As String = Convert.ToString(row("教職員ID"))
            Dim content As String = Convert.ToString(row("氏名"))
            Dim item As New ListItem
            item.Text = cd & ":" & content
            item.Value = cd
            cmb.Items.Add(item)
        Next

        'ログイン者も追加しておく
        If HttpContext.Current.Session(S_COM_UserCD) IsNot Nothing And HttpContext.Current.Session(S_COM_User_Name) IsNot Nothing Then
            Dim userCd As String = Convert.ToString(HttpContext.Current.Session(S_COM_UserCD))
            Dim userName As String = Convert.ToString(HttpContext.Current.Session(S_COM_User_Name))
            If cmb.Items.FindByValue(userCd) Is Nothing Then
                Dim item As New ListItem
                item.Text = userCd & ":" & userName
                item.Value = userCd
                cmb.Items.Add(item)
            End If

            If selectLoginUser Then
                cmb.SelectedValue = userCd
            End If
        End If
    End Sub

    Public Shared Function Get訪問担当Flg(ByVal 教職員ID As String) As Boolean
        Dim returnValue As Boolean = False
        Using spm As New StoredProcedureManager("学校_GET訪問担当FLG")
            spm.AddPrmIn("@教職員ID", SqlDbType.VarChar, 教職員ID)
            spm.Fill()
            If spm.ds IsNot Nothing AndAlso spm.ds.Tables.Count > 0 AndAlso spm.ds.Tables(0).Rows.Count > 0 Then
                returnValue = Convert.ToBoolean((spm.ds.Tables(0).Rows(0)("担当者FLG_学校訪問")))
            End If
        End Using

        Return returnValue
    End Function

    Public Shared Sub 学校訪問_既読処理(ByVal 分類CD As String, ByVal 学校CD As String, ByVal 担当CD As String, ByVal 訪問日 As String, ByVal 利用者 As String)
        Using spm As New StoredProcedureManager("SP閲覧済IN")
            spm.AddPrmIn("@分類CD", Data.SqlDbType.VarChar, 分類CD)
            spm.AddPrmIn("@学校CD", Data.SqlDbType.VarChar, 学校CD)
            spm.AddPrmIn("@担当CD", Data.SqlDbType.VarChar, 担当CD)
            spm.AddPrmIn("@訪問日", Data.SqlDbType.DateTime, 訪問日)
            spm.AddPrmIn("@利用者", Data.SqlDbType.VarChar, 利用者)
            spm.Exec()
        End Using
    End Sub

    Public Shared Sub SetDropDown学園リスト(ByRef cmb As DropDownList, ByVal portalId As String)
        cmb.Items.Clear()
        cmb.Items.Add("")

        Dim table As DataTable
        Using spm As New StoredProcedureManager("共通_学園_DDL")
            spm.AddPrmIn("@PortalId", SqlDbType.VarChar, portalId)
            spm.Fill()
            table = spm.ds.Tables(0)
        End Using

        For Each row As DataRow In table.Rows
            Dim value As String = Convert.ToString(row("学園CD"))
            Dim text As String = Convert.ToString(row("学園CD")) & ":" & Convert.ToString(row("名前"))
            Dim item As New ListItem
            item.Text = text
            item.Value = value
            cmb.Items.Add(item)
        Next
    End Sub

    Public Shared Sub SetDropDown出予年度(ByRef cmb As DropDownList)
        Dim table As DataTable
        Using spm As New StoredProcedureManager("AS_共通_CMB_汎用")
            spm.AddPrmIn("@テーブル", SqlDbType.VarChar, "DB請求")
            spm.AddPrmIn("@項目1", SqlDbType.VarChar, "出予年度")
            spm.Fill()
            table = spm.ds.Tables(0)
        End Using

        For Each row As DataRow In table.Rows
            Dim value As String = Convert.ToString(row("出予年度"))
            Dim item As New ListItem
            item.Text = value
            item.Value = value
            cmb.Items.Add(item)
        Next
    End Sub
    '2018/8/24 ADD END /Liu

    '2024/02/23 M.Okabe ADD Start
    Public Shared Function CacheClearQuery() As String
        Return DateTime.Now.ToString("?yyyyMMddHHmmss")
    End Function

    ''' <summary>
    ''' オブジェクトが Nothing または DBNull の場合に長さ 0 の文字列("")または指定したその他の値を返す
    ''' </summary>
    ''' <param name="Value">対象となるオブジェクト</param>
    ''' <param name="ValueIfNull">Nothing または DBNull のときに返す値を指定、長さ 0 の文字列("")以外の値を返す場合に指定</param>
    ''' <returns>長さ 0 の文字列("")または、指定したその他の値</returns>
    ''' <remarks>AccessのNz関数をVB.NET版として作成。ただし数値の場合は ValueIfNull に 0 を指定しないと長さ 0 の文字列("")を返す</remarks>
    Public Shared Function Nz(ByVal Value As Object, Optional ByVal ValueIfNull As Object = Nothing) As String
        Nz = ""

        Dim res As Object

        If ValueIfNull Is Nothing Then
            res = Space(0)
        Else
            res = ValueIfNull
        End If

        If IsDBNull(Value) Or Value Is Nothing Then
            Nz = res
        Else
            Nz = Value.ToString()
        End If

    End Function
    '2024/02/23 M.Okabe ADD End

    Public Shared Function Com_Get_案内文(用途 As String) As String
        Dim ret As String = ""

        Using spm As New StoredProcedureManager("共通_案内文_SEL")
            spm.AddPrmIn("@用途", Data.SqlDbType.VarChar, 100, 用途)
            spm.Fill()

            If spm.ds IsNot Nothing And spm.ds.Tables(0).Rows.Count > 0 Then
                ret = (spm.ds.Tables(0).Rows(0))("内容")
            End If
        End Using

        Return ret
    End Function

    ''' <summary>
    ''' アップロードされたファイルの拡張子チェック
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function CheckReportFileExtension(ByVal strFileName As String) As Boolean

        Dim bolResult As Boolean = False

        '2020/3/24 MOD START PDFのみに変更 /Liu
        'Dim ValidTypes As String() = {".pdf", ".doc", ".docx", ".txt"}
        Dim ValidTypes As String() = {".pdf"}
        '2020/3/24 MOD END /Liu

        For Each filetype As String In ValidTypes
            If System.IO.Path.GetExtension(strFileName).ToLower() = filetype Then
                bolResult = True
            End If
        Next

        Return bolResult
    End Function

    '2018.06.25 ADD START /Liu
    ''' <summary>
    ''' [PT_CDSORT]テーブルから並べ替え列を取得
    ''' </summary>
    ''' <param name="機能名"></param>
    ''' <param name="PORTAL区分"></param>
    ''' <returns></returns>
    Shared Function Com_Get_SortColumnTable(機能名 As String,
                                            PORTAL区分 As String) As DataTable
        Using spm As New StoredProcedureManager("共通_SORT列_DDL")
            spm.AddPrmIn("@機能名", Data.SqlDbType.VarChar, 50, 機能名)
            spm.AddPrmIn("@PORTAL区分", Data.SqlDbType.VarChar, 20, PORTAL区分)
            spm.Fill()

            Return spm.ds.Tables(0)
        End Using
    End Function

    ''' <summary>
    ''' 並べ替えのDropdownlistのデータソースを設定する
    ''' </summary>
    ''' <param name="ddl_sort列"></param>
    ''' <param name="機能名"></param>
    ''' <param name="PORTAL区分"></param>
    Shared Sub Com_Bind_DDL_Sort列(ByRef ddl_sort列 As DropDownList,
                                   ByVal 機能名 As String,
                                   ByVal PORTAL区分 As String)
        ddl_sort列.DataSource = AppCommon.Com_Get_SortColumnTable(機能名, PORTAL区分)
        ddl_sort列.DataTextField = "TextField"
        ddl_sort列.DataValueField = "ValueField"
        ddl_sort列.DataBind()
    End Sub
    '2018.06.25 ADD END /Liu

    '2019.02.19 ADD START /Liu
    Shared Function Manual_FileFolder_Path() As String
        Return Com_Get_変数("PT_COMMON_DIRECTORY") & Com_Get_変数("FolderPath_マニュアルFILE")
    End Function
    '2019.02.19 ADD END /Liu

    '2020/08/26 ADD START #5608 掲示板URLリンク対応 /Liu
    ''' <summary>
    ''' URLをaタグに変換
    ''' </summary>
    ''' <param name="Str"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function CnvHyperLink(ByVal Str As String) As String
        '改行コードをbrタグに変換
        Str = Str.Replace(vbCrLf, "<br />")
        Str = Str.Replace(vbLf, "<br />")

        'Httpを小文字に変換
        Str = System.Text.RegularExpressions.Regex.Replace(Str, "Http://", "http://", RegexOptions.IgnoreCase)
        Str = System.Text.RegularExpressions.Regex.Replace(Str, "Https://", "https://", RegexOptions.IgnoreCase)

        'URLをaタグに変換
        Str = System.Text.RegularExpressions.Regex.Replace(Str, "s?https?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+", "<a href=""$&"" target=""_blank"">$&</a>")
        Return Str
    End Function
    '2020/08/26 ADD END /Liu

    Public Shared Function GetUserData(userCdOrPortalId As String, isUserCd As Boolean) As DataTable

        Using spm As New StoredProcedureManager("PT_USER_GET")
            spm.AddPrmIn("@userCdOrPortalId", Data.SqlDbType.VarChar, 200, userCdOrPortalId)
            spm.AddPrmIn("@isUserCd", Data.SqlDbType.Bit, isUserCd)
            spm.Fill()

            Return spm.ds.Tables(0)
        End Using

    End Function

    Public Shared Function GetUserDataByPortalId(portalId As String) As DataTable
        Dim isUserCd As Boolean = False
        Return GetUserData(portalId, isUserCd)
    End Function

    Public Shared Function GetUserDataByUserCd(userCd As String) As DataTable
        Dim isUserCd As Boolean = True
        Return GetUserData(userCd, isUserCd)
    End Function

    Public Shared Function GetApplyData(applyNo As String) As DataTable

        Using spm As New StoredProcedureManager("PT_申込_GET")
            spm.AddPrmIn("@申込番号", Data.SqlDbType.VarChar, 20, applyNo)
            spm.Fill()

            Return spm.ds.Tables(0)
        End Using

    End Function

    Public Shared Function GetFileFolderPath() As String
        Dim path As String = Com_Get_変数("PT_FILE_FOLDER_DIRECTORY")
        Return path
    End Function

    Public Shared Function GetTempFolderPath() As String
        Dim path As String = Com_Get_変数("PT_TEMP_FOLDER_DIRECTORY")
        Return path
    End Function

    Public Shared Function ValidateFileName(fileName As String, ByRef errorMessage As String) As Boolean
        If String.IsNullOrWhiteSpace(fileName) Then
            errorMessage = "ファイル名が空です。"
            Return False
        End If

        Try
            ' DBから禁止文字を取得
            Dim prohibitedChars As New List(Of String)()
            Dim dt As DataTable

            Using spm As New StoredProcedureManager("PT_禁止文字_SELECT")
                spm.Fill()
                dt = spm.ds.Tables(0)
            End Using

            For Each row As DataRow In dt.Rows
                Dim character As String = Convert.ToString(row("禁止文字"))
                If Not String.IsNullOrEmpty(character) Then
                    prohibitedChars.Add(character)
                End If
            Next

            ' 禁止文字チェック
            For Each prohibitedChar In prohibitedChars
                If fileName.Contains(prohibitedChar) Then
                    errorMessage = String.Format("ファイル名に「{0}」は使用できません。別の文字に変更してください。", prohibitedChar)
                    Return False
                End If
            Next

            errorMessage = ""
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function Get禁止文字ListFromDB() As List(Of String)
        Dim prohibitedChars As New List(Of String)

        Try
            ' DBから禁止文字を取得
            Dim dt As DataTable

            Using spm As New StoredProcedureManager("PT_禁止文字_SELECT")
                spm.Fill()
                dt = spm.ds.Tables(0)
            End Using

            For Each row As DataRow In dt.Rows
                Dim character As String = Convert.ToString(row("禁止文字"))
                If Not String.IsNullOrEmpty(character) Then
                    prohibitedChars.Add(character)
                End If
            Next

        Catch ex As Exception
            System.Diagnostics.Debug.WriteLine("禁止文字取得エラー: " & ex.Message)
        End Try

        Return prohibitedChars
    End Function

    Public Shared Function Set禁止文字リスト() As String
        Dim csvString As String = "&lt;,&gt;,:,&quot;,|,?,*,\,/,&amp;,%"
        Try
            ' 禁止文字を取得
            Dim prohibitedChars As List(Of String) = Get禁止文字ListFromDB()
            ' カンマ区切りに変換
            csvString = String.Join(",", prohibitedChars.Select(Function(c) EscapeSpecialChar(c)).ToArray())
        Catch ex As Exception
            csvString = csvString
        End Try
        Return csvString
    End Function

    Public Shared Function EscapeSpecialChar(moji As String) As String
        ' HTMLエスケープで特殊文字を処理
        Select Case moji
            Case "<"
                Return "&lt;"
            Case ">"
                Return "&gt;"
            Case """"
                Return "&quot;"
            Case "&"
                Return "&amp;"
            Case Else
                Return moji
        End Select
    End Function

    'DB登録時NULL対応 ADD 20260119 S.Iguchi
    Public Shared Function ToDbValue(value As String) As Object
        Return If(String.IsNullOrEmpty(value), DBNull.Value, CObj(value))
    End Function
    Public Shared Function ToDbDate(value As String) As Object
        If String.IsNullOrEmpty(value) Then
            Return DBNull.Value
        Else
            Dim dt As Date
            If Date.TryParse(value, dt) Then
                Return dt
            Else
                Return DBNull.Value
            End If
        End If
    End Function
End Class
