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