Imports System.Web Imports ULA.Davivienda.WCFServiciosCobisCartera.DAL Imports System.Configuration Public Class CreacionOperacion #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 RegistrarOperacionCartera(ByVal Solicitud As String, ByVal Proceso As String, ByVal NumOperacion As String, ByVal strXML As String, ByVal Usuario As String ) As String Dim strError 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 nElementoIn 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" '------------------------------------------------------------------- Dim arrXMLCrearOperacion() As String = New String(7) {"", "", "", "", "", "", "", ""} Dim strXMLCrearOperacion As String = String.Empty Dim strXMLInCrearOperacion As String = String.Empty '------------------------------------------------------------------- objPI = xmlFormado.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'") xmlFormado.appendChild(objPI) rootElemento = xmlFormado.createElement("Resultado") xmlFormado.appendChild(rootElemento) nElemento = xmlFormado.createElement("DatosRegistrarOperacionCartera") nElementoIn = xmlFormado.createElement("DatosRegistrarOperacionCarteraIn") rootElemento.appendChild(nElemento) rootElemento.appendChild(nElementoIn) Try '*********************************************************************************** 'OBTIENE LA DATA DE LA OPERACION '*********************************************************************************** arrXMLCrearOperacion = UtilitariaBD.BuscaOperacionSQL(Proceso, Solicitud, Usuario) strXMLCrearOperacion = arrXMLCrearOperacion(0) strXMLInCrearOperacion = arrXMLCrearOperacion(1) '*********************************************************************************** 'SI YA EXISTE UN NUMERO DE OPERACION '*********************************************************************************** If (strXMLCrearOperacion.Trim() <> "") Then nElemento.text &= strXMLCrearOperacion nElementoIn.text &= strXMLInCrearOperacion Else '******************************************************************************* 'CREACION OPERACION '******************************************************************************* NumOperacion = ExecuteCrearOperacion(Proceso, strXML, strXMLCrearOperacion, Usuario) nElemento.text &= strXMLCrearOperacion Dim xmlEsquemaDev As MSXML2.DOMDocument = New MSXML2.DOMDocument() xmlEsquemaDev.async = False xmlEsquemaDev.validateOnParse = False xmlEsquemaDev.preserveWhiteSpace = True xmlEsquemaDev.loadXML(strXML) nElementoIn.text &= xmlEsquemaDev.documentElement.xml '******************************************************************************* 'REGISTRAR OPERACION SQL '******************************************************************************* UtilitariaBD.GuardaOperacionSQL(Proceso, Solicitud, NumOperacion, strXMLCrearOperacion, strXML, Usuario) End If Catch ex As Exception strError = "RegistrarOperacionCartera - " & 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 "ExecuteCrearOperacion" Private Function ExecuteCrearOperacion(ByVal Proceso As String, ByVal strXML As String, ByRef strXMLout As String, ByVal Usuario As String ) As String Dim strXMLCrearOperacion As String = String.Empty Dim xmlDoc As MSXML2.DOMDocument = New MSXML2.DOMDocument() Dim xmlRootDoc As MSXML2.IXMLDOMNode Dim xmlRootProc As MSXML2.IXMLDOMNode Dim strNumOperacion As String = String.Empty Dim strError As String = String.Empty Try xmlDoc.async = False xmlDoc.preserveWhiteSpace = True xmlDoc.validateOnParse = False strXMLCrearOperacion = CrearOperacion(Proceso, strXML, Usuario) xmlDoc.loadXML(strXMLCrearOperacion) xmlRootDoc = xmlDoc.documentElement If (Not IsNothing(xmlRootDoc.selectSingleNode("ERROR"))) Then Throw New Exception(xmlRootDoc.selectSingleNode("ERROR").text) End If If (Not IsNothing(xmlRootDoc.selectSingleNode("DatosOperacionCartera"))) Then xmlRootProc = xmlRootDoc.selectSingleNode("DatosOperacionCartera") strNumOperacion = xmlRootProc.selectSingleNode("num_operacion").text strXMLout = xmlRootProc.xml End If Catch ex As Exception strError = "ExecuteCrearOperacion - " & ex.Message Throw New Exception(strError) End Try Return strNumOperacion End Function #End Region #Region "CrearOperacion" Private Function CrearOperacion( ByVal Proceso As String, ByVal strXML As String, ByVal Usuario As String ) As String Dim strError As String = String.Empty Dim bIsDummie As Boolean = False Dim respXML As MSXML2.DOMDocument = New MSXML2.DOMDocument() Dim node As MSXML2.IXMLDOMNode Dim xmlFormado As MSXML2.DOMDocument = New MSXML2.DOMDocument() Dim rootElemento As MSXML2.IXMLDOMNode Dim nElemento = Nothing, nElemento2 = Nothing, nElemento3 = Nothing, nElemento4 As MSXML2.IXMLDOMNode = Nothing 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" Dim xmNodeMessages As MSXML2.IXMLDOMNode Dim aCampos(34), aSoap(34) As String '------------------------------------------------------------------- objPI = xmlFormado.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'") xmlFormado.appendChild(objPI) rootElemento = xmlFormado.createElement("Resultado") xmlFormado.appendChild(rootElemento) nElemento = xmlFormado.createElement("DatosOperacionCartera") rootElemento.appendChild(nElemento) Try respXML.async = False respXML.preserveWhiteSpace = True respXML.validateOnParse = False bIsDummie = ConfigurationManager.AppSettings("isDummie") If (bIsDummie) Then respXML.loadXML("true10410548553700119S007/12/201501/12/20228401/01/201601/01/2016255128401/01/201612.953.52.00.0572.91BYRON JOHANNES MADRIGAL UGALDEAGNNY PAMELA RODRIGUEZ HIDALGOSAN JOSEAUXILIARSAN RAFAEL CENTRO 100 N 50 E DE BAR REST LA CUBANA CASA MD COLOR GRISBanco Davivienda (COSTA RICA),S.A.31010460080MENSUAL01/01/20161.0COMERCIALTREINTA0.0ATLIB340106.8") arrPrefix = outSoapConector.ObtienePrefijosNameSpace(respXML, "WS_COBIS_1") Else respXML = outSoapConector.InvocaWebServiceSoap(strXML, strError, arrPrefix, Proceso, Usuario) End If 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(11) & ":estadoProceso"))) Then If (respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(11) & ":estadoProceso").text.Trim() = "N") Then strCode = respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(11) & ":codError").text strMessage = respXML.childNodes(0).childNodes(0).selectSingleNode(arrPrefix(11) & ":descripcionError").text strError = "Error: Code:" & strCode & " - Message:" & strMessage Throw New Exception(strError) End If End If '*************************************************************************************** node = respXML.childNodes(0).childNodes(0) '*************************************************************************************** 'Numero de Operacion '*************************************************************************************** If node.selectSingleNode(arrPrefix(11) & ":numOperacionGenerado") Is Nothing Then Throw New Exception("No se encontro la variable de salida: " & arrPrefix(11) & ":numOperacionGenerado") End If aCampos(0) = "num_operacion" aCampos(1) = "fecha_inicio" aCampos(2) = "fecha_vencim" aCampos(3) = "num_cuotas" aCampos(4) = "fe_1_pago_cap" aCampos(5) = "fe_1_pago_int" aCampos(6) = "plazo_dias" aCampos(7) = "fe_rev_tasa" aCampos(8) = "nu_ope_vigentes" aCampos(9) = "plazo" aCampos(10) = "fecha_pago_men" aCampos(11) = "dia_pago" aCampos(12) = "tasa_interes" aCampos(13) = "comision" aCampos(14) = "mora1" aCampos(15) = "mora2" aCampos(16) = "nom_fiador" aCampos(17) = "ced_fiador" aCampos(18) = "cuota_mens" aCampos(19) = "deudor" aCampos(20) = "nom_ejecutivo" aCampos(21) = "nom_sucursal" aCampos(22) = "calidades" aCampos(23) = "dir_cliente" aCampos(24) = "nom_acreedor" aCampos(25) = "cedula_acreedor" aCampos(26) = "periodo_gracia" aCampos(27) = "forma_pago" aCampos(28) = "fe_prox_pago" aCampos(29) = "spread" aCampos(30) = "base_operacion" aCampos(31) = "base_operacion1" aCampos(32) = "monto_mora" aCampos(33) = "tipo_tasa_base" aCampos(34) = "monto_desembolso" 'aCampos(34) = "frecuencia_pago" 'Es dependiendo el valor que se envie en el parametro de periodoPagoCapital : 1=MENSUAL,2:BIMESTRAL,3:TRIMESTRAL,4:CUATRIMESTRAL, 12=ANUAL ETC 'aCampos(35) = "abono" 'No se posee este valor 'aCampos(36) = "fecha_pago_quin" 'No se posee este valor 'aCampos(37) = "cuota_plas" 'Se envia en el parametro de entrada, por tanto se toma del spreadsheet aSoap(0) = arrPrefix(11) & ":numOperacionGenerado" aSoap(1) = arrPrefix(11) & ":fechaInicio" aSoap(2) = arrPrefix(11) & ":fechaFin" aSoap(3) = arrPrefix(11) & ":numCuotas" aSoap(4) = arrPrefix(11) & ":fechaPpagoCap" aSoap(5) = arrPrefix(11) & ":fechaPpagoInt" aSoap(6) = arrPrefix(11) & ":plazoDias" aSoap(7) = arrPrefix(11) & ":fechaRev" aSoap(8) = arrPrefix(11) & ":numOpVigentes" aSoap(9) = arrPrefix(11) & ":plazoMeses" aSoap(10) = arrPrefix(11) & ":fechaPago" aSoap(11) = arrPrefix(11) & ":diaPago" aSoap(12) = arrPrefix(11) & ":tasaInt" aSoap(13) = arrPrefix(11) & ":comision" aSoap(14) = arrPrefix(11) & ":mora1" aSoap(15) = arrPrefix(11) & ":mora2" aSoap(16) = arrPrefix(11) & ":nomFiador" aSoap(17) = arrPrefix(11) & ":ceduFiador" aSoap(18) = arrPrefix(11) & ":cuotaMensual" aSoap(19) = arrPrefix(11) & ":deudor" aSoap(20) = arrPrefix(11) & ":nomEjecutivo" aSoap(21) = arrPrefix(11) & ":nomSucursal" aSoap(22) = arrPrefix(11) & ":calidades" aSoap(23) = arrPrefix(11) & ":dirCliente" aSoap(24) = arrPrefix(11) & ":nomBanco" aSoap(25) = arrPrefix(11) & ":cedBanco" aSoap(26) = arrPrefix(11) & ":periodoGracia" aSoap(27) = arrPrefix(11) & ":formaPago" aSoap(28) = arrPrefix(11) & ":fechaProxPago" aSoap(29) = arrPrefix(11) & ":spread" aSoap(30) = arrPrefix(11) & ":baseOpe" aSoap(31) = arrPrefix(11) & ":baseOpe1" aSoap(32) = arrPrefix(11) & ":montoMora" aSoap(33) = arrPrefix(11) & ":tipoTasaBase" aSoap(34) = arrPrefix(11) & ":montoDesembolso" For J As Integer = 0 To aCampos.Length() - 1 outSoapConector.AgregarNodeValue(node, xmlFormado, nElemento2, nElemento, aSoap(J), aCampos(J)) Next outSoapConector.AgregarNodeValue(node, xmlFormado, nElemento2, nElemento, "default", "fiadores") outSoapConector.AgregarNodeValue(node, xmlFormado, nElemento3, nElemento2, "default", "fiador") outSoapConector.AgregarNodeValue(node, xmlFormado, nElemento4, nElemento3, arrPrefix(11) & ":nomFiador", "nom_fiador") outSoapConector.AgregarNodeValue(node, xmlFormado, nElemento4, nElemento3, arrPrefix(11) & ":ceduFiador", "ced_fiador") Catch ex As Exception strError = "CrearOperacion - " & ex.Message Finally If strError <> "" Then nElemento = xmlFormado.createElement("ERROR") nElemento.text = strError rootElemento.appendChild(nElemento) End If CrearOperacion = xmlFormado.xml End Try End Function #End Region End Class