public ResultadoValidaciones validar(string mensajeXml, ResultadoValidaciones resultadoValidaciones) { XPathDocument document = new XPathDocument(XmlReader.Create(new StringReader(mensajeXml))); XPathNavigator navigator = document.CreateNavigator(); try { Double monto = Double.Parse(navigator.SelectSingleNode("/notaVenta/monto").Value); Double porcentajeImpuesto = Double.Parse(navigator.SelectSingleNode("/notaVenta/porcentajeImpuesto").Value); Double total = Double.Parse(navigator.SelectSingleNode("/notaVenta/total").Value); if (monto * porcentajeImpuesto != total) { resultadoValidaciones.agregarEvento(new EventoValidacion { error = "Total no cuadra con monto por impuesto", accion = "Corregir total" }); } } catch (Exception ex) { resultadoValidaciones.agregarEvento(new EventoValidacion { error = "No se pudo evaluar los calculos", accion = "Revisar" }); } return(resultadoValidaciones); }
public void SetNumeroAutorizacion(ResultadoValidaciones resultadoValidaciones) { this.resultadoValidaciones = resultadoValidaciones; if (this.resultadoValidaciones.resultadoValidacion == ResultadoValidacionEnum.OK) { numeroAutorizacion = 100 + new Random().Next(10000); } }
public ResultadoValidaciones validar(string mensajeXml, ResultadoValidaciones resultadoValidaciones) { XPathDocument document = new XPathDocument(XmlReader.Create(new StringReader(mensajeXml))); XPathNavigator navigator = document.CreateNavigator(); try { string categoria = navigator.SelectSingleNode("/notaVenta/categoria").Value; Double monto = Double.Parse(navigator.SelectSingleNode("/notaVenta/monto").Value); Double porcentajeImpuesto = Double.Parse(navigator.SelectSingleNode("/notaVenta/porcentajeImpuesto").Value); Double total = Double.Parse(navigator.SelectSingleNode("/notaVenta/total").Value); if (categoria == "VIVERES" && porcentajeImpuesto != 0) { resultadoValidaciones.agregarEvento(new EventoValidacion { error = "Tasa no aplica a " + categoria, accion = "Corregir" }); } if (categoria == "LICORES" && porcentajeImpuesto != 10) { resultadoValidaciones.agregarEvento(new EventoValidacion { error = "Tasa no aplica a " + categoria, accion = "Corregir" }); } if (categoria == "LIMPIEZA" && porcentajeImpuesto != 7) { resultadoValidaciones.agregarEvento(new EventoValidacion { error = "Tasa no aplica a " + categoria, accion = "Corregir" }); } Double totalCalculado = monto + (monto * porcentajeImpuesto / 100); if (totalCalculado != total) { resultadoValidaciones.agregarEvento( new EventoValidacion { error = "Total no cuadra con monto por impuesto (calculado: " + totalCalculado + " total: " + total, accion = "Corregir total" }); } } catch (Exception ex) { resultadoValidaciones.agregarEvento(new EventoValidacion { error = "No se pudo evaluar los calculos" + ex.Message, accion = "Revisar" }); } return(resultadoValidaciones); }
// TODO: REVISAR PARA CAMBIAR A XmlSchemaValidator Push-Based Validation public ResultadoValidaciones validar(string mensajeXml, ResultadoValidaciones resultadoValidaciones) { this.resultadoValidaciones = resultadoValidaciones; XmlReaderSettings feSettings = new XmlReaderSettings(); feSettings.Schemas.Add(feNameSpace, new XmlTextReader(HostingEnvironment.MapPath(xsdFile))); feSettings.ValidationType = ValidationType.Schema; feSettings.ValidationEventHandler += new ValidationEventHandler(feSettingsValidationEventHandler); XmlReader deXml = XmlReader.Create(new StringReader(mensajeXml), feSettings); while (deXml.Read()) { } return(this.resultadoValidaciones); }
// TODO: REVISAR PARA CAMBIAR A XmlSchemaValidator Push-Based Validation public ResultadoValidaciones validar(string mensajeXml, ResultadoValidaciones resultadoValidaciones) { this.resultadoValidaciones = resultadoValidaciones; XmlReaderSettings feSettings = new XmlReaderSettings(); feSettings.ValidationType = ValidationType.Schema; feSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; //XmlTextReader xmltxtreader = new XmlTextReader(xsdFile); feSettings.Schemas.Add(feNameSpace, xsdFile); feSettings.ValidationEventHandler += new ValidationEventHandler(feSettingsValidationEventHandler); XmlReader deXml = XmlReader.Create(new StringReader(mensajeXml), feSettings); while (deXml.Read()) { } deXml.Close(); return(this.resultadoValidaciones); }
private MensajeRespuesta validarNV(MensajeEntrada mensajeEntrada) { ResultadoValidaciones resultadoValidaciones = new ResultadoValidaciones(); if (validarEsquemaFlag == "1") { ValidarSchema validarEsquema = new ValidarSchema(); validarEsquema.validar(mensajeEntrada.mensaje, resultadoValidaciones); } if (validarCalculosFlag == "1") { ValidarCalculos validarCalculos = new ValidarCalculos(); validarCalculos.validar(mensajeEntrada.mensaje, resultadoValidaciones); } ResultadoProceso resultadoProceso = new ResultadoProceso(); resultadoProceso.SetNumeroAutorizacion(resultadoValidaciones); MensajeRespuesta mensajeRespuesta = new MensajeRespuesta(); mensajeRespuesta.resultado = resultadoProceso; return(mensajeRespuesta); }