Imports System.Web Imports ULA.Davivienda.WCFServiciosCobisCartera.DAL Public Class CreacionGarantia #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 "IniciarCrearGarantia " Public Function IniciarCrearGarantia(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 strXMLGarantiaOut 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("DatosIniciarCrearGarantia") rootElemento.appendChild(nElemento) Try '******************************************************************************* 'REGISTRAR LA GARANTIA '******************************************************************************* ExecuteCrearGarantia(Proceso, strXML, strXMLGarantiaOut, Usuario, Solicitud) nElemento.text &= strXMLGarantiaOut Catch ex As Exception strError = "IniciarCrearGarantia - " & 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 "ExecuteCrearGarantia" Private Sub ExecuteCrearGarantia(ByVal Proceso As String, ByVal strXML As String, ByRef strXMLout As String, ByVal Usuario As String, ByVal Solicitud As String) Dim strXMLCrearGarantia 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 strXMLCrearGarantia = CrearGarantia(Solicitud, Usuario, Proceso, strXML) xmlDoc.loadXML(strXMLCrearGarantia) xmlRootDoc = xmlDoc.documentElement If (Not IsNothing(xmlRootDoc.selectSingleNode("ERROR"))) Then Throw New Exception(xmlRootDoc.selectSingleNode("ERROR").text) End If If (Not IsNothing(xmlRootDoc.selectSingleNode("DatosCrearGarantia"))) Then strXMLout = xmlRootDoc.selectSingleNode("DatosCrearGarantia").xml End If Catch ex As Exception strError = "ExecuteCrearGarantia - " & ex.Message Throw New Exception(strError) End Try End Sub #End Region #Region "CrearGarantia" Private Function CrearGarantia(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 strNumGarantia 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("DatosCrearGarantia") rootElemento.appendChild(nElemento) '*********************************************************************************** 'OBTIENE LA DATA DE LA FASE II DE LA OPERACION '*********************************************************************************** arrInfoCreditoFaseII = UtilitariaBD.BuscaOperacionSQL(Proceso, Solicitud, Usuario) strNumGarantia = arrInfoCreditoFaseII(6) '*********************************************************************************** 'SI YA EXISTEN SEGUROS REGISTRADOS '*********************************************************************************** If (Not String.IsNullOrEmpty(strNumGarantia)) Then '*************************************************************************************** 'Estado Proceso '*************************************************************************************** nElemento2 = xmlFormado.createElement("ESTADOPROCESO") nElemento2.text = "S" nElemento.appendChild(nElemento2) '*************************************************************************************** 'Codigo Externo '*************************************************************************************** nElemento2 = xmlFormado.createElement("NUMGARANTIA") nElemento2.text = strNumGarantia 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 '*************************************************************************************** 'Valida estructura de control de errores '*************************************************************************************** If (Not IsNothing(respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(2) & ":success"))) Then strSuccess = respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(2) & ":success").text If (strSuccess.Trim().ToLower() = "false") Then If (Not IsNothing(respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(2) & ":messages"))) Then xmNodeMessages = respXML.childNodes(0).childNodes(0).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 (Not IsNothing(respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(10) & ":estadoProceso"))) Then If (respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(10) & ":estadoProceso").text.Trim() = "N") Then strCode = respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(10) & ":codigoError").text strMessage = respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(10) & ":descripError").text strError = "Error: Code:" & strCode & " - Message:" & strMessage Throw New Exception(strError) End If End If '*************************************************************************************** node = respXML.childNodes(0).childNodes(0) '*************************************************************************************** 'Estado del Proceso '*************************************************************************************** If node.selectSingleNode(arrPrefix(10) & ":estadoProceso") Is Nothing Then Throw New Exception("No se encontro la variable de salida: ns9:estadoProceso") End If nElemento2 = xmlFormado.createElement("ESTADOPROCESO") nElemento2.text = node.selectSingleNode(arrPrefix(10) & ":estadoProceso").text nElemento.appendChild(nElemento2) '*************************************************************************************** 'Codigo Externo '*************************************************************************************** If node.selectSingleNode(arrPrefix(10) & ":codExterno") Is Nothing Then Throw New Exception("No se encontro la variable de salida: ns9:codExterno") End If nElemento2 = xmlFormado.createElement("NUMGARANTIA") nElemento2.text = node.selectSingleNode(arrPrefix(10) & ":codExterno").text nElemento.appendChild(nElemento2) '******************************************************************************* 'REGISTRAR POLIZAS EN SQL LOCAL '******************************************************************************* UtilitariaBD.GuardaGarantiaSQL(Proceso, Solicitud, nElemento.selectSingleNode("NUMGARANTIA").text, Usuario) End If Catch ex As Exception strError = "CrearGarantia - " & 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