Constancia

VB_CLS_Naviweb

Jul 12th, 2015
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 27.74 KB | None | 0 0
  1. Imports System.Windows.Forms
  2. Imports mshtml
  3.  
  4. Public Class NaviWeb
  5.  
  6.     Public L_Elemento As List(Of IHTMLElement)
  7.     Public oTabla As IHTMLTable, Tabla_TR As IHTMLTableRow, Tabla_TD As IHTMLTableCell
  8.     Private Doc As mshtml.HTMLDocument
  9.     Public oFrame As IHTMLFrameBase
  10.  
  11.     Public Sub New(oNav As AxSHDocVw.AxWebBrowser)
  12.         oNavegador = oNav
  13.         bbNaviScriptError = True
  14.         'oNavegador.ScriptErrorsSuppressed = bbNaviScriptError
  15.  
  16.     End Sub
  17.  
  18. #Region "PROPIEDADES"
  19.  
  20.  
  21.     Private _sError As String
  22.     Public Property sError() As String
  23.         Get
  24.             Return _sError
  25.         End Get
  26.         Set(value As String)
  27.             _sError = value
  28.         End Set
  29.     End Property
  30.  
  31.     Private oNavegador As AxSHDocVw.AxWebBrowser
  32.     Public Property Navegador() As AxSHDocVw.AxWebBrowser
  33.         Get
  34.             Return oNavegador
  35.         End Get
  36.         Set(oNav As AxSHDocVw.AxWebBrowser)
  37.             oNavegador = oNav
  38.         End Set
  39.     End Property
  40.  
  41.     Private bbNaviScriptError As Boolean
  42.     Public Property bNaviScriptError As Boolean
  43.         Get
  44.             Return bbNaviScriptError
  45.         End Get
  46.         Set(b As Boolean)
  47.             bbNaviScriptError = b
  48.         End Set
  49.     End Property
  50.  
  51.     Private _DocNavi As IHTMLDocument3
  52.     Public Property DocNavi() As IHTMLDocument3
  53.         Get
  54.             Return _DocNavi
  55.         End Get
  56.         Set(oDoc As IHTMLDocument3)
  57.             _DocNavi = oDoc
  58.         End Set
  59.     End Property
  60.  
  61.     Private _DocActivo As IHTMLDocument3
  62.     Public Property DocActivo() As IHTMLDocument3
  63.         Get
  64.             Return _DocActivo
  65.         End Get
  66.         Set(oDoc As IHTMLDocument3)
  67.             _DocActivo = oDoc
  68.         End Set
  69.     End Property
  70.  
  71.     Private oFormu As IHTMLFormElement
  72.     Public Property Formu() As IHTMLFormElement
  73.         Get
  74.             Return oFormu
  75.         End Get
  76.         Set(oForm As IHTMLFormElement)
  77.             oFormu = oForm
  78.         End Set
  79.     End Property
  80.  
  81.     Private oElemento As IHTMLElement
  82.     Public Property Elemento() As IHTMLElement
  83.         Get
  84.             Return oElemento
  85.         End Get
  86.         Set(Obj As IHTMLElement)
  87.             oElemento = Obj
  88.         End Set
  89.     End Property
  90.  
  91.     Private oEvento As IHTMLEventObj
  92.     Public Property Evento() As IHTMLEventObj
  93.         Get
  94.             'Return oEvento
  95.             Return _DocActivo.CreateEventObject()
  96.         End Get
  97.         Set(Obj As IHTMLEventObj)
  98.             oEvento = Obj
  99.         End Set
  100.     End Property
  101.  
  102.     Private oCombo As IHTMLSelectElement
  103.     Public Property Combo() As IHTMLSelectElement
  104.         Get
  105.             Return oCombo
  106.         End Get
  107.         Set(Obj As IHTMLSelectElement)
  108.             oCombo = Obj
  109.         End Set
  110.     End Property
  111.  
  112.     'Private _L_Elemento As List(Of IHTMLElement)
  113.     'Public Property L_Elemento() As List(Of IHTMLElement)
  114.     '    Get
  115.     '        Return _L_Elemento
  116.     '    End Get
  117.     '    Set(Obj As List(Of IHTMLElement))
  118.     '        _L_Elemento = Obj
  119.     '    End Set
  120.     'End Property
  121.  
  122.     Private bbComboValor As Boolean
  123.     Public Property bComboValor As Boolean
  124.         Get
  125.             Return bbComboValor
  126.         End Get
  127.         Set(b As Boolean)
  128.             bbComboValor = b
  129.         End Set
  130.     End Property
  131.  
  132.     '************* PROPIEDADES DE LAS VENTANA EMERGENTE 1
  133.     Private oNavegador_POP As AxSHDocVw.AxWebBrowser
  134.     Public Property Navegador_POP() As AxSHDocVw.AxWebBrowser
  135.         Get
  136.             Return oNavegador_POP
  137.         End Get
  138.         Set(oNav As AxSHDocVw.AxWebBrowser)
  139.             oNavegador_POP = oNav
  140.         End Set
  141.     End Property
  142.  
  143.     Private _DocActivo_POP As IHTMLDocument3
  144.     Public Property DocActivo_POP() As IHTMLDocument3
  145.         Get
  146.             Return _DocActivo_POP
  147.         End Get
  148.         Set(oDoc As IHTMLDocument3)
  149.             _DocActivo_POP = oDoc
  150.         End Set
  151.     End Property
  152.  
  153.     Private _bPop As Boolean
  154.     Public Property bPop() As Boolean
  155.         Get
  156.             Return _bPop
  157.         End Get
  158.         Set(value As Boolean)
  159.             _bPop = value
  160.         End Set
  161.     End Property
  162.  
  163.     Private _bPopVisible As Boolean
  164.     Public Property bPopVisible() As Boolean
  165.         Get
  166.             Return _bPopVisible
  167.         End Get
  168.         Set(value As Boolean)
  169.             _bPopVisible = value
  170.         End Set
  171.     End Property
  172.  
  173.     Private _TituloPop As String
  174.     Public Property TituloPop() As String
  175.         Get
  176.             Return _TituloPop
  177.         End Get
  178.         Set(value As String)
  179.             _TituloPop = value
  180.         End Set
  181.     End Property
  182.  
  183.     '************* PROPIEDADES DE LAS VENTANA EMERGENTE 2
  184.  
  185.     'Private oNavegador_POP2 As AxSHDocVw.AxWebBrowser
  186.     'Public Property Navegador_POP2() As AxSHDocVw.AxWebBrowser
  187.     '    Get
  188.     '        Return oNavegador_POP2
  189.     '    End Get
  190.     '    Set(oNav As AxSHDocVw.AxWebBrowser)
  191.     '        oNavegador_POP2 = oNav
  192.     '    End Set
  193.     'End Property
  194.  
  195.     'Private _DocActivo_POP2 As IHTMLDocument3
  196.     'Public Property DocActivo_POP2() As IHTMLDocument3
  197.     '    Get
  198.     '        Return _DocActivo_POP2
  199.     '    End Get
  200.     '    Set(oDoc As IHTMLDocument3)
  201.     '        _DocActivo_POP2 = oDoc
  202.     '    End Set
  203.     'End Property
  204.  
  205.     Private _bPop2 As Boolean
  206.     Public Property bPop2() As Boolean
  207.         Get
  208.             Return _bPop2
  209.         End Get
  210.         Set(value As Boolean)
  211.             _bPop2 = value
  212.         End Set
  213.     End Property
  214.  
  215.     Private _bPopVisible2 As Boolean
  216.     Public Property bPopVisible2() As Boolean
  217.         Get
  218.             Return _bPopVisible2
  219.         End Get
  220.         Set(value As Boolean)
  221.             _bPopVisible2 = value
  222.         End Set
  223.     End Property
  224.  
  225.     Private _TituloPop2 As String
  226.     Public Property TituloPop2() As String
  227.         Get
  228.             Return _TituloPop2
  229.         End Get
  230.         Set(value As String)
  231.             _TituloPop2 = value
  232.         End Set
  233.     End Property
  234.  
  235.  
  236.     '************* PROPIEDADES DE LAS VENTANA EMERGENTE 3
  237.  
  238.     'Private oNavegador_POP2 As AxSHDocVw.AxWebBrowser
  239.     'Public Property Navegador_POP2() As AxSHDocVw.AxWebBrowser
  240.     '    Get
  241.     '        Return oNavegador_POP2
  242.     '    End Get
  243.     '    Set(oNav As AxSHDocVw.AxWebBrowser)
  244.     '        oNavegador_POP2 = oNav
  245.     '    End Set
  246.     'End Property
  247.  
  248.     'Private _DocActivo_POP2 As IHTMLDocument3
  249.     'Public Property DocActivo_POP2() As IHTMLDocument3
  250.     '    Get
  251.     '        Return _DocActivo_POP2
  252.     '    End Get
  253.     '    Set(oDoc As IHTMLDocument3)
  254.     '        _DocActivo_POP2 = oDoc
  255.     '    End Set
  256.     'End Property
  257.  
  258.     Private _bPop3 As Boolean
  259.     Public Property bPop3() As Boolean
  260.         Get
  261.             Return _bPop3
  262.         End Get
  263.         Set(value As Boolean)
  264.             _bPop3 = value
  265.         End Set
  266.     End Property
  267.  
  268.     Private _bPopVisible3 As Boolean
  269.     Public Property bPopVisible3() As Boolean
  270.         Get
  271.             Return _bPopVisible3
  272.         End Get
  273.         Set(value As Boolean)
  274.             _bPopVisible3 = value
  275.         End Set
  276.     End Property
  277.  
  278.     Private _TituloPop3 As String
  279.     Public Property TituloPop3() As String
  280.         Get
  281.             Return _TituloPop3
  282.         End Get
  283.         Set(value As String)
  284.             _TituloPop3 = value
  285.         End Set
  286.     End Property
  287.  
  288. #End Region
  289.  
  290. #Region "MÉTODOS PÚBLICOS"
  291.  
  292.     Public Sub Navegar(sURL As String)
  293.         oNavegador.Navigate(sURL)
  294.         EsperaCarga(3)
  295.         _DocNavi = oNavegador.Document
  296.     End Sub
  297.  
  298.     ''' <summary>
  299.     '''
  300.     ''' </summary>
  301.     ''' <param name="iEstado">3-Interactive / 4-Complete</param>
  302.     ''' <remarks></remarks>
  303.     Public Sub EsperaCarga(iEstado As Integer)
  304.         While oNavegador.ReadyState <> iEstado And oNavegador.ReadyState <> 4
  305.             Application.DoEvents()
  306.         End While
  307.     End Sub
  308.  
  309.     Public Function DameDoc(Tipo As String, Optional Id As String = "", _
  310.                             Optional Nombre As String = "", _
  311.                             Optional Texto As String = "", _
  312.                             Optional bTextoExacto As Boolean = True, _
  313.                             Optional Atributo As String = "", _
  314.                             Optional ValAtributo As String = "", _
  315.                             Optional bAtributoExacto As Boolean = True,
  316.                             Optional bCol As Boolean = False, _
  317.                             Optional sHTML As String = "", _
  318.                             Optional bHTMLExacto As Boolean = True) As Boolean
  319.  
  320.         DameDoc = False
  321.  
  322.         Dim Docu As IHTMLDocument3
  323.         Dim DocuTemp1 As IHTMLDocument3, DocuTemp2 As IHTMLDocument3, DocuTemp3 As IHTMLDocument3, DocuTemp4 As IHTMLDocument3, DocuTemp5 As IHTMLDocument3
  324.         Dim iFrame1 As Integer, iFrame2 As Integer, iFrame3 As Integer, iFrame4 As Integer, iFrame5 As Integer
  325.  
  326.         Docu = oNavegador.Document
  327.  
  328.         '************************************************************************>> EL DOCUMENTO NO TIENE FRAMES
  329.         If Docu.frames.length = 0 Then
  330.  
  331.             If ExisteElemento(Docu, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  332.                 _DocActivo = Docu : Return True
  333.             End If
  334.  
  335.         Else
  336.             '***********************************************************************************>> FRAMES NIVEL1
  337.             For iFrame1 = 0 To Docu.frames.length - 1
  338.  
  339.                 DocuTemp1 = Docu.frames(iFrame1).document
  340.                 If ExisteElemento(DocuTemp1, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  341.                     _DocActivo = DocuTemp1 : Return True
  342.                 End If
  343.  
  344.                 If DocuTemp1.frames.length > 0 Then
  345.  
  346.                     '****************************************************************************>> FRAMES NIVEL2
  347.                     For iFrame2 = 0 To DocuTemp1.frames.length - 1
  348.  
  349.                         DocuTemp2 = DocuTemp1.frames(iFrame2).document
  350.                         If ExisteElemento(DocuTemp2, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  351.                             _DocActivo = DocuTemp2 : Return True
  352.                         End If
  353.  
  354.                         If DocuTemp2.frames.length > 0 Then
  355.                             '**********************************************************************>> FRAMES NIVEL3
  356.                             For iFrame3 = 0 To DocuTemp2.frames.length - 1
  357.  
  358.                                 DocuTemp3 = DocuTemp2.frames(iFrame3).document
  359.                                 If ExisteElemento(DocuTemp3, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  360.                                     _DocActivo = DocuTemp3 : Return True
  361.                                 End If
  362.  
  363.                                 If DocuTemp3.frames.length > 0 Then
  364.  
  365.                                     '***************************************************************>> FRAMES NIVEL4
  366.                                     For iFrame4 = 0 To DocuTemp3.frames.length - 1
  367.  
  368.                                         DocuTemp4 = DocuTemp3.frames(iFrame4).document
  369.                                         If ExisteElemento(DocuTemp4, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  370.                                             _DocActivo = DocuTemp4 : Return True
  371.                                         End If
  372.  
  373.                                         If DocuTemp4.frames.length > 0 Then
  374.  
  375.                                             '*******************************************************>> FRAMES NIVEL5
  376.                                             For iFrame5 = 0 To DocuTemp4.frames.length - 1
  377.  
  378.                                                 DocuTemp5 = DocuTemp4.frames(iFrame5).document
  379.                                                 If ExisteElemento(DocuTemp5, Tipo, Id, Nombre, Texto, bTextoExacto, Atributo, ValAtributo, bAtributoExacto, bCol, sHTML, bHTMLExacto) Then
  380.                                                     _DocActivo = DocuTemp5 : Return True
  381.                                                 End If
  382.  
  383.                                                 'If Docu.frames.length > 0 Then
  384.  
  385.                                                 'End If
  386.  
  387.                                             Next
  388.                                             '*******************************************************>> FRAMES NIVEL5
  389.  
  390.                                         End If
  391.  
  392.                                     Next
  393.                                     '***************************************************************>> FRAMES NIVEL4
  394.  
  395.                                 End If
  396.  
  397.                             Next
  398.                             '***********************************************************************>> FRAMES NIVEL3
  399.                         End If
  400.  
  401.                     Next
  402.                     '********************************************************************************>> FRAMES NIVEL2
  403.                 End If
  404.  
  405.             Next
  406.             '****************************************************************************************>> FRAMES NIVEL1
  407.         End If
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.     End Function
  415.  
  416.  
  417.     'Public Function ExisteElemento(oDoc As IHTMLDocument3, Tipo As String, _
  418.     '                               Optional Id As String = "", _
  419.     '                               Optional Nombre As String = "", _
  420.     '                               Optional Texto As String = "", _
  421.     '                               Optional bTextoExacto As Boolean = True, _
  422.     '                               Optional Atributo As String = "", _
  423.     '                               Optional ValAtributo As String = "", _
  424.     '                               Optional bAtributoExacto As Boolean = True,
  425.     '                               Optional bCol As Boolean = False, _
  426.     '                               Optional sHTML As String = "", _
  427.     '                               Optional bHTMLExacto As Boolean = True) As Boolean
  428.  
  429.  
  430.  
  431.     '    Dim bItem As Boolean
  432.     '    ' Dim bItemCol As Boolean = False
  433.  
  434.     '    bItem = False
  435.     '    ExisteElemento = False
  436.  
  437.     '    'Doc = DirectCast(oDoc, mshtml.HTMLDocument)
  438.     '    'Doc = Nothing
  439.  
  440.     '    If bCol Then L_Elemento = New List(Of IHTMLElement)
  441.  
  442.     '    'For Each item In oDoc.getElementsByName(Nombre)
  443.     '    '    If Nombre <> "" And item.Name = Nombre Then ExisteElemento = True
  444.     '    '    Debug.Print(item.name)
  445.     '    'Next
  446.  
  447.     '    For Each item In oDoc.getElementsByTagName(Tipo)
  448.  
  449.  
  450.     '        'Debug.Print(item.name)
  451.  
  452.     '        '******** ID
  453.     '        If Id <> "" And item.Id = Id Then bItem = True
  454.  
  455.     '        '******** NOMBRE
  456.     '        If Nombre <> "" Then
  457.     '            If item.Name = Nombre Then bItem = True
  458.     '        End If
  459.  
  460.     '        '******** TEXTO
  461.     '        If Texto <> "" Then
  462.     '            If bTextoExacto And Trim(UCase(item.InnerText)) = Trim(UCase(Texto)) Then
  463.     '                bItem = True
  464.     '            End If
  465.     '            If Not bTextoExacto And InStr(1, Trim(UCase(item.InnerText)), Trim(UCase(Texto))) > 0 Then
  466.     '                bItem = True
  467.     '            End If
  468.     '        End If
  469.  
  470.     '        '******** HTML
  471.     '        Try
  472.     '            If sHTML <> "" Then
  473.     '                If bHTMLExacto And item.InnerHTML = sHTML Then
  474.     '                    bItem = True
  475.     '                End If
  476.     '                If Not bHTMLExacto And InStr(1, item.InnerHTML, sHTML) > 0 Then
  477.     '                    bItem = True
  478.     '                End If
  479.     '            End If
  480.     '        Catch ex As Exception
  481.     '        End Try
  482.  
  483.     '        '******** ATRIBUTO
  484.     '        If Atributo <> "" Then
  485.  
  486.     '            If Not item.GetAttribute(Atributo) Is Nothing Then
  487.  
  488.     '                If bAtributoExacto Then
  489.     '                    If item.GetAttribute(Atributo).ToString = ValAtributo Then bItem = True
  490.     '                Else
  491.     '                    If InStr(1, item.GetAttribute(Atributo).ToString, ValAtributo) > 0 Then bItem = True
  492.     '                End If
  493.  
  494.     '            End If
  495.  
  496.     '            'If bAtributoExacto And item.GetAttribute(Atributo) = ValAtributo Then
  497.     '            '    ExisteElemento = True
  498.     '            'End If
  499.     '            'If Not bAtributoExacto And InStr(1, item.GetAttribute(Atributo), ValAtributo) > 0 Then
  500.     '            '    ExisteElemento = True
  501.     '            'End If
  502.  
  503.     '        End If
  504.  
  505.     '        If bItem Then
  506.     '            oElemento = item
  507.     '            If Tipo = "SELECT" Then oCombo = oElemento
  508.     '            If Tipo = "TABLE" Then oTabla = oElemento
  509.     '            If bCol Then L_Elemento.Add(oElemento) Else Return bItem
  510.     '            bItem = False
  511.     '        End If
  512.  
  513.     '    Next
  514.  
  515.     '    If bCol And L_Elemento.Count > 0 Then Return True
  516.  
  517.     '    Return False
  518.  
  519.     'End Function
  520.  
  521.  
  522.     '**************************************************************************************************************************************
  523.  
  524.  
  525.     ''' <summary>
  526.     '''
  527.     ''' </summary>
  528.     ''' <param name="oDoc">Documento HTML en el que se busca el Elemento</param>
  529.     ''' <param name="Tipo">Tipo de TAG HTML</param>
  530.     ''' <param name="Id"></param>
  531.     ''' <param name="Nombre"></param>
  532.     ''' <param name="Texto"></param>
  533.     ''' <param name="bTextoExacto"></param>
  534.     ''' <param name="Atributo"></param>
  535.     ''' <param name="ValAtributo"></param>
  536.     ''' <param name="bAtributoExacto"></param>
  537.     ''' <param name="bCol">Si es True Rellena un List con todos los Elementos que coincidan</param>
  538.     ''' <returns></returns>
  539.     ''' <remarks></remarks>
  540.     Public Function ExisteElemento(oDoc As IHTMLDocument3, Tipo As String, _
  541.                                    Optional Id As String = "", _
  542.                                    Optional Nombre As String = "", _
  543.                                    Optional Texto As String = "", _
  544.                                    Optional bTextoExacto As Boolean = True, _
  545.                                    Optional Atributo As String = "", _
  546.                                    Optional ValAtributo As String = "", _
  547.                                    Optional bAtributoExacto As Boolean = True,
  548.                                    Optional bCol As Boolean = False, _
  549.                                    Optional sHTML As String = "", _
  550.                                    Optional bHTMLExacto As Boolean = True) As Boolean
  551.  
  552.  
  553.  
  554.  
  555.         Dim bElemento As Boolean = False
  556.         ExisteElemento = False
  557.  
  558.         'Doc = DirectCast(oDoc, mshtml.HTMLDocument)
  559.         'Doc = Nothing
  560.  
  561.         If bCol Then L_Elemento = New List(Of IHTMLElement)
  562.  
  563.         'For Each item In oDoc.getElementsByName(Nombre)
  564.         '    If Nombre <> "" And item.Name = Nombre Then bElemento = True
  565.         '    Debug.Print(item.name)
  566.         'Next
  567.  
  568.         For Each item In oDoc.getElementsByTagName(Tipo)
  569.  
  570.             'ExisteElemento = False
  571.  
  572.             'Debug.Print(item.name)
  573.  
  574.             '******** ID
  575.             If Id <> "" And item.Id = Id Then bElemento = True
  576.  
  577.             '******** NOMBRE
  578.             If Nombre <> "" Then
  579.                 If item.Name = Nombre Then bElemento = True
  580.             End If
  581.  
  582.             '******** TEXTO
  583.             If Texto <> "" Then
  584.                 If bTextoExacto And Trim(UCase(item.InnerText)) = Trim(UCase(Texto)) Then
  585.                     bElemento = True
  586.                 End If
  587.                 If Not bTextoExacto And InStr(1, Trim(UCase(item.InnerText)), Trim(UCase(Texto))) > 0 Then
  588.                     bElemento = True
  589.                 End If
  590.             End If
  591.  
  592.             '******** HTML
  593.             Try
  594.                 If sHTML <> "" Then
  595.                     If bHTMLExacto And item.InnerHTML = sHTML Then
  596.                         bElemento = True
  597.                     End If
  598.                     If Not bHTMLExacto And InStr(1, item.InnerHTML, sHTML) > 0 Then
  599.                         bElemento = True
  600.                     End If
  601.                 End If
  602.             Catch ex As Exception
  603.             End Try
  604.  
  605.             '******** ATRIBUTO
  606.             If Atributo <> "" Then
  607.  
  608.                 If Not item.GetAttribute(Atributo) Is Nothing Then
  609.  
  610.                     If bAtributoExacto Then
  611.                         If item.GetAttribute(Atributo).ToString = ValAtributo Then bElemento = True
  612.                     Else
  613.                         If InStr(1, item.GetAttribute(Atributo).ToString, ValAtributo) > 0 Then bElemento = True
  614.                     End If
  615.  
  616.                 End If
  617.  
  618.                 'If bAtributoExacto And item.GetAttribute(Atributo) = ValAtributo Then
  619.                 '    bElemento = True
  620.                 'End If
  621.                 'If Not bAtributoExacto And InStr(1, item.GetAttribute(Atributo), ValAtributo) > 0 Then
  622.                 '    bElemento = True
  623.                 'End If
  624.  
  625.             End If
  626.  
  627.             If bElemento Then
  628.                 ExisteElemento = bElemento
  629.                 oElemento = item
  630.                 If Tipo = "SELECT" Then oCombo = oElemento
  631.                 If Tipo = "TABLE" Then oTabla = oElemento
  632.                 If bCol Then L_Elemento.Add(oElemento) Else Exit Function
  633.                 bElemento = False
  634.             End If
  635.  
  636.         Next
  637.  
  638.         ' If bCol And L_Elemento.Count > 0 Then Return True
  639.  
  640.     End Function
  641.  
  642.  
  643.     '**************************************************************************************************************************************
  644.  
  645.     'Public Function ExisteElemento2(oDoc As IHTMLDocument3, Tipo As String, _
  646.     '                              Optional Id As String = "", _
  647.     '                              Optional Nombre As String = "", _
  648.     '                              Optional Texto As String = "", _
  649.     '                              Optional bTextoExacto As Boolean = True, _
  650.     '                              Optional Atributo As String = "", _
  651.     '                              Optional ValAtributo As String = "", _
  652.     '                              Optional bAtributoExacto As Boolean = True,
  653.     '                              Optional bCol As Boolean = False, _
  654.     '                              Optional sHTML As String = "", _
  655.     '                              Optional bHTMLExacto As Boolean = True) As Boolean
  656.  
  657.     '    ExisteElemento2 = False
  658.  
  659.     '    Dim Docu As IHTMLDocument3
  660.     '    Dim iFrames As Integer
  661.  
  662.  
  663.     '    Doc = DirectCast(oDoc, mshtml.HTMLDocument)
  664.  
  665.  
  666.     '    If Doc.frames.length = 0 Then
  667.  
  668.     '    End If
  669.  
  670.  
  671.     '    For iFrames = 0 To Doc.frames.length
  672.  
  673.     '    Next
  674.  
  675.  
  676.     '    If bCol Then L_oElemento = New List(Of IHTMLElement)
  677.  
  678.     '    'For Each item In oDoc.getElementsByName(Nombre)
  679.     '    '    If Nombre <> "" And item.Name = Nombre Then ExisteElemento2 = True
  680.     '    '    Debug.Print(item.name)
  681.     '    'Next
  682.  
  683.     '    For Each item In oDoc.getElementsByTagName(Tipo)
  684.  
  685.     '        'Debug.Print(item.name)
  686.  
  687.     '        '******** ID
  688.     '        If Id <> "" And item.Id = Id Then ExisteElemento2 = True
  689.  
  690.     '        '******** NOMBRE
  691.     '        If Nombre <> "" And item.Name = Nombre Then
  692.     '            ExisteElemento2 = True
  693.     '        End If
  694.  
  695.     '        '******** TEXTO
  696.     '        If Texto <> "" Then
  697.     '            If bTextoExacto And item.InnerText = Texto Then
  698.     '                ExisteElemento2 = True
  699.     '            End If
  700.     '            If Not bTextoExacto And InStr(1, item.InnerText, Texto) > 0 Then
  701.     '                ExisteElemento2 = True
  702.     '            End If
  703.     '        End If
  704.  
  705.     '        '******** HTML
  706.     '        If sHTML <> "" Then
  707.     '            If bHTMLExacto And item.InnerHTML = sHTML Then
  708.     '                ExisteElemento2 = True
  709.     '            End If
  710.     '            If Not bHTMLExacto And InStr(1, item.InnerHTML, sHTML) > 0 Then
  711.     '                ExisteElemento2 = True
  712.     '            End If
  713.     '        End If
  714.  
  715.     '        '******** ATRIBUTO
  716.     '        If Atributo <> "" Then
  717.  
  718.     '            If Not item.GetAttribute(Atributo) Is Nothing Then
  719.  
  720.     '                If bAtributoExacto Then
  721.     '                    If item.GetAttribute(Atributo) = ValAtributo Then ExisteElemento2 = True
  722.     '                Else
  723.     '                    If InStr(1, item.GetAttribute(Atributo), ValAtributo) > 0 Then ExisteElemento2 = True
  724.     '                End If
  725.  
  726.     '            End If
  727.  
  728.     '            'If bAtributoExacto And item.GetAttribute(Atributo) = ValAtributo Then
  729.     '            '    ExisteElemento2 = True
  730.     '            'End If
  731.     '            'If Not bAtributoExacto And InStr(1, item.GetAttribute(Atributo), ValAtributo) > 0 Then
  732.     '            '    ExisteElemento2 = True
  733.     '            'End If
  734.  
  735.     '        End If
  736.  
  737.     '        If ExisteElemento2 Then
  738.     '            oElemento = item
  739.     '            If Tipo = "SELECT" Then oCombo = oElemento
  740.     '            If bCol Then L_oElemento.Add(oElemento) Else Exit Function
  741.     '        End If
  742.  
  743.     '    Next
  744.  
  745.     '    Doc = Nothing
  746.  
  747.     'End Function
  748.  
  749.     Public Function DameValor(oDoc As IHTMLDocument3, Tipo As String, Nombre As String) As String
  750.  
  751.         DameValor = ""
  752.  
  753.         If Not ExisteElemento(oDoc, Tipo, , Nombre) Then Exit Function
  754.  
  755.         DameValor = oElemento.value
  756.  
  757.     End Function
  758.  
  759.     Public Sub Click()
  760.         oElemento.click()
  761.     End Sub
  762.  
  763.     Public Sub Valor(sTexto As String, Optional bComboSel As Boolean = False, _
  764.                      Optional bFocus As Boolean = False, _
  765.                      Optional bOnFocus As Boolean = False, _
  766.                      Optional bOnChange As Boolean = False, _
  767.                      Optional bOnBlur As Boolean = False)
  768.  
  769.         On Error GoTo TrataError
  770.  
  771.  
  772.         If bFocus Then oElemento.focus()
  773.         If bOnFocus Then oElemento.onfocus()
  774.  
  775.         oElemento.setAttribute("value", sTexto)
  776.  
  777.         '*** El Elemento es un Combo
  778.         If bComboSel Then
  779.  
  780.             bbComboValor = False
  781.  
  782.             For i As Integer = 0 To oElemento.length - 1
  783.                 If Trim(UCase(oElemento.item(i).text)) = Trim(UCase(sTexto)) Then
  784.                     oElemento.selectedIndex = i : bbComboValor = True : Exit For
  785.                 End If
  786.             Next
  787.         End If
  788.  
  789.         If bOnChange Then oElemento.onchange()
  790.         If bOnBlur Then oElemento.onblur()
  791.  
  792.  
  793.         Exit Sub
  794. TrataError:
  795.  
  796.         _sError = "NaviWeb : Valor() : " & Err.Description
  797.     End Sub
  798.  
  799.     Public Function Combo_Elementos() As Integer
  800.         Combo_Elementos = oCombo.length
  801.     End Function
  802.  
  803.     Public Function Combo_ExisteValor(sValor As String) As Boolean
  804.  
  805.         Combo_ExisteValor = False
  806.  
  807.         For i As Integer = 0 To Combo_Elementos() - 1
  808.  
  809.             Debug.Print(Trim(UCase(oCombo.item(i).text)))
  810.  
  811.             If Trim(UCase(oCombo.item(i).text)) = Trim(UCase(sValor)) Then Combo_ExisteValor = True : Exit Function
  812.         Next
  813.  
  814.  
  815.     End Function
  816.  
  817.     Public Sub Espera(Num As Long)
  818.  
  819.         Dim i As Long
  820.         For i = 0 To Num * 250000
  821.             Application.DoEvents()
  822.         Next i
  823.  
  824.     End Sub
  825.  
  826.  
  827. #Region "TABLA"
  828.  
  829.     Public Function Tabla_Celda_Valor(Fila As Integer, Columna As Integer) As String
  830.  
  831.         If IsNothing(oTabla.rows(Fila).Cells(Columna).Innertext) Then Return ""
  832.  
  833.         Tabla_Celda_Valor = Trim(oTabla.rows(Fila).Cells(Columna).Innertext.ToString)
  834.  
  835.     End Function
  836.  
  837.     Public Function Tabla_Filas() As Integer
  838.         Tabla_Filas = oTabla.rows.length
  839.     End Function
  840.  
  841.     Public Function Tabla_Columnas(Fila As Integer) As Integer
  842.         Tabla_Columnas = oTabla.rows(Fila).cells.length
  843.     End Function
  844.  
  845. #End Region
  846.  
  847. #End Region
  848.  
  849. End Class
Advertisement
Add Comment
Please, Sign In to add comment