private void btnConsultaClave_Click(object sender, EventArgs e) { try { if (!this.txtFolderSalida.Text.EndsWith("\\")) { this.txtFolderSalida.Text += "\\"; } if ((this.txtClave.Text.Trim().Length == 0)) { MessageBox.Show("Indique la clave a consultar"); this.txtClave.Focus(); return; } string directorio = this.txtFolderSalida.Text; string nombreArchivo; if ((txtConsecutivo.Text.Trim().Length == 0)) { nombreArchivo = this.txtClave.Text; } else { nombreArchivo = this.txtConsecutivo.Text; } string Token = ""; Token = getToken(); this.txtTokenHacienda.Text = Token; Comunicacion enviaFactura = new Comunicacion(); enviaFactura.ConsultaEstatus(Token, this.txtClave.Text); string jsonRespuesta = ""; jsonRespuesta = enviaFactura.jsonRespuesta; txtJSONRespuesta.Text = jsonRespuesta; System.IO.StreamWriter outputFile = new System.IO.StreamWriter((directorio + (nombreArchivo + "_06_jsonRespuestaClave.txt"))); outputFile.Write(jsonRespuesta); outputFile.Close(); if (!(enviaFactura.xmlRespuesta == null)) { this.txtRespuestaHacienda.Text = enviaFactura.xmlRespuesta.OuterXml; enviaFactura.xmlRespuesta.Save((directorio + (nombreArchivo + "_07_RespuestaClave.xml"))); } else { this.txtRespuestaHacienda.Text = "Consulte en unos minutos, factura se est� procesando."; this.txtRespuestaHacienda.Text = (this.txtRespuestaHacienda.Text + ("\r\n" + ("\r\n" + "Consulte por Clave"))); this.txtRespuestaHacienda.Text = (this.txtRespuestaHacienda.Text + ("\r\n" + ("\r\n" + enviaFactura.mensajeRespuesta))); } MessageBox.Show(enviaFactura.mensajeRespuesta); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Procesa(string xmlFactura) { if (!this.txtFolderSalida.Text.EndsWith("\\")) { this.txtFolderSalida.Text += "\\"; } string directorio = this.txtFolderSalida.Text; string nombreArchivo = this.txtConsecutivo.Text; XmlDocument xmlDocSF = new XmlDocument(); xmlDocSF.LoadXml(xmlFactura); xmlDocSF.Save((directorio + (nombreArchivo + "_01_SF.xml"))); XmlTextWriter xmlTextWriter = new XmlTextWriter((directorio + (nombreArchivo + "_01_SF.xml")), new System.Text.UTF8Encoding(false)); xmlDocSF.WriteTo(xmlTextWriter); xmlTextWriter.Close(); xmlDocSF = null; Firma _firma = new Firma(); _firma.FirmaXML_Xades((directorio + nombreArchivo), this.txtThumbprint.Text); XmlDocument xmlElectronica = new XmlDocument(); xmlElectronica.Load((directorio + (nombreArchivo + "_02_Firmado.xml"))); this.txtXMLFirmado.Text = xmlElectronica.OuterXml; Emisor myEmisor = new Emisor(); myEmisor.numeroIdentificacion = this.txtEmisorNumero.Text; myEmisor.TipoIdentificacion = this.txtEmisorTipo.Text; Receptor myReceptor = new Receptor(); if ((this.txtReceptorNumero.Text.Trim().Length > 0)) { myReceptor.sinReceptor = false; myReceptor.numeroIdentificacion = this.txtReceptorNumero.Text; myReceptor.TipoIdentificacion = this.txtReceptorTipo.Text; } else { myReceptor.sinReceptor = true; } Recepcion myRecepcion = new Recepcion(); myRecepcion.emisor = myEmisor; myRecepcion.receptor = myReceptor; myRecepcion.clave = this.txtClave.Text; myRecepcion.fecha = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz"); myRecepcion.comprobanteXml = Funciones.EncodeStrToBase64(xmlElectronica.OuterXml); xmlElectronica = null; string Token = ""; Token = getToken(); this.txtTokenHacienda.Text = Token; Comunicacion enviaFactura = new Comunicacion(); enviaFactura.EnvioDatos(Token, myRecepcion); string jsonEnvio = ""; jsonEnvio = enviaFactura.jsonEnvio; string jsonRespuesta = ""; jsonRespuesta = enviaFactura.jsonRespuesta; txtJSONEnvio.Text = jsonEnvio; txtJSONRespuesta.Text = jsonRespuesta; System.IO.StreamWriter outputFile = new System.IO.StreamWriter((directorio + (nombreArchivo + "_03_jsonEnvio.txt"))); outputFile.Write(jsonEnvio); outputFile.Close(); outputFile = new System.IO.StreamWriter((directorio + (nombreArchivo + "_04_jsonRespuesta.txt"))); outputFile.Write(jsonRespuesta); outputFile.Close(); if (!(enviaFactura.xmlRespuesta == null)) { this.txtRespuestaHacienda.Text = enviaFactura.xmlRespuesta.OuterXml; enviaFactura.xmlRespuesta.Save((directorio + (nombreArchivo + "_05_RESP.xml"))); } else { outputFile = new System.IO.StreamWriter((directorio + (nombreArchivo + "_05_RESP_SinRespuesta.txt"))); outputFile.Write(""); outputFile.Close(); this.txtRespuestaHacienda.Text = "Consulte en unos minutos, factura se est� procesando."; this.txtRespuestaHacienda.Text = (this.txtRespuestaHacienda.Text + ("\r\n" + ("\r\n" + "Consulte por Clave"))); this.txtRespuestaHacienda.Text = (this.txtRespuestaHacienda.Text + ("\r\n" + ("\r\n" + enviaFactura.mensajeRespuesta))); } MessageBox.Show(enviaFactura.mensajeRespuesta); }