Imports	System
Imports	Microsoft.Office.Interop.InfoPath.SemiTrust
Imports Microsoft.VisualBasic

' Office integration attribute. Identifies the startup class for the form. Do not
' modify.
<Assembly: System.ComponentModel.DescriptionAttribute("InfoPathStartupClass, Version=1.0, Class=r01ipnet.r01ipnet")>


Namespace r01ipnet


    ' The namespace prefixes defined in this attribute must remain synchronized with
    ' those in the form definition file (.xsf).
    <InfoPathNamespace("xmlns:xsf=""http://schemas.microsoft.com/office/infopath/2003/solutionDefinition"" xmlns:msxsl=""urn:schemas-microsoft-com:xslt"" xmlns:xd=""http://schemas.microsoft.com/office/infopath/2003"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xdUtil=""http://schemas.microsoft.com/office/infopath/2003/xslt/Util"" xmlns:xdXDocument=""http://schemas.microsoft.com/office/infopath/2003/xslt/xDocument"" xmlns:xdMath=""http://schemas.microsoft.com/office/infopath/2003/xslt/Math"" xmlns:xdDate=""http://schemas.microsoft.com/office/infopath/2003/xslt/Date"" xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-05-06T18:09:01""")> _
    Public Class r01ipnet


        Private thisXDocument As XDocument
        Private thisApplication As Application

        Public Sub _Startup(ByVal app As Application, ByVal doc As XDocument)
            thisXDocument = doc
            thisApplication = app

            ' Tutaj można wprowadzić dodatkowy kod inicjalizacji.
        End Sub

        ' Kod InfoPath.
        Public Sub _Shutdown()
            Dim wb As Microsoft.Office.Interop.Excel.Workbook
            Dim lo As Microsoft.Office.Interop.Excel.ListObject
            ' Przy założeniu, że szablon jest w tym samym folderze, co skoroszyt.
            Dim pth As String = System.IO.Path.GetFullPath(".")
            ' Pobranie skoroszytu w Excelu.
            wb = GetObject(pth & "\r01net.xls")
            ' Pobranie listy i zaimportowanie XML.
            lo = wb.Worksheets("Arkusz1").ListObjects("Lista1")
            lo.XmlMap.ImportXml(thisXDocument.DOM.xml)
        End Sub


        ' Alternatywnie można wykorzystać to zdarzenie w celu odświeżenia listy Excela.
        <InfoPathEventHandler(EventType:=InfoPathEventType.OnSaveRequest)> _
        Public Sub OnSaveRequest(ByVal e As SaveEvent)
            ' Tu wpisz kod, który ma się uruchomić przed zapisem.

            e.IsCancelled = e.PerformSaveOperation


            e.ReturnStatus = True
        End Sub

        ' Ten przycisk ułatwia debugowanie procedury _Shutdown.
        ' Aby wyświetlić przycisk, wpisz "Debug" w polu "Wybierz obiekt:".
        <InfoPathEventHandler(MatchPath:="CTRL11_5", EventType:=InfoPathEventType.OnClick)> _
        Public Sub CTRL11_5_OnClick(ByVal e As DocActionEvent)
            _Shutdown()
            ' Zamknięcie formularza.
            'thisApplication.XDocuments.Close(thisXDocument)
        End Sub
    End Class


End Namespace
