Imports System.Windows.Forms
Imports UTS_Core.EnumExtend

Namespace UTSModule.Project
    Public Class DlgLoadProject
        Public Property LoadMode As ProjectInfo.InitializeModeEnum = ProjectInfo.InitializeModeEnum.RemoteDatabaseLoad

        Public Property ProjectName() As String

        Private Sub UpdateProjectCombobox()
            CboProjectName.Items.Clear()
            CboProjectName.Items.AddRange(ProjectInfo.LoadProjectList(LoadMode))
            If CboProjectName.Items.Count > 0 Then CboProjectName.SelectedIndex = 0
        End Sub

        Private Sub DlgLoadProject_Load(sender As Object, e As EventArgs) Handles Me.Load
            Text = $"加载项目"

            CboLoadProjectMode.Items.Clear()
            CboLoadProjectMode.Items.AddRange(EnumExtender.GetEnumAllDesc(GetType(ProjectInfo.InitializeModeEnum)))
            CboLoadProjectMode.SelectedIndex = LoadMode

            UpdateProjectCombobox()
        End Sub


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

            DialogResult = DialogResult.OK
            Close()
        End Sub

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

        Private Sub CboLoadProjectMode_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CboLoadProjectMode.SelectedIndexChanged
            If LoadMode <> CboLoadProjectMode.SelectedIndex Then
                LoadMode = CType([Enum].Parse(GetType(ProjectInfo.InitializeModeEnum), CboLoadProjectMode.SelectedIndex.ToString()), ProjectInfo.InitializeModeEnum)

                UpdateProjectCombobox()
            End If
        End Sub
    End Class
End Namespace
