Imports XCCLibrary
Imports System.Environment

Public Class AppForm
    Public Shared fillMode As Boolean
    Public Shared appDataPath As String

    Sub AppForm_Load() Handles MyBase.Load
        Dim appData As String = GetFolderPath(SpecialFolder.ApplicationData)
        Dim appDataDir As New IO.DirectoryInfo(appData & "\Floor Grating Configurator")
        appDataPath = appDataDir.FullName
        If Not appDataDir.Exists Then
            System.IO.Directory.CreateDirectory(appDataPath)
            System.IO.File.Create(appDataPath & "\SavedData.txt").Dispose()
        End If

        Dim savedData As String() = System.IO.File.ReadAllLines(appDataPath & "\SavedData.txt")
        For i = 0 To savedData.Length - 1
            If savedData(i) = "Export Folder Path" Then
                Settings.exportFolder = savedData(i + 1)
                Main_Menu.Button_Order.Enabled = True
                Main_Menu.Label_FilePathError.Visible = False
            End If
        Next


        Dim appDir As String = Application.StartupPath
        Dim appDirArray As String() = appDir.Split("\")
        For i = 0 To appDirArray.Length - 5
            If i = appDirArray.Length - 5 Then
                Settings.filesFolder += appDirArray(i)
            Else
                Settings.filesFolder += appDirArray(i) & "\"
            End If
        Next
        For i = 0 To appDirArray.Length - 4
            If i = appDirArray.Length - 4 Then
                Settings.HLCtFolder += appDirArray(i)
            Else
                Settings.HLCtFolder += appDirArray(i) & "\"
            End If
        Next


        Me.Width = 1400
        Me.Height = 800
        Me.Top = 20
        Me.Left = 50

        Panel_Start.Controls.Clear()
        Main_Menu.TopLevel = False
        Panel_Start.Controls.Add(Main_Menu)
        Main_Menu.Show()

        ' Get floor gratings database
        Database.Retrive_Database()

        ' Initialize DataTables, Measurments and more
        Data.Init_Data()

        ' Initialize DrawingPanel
        Draw_Grating.Load_DrawingPanel()

        ' Load XCC settings
        adminClass.loadSettings(Settings.filesFolder, Settings.HLCtFolder, "SolidWorks")

        Individual.ComboBox_Type.Items.Add("Pressure Welded")
        Individual.ComboBox_Type.Items.Add("Type A")
    End Sub

End Class