Imports Word = Microsoft.Office.Interop.Word Public Class GUI_Export Private Shared gratingTable As New DataTable Public Shared Sub Generate_Quote() gratingTable = User_Input.Create_ExportTable() Dim doc As Word.Document = New Word.Document() 'Page 1 Create_HeaderFooter(doc) Create_QuoteInfo(doc) Create_ProductsInfo(doc) 'Page 2-X doc.Words.Last.InsertBreak(Word.WdBreakType.wdPageBreak) Generate_Screenshot() Create_GratingPicture(doc) Create_GratingData(doc) doc.ExportAsFixedFormat(Settings.folderPaths("object_" & Data.objectNum & "_quote") & "\Specification.pdf", Word.WdExportFormat.wdExportFormatPDF) doc.Close(False) End Sub Private Shared Sub Generate_Screenshot() Dim gratingImg As New Bitmap(Grating_Configurator.Panel_Grating.Width - 1, Grating_Configurator.Panel_Grating.Height - 1) Dim graphicImg As Graphics = Graphics.FromImage(gratingImg) Draw_Grating.Draw_ForExport(graphicImg, 12) gratingImg.Save(Settings.folderPaths("object_" & Data.objectNum & "_quote") & "\GUI.png", Imaging.ImageFormat.Png) End Sub Private Shared Sub Create_HeaderFooter(doc As Word.Document) doc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = False 'Header Dim headerTable As Word.Table headerTable = doc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range. Tables.Add(doc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range, 1, 2) headerTable.Cell(1, 1).Range.InlineShapes.AddPicture(Settings.HLCtFolder & "\Files Needed\Weland_Logo.png") headerTable.Cell(1, 1).Range.InlineShapes(1).ScaleHeight = 50 headerTable.Cell(1, 1).Range.InlineShapes(1).ScaleWidth = 50 headerTable.Cell(1, 2).Range.Text = "QUOTE" headerTable.Cell(1, 2).Range.Font.Size = 18 headerTable.Cell(1, 2).Range.Font.Bold = True headerTable.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight headerTable.Cell(1, 2).VerticalAlignment = Word.WdVerticalAlignment.wdAlignVerticalBottom 'Footer Dim footerTable As Word.Table footerTable = doc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range. Tables.Add(doc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range, 3, 2) footerTable.Columns(1).SetWidth(360, 2) footerTable.Cell(1, 1).Range.Text = "Phone Number: " footerTable.Cell(2, 1).Range.Text = "Email: " footerTable.Cell(3, 1).Range.Text = "Webpage: " footerTable.Cell(1, 2).Range.Text = "0731-344 00" footerTable.Cell(2, 2).Range.Text = "info@weland.se" footerTable.Cell(3, 2).Range.Text = "www.weland.com" For i = 1 To footerTable.Rows.Count footerTable.Cell(i, 1).Range.Font.Bold = True For j = 1 To footerTable.Columns.Count footerTable.Cell(i, j).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight footerTable.Cell(i, j).Range.Font.Size = 10 Next Next End Sub Private Shared Sub Create_QuoteInfo(doc) Dim lineBreak As Word.Paragraph lineBreak = doc.Content.Paragraphs.Add lineBreak.Range.InsertParagraphBefore() lineBreak.Range.Text = "" lineBreak.Format.SpaceAfter = 20 lineBreak.Range.InsertParagraphAfter() Dim infoTable As Word.Table Dim tableRange As Word.Range = doc.Bookmarks.Item("\endofdoc").Range infoTable = doc.Tables.Add(tableRange, 6, 2) infoTable.Columns(1).SetWidth(120, 2) infoTable.Rows.SetHeight(18, 2) Dim date2 As Date = Date.Today infoTable.Cell(1, 1).Range.Text = "Quote Date:" infoTable.Cell(1, 2).Range.Text = date2.ToString("dd-MM-yyyy") infoTable.Cell(2, 1).Range.Text = "Order number:" infoTable.Cell(2, 2).Range.Text = date2.ToString("ddMMyyyy") & Get_RandomNumber(10000, 99999) infoTable.Cell(3, 1).Range.Text = "Customer number:" infoTable.Cell(3, 2).Range.Text = Get_RandomNumber(10000, 99999) infoTable.Cell(4, 1).Range.Text = "Sales Representative:" infoTable.Cell(4, 2).Range.Text = Settings.SRName infoTable.Cell(5, 1).Range.Text = "Phone Number:" infoTable.Cell(5, 2).Range.Text = Settings.SRPhone infoTable.Cell(6, 1).Range.Text = "Mail:" infoTable.Cell(6, 2).Range.Text = Settings.SRMail End Sub Private Shared Sub Create_ProductsInfo(doc) Dim lineBreak As Word.Paragraph Dim lineRange As Word.Range = doc.Bookmarks.Item("\endofdoc").Range lineBreak = doc.Content.Paragraphs.Add(lineRange) lineBreak.Range.InsertParagraphBefore() lineBreak.Range.Text = "" lineBreak.Format.SpaceAfter = 10 lineBreak.Range.InsertParagraphAfter() Dim productsTable As Word.Table Dim tableRange As Word.Range = doc.Bookmarks.Item("\endofdoc").Range productsTable = doc.Tables.Add(tableRange, 16, 5) productsTable.Rows.SetHeight(18, 2) productsTable.Columns(1).SetWidth(240, 2) productsTable.Columns(2).SetWidth(78, 2) productsTable.Columns(3).SetWidth(40, 2) productsTable.Columns(4).SetWidth(60, 2) productsTable.Columns(5).SetWidth(52, 2) Dim productInfoDT As New DataTable productInfoDT = Generate_ProductInfo() For c = 1 To productsTable.Columns.Count productsTable.Cell(1, c).Range.Font.Color = Word.WdColor.wdColorWhite productsTable.Cell(1, c).Shading.BackgroundPatternColor = Word.WdColor.wdColorBlack productsTable.Cell(1, c).VerticalAlignment = Word.WdVerticalAlignment.wdAlignVerticalBottom If c > 2 Then For r = 1 To productsTable.Rows.Count productsTable.Cell(r, c).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight Next End If If c = 5 Then For r = 2 To productsTable.Rows.Count productsTable.Cell(r, c).Range.Font.Bold = True Next End If Next productsTable.Cell(1, 1).Range.Text = "Description" productsTable.Cell(1, 2).Range.Text = "Art. Nr." productsTable.Cell(1, 3).Range.Text = "QTY" productsTable.Cell(1, 4).Range.Text = "Unit Price" productsTable.Cell(1, 5).Range.Text = "Price" For i = 2 To productInfoDT.Rows.Count + 1 productsTable.Cell(i, 1).Range.Text = productInfoDT.Rows(i - 2)("Description") productsTable.Cell(i, 2).Range.Text = productInfoDT.Rows(i - 2)("Art. Nr.") productsTable.Cell(i, 3).Range.Text = CInt(productInfoDT.Rows(i - 2)("QTY")).ToString("### ###") productsTable.Cell(i, 4).Range.Text = CInt(productInfoDT.Rows(i - 2)("Unit Price")).ToString("### ###") productsTable.Cell(i, 5).Range.Text = CInt(productInfoDT.Rows(i - 2)("Price")).ToString("### ###") For j = 1 To productsTable.Columns.Count productsTable.Cell(i, j).Range.Font.Size = 10 Next Next Dim lineBreak2 As Word.Paragraph lineRange = doc.Bookmarks.Item("\endofdoc").Range lineBreak2 = doc.Content.Paragraphs.Add(lineRange) lineBreak2.Range.InsertParagraphBefore() lineBreak2.Range.Text = "" lineBreak2.Format.SpaceAfter = 20 lineBreak2.Range.InsertParagraphAfter() Dim priceTable As Word.Table tableRange = doc.Bookmarks.Item("\endofdoc").Range priceTable = doc.Tables.Add(tableRange, 1, 2) priceTable.Columns(1).SetWidth(370, 2) priceTable.Cell(1, 1).Range.Text = "Total Price:" priceTable.Cell(1, 1).Range.Font.Bold = True priceTable.Cell(1, 1).Range.Font.Size = 20 Dim totPrice As Integer = 0 For i = 2 To productsTable.Rows.Count totPrice += CInt(Val(productsTable.Cell(i, 5).Range.Text)) Next priceTable.Cell(1, 2).Range.Text = totPrice.ToString("### ###") priceTable.Cell(1, 2).Range.Font.Bold = True priceTable.Cell(1, 2).Range.Font.Size = 20 priceTable.Cell(1, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight priceTable.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight End Sub Private Shared Sub Create_GratingPicture(doc As Word.Document) Dim drawingPara As Word.Paragraph Dim lineRange As Word.Range = doc.Bookmarks.Item("\endofdoc").Range drawingPara = doc.Content.Paragraphs.Add(lineRange) drawingPara.Range.InsertParagraphBefore() drawingPara.Format.SpaceBefore = 10 drawingPara.Range.InlineShapes.AddPicture(Settings.folderPaths("object_" & Data.objectNum & "_quote") & "\GUI.png") drawingPara.Range.InlineShapes(1).ScaleHeight = 55 drawingPara.Range.InlineShapes(1).ScaleWidth = 55 drawingPara.Format.SpaceAfter = 1 drawingPara.Range.InsertParagraphAfter() End Sub Private Shared Sub Create_GratingData(doc As Word.Document) Dim gratingInfoTable As Word.Table Dim tableRange As Word.Range = doc.Bookmarks.Item("\endofdoc").Range gratingInfoTable = doc.Tables.Add(tableRange, 10, 2) gratingInfoTable.Columns(1).SetWidth(80, 2) gratingInfoTable.Rows.SetHeight(18, 2) gratingInfoTable.Cell(1, 1).Range.Text = "Description: " gratingInfoTable.Cell(2, 1).Range.Text = "Type: " gratingInfoTable.Cell(3, 1).Range.Text = "Material: " gratingInfoTable.Cell(4, 1).Range.Text = "Mesh Size: " gratingInfoTable.Cell(5, 1).Range.Text = "Height: " gratingInfoTable.Cell(6, 1).Range.Text = "Thickness: " gratingInfoTable.Cell(7, 1).Range.Text = "Length: " gratingInfoTable.Cell(8, 1).Range.Text = "Width: " gratingInfoTable.Cell(9, 1).Range.Text = "Other: " For i = 1 To gratingInfoTable.Rows.Count gratingInfoTable.Cell(i, 1).Range.Font.Bold = True Next gratingInfoTable.Cell(1, 2).Range.Text = "Floor Grating " & gratingTable.Rows(0)("NAME") & " " & gratingTable.Rows(0)("LOADBAR_HEIGHT") & "/" & gratingTable.Rows(0)("LOADBAR_THICKNESS") If gratingTable.Rows(0)("TYPE") = "pressure_welded" Then gratingInfoTable.Cell(2, 2).Range.Text = "Pressure Welded" Else gratingInfoTable.Cell(2, 2).Range.Text = "Type A" End If gratingInfoTable.Cell(3, 2).Range.Text = gratingTable.Rows(0)("MATERIAL") gratingInfoTable.Cell(4, 2).Range.Text = gratingTable.Rows(0)("LOADBAR_SPACING") & "x" & gratingTable.Rows(0)("CROSSBAR_SPACING") & " (" & gratingTable.Rows(0)("NAME") & ")" gratingInfoTable.Cell(5, 2).Range.Text = gratingTable.Rows(0)("LOADBAR_HEIGHT") & " [mm]" gratingInfoTable.Cell(6, 2).Range.Text = gratingTable.Rows(0)("LOADBAR_THICKNESS") & " [mm]" gratingInfoTable.Cell(7, 2).Range.Text = gratingTable.Rows(0)("LENGTH") & " [mm]" gratingInfoTable.Cell(8, 2).Range.Text = gratingTable.Rows(0)("WIDTH") & " [mm]" If gratingTable.Rows(0)("SERRATED") AndAlso gratingTable.Rows(0)("LACQUERED") Then gratingInfoTable.Cell(9, 2).Range.Text = "Serrated, Lacquered" ElseIf gratingTable.Rows(0)("SERRATED") Then gratingInfoTable.Cell(9, 2).Range.Text = "Serrated" ElseIf gratingTable.Rows(0)("LACQUERED") Then gratingInfoTable.Cell(9, 2).Range.Text = "Lacquered" Else gratingInfoTable.Cell(9, 2).Range.Text = "-" End If End Sub Public Shared Function Get_RandomNumber(Min As Integer, Max As Integer) As Integer Static Generator As System.Random = New System.Random() Return Generator.Next(Min, Max) End Function Private Shared Function Generate_ProductInfo() Dim productIDT As New DataTable productIDT.Columns.Add("Description", GetType(String)) productIDT.Columns.Add("Art. Nr.", GetType(String)) productIDT.Columns.Add("QTY", GetType(Integer)) productIDT.Columns.Add("Unit Price", GetType(Integer)) productIDT.Columns.Add("Price", GetType(Integer)) If AppForm.fillMode = True Then For i = 0 To Calculate_Fill_Grid.gratingDimensionsDT.Rows.Count - 1 Dim DR As DataRow = Calculate_Fill_Grid.gratingDimensionsDT.Rows(i) Dim newDR As DataRow = productIDT.NewRow Dim descStr As String = "Floor Grating " & gratingTable.Rows(0)("NAME") & " " & gratingTable.Rows(0)("LOADBAR_HEIGHT") & "/" & gratingTable.Rows(0)("LOADBAR_THICKNESS") & " " & DR("LENGTH") & "x" & DR("WIDTH") Dim withRecess As Boolean = False 'For j = 0 To Data.recessData.Rows.Count - 1 'FIXA recessdata "GRATINGS" finns inte ' Dim recessGratings As List(Of Integer) = Data.recessData.Rows(j)("GRATINGS") ' For k = 0 To recessGratings.Count - 1 ' If recessGratings(k) = DR("INDEX") Then ' withRecess = True ' End If ' Next 'Next If withRecess = True Then descStr += " (With Recess)" End If Dim newRow As Boolean = True For j = 0 To productIDT.Rows.Count - 1 If productIDT.Rows(j)("Description") = descStr Then productIDT.Rows(j)("QTY") += 1 newRow = False Exit For End If Next If newRow = True Then newDR("Description") = descStr If gratingTable.Rows(0)("SERRATED") = True Then newDR("Art. Nr.") = gratingTable.Rows(0)("NAME").substring(0, 1) & "S" & gratingTable.Rows(0)("LOADBAR_HEIGHT") & Get_RandomNumber(10000000, 99999999) Else newDR("Art. Nr.") = gratingTable.Rows(0)("NAME") & gratingTable.Rows(0)("LOADBAR_HEIGHT") & Get_RandomNumber(10000000, 99999999) End If newDR("QTY") = 1 Dim gratingArea As Double = (DR("LENGTH") / 1000) * (DR("WIDTH") / 1000) Dim unitprice As Double = gratingArea * 1000 If withRecess = True Then unitprice += 300 End If newDR("Unit Price") = unitprice productIDT.Rows.Add(newDR) End If Next Else 'Individual Dim newDR As DataRow = productIDT.NewRow Dim descStr As String = "Floor Grating " & gratingTable.Rows(0)("NAME") & " " & gratingTable.Rows(0)("LOADBAR_HEIGHT") & "/" & gratingTable.Rows(0)("LOADBAR_THICKNESS") & " " & Data.gratingL & "x" & Data.gratingW Dim withRecess As Boolean = False 'For j = 0 To Data.recessData.Rows.Count - 1 'FIXA recessdata "GRATINGS" finns inte ' Dim recessGratings As List(Of Integer) = Data.recessData.Rows(j)("GRATINGS") ' For k = 0 To recessGratings.Count - 1 ' If recessGratings(k) = DR("INDEX") Then ' withRecess = True ' End If ' Next 'Next If withRecess = True Then descStr += " (With Recess)" End If newDR("Description") = descStr If gratingTable.Rows(0)("SERRATED") = True Then newDR("Art. Nr.") = gratingTable.Rows(0)("NAME").substring(0, 1) & "S" & gratingTable.Rows(0)("LOADBAR_HEIGHT") & Get_RandomNumber(10000000, 99999999) Else newDR("Art. Nr.") = gratingTable.Rows(0)("NAME") & gratingTable.Rows(0)("LOADBAR_HEIGHT") & Get_RandomNumber(10000000, 99999999) End If newDR("QTY") = 1 Dim gratingArea As Double = (Data.gratingL / 1000) * (Data.gratingW / 1000) Dim unitprice As Double = gratingArea * 2500 If withRecess = True Then unitprice += 300 End If newDR("Unit Price") = unitprice productIDT.Rows.Add(newDR) End If If User_Input.addFrame = True Then Frame_3D.Generate_FrameVariables() If User_Input.preCutFrame = True Then 'Precut For Each sideFrame As KeyValuePair(Of String, Integer) In Frame_3D.sideFrameLengths Dim newDR As DataRow = productIDT.NewRow newDR("Description") = "Frame L-Profile Side " & sideFrame.Value & "mm " & User_Input.frameSize & "x" & User_Input.frameSize Dim newRow As Boolean = True For j = 0 To productIDT.Rows.Count - 1 If productIDT.Rows(j)("Description") = newDR("Description") Then productIDT.Rows(j)("QTY") += 1 newRow = False Exit For End If Next If newRow = True Then newDR("Art. Nr.") = 161 & Get_RandomNumber(100000, 999999) newDR("QTY") = 1 newDR("Unit Price") = ((26 * User_Input.frameSize) / 2000) * sideFrame.Value + 50 productIDT.Rows.Add(newDR) End If Next Else 'Whole frames Dim newDR As DataRow = productIDT.NewRow newDR("Description") = "Frame L-Profile Side 2000mm " & User_Input.frameSize & "x" & User_Input.frameSize newDR("Art. Nr.") = 161 & Get_RandomNumber(100000, 999999) newDR("QTY") = Frame_3D.cuttingList.Count newDR("Unit Price") = 26 * User_Input.frameSize productIDT.Rows.Add(newDR) End If 'Corners If Frame_3D.frameDT.Rows.Count - Frame_3D.sideFrameLengths.Count > 0 Then Dim newDR2 As DataRow = productIDT.NewRow newDR2("Description") = "Frame L-Profile Corner " & User_Input.frameSize & "x" & User_Input.frameSize newDR2("Art. Nr.") = 161 & Get_RandomNumber(100000, 999999) newDR2("QTY") = Frame_3D.frameDT.Rows.Count - Frame_3D.sideFrameLengths.Count newDR2("Unit Price") = 12 * User_Input.frameSize productIDT.Rows.Add(newDR2) End If End If For i = 0 To productIDT.Rows.Count - 1 productIDT.Rows(i)("Price") = productIDT.Rows(i)("Unit Price") * productIDT.Rows(i)("QTY") Next Return productIDT End Function End Class