private void BtnEnviarXML_Click(object sender, EventArgs e) { try { FechaEmision = Funcion.reemplazarcaracterFecha(DtpFecha.Value.Date.ToShortDateString()); DataTable DtDocuemtosXML = objConsult.BoolDataTableFactElect("Select * from TbDocumentosGeneradosFact DocFact where DocFact.FechaEmision = '" + FechaEmision + "' and EstadoAutorizacion = '0'"); String RecepcionSRIRespuesta = ""; if (DtDocuemtosXML.Rows.Count > 0) { foreach (DataRow myRow in DtDocuemtosXML.Rows) { RutaXML = myRow["RutaXML"].ToString(); NombreXML = myRow["NombreXML"].ToString(); FechaEmision = myRow["FechaEmision"].ToString(); //Inicio menuInferior TollMenuLablelDocumento.Text = "Documento : " + NombreXML + ".xml"; TollMenuLablelFecha.Text = "Fecha : " + Funcion.reemplazarcaracterFecha(Convert.ToDateTime(FechaEmision).Date.ToShortDateString()); //Fin menuInferior //Firmar Documento Funcion.FirmaXML(RutaXML + @"\Generados" + @"\" + NombreXML + ".xml", NombreXML); //Fin Firmar Documento //RecepcionSRI SRIRecepcionComprobante sriRecepcion = new SRIRecepcionComprobante(); RecepcionSRIRespuesta = sriRecepcion.LlamarSRIRecepcion(RutaXML + @"\Firmados" + @"\" + NombreXML + ".xml", NombreXML); //Fin RecepcionSRI String[] axuAto = RecepcionSRIRespuesta.Split(';'); String claveAcceso = axuAto[1]; switch (RecepcionSRIRespuesta) { case "DEVUELTA": RecepcionSRIRespuesta = "D"; break; case "RECIBIDA": RecepcionSRIRespuesta = "R"; break; default: break; } //Autorizacion //SRIAutorizacionComprobante sriAutori = new SRIAutorizacionComprobante(); //sriAutori.ConsultarAutorizaciones(claveAcceso); //FIN Autorizacion } } } catch (Exception ex) { } }
private void FrmParametrosFactura_Load(object sender, EventArgs e) { consultas.BoolLlenarComboBox(cbIVA, "select IDIVA as ID, IVA as Texto FROM [dbo].[TbIva]"); //LLENAR LOS DATOS //Llenar el DataTable DataTable dt = consultas.BoolDataTable("Select * from View_ParametrosFactura where IDEMPRESA =" + Program.IDEMPRESA + ";"); //Verificar si tiene Datos if (dt.Rows.Count > 0) { Estado_Existe = true; btnGuardarEmpresa.Text = "Modificar"; DataRow myRow = dt.Rows[0]; ////Cargar los demas Datos txtMontoMinimoFacturaEmpresa.Text = myRow["MONTO_MINIMO_FACTURA"].ToString(); cbIVA.SelectedItem = myRow["IVA"].ToString(); ckbContribuyenteEspecial.Checked = Convert.ToBoolean(myRow["CONTRIBUYENTEESPECIAL"]); ckbObligadoContabilidad.Checked = Convert.ToBoolean(myRow["OBLIGADOLLEVARCONTABILIDAD"]); TxtPie1.Text = myRow["PIE1"].ToString(); TxtPie2.Text = myRow["PIE2"].ToString(); TxtPie3.Text = myRow["PIE3"].ToString(); TxtPie4.Text = myRow["PIE4"].ToString(); TxtAncho.Text = Funcion.reemplazarcaracter(myRow["ANCHO"].ToString()); TxtLargo.Text = Funcion.reemplazarcaracter(myRow["LARGO"].ToString()); TxtTamañoEncabezadoFact.Text = Funcion.reemplazarcaracter(myRow["TAMANOENCABEZADOFACTURA"].ToString()); TxtTamañoPieFact.Text = Funcion.reemplazarcaracter(myRow["TAMANOPIEFACTURA"].ToString()); TxtNumeroItemsFactura.Text = myRow["NUMEROITEMS"].ToString(); rbAutorizadoImprimir.Checked = Convert.ToBoolean(myRow["AUTORIZADOIMPRIMIR"]); rbPreimpresa.Checked = Convert.ToBoolean(myRow["PREIMPRESA"]); txtNumeroResolucion.Text = myRow["NUMERORESOLUCION"].ToString(); if (Program.BoolAutorizadoImprimir) { try { DataTable dtFactElectCertificado = consultas.BoolDataTableFactElect("Select * from TbCertificado;"); if (dtFactElectCertificado.Rows.Count > 0) { DataRow Row = dtFactElectCertificado.Rows[0]; LblUnidadCertificadora.Text = Row["EntidadCertificadora"].ToString(); LblEstadoCertificado.Text = Row["Usuario"].ToString(); } } catch (Exception ex) { } } } }
private void btnEnviar_Click(object sender, EventArgs e) { try { //Select * from [TbEncabezadoFactura] DocFact where DocFact.[FECHA] = '" + FechaEmision + "' //Select * from TbDocumentosGeneradosFact DocFact where DocFact.FechaEmision = '" + FechaEmision + "' and EstadoAutorizacion = '0'" FechaEmision = Funcion.reemplazarcaracterFecha(DtpFecha.Value.Date.ToShortDateString()); DtDocuemtosXML = Objconsul.BoolDataTableFactElect("Select * from TbDocumentosGeneradosFact DocFact where DocFact.FechaEmision = '" + FechaEmision + "' and EstadoAutorizacion = '0'"); lblTotalArchivos.Text = "Cantidad Facturas: " + DtDocuemtosXML.Rows.Count; if (DtDocuemtosXML.Rows.Count > 0) { btnEnviar.Enabled = false; //Creamos el delegado ThreadStart h1 = new ThreadStart(Procesar); //Creamos la instancia del hilo h2 = new Thread(h1); //Iniciamos el hilo h2.Start(); } } catch (Exception ex) { } }
private void Procesar() { try { if (tipocomprobante == "Factura") { DtDocuemtosXML = objconsul.BoolDataTableFactElect("Select * from TbDocumentosGeneradosFact DocFact where DocFact.NombreXML='" + nombrexml + "'"); } else { DtDocuemtosXML = objconsul.BoolDataTableFactElect("Select * from TbDocumentosGeneradosRect DocRect where DocRect.NombreXML='" + nombrexml + "'"); } int contadorAutorizado = 0, contadorEnviados = 0, contadorNoautorizados = 0, contadorDevuelta = 0, contadorRecibida = 0, contador = 0, estadoautorizacion = 0; string Recibida = "", AUT = "NO"; if (DtDocuemtosXML.Rows.Count > 0) { foreach (DataRow myRow in DtDocuemtosXML.Rows) { RutaXML = myRow["Ruta"].ToString(); NombreXML = myRow["NombreXML"].ToString(); FechaEmision = myRow["FechaEmision"].ToString(); contador++; string RutaXML1 = ConfigurationManager.AppSettings["XmlServidor"]; string SRIRecepcion = ConfigurationManager.AppSettings["SRIRecepcion"]; string SRIAutorizacion = ConfigurationManager.AppSettings["SRIAutorizacion"]; if (System.IO.File.Exists(RutaXML1 + @"\Generados" + @"\" + NombreXML + ".xml")) { //Firmar Documento Firma.Firmalo(Program.RutaCertificado, Program.passwordCertificado, RutaXML1 + @"\Generados\" + NombreXML + ".xml", RutaXML1 + @"\Firmados\" + NombreXML + ".xml", RutaXML1); // Inicio RecepcionSRI SRIRecepcionComprobante sriRecepcion = new SRIRecepcionComprobante(); string respuestaRecepcion = sriRecepcion.RecepcionArchivos(RutaXML1 + @"\Firmados" + @"\" + NombreXML + ".xml", SRIRecepcion, NombreXML, RutaXML1); string[] valoresrecepcion = respuestaRecepcion.Split(';'); //Fin RecepcionSRI if (valoresrecepcion[0] == "RECIBIDA" || valoresrecepcion[1] == "CLAVE ACCESO REGISTRADA") { contadorRecibida++; Recibida = "R"; //Inicio Autorizacion SRIAutorizacionComprobante sriAutori = new SRIAutorizacionComprobante(SRIAutorizacion); string estado = sriAutori.AutorizacionArchivos(NombreXML, RutaXML1, respuestaRecepcion); string[] autorizado = estado.Split(';'); if (autorizado.Length > 1) { fechaAutorizacion = autorizado[1]; } if (autorizado[0] == "AUTORIZADO") { contadorAutorizado++; estadoautorizacion = 1; AUT = "SI"; } else { contadorNoautorizados++; estadoautorizacion = 0; AUT = "NO"; } //Fin Autorizacion contadorEnviados++; string contadoraenviar = contador + " de " + DtDocuemtosXML.Rows.Count + " Archivos."; CambiarProgreso(NombreXML, FechaEmision, contadorDevuelta.ToString(), contadorRecibida.ToString(), contadorAutorizado.ToString(), contadorNoautorizados.ToString(), contadorEnviados.ToString(), contadoraenviar, "" + DtDocuemtosXML.Rows.Count); } else { contadorDevuelta++; Recibida = "D"; } Consultas Objconsul = new Consultas(); if (tipocomprobante == "Factura") { Objconsul.EjecutarSQLFactElectronica("UPDATE [dbo].[TbDocumentosGeneradosFact] SET [EstadoAutorizacion] = '" + estadoautorizacion + "',[RecepcionSRI] ='" + Recibida + "',[AutorizadoSRI]='" + AUT + "' WHERE NombreXML = '" + NombreXML + "'"); } else { Objconsul.EjecutarSQLFactElectronica("UPDATE [dbo].[TbDocumentosGeneradosRect] SET [EstadoAutorizacion] = '" + estadoautorizacion + "',[RecepcionSRI] ='" + Recibida + "',[AutorizadoSRI]='" + AUT + "' WHERE NombreXML = '" + NombreXML + "'"); } if (estadoautorizacion == 0) { Objconsul.EjecutarSQLFactElectronica("UPDATE [dbo].[TbErroresDocEnviados] SET [EstadoError] = '1' WHERE NombreXML = '" + NombreXML + "'"); } else { Objconsul.EjecutarSQLFactElectronica("UPDATE [dbo].[TbErroresDocEnviados] SET [EstadoError] = '0' WHERE NombreXML = '" + NombreXML + "'"); } } } } else { MessageBox.Show("No se encontró ningun archivo."); } } catch (Exception ex) { MessageBox.Show("Error en enviar al SRI: No responde o el xml contiene errores\n Intentelo más tarde en el formulario Corregir Errores"); } }