Database to Datatable
This commit is contained in:
parent
a9567f6b39
commit
bc1bbf48f2
BIN
Databas.xlsx
BIN
Databas.xlsx
Binary file not shown.
164
Wardrobe/GUI.vb
164
Wardrobe/GUI.vb
|
|
@ -2,8 +2,8 @@
|
|||
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"
|
||||
Public Shared filepath As String = "C:\Users\Anton\Documents\Exjobb"
|
||||
'Public Shared filepath As String = "C:\Users\xperd\Documents"
|
||||
|
||||
Dim filesFolder As String = filepath ' Hämta från settings
|
||||
Dim HLCtFolder As String = filepath & "\X2021" ' Hämta från settings
|
||||
|
|
@ -42,8 +42,12 @@ Public Class GUI
|
|||
Dim excelWB As Excel.Workbook
|
||||
Dim excelSheet As Excel.Worksheet
|
||||
|
||||
Dim serratedCheckBox As New CheckBox
|
||||
Dim serratedCheckBoxBol As Boolean = False
|
||||
|
||||
|
||||
Dim dataBase As New Dictionary(Of String, DataTable)
|
||||
|
||||
' --- Start method (main) for GUI ---
|
||||
Sub GUI_load() Handles MyBase.Load
|
||||
containerPanel = DrawingPanel
|
||||
|
|
@ -64,7 +68,42 @@ Public Class GUI
|
|||
Create_StartPoints()
|
||||
|
||||
Program.Load_XCC(filesFolder, HLCtFolder)
|
||||
Get_Database()
|
||||
End Sub
|
||||
|
||||
Private Sub Get_Database()
|
||||
excelWB = excelApp.Workbooks.Open(HLCtFolder & "\Databas.xlsx")
|
||||
|
||||
For i = 1 To 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 columnName As String = activeSheet.Cells(1, columnCounter).Value
|
||||
While columnName <> ""
|
||||
tempDT.Columns.Add(columnName, GetType(String))
|
||||
columnCounter = columnCounter + 1
|
||||
columnName = activeSheet.Cells(1, columnCounter).Value
|
||||
numOfColumns = numOfColumns + 1
|
||||
End While
|
||||
|
||||
Dim rowCounter As Integer = 2
|
||||
Dim rowValue As String = activeSheet.Cells(rowCounter, 1).Value
|
||||
While rowValue <> ""
|
||||
tempDT.Rows.Add()
|
||||
For j = 0 To numOfColumns - 1
|
||||
tempDT.Rows(tempDT.Rows.Count - 1)(j) = activeSheet.Cells(rowCounter, j + 1).Value
|
||||
Next
|
||||
rowCounter = rowCounter + 1
|
||||
rowValue = activeSheet.Cells(rowCounter, 1).Value
|
||||
End While
|
||||
|
||||
dataBase.Add(activeSheet.Name, tempDT)
|
||||
Next
|
||||
' HANTERA OLIKA LÄNGDER PÅ COLUMNER
|
||||
End Sub
|
||||
|
||||
' --- Retrive parameters for the drawing box ---
|
||||
|
|
@ -318,41 +357,34 @@ Public Class GUI
|
|||
|
||||
' --- When user changes grating type ---
|
||||
Private Sub ComboBox_TypeChooser_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_TypeChooser.TextChanged
|
||||
gratingType = ComboBox_TypeChooser.Text
|
||||
ComboBox_Material.Enabled = True
|
||||
ComboBox_Material.Items.Clear()
|
||||
Dim materialSheet As Excel.Worksheet
|
||||
materialSheet = excelWB.Sheets("Material")
|
||||
gratingType = ComboBox_TypeChooser.Text
|
||||
|
||||
Dim typeColumn As Integer
|
||||
typeColumn = Get_ColumnIndex("TYPE", materialSheet)
|
||||
|
||||
|
||||
Dim materialColumn As Integer
|
||||
materialColumn = Get_ColumnIndex("MATERIAL", materialSheet)
|
||||
|
||||
Dim typeInExcel As String
|
||||
Dim rowCounter As Integer = 2
|
||||
typeInExcel = materialSheet.Cells(rowCounter, typeColumn).value
|
||||
While typeInExcel <> ""
|
||||
If gratingType = typeInExcel Then
|
||||
ComboBox_Material.Items.Add(materialSheet.Cells(rowCounter, materialColumn).Value)
|
||||
Dim materialDT As DataTable = dataBase("Material")
|
||||
Dim typeColumn As Integer = Get_ColumnIndex("TYPE", materialDT)
|
||||
Dim materialColumn As Integer = Get_ColumnIndex("MATERIAL", materialDT)
|
||||
|
||||
Dim typeInDT As String = materialDT.Rows(0)(typeColumn)
|
||||
For i = 0 To materialDT.Rows.Count - 1
|
||||
If gratingType = materialDT.Rows(i)(typeColumn) Then
|
||||
ComboBox_Material.Items.Add(materialDT.Rows(i)(materialColumn))
|
||||
End If
|
||||
rowCounter = rowCounter + 1
|
||||
typeInExcel = materialSheet.Cells(rowCounter, typeColumn).value
|
||||
End While
|
||||
Try
|
||||
typeInDT = materialDT.Rows(i + 1)(typeColumn)
|
||||
Catch ex As Exception
|
||||
End Try
|
||||
Next
|
||||
|
||||
ComboBox_Material.Text = ComboBox_Material.Items(0)
|
||||
End Sub
|
||||
|
||||
Private Function Get_ColumnIndex(columnName As String, activeSheet As Excel.Worksheet)
|
||||
Dim columnIndex As Integer = 0
|
||||
Dim columnCounter As Integer = 1
|
||||
While columnIndex = 0
|
||||
If activeSheet.Cells(1, columnCounter).value = columnName Then
|
||||
columnIndex = activeSheet.Cells(1, columnCounter).column
|
||||
|
||||
Private Function Get_ColumnIndex(columnName As String, activeDT As DataTable)
|
||||
Dim columnIndex As Integer = -1
|
||||
Dim columnCounter As Integer = 0
|
||||
While columnIndex = -1
|
||||
If activeDT.Columns(columnCounter).ColumnName = columnName Then
|
||||
columnIndex = columnCounter
|
||||
End If
|
||||
columnCounter = columnCounter + 1
|
||||
End While
|
||||
|
|
@ -360,61 +392,59 @@ Public Class GUI
|
|||
Return columnIndex
|
||||
End Function
|
||||
|
||||
|
||||
' --- When user changes grating material ---
|
||||
Private Sub ComboBox_Material_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Material.TextChanged
|
||||
ComboBox_MeshSize.Enabled = True
|
||||
ComboBox_MeshSize.Items.Clear()
|
||||
gratingMaterial = ComboBox_Material.Text
|
||||
|
||||
Dim serratedSheet As Excel.Worksheet
|
||||
serratedSheet = excelWB.Sheets("Serrated")
|
||||
Dim serratedDT As DataTable = dataBase("Serrated")
|
||||
Dim typeColumn As Integer = Get_ColumnIndex("TYPE", serratedDT)
|
||||
Dim materialColumn As Integer = Get_ColumnIndex("MATERIAL", serratedDT)
|
||||
|
||||
Dim typeColumn As Integer
|
||||
typeColumn = Get_ColumnIndex("TYPE", serratedSheet)
|
||||
|
||||
|
||||
Dim materialColumn As Integer
|
||||
materialColumn = Get_ColumnIndex("MATERIAL", serratedSheet)
|
||||
|
||||
Dim typeInExcel As String
|
||||
Dim materialInExcel As String
|
||||
Dim removeCheckBox As Boolean = True
|
||||
Dim rowCounter As Integer = 2
|
||||
materialInExcel = serratedSheet.Cells(rowCounter, materialColumn).value
|
||||
typeInExcel = serratedSheet.Cells(rowCounter, typeColumn).value
|
||||
Dim typeInDT As String = serratedDT.Rows(0)(typeColumn)
|
||||
Dim materialInDT As String = serratedDT.Rows(0)(materialColumn)
|
||||
If serratedCheckBoxBol = False Then
|
||||
While typeInExcel <> ""
|
||||
If gratingType = typeInExcel And gratingMaterial = materialInExcel Then
|
||||
Dim serratedCheckBox As New CheckBox
|
||||
For i = 0 To serratedDT.Rows.Count - 1
|
||||
If gratingType = typeInDT And gratingMaterial = materialInDT Then
|
||||
serratedCheckBox.Name = "CheckBox_Serrated"
|
||||
serratedCheckBox.Text = "Serrated"
|
||||
serratedCheckBox.Left = 115
|
||||
serratedCheckBox.Top = 115
|
||||
AddHandler serratedCheckBox.CheckedChanged, AddressOf CheckBox_Serrated_CheckedChanged
|
||||
Me.Controls.Add(serratedCheckBox)
|
||||
serratedCheckBoxBol = True
|
||||
Exit While
|
||||
Exit For
|
||||
End If
|
||||
rowCounter = rowCounter + 1
|
||||
typeInExcel = serratedSheet.Cells(rowCounter, typeColumn).value
|
||||
materialInExcel = serratedSheet.Cells(rowCounter, materialColumn).value
|
||||
End While
|
||||
Try
|
||||
typeInDT = serratedDT.Rows(i + 1)(typeColumn)
|
||||
materialInDT = serratedDT.Rows(i + 1)(materialColumn)
|
||||
Catch ex As Exception
|
||||
End Try
|
||||
Next
|
||||
Else
|
||||
While typeInExcel <> ""
|
||||
If gratingType = typeInExcel And gratingMaterial = materialInExcel Then
|
||||
For i = 0 To serratedDT.Rows.Count - 1
|
||||
If gratingType = typeInDT And gratingMaterial = materialInDT Then
|
||||
removeCheckBox = False
|
||||
Exit While
|
||||
Exit For
|
||||
End If
|
||||
rowCounter = rowCounter + 1
|
||||
typeInExcel = serratedSheet.Cells(rowCounter, typeColumn).value
|
||||
materialInExcel = serratedSheet.Cells(rowCounter, materialColumn).value
|
||||
End While
|
||||
Try
|
||||
typeInDT = serratedDT.Rows(i + 1)(typeColumn)
|
||||
materialInDT = serratedDT.Rows(i + 1)(materialColumn)
|
||||
Catch ex As Exception
|
||||
End Try
|
||||
Next
|
||||
If serratedCheckBoxBol = True And removeCheckBox = True Then
|
||||
RemoveHandler serratedCheckBox.CheckedChanged, AddressOf CheckBox_Serrated_CheckedChanged
|
||||
Me.Controls.RemoveByKey("CheckBox_Serrated")
|
||||
serratedCheckBoxBol = False
|
||||
End If
|
||||
End If
|
||||
|
||||
' UPDATE MESHES
|
||||
|
||||
|
||||
|
||||
' Add Meshes
|
||||
If gratingType = "Pressure Welded" Then
|
||||
ComboBox_MeshSize.Items.Add("12x100 (B9)") 'Tillfällig
|
||||
|
|
@ -434,6 +464,22 @@ Public Class GUI
|
|||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub CheckBox_Serrated_CheckedChanged(sender As Object, e As EventArgs)
|
||||
If sender.Checked Then
|
||||
' UPDATE MESHES
|
||||
Else
|
||||
' UPDATE MESHES
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub Update_AvalaibleMeshes()
|
||||
ComboBox_MeshSize.Items.Clear()
|
||||
|
||||
|
||||
ComboBox_MeshSize.Items.Add("12x100 (B9)")
|
||||
End Sub
|
||||
|
||||
' --- When user changes mesh size ---
|
||||
Private Sub ComboBox_MeshSize_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_MeshSize.TextChanged
|
||||
ComboBox_Height.Enabled = True
|
||||
|
|
|
|||
Loading…
Reference in New Issue