Imports System.Text
Imports UTS_Core.UTSModule.Service

Public Class FrmListenTasks
    Implements ITaskForm

    ''' <summary>
    ''' 显示窗体
    ''' </summary>
    ''' <param name="parentControl">把本窗体打包放在其他容器内</param>
    Public Sub ShowForm(parentControl As Control) Implements ITaskForm.ShowForm
        FormBorderStyle = FormBorderStyle.None
        TopLevel = False
        Dock = DockStyle.Fill
        Parent = parentControl

        Show()
    End Sub

    ''' <summary>
    ''' 根据类型不同，快速生成ConnJsonString
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub BtnRapidGenerating_Click(sender As Object, e As EventArgs) Handles BtnRapidGeneratListen.Click
        TBoConnStringListen.Text = RapidGenerating()
    End Sub

    ''' <summary>
    ''' 快捷生成字符串
    ''' </summary>
    ''' <returns></returns>
    Private Function RapidGenerating() As String
        Dim connStr As New StringBuilder
        Using fileDialog As New OpenFileDialog
            fileDialog.InitialDirectory = Application.StartupPath
            If fileDialog.ShowDialog() = DialogResult.OK Then
                connStr.Append(fileDialog.FileName)
                connStr = connStr.Replace("\", "/")
            End If
        End Using
        Return connStr.ToString
    End Function

    Public Function GetParams() As Dictionary(Of String, String) Implements ITaskForm.GetParams
        Dim jsonParam As New Dictionary(Of String, String) From {
            {"Type", TBoTasksType.Text},
            {"Name", TBoTasksName.Text},
            {"Interval", NudTasksInterval.Value.ToString()},
            {"Path", TBoConnStringListen.Text}
        }
        Return jsonParam
    End Function

    Public Sub SetParam(params As Dictionary(Of String, String)) Implements ITaskForm.SetParam
        For Each param As KeyValuePair(Of String, String) In params
            Select Case param.Key
                Case "Name"
                    TBoTasksName.Text = param.Value
                Case "Interval"
                    NudTasksInterval.Value = CInt(param.Value)
                Case "Path"
                    TBoConnStringListen.Text = param.Value
            End Select
        Next

    End Sub

    Private Sub FrmListenTasks_Load(sender As Object, e As EventArgs) Handles Me.Load
        TBoTasksType.Text = ServiceTask.ServiceTaskTypeEnum.ListenJsonFile.ToString()
    End Sub


End Class