X2021/Wardrobe/GUI/Individual.vb

381 lines
14 KiB
VB.net

Imports Word = Microsoft.Office.Interop.Word
Public Class Individual
Public Shared filepath As String
Sub Load_GUI()
' Initialize GUI
Init_Form()
Draw_Grating.Update_GratingPoints()
End Sub
' --- Initialize GUI (form) size and position ---
Private Sub Init_Form()
Me.Width = AppForm.Width
Me.Height = AppForm.Height
If AppForm.fillMode = True Then
Init_Multiple()
Else
Init_Individual()
End If
Me.ComboBox_Material.Enabled = False
Me.ComboBox_Mesh.Enabled = False
Me.ComboBox_Height.Enabled = False
Me.ComboBox_Thickness.Enabled = False
Me.ComboBox_Width.Enabled = False
Me.TextBox_Width.Enabled = False
Me.TextBox_Length.Enabled = False
Me.Button_Export_GUI.Enabled = False
Me.Button_Export_SW.Enabled = False
Me.Button_Angle_Corner.Enabled = False
Me.Button_Angle_Side.Enabled = False
Me.Button_Square_Corner.Enabled = False
Me.Button_Square_Side.Enabled = False
Me.Button_Square_Middle.Enabled = False
End Sub
Private Sub Init_Individual()
Me.Panel_Data.BackColor = Color.AliceBlue
Me.Panel_Recesses.BackColor = Color.LightGray
Dim CheckTemp As New CheckBox With {
.Name = "CheckBox_Whole_Mesh",
.Text = "Whole Mesh Widths",
.Left = 110,
.Top = 443,
.Font = New Font("Microsoft Sans Serif", 7.8),
.Checked = True,
.Enabled = False,
.AutoSize = True,
.BackColor = Color.Transparent
}
AddHandler CheckTemp.CheckedChanged, AddressOf CheckBox_Whole_Mesh_CheckedChanged
Me.Panel_Data.Controls.Add(CheckTemp)
Me.ComboBox_Width.Visible = True
Me.TextBox_Width.Visible = False
End Sub
Private Sub Init_Multiple()
Me.Panel_Data.BackColor = Color.Salmon
Me.Panel_Recesses.BackColor = Color.LightPink
Dim LabelTemp As New Label With {
.Name = "Label_Max_Load",
.Text = "Max Load",
.Left = 35,
.Top = 525,
.AutoSize = True,
.Font = New Font("Microsoft Sans Serif", 10)
}
Me.Panel_Data.Controls.Add(LabelTemp)
Dim textBoxTemp As New TextBox With {
.Name = "TextBox_Max_Load",
.Text = "5",
.Left = 110,
.Top = 525,
.Width = 155,
.Font = New Font("Microsoft Sans Serif", 8),
.Enabled = False
}
AddHandler textBoxTemp.KeyPress, AddressOf TextBox_Max_Load_KeyPress
Me.Panel_Data.Controls.Add(textBoxTemp)
Dim LabelTemp2 As New Label With {
.Name = "Label_Max_Load_Unit",
.Text = "kN/m²",
.Left = 269,
.Top = 529,
.Font = New Font("Microsoft Sans Serif", 8)
}
Me.Panel_Data.Controls.Add(LabelTemp2)
Dim calculateButton As New Button With {
.Name = "Button_Calculate",
.Text = "Calculate",
.Left = 100,
.Top = 600,
.Width = 100,
.Height = 40,
.BackColor = Color.Transparent,
.UseVisualStyleBackColor = False,
.Enabled = False
}
AddHandler calculateButton.Click, AddressOf Button_Calculate_Click
Me.Panel_Data.Controls.Add(calculateButton)
Me.ComboBox_Width.Visible = False
Me.TextBox_Width.Visible = True
End Sub
' ---------------------------------- Individual Templates ----------------------------------
' --- TextBox Template ---
Public Sub Create_TextBox_Recesses(TextBoxName As String, TextBoxText As String, TextBoxLeft As Integer, TextBoxTop As Integer,
TextBoxWidth As Integer)
Dim textBoxTemp As New TextBox With {
.Name = TextBoxName,
.Text = TextBoxText,
.Left = TextBoxLeft,
.Top = TextBoxTop,
.Width = TextBoxWidth,
.Font = New Font("Microsoft Sans Serif", 10)
}
Me.Panel_Recesses.Controls.Add(textBoxTemp)
End Sub
' --- Label Template for Individual ---
Public Sub Create_Label_Recesses(LabelName As String, LabelText As String, LabelLeft As Integer, LabelTop As Integer)
Dim LabelTemp As New Label With {
.Name = LabelName,
.Text = LabelText,
.Left = LabelLeft,
.Top = LabelTop,
.Font = New Font("Microsoft Sans Serif", 10)
}
Me.Panel_Recesses.Controls.Add(LabelTemp)
End Sub
' ---------------------------------- Gratings Data ----------------------------------
' --- When user changes grating type ---
Private Sub ComboBox_Type_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Type.TextChanged
User_Input.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
User_Input.MaterialChanged(sender, e)
End Sub
' --- When user changes mesh size ---
Private Sub ComboBox_Mesh_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Mesh.TextChanged
User_Input.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
User_Input.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
User_Input.ThicknessChanged(sender, e)
End Sub
' --- When user checkes/uncheckes whole meshes ---
Private Sub CheckBox_Whole_Mesh_CheckedChanged(sender As Object, e As EventArgs)
User_Input.WholeMeshWidthsChanged(sender, e)
End Sub
' --- Grating width changed ---
Private Sub ComboBox_Width_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Width.TextChanged
User_Input.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
User_Input.Check_IfNumber(e)
End Sub
' --- Grating width changed ---
Private Sub TextBox_Width_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Width.TextChanged
User_Input.WidthChanged(sender, e)
End Sub
' --- Check if width is a number ---
Private Sub TextBox_Width_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox_Width.KeyPress
User_Input.Check_IfNumber(e)
End Sub
' --- Grating length changed ---
Private Sub LengthBox_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Length.TextChanged
User_Input.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
User_Input.Check_IfNumber(e)
End Sub
' --- Check if max laod is a number ---
Public Sub TextBox_Max_Load_KeyPress(sender As Object, e As KeyPressEventArgs)
User_Input.Check_IfNumber(e)
End Sub
' ---------------------------------- Functions ----------------------------------
' --- When angle button is pressed ---
Private Sub Button_Angle_Corner_Click(sender As Object, e As EventArgs) Handles Button_Angle_Corner.Click
Corner_Angle.AngleButton(sender, e)
End Sub
' --- When angle side button is pressed ---
Private Sub Button_Angle_Side_Click(sender As Object, e As EventArgs) Handles Button_Angle_Side.Click
End Sub
' --- When square corner button is pressed ---
Private Sub Button_Square_Corner_Click(sender As Object, e As EventArgs) Handles Button_Square_Corner.Click
Corner_Rectangle.SquareButtton(sender, e)
End Sub
' --- When square side button is pressed ---
Private Sub Button_Square_Side_Click(sender As Object, e As EventArgs) Handles Button_Square_Side.Click
Side_Rectangle.SquareSideButtton(sender, e)
End Sub
' --- When middle square button is pressed ---
Private Sub Button_Square_Middle_Click(sender As Object, e As EventArgs) Handles Button_Square_Middle.Click
Middle_Rectangle.SquareMiddleButtton(sender, e)
End Sub
' ---------------------------------- Calculate ----------------------------------
' --- When calculate button is pressed ---
Public Sub Button_Calculate_Click(sender As Object, e As EventArgs)
Grating_Fill.Calculate_Grid()
'Grating_Fill.Calculate_Recesses()
End Sub
' ---------------------------------- Export to SW ----------------------------------
' --- When export to SW button is pressed ---
Private Sub Button_Export_SW_Click(sender As Object, e As EventArgs) Handles Button_Export_SW.Click
If AppForm.fillMode Then
Grating_Fill.Calculate_Grid()
'Grating_Fill.Calculate_Recesses()
Model_3D_Fill.BuildGrid()
Else
Model_3D.BuildGrating()
Drawing.Create_Model_For_Drawing()
End If
End Sub
' ---------------------------------- Export GUI ----------------------------------
' --- When export GUI button is pressed ---
Private Sub Button_Export_GUI_Click(sender As Object, e As EventArgs) Handles Button_Export_GUI.Click
'Dim startPoint As New Point(Me.Left + Panel_Grating.Left, Me.Top + Panel_Grating.Top)
Dim startPoint As New Point
startPoint = Panel_Grating.PointToScreen(Point.Empty)
Dim tempImg As New Bitmap(Panel_Grating.Width - 1, Panel_Grating.Height - 1)
Dim test As Graphics = Graphics.FromImage(tempImg)
test.CopyFromScreen(startPoint, New Point(0, 0), tempImg.Size)
tempImg.Save(filepath & "\X2021\Specification_PDF\GUI.png", Imaging.ImageFormat.Png)
Dim doc As Word.Document = New Word.Document()
'doc.Content.Text = "Hello World"
Dim Para1 As Word.Paragraph
Para1 = doc.Content.Paragraphs.Add
Para1.Range.InlineShapes.AddPicture(filepath & "\X2021\Specification_PDF\Weland_Logo.png")
doc.InlineShapes(1).ScaleHeight = 50
doc.InlineShapes(1).ScaleWidth = 50
Para1.Format.SpaceAfter = 30
Para1.Range.InsertParagraphAfter()
Dim table1 As Word.Table
table1 = doc.Tables.Add(doc.Bookmarks.Item("\endofdoc").Range, 4, 2)
table1.Columns(1).SetWidth(120, 2)
table1.Rows.SetHeight(18, 2)
table1.Cell(1, 1).Range.Text = "Quote Date:"
table1.Cell(1, 2).Range.Text = Date.Today
table1.Cell(2, 1).Range.Text = "Order number:"
table1.Cell(2, 2).Range.Text = "1337"
table1.Cell(3, 1).Range.Text = "Customer number:"
table1.Cell(3, 2).Range.Text = "20041605"
table1.Cell(4, 1).Range.Text = "Sales Representative:"
table1.Cell(4, 2).Range.Text = "Sven Svensson"
table1.Range.ParagraphFormat.SpaceAfter = 30
'table1.Range.InsertParagraphAfter()
'table1.Range.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
Dim oLineBreak As Word.Paragraph
oLineBreak = doc.Content.Paragraphs.Add(doc.Bookmarks.Item("\endofdoc").Range)
oLineBreak.Range.InsertParagraphBefore()
oLineBreak.Range.Text = ""
oLineBreak.Format.SpaceAfter = 0.5
oLineBreak.Range.InsertParagraphAfter()
Dim table2 As Word.Table
table2 = doc.Tables.Add(doc.Bookmarks.Item("\endofdoc").Range, 5, 5) 'FIXA generiskt
table2.Rows.SetHeight(18, 2)
For i = 1 To table2.Columns.Count
table2.Cell(1, i).Range.Font.Color = Word.WdColor.wdColorWhite
table2.Cell(1, i).Shading.BackgroundPatternColor = Word.WdColor.wdColorBlack
Next
table2.Cell(1, 1).Range.Text = "Description"
table2.Cell(1, 2).Range.Text = "QTY"
table2.Cell(1, 3).Range.Text = "Art. Nr."
table2.Cell(1, 4).Range.Text = "Unit Price"
table2.Cell(1, 5).Range.Text = "Total Price"
For i = 2 To table2.Rows.Count
table2.Cell(i, 1).Range.Text = "Floor Grating" & i
table2.Cell(i, 2).Range.Text = "QTY"
table2.Cell(i, 3).Range.Text = "Art. Nr."
table2.Cell(i, 4).Range.Text = "Unit Price"
table2.Cell(i, 5).Range.Text = "Total Price"
Next
table2.Range.ParagraphFormat.SpaceAfter = 40
Dim Para2 As Word.Paragraph
Para2 = doc.Content.Paragraphs.Add
Para2.Range.InsertParagraphBefore()
Para2.Range.Text = "Total Price: " & "2200"
Para2.Range.Font.Bold = True
Para2.Range.Font.Size = 20
Para2.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
Para2.Format.SpaceAfter = 24
Dim table3 As Word.Table
doc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = False
table3 = doc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Tables.Add(doc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range, 3, 2)
table3.Columns(1).SetWidth(360, 2)
table3.Cell(1, 1).Range.Text = "Phone Number: "
table3.Cell(2, 1).Range.Text = "Email: "
table3.Cell(3, 1).Range.Text = "Webpage: "
table3.Cell(1, 2).Range.Text = "0731-344 00"
table3.Cell(2, 2).Range.Text = "info@weland.se"
table3.Cell(3, 2).Range.Text = "www.weland.com"
For i = 1 To table3.Rows.Count
table3.Cell(i, 1).Range.Font.Bold = True
For j = 1 To table3.Columns.Count
table3.Cell(i, j).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
table3.Cell(i, j).Range.Font.Size = 10
Next
Next
doc.ExportAsFixedFormat(filepath & "\X2021\Specification_PDF\Specification.pdf", Word.WdExportFormat.wdExportFormatPDF)
doc.Close(False)
End Sub
' ---------------------------------- Back to main menu ----------------------------------
' --- When export back button is pressed ---
Private Sub Button_Back_Click(sender As Object, e As EventArgs) Handles Button_Back.Click
AppForm.Panel_Start.Controls.Clear()
Main_Menu.TopLevel = False
AppForm.Panel_Start.Controls.Add(Main_Menu)
Main_Menu.Show()
End Sub
End Class