

Public Class Main_Menu

    Private Sub Generate_Folders()
        Settings.folderPaths.Add("object_" & Data.objectNum, Settings.folderPaths("order") & "\Object " & Data.objectNum) 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum))

        ' 3D-Models
        Settings.folderPaths.Add("object_" & Data.objectNum & "_models3D", Settings.folderPaths("object_" & Data.objectNum) & "\3D-Models") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_models3D"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_models3D_gratings", Settings.folderPaths("object_" & Data.objectNum & "_models3D") & "\Floor Gratings") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_models3D_gratings_sw", Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings") & "\SLD") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_models3D_gratings_sw_support", Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw") & "\Support Models") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_models3D_gratings_stp", Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings") & "\STP") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_stp"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_models3D_frames", Settings.folderPaths("object_" & Data.objectNum & "_models3D") & "\Frames") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_models3D_frames"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_models3D_frames_sw", Settings.folderPaths("object_" & Data.objectNum & "_models3D_frames") & "\SLD") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_models3D_frames_sw"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_models3D_frames_sw_support", Settings.folderPaths("object_" & Data.objectNum & "_models3D_frames_sw") & "\Support Models") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_models3D_frames_sw_support"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_models3D_frames_stp", Settings.folderPaths("object_" & Data.objectNum & "_models3D_frames") & "\STP") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_models3D_frames_stp"))

        ' Drawings
        Settings.folderPaths.Add("object_" & Data.objectNum & "_drawings", Settings.folderPaths("object_" & Data.objectNum) & "\Drawings") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_drawings"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_drawings_gratings", Settings.folderPaths("object_" & Data.objectNum & "_drawings") & "\Floor Gratings") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_drawings_gratings"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_drawings_gratings_sw", Settings.folderPaths("object_" & Data.objectNum & "_drawings_gratings") & "\SLD") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_drawings_gratings_sw"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_drawings_gratings_pdf", Settings.folderPaths("object_" & Data.objectNum & "_drawings_gratings") & "\PDF") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_drawings_gratings_pdf"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_drawings_frames", Settings.folderPaths("object_" & Data.objectNum & "_drawings") & "\Frames") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_drawings_frames"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_drawings_frames_sw", Settings.folderPaths("object_" & Data.objectNum & "_drawings_frames") & "\SLD") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_drawings_frames_sw"))
        Settings.folderPaths.Add("object_" & Data.objectNum & "_drawings_frames_pdf", Settings.folderPaths("object_" & Data.objectNum & "_drawings_frames") & "\PDF") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_drawings_frames_pdf"))

        ' Quote
        Settings.folderPaths.Add("object_" & Data.objectNum & "_quote", Settings.folderPaths("object_" & Data.objectNum) & "\Quote") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_quote"))

        ' Placement Guides
        Settings.folderPaths.Add("object_" & Data.objectNum & "_guide", Settings.folderPaths("object_" & Data.objectNum) & "\Placement Guides") 'FIXA
        System.IO.Directory.CreateDirectory(Settings.folderPaths("object_" & Data.objectNum & "_guide"))
    End Sub
    Private Sub Button_Individual_Click(sender As Object, e As EventArgs) Handles Button_Individual.Click
        If AppForm.fillMode = True Then
            Individual.Panel_Data.Controls.RemoveByKey("Label_Max_Load")
            RemoveHandler Individual.Panel_Data.Controls("TextBox_Max_Load").KeyPress, AddressOf Individual.TextBox_Max_Load_KeyPress
            Individual.Panel_Data.Controls.RemoveByKey("TextBox_Max_Load")
            Individual.Panel_Data.Controls.RemoveByKey("Label_Max_Load_Unit")
            RemoveHandler Individual.Panel_Data.Controls("Button_Calculate").Click, AddressOf Individual.Button_Calculate_Click
            Individual.Panel_Data.Controls.RemoveByKey("Button_Calculate")
        End If
        AppForm.fillMode = False
        AppForm.Panel_Start.Controls.Clear()
        Individual.TopLevel = False
        AppForm.Panel_Start.Controls.Add(Individual)
        Individual.Load_GUI()
        Individual.Show()

        Data.objectNum += 1
        Generate_Folders()
    End Sub

    Private Sub Button_Multiple_Click(sender As Object, e As EventArgs) Handles Button_Multiple.Click
        AppForm.fillMode = True
        AppForm.Panel_Start.Controls.Clear()
        Individual.TopLevel = False
        AppForm.Panel_Start.Controls.Add(Individual)
        Individual.Load_GUI()
        Individual.Show()

        Data.objectNum += 1
        Generate_Folders()
    End Sub

    ' ---------------------------------- Settings ----------------------------------
    ' --- Settings button clicked ---
    Private Sub Button_Settings_Click(sender As Object, e As EventArgs) Handles Button_Settings.Click
        Settings.ButtonClicked(sender, e)
    End Sub

    Private Sub Button_FilePath_Click(sender As Object, e As EventArgs) Handles Button_FilePath.Click
        Dim ofd As FolderBrowserDialog = New FolderBrowserDialog
        If ofd.ShowDialog() <> DialogResult.Cancel Then
            Settings.exportFolder = ofd.SelectedPath

            Dim appData As String() = System.IO.File.ReadAllLines(AppForm.appDataPath & "\SavedData.txt")
            Dim appDataList As New List(Of String)
            For i = 0 To appData.Length - 1
                appDataList.Add(appData(i))
            Next

            Dim pathUpdated As Boolean = False
            For i = 0 To appDataList.Count - 1
                If appDataList(i) = "Export Folder Path" Then
                    appDataList(i + 1) = ofd.SelectedPath
                    pathUpdated = True
                    Exit For
                End If
            Next

            If pathUpdated = False Then
                appDataList.Add("")
                appDataList.Add("Export Folder Path")
                appDataList.Add(ofd.SelectedPath)
            End If

            System.IO.File.WriteAllLines(AppForm.appDataPath & "\SavedData.txt", appDataList.ToArray())

            Button_Order.Enabled = True
            Label_FilePathError.Visible = False
        End If
    End Sub

    Private Sub Button_Order_Click(sender As Object, e As EventArgs) Handles Button_Order.Click
        Button_Individual.Enabled = True
        Button_Multiple.Enabled = True

        Settings.folderPaths.Add("order", Settings.exportFolder & "\Order " & GUI_Export.Get_RandomNumber(1000, 9999))
        System.IO.Directory.CreateDirectory(Settings.folderPaths("order"))

        Data.objectNum = 0
    End Sub
End Class