Imports UTS_Core.UTSModule.Service

Public Class FrmAddTask
    Public TaskForm As ITaskForm

    Private _syncForm As FrmSyncTasks
    Private _listenForm As FrmListenTasks

    ''' <summary>
    ''' 加载窗体时，添加任务类型
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub FrmAddTask_Load(sender As Object, e As EventArgs) Handles Me.Load
        InitTabMain()

        CboTasksType.Items.Clear()
        CboTasksType.Items.Add(ServiceTask.ServiceTaskTypeEnum.DbSync.ToString())
        CboTasksType.Items.Add(ServiceTask.ServiceTaskTypeEnum.ListenJsonFile.ToString())

        If CboTasksType.Items.Count > 0 Then
            CboTasksType.SelectedIndex = 0
        End If

    End Sub

    Private Sub InitTabMain()
        TabTasksPages.SizeMode = TabSizeMode.Fixed '隐藏TabControl的表头
        TabTasksPages.ItemSize = New Size(0, 1)

        Dim tp As New TabPage
        _syncForm = New FrmSyncTasks
        _syncForm.ShowForm(tp)
        TabTasksPages.TabPages.Add(tp)


        Dim tp2 As New TabPage
        _listenForm = New FrmListenTasks
        _listenForm.ShowForm(tp2)
        TabTasksPages.TabPages.Add(tp2)
    End Sub

    ''' <summary>
    ''' 任务类型分页
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub CboTasksType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CboTasksType.SelectedIndexChanged
        TabTasksPages.SelectedIndex = CboTasksType.SelectedIndex

        Select Case CboTasksType.SelectedIndex
            Case ServiceTask.ServiceTaskTypeEnum.DbSync
                TaskForm = _syncForm
            Case ServiceTask.ServiceTaskTypeEnum.ListenJsonFile
                TaskForm = _listenForm
            Case Else

        End Select

        Dim param As New Dictionary(Of String, String)
        param.Add("Name", $"Task{Now.Ticks}")
        TaskForm.SetParam(param)
    End Sub





    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

End Class
