Imports System.Windows.Forms
Imports UTS_Core.UTSModule.Test.Controls


Namespace UTSModule.Test.Command.SystemCommand
    Public Class ShowInputBoxExecutor
        Inherits TestCommandExecutor

        Private ReadOnly _tipText As String
        Private ReadOnly _title As String
        Private ReadOnly _defaultText As String

        Private stringLen_LowwerLimit As String = ""
        Private stringLen_UpperLimit As String = ""
        Private Char_VerfiyMode As String = ""
        Private InputBox_InputString As String = ""

        Sub New(command As TestCommand)
            MyBase.New(command)

            _tipText = TestCommand.Parameter(0)
            _title = TestCommand.Parameter(1)
            _defaultText = TestCommand.Parameter(2)

            CommandReturn.LowerLimit = TestCommand.Parameter(3)

            CommandReturn.UpperLimit = TestCommand.Parameter(4)

            If TestCommand.Parameter.Count > 5 Then '判断参数数量，以便新版本软件与旧版本testplan兼容
                stringLen_LowwerLimit = Trim(TestCommand.Parameter(5))
                stringLen_UpperLimit = Trim(TestCommand.Parameter(6))
                Char_VerfiyMode = Trim(TestCommand.Parameter(7))
            End If

            CommandReturn.RecordValue = String.Empty

            CommandReturn.ExecuteResultTipString = String.Empty

            CommandReturn.ExecuteResult = True
        End Sub


        Public Overrides Function Execute() As TestCommandReturn
            Using box As New UtsInputBox
                box.DefaultText = _defaultText
                box.TipText = _tipText
                box.Title = _title
                box.StartPosition = FormStartPosition.CenterScreen
                box.TopMost = True
                If box.ShowDialog() = DialogResult.OK Then
                    'CommandReturn.RecordValue = box.InputText
                    InputBox_InputString = Trim(box.InputText)
                Else
                    CommandReturn.RecordValue = String.Empty
                    CommandReturn.ExecuteResultTipString = "已取消输入框的输入"
                    CommandReturn.ExecuteResult = False
                    Return CommandReturn
                End If
            End Using

            '对比上下限 （忽略大小写，上下限字符均包含则返回TRUE，上下限为空白返回 TRUE）
            If CompareFunction.StringContain_Momo(InputBox_InputString, CommandReturn.LowerLimit, CommandReturn.UpperLimit) = True Then
                '对比字符串长度（长度符合上下限范围返回 TRUE，长度上下限为空白返回 TRUE）
                If CompareFunction.StringLengthCheck(InputBox_InputString, stringLen_LowwerLimit, stringLen_UpperLimit) = True Then
                    '逐个字符格式比对
                    If CompareFunction.StringEachCharCheck(InputBox_InputString, Char_VerfiyMode) = True Then
                        CommandReturn.ExecuteResult = True
                        CommandReturn.RecordValue = InputBox_InputString
                        CommandReturn.ExecuteResultTipString = "输入框显示成功"
                    Else
                        CommandReturn.ExecuteResult = False
                        CommandReturn.RecordValue = ""
                        CommandReturn.ExecuteResultTipString = $"返回值 {InputBox_InputString},长度：{InputBox_InputString.Length}, 逐字符格式匹配失败,匹配模式： {Char_VerfiyMode} "
                    End If
                Else
                    CommandReturn.ExecuteResult = False
                    CommandReturn.RecordValue = ""
                    CommandReturn.ExecuteResultTipString = $"返回值 {InputBox_InputString},长度：{InputBox_InputString.Length}, 不在 {stringLen_LowwerLimit} ~ {stringLen_UpperLimit} 之间"
                End If
            Else
                CommandReturn.ExecuteResult = False
                CommandReturn.RecordValue = ""
                CommandReturn.ExecuteResultTipString = $"返回值 {InputBox_InputString},长度：{InputBox_InputString.Length}, 未包含：{stringLen_LowwerLimit} 或 {stringLen_UpperLimit} "
            End If

            'If CommandReturn.ExecuteResult Then
            '    CommandReturn.RecordValue = InputBox_InputString
            '    CommandReturn.ExecuteResultTipString = "输入框显示成功"
            'Else
            '    CommandReturn.ExecuteResultTipString = $"返回值 {CommandReturn.RecordValue} 不在 { CommandReturn.LowerLimit} ~ { CommandReturn.UpperLimit} 之间"
            'End If

            Return CommandReturn
        End Function

    End Class
End Namespace