Imports System.Web Imports ULA.Davivienda.WCFServiciosCobisCartera.DAL Public Class RegistrarBeneficiario #Region "PROPIEDADES" Dim gProceso As String Dim gHttpServer As HttpServerUtility Dim arrPrefix As String() = New String() {} #End Region #Region "Constructor" Public Sub New(Proceso As String, ByRef httpServer As HttpServerUtility) gProceso = Proceso gHttpServer = httpServer End Sub #End Region #Region "RegistrarBeneficiario " Public Function IniciarRegistrarBeneficiario(ByVal Solicitud As String, ByVal Usuario As String, ByVal Proceso As String, ByVal strXML As String) As String Dim strError As String = String.Empty Dim strBeneficiariosREgistrados As String = String.Empty Dim respXML As MSXML2.DOMDocument = New MSXML2.DOMDocument() Dim xmlFormado As MSXML2.DOMDocument = New MSXML2.DOMDocument() Dim rootElemento As MSXML2.IXMLDOMNode Dim nElemento As MSXML2.IXMLDOMNode Dim objPI As MSXML2.IXMLDOMProcessingInstruction '------------------------------------------------------------------- Dim strSuccess As String = String.Empty Dim strCode As String = "0" Dim strMessage As String = String.Empty Dim strType As String = "0" '------------------------------------------------------------------- objPI = xmlFormado.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'") xmlFormado.appendChild(objPI) rootElemento = xmlFormado.createElement("Resultado") xmlFormado.appendChild(rootElemento) nElemento = xmlFormado.createElement("DatosIniciarRegistrarBeneficiario") rootElemento.appendChild(nElemento) Try '******************************************************************************* 'REGISTRAR EL BENEFICIARIO '******************************************************************************* ExecuteRegistrarBeneficiario(Proceso, strXML, strBeneficiariosREgistrados, Usuario, Solicitud) nElemento.text &= strBeneficiariosREgistrados Catch ex As Exception strError = "IniciarRegistrarBeneficiario - " & ex.Message Finally If strError <> "" Then nElemento = xmlFormado.createElement("ERROR") nElemento.text = strError rootElemento.appendChild(nElemento) End If End Try Return gHttpServer.HtmlDecode(xmlFormado.xml) End Function #End Region #Region "ExecuteRegistrarBeneficiario" Private Sub ExecuteRegistrarBeneficiario(ByVal Proceso As String, ByVal strXML As String, ByRef strXMLout As String, ByVal Usuario As String, ByVal Solicitud As String) Dim strXMLRegistrarBeneficiario As String = String.Empty Dim xmlDoc As MSXML2.DOMDocument = New MSXML2.DOMDocument() Dim xmlRootDoc As MSXML2.IXMLDOMNode Dim strError As String = String.Empty Try xmlDoc.async = False xmlDoc.preserveWhiteSpace = True xmlDoc.validateOnParse = False strXMLRegistrarBeneficiario = RegistrarBeneficiario(Solicitud, Usuario, Proceso, strXML) xmlDoc.loadXML(strXMLRegistrarBeneficiario) xmlRootDoc = xmlDoc.documentElement If (Not IsNothing(xmlRootDoc.selectSingleNode("ERROR"))) Then Throw New Exception(xmlRootDoc.selectSingleNode("ERROR").text) End If If (Not IsNothing(xmlRootDoc.selectSingleNode("DatosRegistrarBeneficiario"))) Then strXMLout = xmlRootDoc.selectSingleNode("DatosRegistrarBeneficiario").xml End If Catch ex As Exception strError = "ExecuteRegistrarBeneficiario - " & ex.Message Throw New Exception(strError) End Try End Sub #End Region #Region "RegistrarBeneficiario" Private Function RegistrarBeneficiario(ByVal Solicitud As String, ByVal Usuario As String, ByVal Proceso As String, ByVal strXML As String) As String Dim respXML As MSXML2.DOMDocument = New MSXML2.DOMDocument() Dim xmlFormado As MSXML2.DOMDocument = New MSXML2.DOMDocument() Dim node As MSXML2.IXMLDOMNode = Nothing Dim nElemento As MSXML2.IXMLDOMNode = Nothing Dim nElemento2 As MSXML2.IXMLDOMNode = Nothing Dim xmNodeMessages As MSXML2.IXMLDOMNode = Nothing Dim rootElemento As MSXML2.IXMLDOMNode = Nothing Dim objPI As MSXML2.IXMLDOMProcessingInstruction = Nothing '------------------------------------------------------------------- Dim strSuccess As String = String.Empty Dim strCode As String = "0" Dim strMessage As String = String.Empty Dim strType As String = "0" Dim strError As String = String.Empty Dim aCampos(34), aSoap(34) As String '------------------------------------------------------------------- Dim arrInfoCreditoFaseII() As String = New String(7) {"", "", "", "", "", "", "", ""} Dim strBeneficiariosREgistrados As String = String.Empty Dim arrBeneficiarios As String() = Nothing Dim arrItemBeneficiarios As String() = Nothing Try objPI = xmlFormado.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'") xmlFormado.appendChild(objPI) rootElemento = xmlFormado.createElement("Resultado") xmlFormado.appendChild(rootElemento) nElemento = xmlFormado.createElement("DatosRegistrarBeneficiario") rootElemento.appendChild(nElemento) '*********************************************************************************** 'OBTIENE LA DATA DE LA FASE II DE LA OPERACION '*********************************************************************************** arrInfoCreditoFaseII = UtilitariaBD.BuscaOperacionSQL(Proceso, Solicitud, Usuario) strBeneficiariosREgistrados = arrInfoCreditoFaseII(5) '*********************************************************************************** 'SI YA EXISTEN SEGUROS REGISTRADOS '*********************************************************************************** If (strBeneficiariosREgistrados.Trim().ToUpper() = "S") Then '*************************************************************************************** 'Estado Proceso '*************************************************************************************** nElemento2 = xmlFormado.createElement("EstadoProceso") nElemento2.text = strBeneficiariosREgistrados nElemento.appendChild(nElemento2) Else respXML.async = False respXML.preserveWhiteSpace = True respXML.validateOnParse = False respXML = outSoapConector.InvocaWebServiceSoap(strXML, strError, arrPrefix, Proceso, Usuario) If (strError.Trim().Length > 0) Then Throw New Exception(strError) End If node = respXML.childNodes(0).childNodes(0) '*************************************************************************************** 'Valida estructura de control de errores '*************************************************************************************** If (Not IsNothing(node.selectSingleNode(arrPrefix(2) & ":success"))) Then strSuccess = node.selectSingleNode(arrPrefix(2) & ":success").text If (strSuccess.Trim().ToLower() = "false") Then If (Not IsNothing(node.selectSingleNode(arrPrefix(2) & ":messages"))) Then xmNodeMessages = node.selectSingleNode(arrPrefix(2) & ":messages") strCode = xmNodeMessages.selectSingleNode("code").text strMessage = xmNodeMessages.selectSingleNode("message").text ' End If strError = "Error: Code:" & strCode & " - Message:" & strMessage & " - Type:" & strType Throw New Exception(strError) End If End If '*************************************************************************************** 'Valida tags de control de Errores '*************************************************************************************** If node.selectSingleNode(arrPrefix(18) & ":estadoProceso") Is Nothing Then Throw New Exception("No se encontro la variable de salida: " & arrPrefix(18) & ":estadoProceso") End If If (node.selectSingleNode(arrPrefix(18) & ":estadoProceso").text.Trim() = "N") Then strCode = node.selectSingleNode(arrPrefix(18) & ":codigoError").text strMessage = node.selectSingleNode(arrPrefix(18) & ":descripcionError").text strError = "Error: Code:" & strCode & " - Message:" & strMessage Throw New Exception(strError) End If '*************************************************************************************** 'Estado Proceso '*************************************************************************************** nElemento2 = xmlFormado.createElement("EstadoProceso") nElemento2.text = node.selectSingleNode(arrPrefix(18) & ":estadoProceso").text nElemento.appendChild(nElemento2) '******************************************************************************* 'REGISTRAR POLIZAS EN SQL LOCAL '******************************************************************************* UtilitariaBD.GuardaOperacionSQL(Proceso, Solicitud, "", nElemento.selectSingleNode("EstadoProceso").text, Usuario) End If Catch ex As Exception strError = "RegistrarBeneficiario - " & ex.Message Finally If strError <> "" Then nElemento = xmlFormado.createElement("ERROR") nElemento.text = strError rootElemento.appendChild(nElemento) End If End Try Return xmlFormado.xml End Function #End Region End Class