Imports Microsoft.Office.InfoPath Imports System.Windows.Forms Imports mshtml Imports System Imports System.Xml Imports System.Xml.XPath Namespace PQRR Public Class FormCode ' Member variables are not supported in browser-enabled forms. ' Instead, write and read these values from the FormState ' dictionary using code such as the following: ' ' Private Property _memberVariable() As Object ' Get ' _memberVariable = FormState("_memberVariable") ' End Get ' Set ' FormState("_memberVariable") = value ' End Set ' End Property ' NOTE: The following procedure is required by Microsoft InfoPath. ' It can be modified using Microsoft InfoPath. Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup AddHandler EventManager.XmlEvents("/my:myFields/my:HiddenFields/my:GCCXElements").Changed, AddressOf Load_Gate_Elements End Sub Public Sub Load_Gate_Elements(ByVal sender As Object, ByVal e As XmlEventArgs) ' Write your code here to change the main data source. ' CurrentView.ExecuteAction(ActionType.XCollectionInsert, "XmlToEdit") ' Dim fieldValue As String = MainDataSource.CreateNavigator().SelectSingleNode( _ ' "/my:myFields/my:field1", NamespaceManager).Value Dim nav As XPathNavigator = MainDataSource.CreateNavigator() ' The following chunk of lines imports the number of elements associated with the selected Gate. ' The underlying data for the Gates is stored in the following SharePoint list: ' https://gmweb.gm.com/sites/qualityreporting/Lists/GVDP%20Events/AllItems.aspx ' This will determine how many rows we need to add/remove to the Repeating Sections. Dim quality As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:QualityElements", NamespaceManager).Value) Dim engineering As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:EngineeringElements", NamespaceManager).Value) Dim ppm As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:PPMElements", NamespaceManager).Value) Dim corpdev As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:CorpDevElements", NamespaceManager).Value) Dim manufacturing As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:ManufacturingElements", NamespaceManager).Value) Dim finance As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:FinanceElements", NamespaceManager).Value) Dim design As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:DesignElements", NamespaceManager).Value) Dim gpsc As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:GPSCElements", NamespaceManager).Value) Dim marketing As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:MarketingElements", NamespaceManager).Value) Dim gccx As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:GCCXElements", NamespaceManager).Value) ' Debug ' Quality Section ' Determine the number of rows in the Quality section Dim current As Integer = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:QualityTotal", NamespaceManager).Value) Dim groupRoot As String = "/my:myFields/my:Quality" AddRemove_SectionRows(current, quality, "group23_205", groupRoot) ' Engineering Section ' Determine the number of rows in the Engineering section current = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:EngineeringTotal", NamespaceManager).Value) groupRoot = "/my:myFields/my:Engineering" AddRemove_SectionRows(current, engineering, "group17_215", groupRoot) ' Manufacturing Section ' Determine the number of rows in the Manufacturing section current = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:ManufacturingTotal", NamespaceManager).Value) groupRoot = "/my:myFields/my:Manufacturing" AddRemove_SectionRows(current, manufacturing, "Manufacturing_410", groupRoot) ' PPM Section ' Determine the number of rows in the PPM section current = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:PPMTotal", NamespaceManager).Value) groupRoot = "/my:myFields/my:PPM" AddRemove_SectionRows(current, ppm, "PPM_411", groupRoot) ' Finance Section ' Determine the number of rows in the Finance section current = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:FinanceTotal", NamespaceManager).Value) groupRoot = "/my:myFields/my:Finance" AddRemove_SectionRows(current, finance, "Finance_412", groupRoot) ' Design Section ' Determine the number of rows in the Finance section current = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:DesignTotal", NamespaceManager).Value) groupRoot = "/my:myFields/my:Design" AddRemove_SectionRows(current, design, "Design_413", groupRoot) ' GPSC Section ' Determine the number of rows in the GPSC section current = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:GPSCTotal", NamespaceManager).Value) groupRoot = "/my:myFields/my:GPSC" AddRemove_SectionRows(current, gpsc, "GPSC_414", groupRoot) ' Marketing Section ' Determine the number of rows in the Marketing section current = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:MarketingTotal", NamespaceManager).Value) groupRoot = "/my:myFields/my:Marketing" AddRemove_SectionRows(current, marketing, "Marketing_415", groupRoot) ' CorpDev Section ' Determine the number of rows in the CorpDev section current = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:CorpDevTotal", NamespaceManager).Value) groupRoot = "/my:myFields/my:CorpDev" AddRemove_SectionRows(current, corpdev, "CorpDev_416", groupRoot) ' GCCX Section ' Determine the number of rows in the GCCX section current = CInt(nav.SelectSingleNode("/my:myFields/my:HiddenFields/my:GCCXTotal", NamespaceManager).Value) groupRoot = "/my:myFields/my:GCCX" AddRemove_SectionRows(current, gccx, "GCCX_417", groupRoot) End Sub Public Sub AddRemove_SectionRows(ByVal currentNumRows As Integer, ByVal neededNumRows As Integer, ByVal groupXMLtoEdit As String, ByVal group2delete As String) ' Loop While currentNumRows < neededNumRows CurrentView.ExecuteAction(ActionType.XCollectionInsert, groupXMLtoEdit) currentNumRows += 1 End While While currentNumRows > neededNumRows Dim selection As String = group2delete + "[" + CStr(currentNumRows) + "]" MainDataSource.CreateNavigator().SelectSingleNode(selection, NamespaceManager).DeleteSelf() currentNumRows -= 1 End While End Sub End Class End Namespace