Public Class FrmMain
    ''' <summary>
    ''' 分页控件包含的页面
    ''' </summary>
    Enum TabControlEnum
        TpProject
        TpStationDesign
        TpStationPlan
        TpHelp
        TpAbout
    End Enum



    Public Property UserInfo As UTS_Core.UTSModule.Login.UserInfo
    Public Property UserLicense As UTS_Core.UTSModule.License.License

    ''' <summary>
    ''' 显示登录窗口
    ''' </summary>
    Private Sub ShowLoginForm()
        If UTS_Core.UTSModule.Login.LoginParams.IsShowLoginForm = False Then Return
        Using frmLogin As New UTS_Core.UTSModule.Login.LoginForm
            If frmLogin.ShowDialog() = DialogResult.OK Then
                UserInfo = frmLogin.UserLoginInfo
                UserLicense = frmLogin.UserLicense
            Else
                Close()
            End If
        End Using
    End Sub

    ''' <summary>修改窗体标题</summary>
    Private Sub ShowFormTitle()
        Text = $"{My.Application.Info.ProductName} {My.Application.Info.Version} Main"
    End Sub

    Private Sub InitTabMain()

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

        AddProjectFormToTabControl(TabControlEnum.TpProject.ToString(), "Project")
    End Sub

    Private Sub InitForm()
        ShowFormTitle()
        InitTabMain()
    End Sub

    ''' <summary>
    ''' 校验文件夹,若文件夹不存在则创建
    ''' </summary>
    Private Sub CheckDirectory()
        UTS_Core.UTSModule.UtsPath.CheckDirectory()
    End Sub

    Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
        CheckDirectory()

        ShowLoginForm()

        InitForm()
    End Sub

    ''' <summary>
    ''' 添加项目设计窗体到分页控件中
    ''' </summary>
    Private Sub AddProjectFormToTabControl(pageName As String, pageText As String)
        If TabMain.TabPages.ContainsKey(pageName) Then Return
        Dim page As New TabPage With {.Name = pageName, .Text = pageText}
        Dim frm As New UTS_Core.UTSModule.Project.FrmProject
        frm.ShowForm(page, UserInfo)

        TabMain.TabPages.Add(page)
    End Sub

    Private Sub MsiProject_Click(sender As Object, e As EventArgs) Handles MsiProject.Click
        TabMain.SelectedIndex = TabControlEnum.TpProject
    End Sub

    Private Sub MsiHelp_Click(sender As Object, e As EventArgs) Handles MsiHelp.Click
        '帮助与关于页面暂时为设置
        ' TabMain.SelectedIndex = TabControlEnum.TpHelp
    End Sub

    Private Sub MsiAbout_Click(sender As Object, e As EventArgs) Handles MsiAbout.Click
        '帮助与关于页面暂时为设置
        'TabMain.SelectedIndex = TabControlEnum.TpAbout
    End Sub
End Class
