Imports System.Web Imports ULA.Davivienda.WCFServiciosCobisCartera.DAL Imports Ultimus.Utilitarios Public Class RegistrarSeguro Public Shared log As LogFile = New LogFile() #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 "RegistrarOperacionCartera" Public Function IniciarRegistrarSeguro(ByVal Solicitud As String, ByVal Proceso As String, ByVal strXML As String, ByVal Usuario As String, ByVal TipoSeguro As String) As String Dim strError As String = String.Empty Dim strPolizasSeguros 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("DatosIniciarRegistrarSeguro") rootElemento.appendChild(nElemento) Try '******************************************************************************* 'REGISTRAR EL SEGURO '******************************************************************************* ExecuteRegistrarSeguro(Proceso, strXML, strPolizasSeguros, Usuario, Solicitud, TipoSeguro) nElemento.text &= strPolizasSeguros Catch ex As Exception strError = "IniciarRegistrarSeguro - " & 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 "ExecuteRegistrarSeguro" Private Sub ExecuteRegistrarSeguro(ByVal Proceso As String, ByVal strXML As String, ByRef strXMLout As String, ByVal Usuario As String, ByVal Solicitud As String, ByVal TipoSeguro As String ) Dim strXMLRegistrarSeguro 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 strXMLRegistrarSeguro = RegistrarSeguro(Proceso, strXML, Usuario, Solicitud, TipoSeguro) xmlDoc.loadXML(strXMLRegistrarSeguro) xmlRootDoc = xmlDoc.documentElement If (Not IsNothing(xmlRootDoc.selectSingleNode("ERROR"))) Then Throw New Exception(xmlRootDoc.selectSingleNode("ERROR").text) End If If (Not IsNothing(xmlRootDoc.selectSingleNode("DatosRegistrarSeguro"))) Then strXMLout = xmlRootDoc.selectSingleNode("DatosRegistrarSeguro").xml End If Catch ex As Exception strError = "ExecuteRegistrarSeguro - " & ex.Message Throw New Exception(strError) End Try End Sub #End Region #Region "RegistrarSeguro" Private Function RegistrarSeguro(ByVal Proceso As String, ByVal strXML As String, ByVal Usuario As String, ByVal Solicitud As String, ByVal TipoSeguro 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 strPolizasSeguros As String = String.Empty Dim arrPolizasSeguros As String() = Nothing Dim arrItemPolizasSeguros As String() = Nothing Dim bRegisdtrado As Boolean = False Try objPI = xmlFormado.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'") xmlFormado.appendChild(objPI) rootElemento = xmlFormado.createElement("Resultado") xmlFormado.appendChild(rootElemento) nElemento = xmlFormado.createElement("DatosRegistrarSeguro") rootElemento.appendChild(nElemento) '*********************************************************************************** 'OBTIENE LA DATA DE LA FASE II DE LA OPERACION '*********************************************************************************** arrInfoCreditoFaseII = UtilitariaBD.BuscaOperacionSQL(Proceso, Solicitud, Usuario) strPolizasSeguros = arrInfoCreditoFaseII(4) log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 1 =>" & strPolizasSeguros) '*********************************************************************************** 'SI YA EXISTEN SEGUROS REGISTRADOS '*********************************************************************************** If (strPolizasSeguros.Trim() <> "") Then respXML.async = False respXML.preserveWhiteSpace = True respXML.validateOnParse = False respXML.loadXML(strXML) arrPolizasSeguros = strPolizasSeguros.Split("|") For Each strItemPoliza In arrPolizasSeguros log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 2 =>" & strItemPoliza) If (strItemPoliza.Trim() <> "") Then arrItemPolizasSeguros = strItemPoliza.Split("-") log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 3 =>" & TipoSeguro.Trim().ToUpper()) log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 4 =>" & TipoSeguro.Trim().ToUpper()) If TipoSeguro.Trim().ToUpper() = arrItemPolizasSeguros(0).Trim().ToUpper() Then bRegisdtrado = True Exit For End If End If Next End If If bRegisdtrado = True Then log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 4") '*************************************************************************************** 'Estado Proceso '*************************************************************************************** nElemento2 = xmlFormado.createElement("EstadoProceso") nElemento2.text = arrItemPolizasSeguros(1) nElemento.appendChild(nElemento2) log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 5") '*************************************************************************************** 'Poliza '*************************************************************************************** nElemento2 = xmlFormado.createElement("Poliza") nElemento2.text = arrItemPolizasSeguros(2) nElemento.appendChild(nElemento2) log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 6") Else log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 7") 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 log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 8") 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(17) & ":estadoProceso") Is Nothing Then Throw New Exception("No se encontro la variable de salida: " & arrPrefix(17) & ":estadoProceso") End If If (node.selectSingleNode(arrPrefix(17) & ":estadoProceso").text.Trim() = "N") Then strCode = node.selectSingleNode(arrPrefix(17) & ":codigoError").text strMessage = node.selectSingleNode(arrPrefix(17) & ":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(17) & ":estadoProceso").text nElemento.appendChild(nElemento2) '*************************************************************************************** 'Poliza '*************************************************************************************** If node.selectSingleNode(arrPrefix(17) & ":poliza") Is Nothing Then Throw New Exception("No se encontro la variable de salida: " & arrPrefix(17) & ":poliza") End If nElemento2 = xmlFormado.createElement("Poliza") nElemento2.text = node.selectSingleNode(arrPrefix(17) & ":poliza").text nElemento.appendChild(nElemento2) log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 9") '******************************************************************************* 'REGISTRAR POLIZAS EN SQL LOCAL '******************************************************************************* UtilitariaBD.GuardaOperacionSQL(Proceso, Solicitud, TipoSeguro & "-" & nElemento.selectSingleNode("EstadoProceso").text & "-" & nElemento.selectSingleNode("Poliza").text, "", Usuario) log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", "Seguros 10") End If Catch ex As Exception strError = "RegistrarSeguro - " & ex.Message log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", ex) 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