179 lines
6.9 KiB
VB.net
179 lines
6.9 KiB
VB.net
Imports XCCLibrary
|
|
Imports Excel = Microsoft.Office.Interop.Excel
|
|
|
|
Public Class GUI
|
|
Public Shared filepath As String = "C:\Users\Anton\Documents\Exjobb"
|
|
'Public Shared filepath As String = "C:\Users\xperd\Documents"
|
|
|
|
Dim excelApp As Excel.Application = New Excel.Application
|
|
Dim excelWB As Excel.Workbook
|
|
|
|
Public Shared dataBase As New Dictionary(Of String, DataTable)
|
|
|
|
' --- Start method (main) for GUI ---
|
|
Sub GUI_load() Handles MyBase.Load
|
|
Me.Width = 1400
|
|
Me.Height = 800
|
|
|
|
AddHandler DrawingPanel.Paint, AddressOf GUI_Drawing_Panel.DrawingPanel_Paint
|
|
GUI_Drawing_Panel.Load_DrawingPanel()
|
|
|
|
adminClass.loadSettings(GUI_Settings.filesFolder, GUI_Settings.HLCtFolder, "SolidWorks")
|
|
|
|
Get_Database()
|
|
|
|
CheckBox_WholeMeshWidths.Checked = True
|
|
End Sub
|
|
|
|
Private Sub Get_Database()
|
|
excelWB = excelApp.Workbooks.Open(GUI_Settings.HLCtFolder & "\Databas.xlsx")
|
|
|
|
For i = 1 To 4 'excelWB.Worksheets.Count
|
|
Dim activeSheet As Excel.Worksheet
|
|
activeSheet = excelWB.Sheets(i)
|
|
|
|
Dim tempDT As New DataTable
|
|
|
|
Dim numOfColumns As Integer = 0
|
|
Dim columnCounter As Integer = 1
|
|
Dim rowCounter As Integer
|
|
Dim rowValue As String
|
|
Dim longestRow As Integer = 0
|
|
Dim columnName As String = activeSheet.Cells(1, columnCounter).Value
|
|
While columnName <> ""
|
|
tempDT.Columns.Add(columnName, GetType(String))
|
|
|
|
rowCounter = 2
|
|
rowValue = activeSheet.Cells(rowCounter, numOfColumns + 1).Value
|
|
While rowValue <> ""
|
|
rowCounter = rowCounter + 1
|
|
rowValue = activeSheet.Cells(rowCounter, numOfColumns + 1).Value
|
|
End While
|
|
If rowCounter > longestRow Then
|
|
longestRow = rowCounter
|
|
End If
|
|
|
|
columnCounter = columnCounter + 1
|
|
columnName = activeSheet.Cells(1, columnCounter).Value
|
|
numOfColumns = numOfColumns + 1
|
|
End While
|
|
|
|
For j = 2 To longestRow - 1
|
|
tempDT.Rows.Add()
|
|
For k = 0 To numOfColumns - 1
|
|
tempDT.Rows(tempDT.Rows.Count - 1)(k) = activeSheet.Cells(j, k + 1).Value
|
|
Next
|
|
Next
|
|
|
|
dataBase.Add(activeSheet.Name, tempDT)
|
|
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(activeSheet)
|
|
Next
|
|
|
|
excelWB.Close()
|
|
excelApp.Quit()
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWB)
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
|
|
End Sub
|
|
|
|
Public Sub Create_TextBox(TextBoxName As String, TextBoxText As String, TextBoxLeft As Integer, TextBoxTop As Integer,
|
|
TextBoxWidth As Integer)
|
|
Dim textBoxTemp As New TextBox
|
|
textBoxTemp.Name = TextBoxName
|
|
textBoxTemp.Text = TextBoxText
|
|
textBoxTemp.Left = TextBoxLeft
|
|
textBoxTemp.Top = TextBoxTop
|
|
textBoxTemp.Width = TextBoxWidth
|
|
textBoxTemp.Font = New Font("Microsoft Sans Serif", 10)
|
|
Me.Controls.Add(textBoxTemp)
|
|
End Sub
|
|
|
|
Public Sub Create_Label(LabelName As String, LabelText As String, LabelLeft As Integer, LabelTop As Integer)
|
|
Dim LabelTemp As New Label
|
|
LabelTemp.Name = LabelName
|
|
LabelTemp.Text = LabelText
|
|
LabelTemp.Left = LabelLeft
|
|
LabelTemp.Top = LabelTop
|
|
LabelTemp.Font = New Font("Microsoft Sans Serif", 10)
|
|
Me.Controls.Add(LabelTemp)
|
|
End Sub
|
|
|
|
|
|
' ---------------------------------- Gratings Data ----------------------------------
|
|
' --- When user changes grating type ---
|
|
Private Sub ComboBox_TypeChooser_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_TypeChooser.TextChanged
|
|
GUI_Gratings_Data.TypeChanged(sender, e)
|
|
End Sub
|
|
|
|
|
|
' --- When user changes grating material ---
|
|
Private Sub ComboBox_Material_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Material.TextChanged
|
|
GUI_Gratings_Data.MaterialChanged(sender, e)
|
|
End Sub
|
|
|
|
' --- When user changes mesh size ---
|
|
Private Sub ComboBox_MeshSize_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_MeshSize.TextChanged
|
|
GUI_Gratings_Data.MeshChanged(sender, e)
|
|
End Sub
|
|
|
|
' --- When user changes grating height ---
|
|
Private Sub ComboBox_Height_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Height.TextChanged
|
|
GUI_Gratings_Data.HeightChanged(sender, e)
|
|
End Sub
|
|
|
|
' --- When user changes grating thickness ---
|
|
Private Sub ComboBox_Thickness_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Thickness.TextChanged
|
|
GUI_Gratings_Data.ThicknessChanged(sender, e)
|
|
End Sub
|
|
|
|
Private Sub CheckBox_WholeMeshWidths_CheckedChanged(sender As Object, e As EventArgs) _
|
|
Handles CheckBox_WholeMeshWidths.CheckedChanged
|
|
|
|
GUI_Gratings_Data.WholeMeshWidthsChanged(sender, e)
|
|
End Sub
|
|
|
|
' --- Grating width changed ---
|
|
Private Sub WidthB_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Width.TextChanged
|
|
GUI_Gratings_Data.WidthChanged(sender, e)
|
|
End Sub
|
|
|
|
' --- Check if width is a number ---
|
|
Private Sub ComboBox_Width_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ComboBox_Width.KeyPress
|
|
GUI_Gratings_Data.Check_IfNumber(e)
|
|
End Sub
|
|
|
|
' --- Grating length changed ---
|
|
Private Sub LengthBox_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Length.TextChanged
|
|
GUI_Gratings_Data.LengthChanged(sender, e)
|
|
End Sub
|
|
|
|
' --- Check if length is a number ---
|
|
Private Sub ComboBox_Length_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox_Length.KeyPress
|
|
GUI_Gratings_Data.Check_IfNumber(e)
|
|
End Sub
|
|
|
|
' ---------------------------------- Functions ----------------------------------
|
|
' --- When angle button is pressed ---
|
|
Private Sub AngleButton_Click(sender As Object, e As EventArgs) Handles AngleButton.Click
|
|
GUI_Functions.AngleButton(sender, e)
|
|
End Sub
|
|
|
|
' --- When square button is pressed ---
|
|
Private Sub Button_Square_Click(sender As Object, e As EventArgs) Handles Button_Square.Click
|
|
GUI_Functions.SquareButtton(sender, e)
|
|
End Sub
|
|
|
|
' ---------------------------------- Settings ----------------------------------
|
|
' --- Settings button clicked ---
|
|
Private Sub SettingsButton_Click(sender As Object, e As EventArgs) Handles SettingsButton.Click
|
|
GUI_Settings.ButtonClicked(sender, e)
|
|
End Sub
|
|
|
|
' ---------------------------------- Export to SW ----------------------------------
|
|
' --- When export to SW button is pressed ---
|
|
Private Sub ExportSWButton_Click(sender As Object, e As EventArgs) Handles ExportSWButton.Click
|
|
SW_HLCt_Gratings.BuildGrating()
|
|
SW_Drawing_Gratings.CreateDrawing()
|
|
End Sub
|
|
|
|
End Class |