Imports System.Diagnostics.Eventing.Reader
Imports System.Windows.Forms
Imports UTS_Core.UTSModule.Test.Controls

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

        Private ReadOnly _msgText As String
        Private ReadOnly _msgType As UtsMsgBox.UtsMsgBoxTypeEnum
        Private ReadOnly _msgTitle As String

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

            If TestCommand.Parameter(1) = "0" Then
                _msgType = UtsMsgBox.UtsMsgBoxTypeEnum.OkOnly
            ElseIf TestCommand.Parameter(1) = "4" Then
                _msgType = UtsMsgBox.UtsMsgBoxTypeEnum.YesNo
            Else
                _msgType = UtsMsgBox.UtsMsgBoxTypeEnum.OkOnly
            End If

            _msgText = TestCommand.Parameter(0)
            _msgTitle = TestCommand.Parameter(2)

            CommandReturn.LowerLimit = TestCommand.Parameter(3)

            CommandReturn.UpperLimit = String.Empty

            CommandReturn.RecordValue = String.Empty

            CommandReturn.ExecuteResultTipString = String.Empty

            CommandReturn.ExecuteResult = True
        End Sub


        Public Overrides Function Execute() As TestCommandReturn

            Using msg As New UtsMsgBox
                msg.MsgType = _msgType
                msg.MsgTitle = _msgTitle
                msg.MsgText = _msgText
                msg.StartPosition = FormStartPosition.CenterScreen
                msg.TopMost = True
                If msg.ShowDialog() = DialogResult.OK Then
                    CommandReturn.RecordValue = "Yes"
                Else
                    CommandReturn.RecordValue = "No"
                End If

                CommandReturn.ExecuteResult = CompareFunction.StringCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)

                If CommandReturn.ExecuteResult Then
                    CommandReturn.ExecuteResultTipString = "显示消息框执行成功"
                Else
                    CommandReturn.ExecuteResultTipString = $"返回值 {CommandReturn.RecordValue} 不在 { CommandReturn.LowerLimit} ~ { CommandReturn.UpperLimit} 之间"
                End If

                'If String.IsNullOrWhiteSpace(CommandReturn.LowerLimit) Then '无期望值
                '    CommandReturn.ExecuteResult = True
                '    CommandReturn.ExecuteResultTipString = "显示消息框执行完成"
                'Else


                '    If String.Compare(CommandReturn.LowerLimit, CommandReturn.RecordValue, True) = 0 Then '与期望值相符
                '        CommandReturn.ExecuteResult = True
                '        CommandReturn.ExecuteResultTipString = "显示消息框执行完成"
                '    Else
                '        CommandReturn.ExecuteResult = False
                '        CommandReturn.ExecuteResultTipString = $"期望值 {CommandReturn.LowerLimit} 实际结果:{ CommandReturn.RecordValue}  ,不相符"
                '    End If
                'End If
            End Using

            Return CommandReturn
        End Function
    End Class
End Namespace