Exemple #1
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (dglista.Rows.Count > 0)
                {
                    var correl = txtCorrel.Text;
                    var documentoResumenDiario = new ResumenDiario
                    {
                        IdDocumento     = string.Format("RC-{0:yyyyMMdd}-" + correl, DateTime.Today),
                        FechaEmision    = DateTime.Today.ToString("yyyy-MM-dd"),
                        FechaReferencia = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd"),
                        Emisor          = CrearEmisor(),
                        Resumenes       = new List <GrupoResumen>()
                    };
                    var nomdoc = "RC-" + string.Format("{0:yyyyMMdd}-" + correl, DateTime.Today);
                    foreach (DataGridViewRow row in dglista.Rows)
                    {
                        GrupoResumen resu = new GrupoResumen();
                        // documentoResumenDiario.
                        resu.Id = Convert.ToInt32(row.Cells[0].Value);
                        resu.CorrelativoInicio = Convert.ToInt32(row.Cells[3].Value);
                        resu.CorrelativoFin    = Convert.ToInt32(row.Cells[4].Value);
                        resu.Moneda            = Convert.ToString(row.Cells[5].Value);
                        resu.TotalVenta        = Convert.ToDecimal(row.Cells[6].Value);
                        resu.TotalIgv          = Convert.ToDecimal(row.Cells[7].Value);
                        resu.Gravadas          = Convert.ToDecimal(row.Cells[8].Value);
                        resu.Exoneradas        = 0;
                        resu.Exportacion       = 0;
                        resu.TipoDocumento     = Convert.ToString(row.Cells[1].Value);
                        resu.Serie             = Convert.ToString(row.Cells[2].Value);
                        documentoResumenDiario.Resumenes.Add(resu);
                    }
                    var invoice       = GeneradorXML.GenerarSummaryDocuments(documentoResumenDiario);
                    var serializador3 = new Serializador();
                    TramaXmlSinFirma = serializador3.GenerarXml(invoice);
                    RutaArchivo      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documentos\\" +
                                                    $"{documentoResumenDiario.IdDocumento}.xml");
                    File.WriteAllBytes(RutaArchivo, Convert.FromBase64String(TramaXmlSinFirma));

                    IdDocumento  = nomdoc;
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("No hay Registros para Generar Documento");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #2
0
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            try
            {
                if (dglista2.Rows.Count > 0)
                {
                    var correl        = txtcorrelativo2.Text;
                    var documentoBaja = new ComunicacionBaja
                    {
                        IdDocumento     = string.Format("RA-{0:yyyyMMdd}-" + correl, DateTime.Today),
                        FechaEmision    = DateTime.Today.ToString("yyyy-MM-dd"),
                        FechaReferencia = DateTime.Today.ToString("yyyy-MM-dd"),//DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd"),
                        Emisor          = CrearEmisor(),
                        Bajas           = new List <DocumentoBaja>()
                    };
                    var nomdoc = "RA-" + string.Format("{0:yyyyMMdd}-" + correl, DateTime.Today);
                    foreach (DataGridViewRow row in dglista2.Rows)
                    {
                        DocumentoBaja baja = new DocumentoBaja();
                        baja.Id            = Convert.ToInt32(row.Cells[0].Value);
                        baja.TipoDocumento = Convert.ToString(row.Cells[1].Value);
                        baja.Serie         = Convert.ToString(row.Cells[2].Value);
                        baja.Correlativo   = Convert.ToString(row.Cells[3].Value);
                        baja.MotivoBaja    = Convert.ToString(row.Cells[4].Value);

                        documentoBaja.Bajas.Add(baja);
                    }
                    var invoice       = GeneradorXML.GenerarVoidedDocuments(documentoBaja);
                    var serializador3 = new Serializador();
                    TramaXmlSinFirma = serializador3.GenerarXml(invoice);
                    RutaArchivo      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documentos\\" +
                                                    $"{documentoBaja.IdDocumento}.xml");
                    File.WriteAllBytes(RutaArchivo, Convert.FromBase64String(TramaXmlSinFirma));
                    IdDocumento = nomdoc;

                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("No hay Registros para Generar Documento");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #3
0
        public EnviarDocumentoResponse EnviarResumenResponse(EnviarDocumentoRequest request)
        {
            var response     = new EnviarDocumentoResponse();
            var serializador = new Serializador();
            //var nombreArchivo = $"{request.Ruc}-{request.TipoDocumento}-{request.IdDocumento}";
            var nombreArchivo = $"{request.Ruc}-{request.IdDocumento}"; // Ver si se reemplza luego

            try
            {
                var tramaZip = serializador.GenerarZip(request.TramaXmlFirmado, nombreArchivo);

                var conexionSunat = new ConexionSunat(new ConexionSunat.Parametros
                {
                    Ruc         = request.Ruc,
                    UserName    = request.UsuarioSol,
                    Password    = request.ClaveSol,
                    EndPointUrl = request.EndPointUrl
                });

                var resultado = conexionSunat.EnviarResumenBaja(tramaZip, $"{nombreArchivo}.zip");

                if (resultado.Item2)
                {
                    response.NroTicket     = resultado.Item1;
                    response.Exito         = true;
                    response.NombreArchivo = nombreArchivo;
                }
                else
                {
                    response.MensajeError = resultado.Item1;
                    response.Exito        = false;
                }
            }
            catch (Exception ex)
            {
                response.MensajeError = ex.Message;
                response.Pila         = ex.StackTrace;
                response.Exito        = false;
            }

            return(response);
        }
Exemple #4
0
        public EnviarDocumentoResponse EnviarDocumentoResponse(EnviarDocumentoRequest request)
        {
            var response = new EnviarDocumentoResponse();

            var serializador  = new Serializador();
            var nombreArchivo = $"{request.Ruc}-{request.TipoDocumento}-{request.IdDocumento}";

            var tramaZip = serializador.GenerarZip(request.TramaXmlFirmado, nombreArchivo);

            var conexionSunat = new ConexionSunat(new ConexionSunat.Parametros
            {
                Ruc         = request.Ruc,
                UserName    = request.UsuarioSol,
                Password    = request.ClaveSol,
                EndPointUrl = request.EndPointUrl
            });

            var resultado = conexionSunat.EnviarDocumento(tramaZip, $"{nombreArchivo}.zip");

            if (resultado.Item2)
            {
                var returnByte = Convert.FromBase64String(resultado.Item1);
                using (var memRespuesta = new MemoryStream(returnByte))
                {
                    using (var zipFile = ZipFile.Read(memRespuesta))
                    {
                        foreach (var entry in zipFile.Entries)
                        {
                            if (!entry.FileName.EndsWith(".xml"))
                            {
                                continue;
                            }
                            using (var ms = new MemoryStream())
                            {
                                entry.Extract(ms);
                                ms.Position = 0;
                                var responseReader = new StreamReader(ms);
                                var responseString = responseReader.ReadToEnd();
                                try
                                {
                                    var xmlDoc = new XmlDocument();
                                    xmlDoc.LoadXml(responseString);

                                    var xmlnsManager = new XmlNamespaceManager(xmlDoc.NameTable);

                                    xmlnsManager.AddNamespace("ar", EspacioNombres.ar);
                                    xmlnsManager.AddNamespace("cac", EspacioNombres.cac);
                                    xmlnsManager.AddNamespace("cbc", EspacioNombres.cbc);

                                    response.CodigoRespuesta = xmlDoc.SelectSingleNode(EspacioNombres.nodoResponseCode,
                                                                                       xmlnsManager)?.InnerText;

                                    response.MensajeRespuesta = xmlDoc.SelectSingleNode(EspacioNombres.nodoDescription,
                                                                                        xmlnsManager)?.InnerText;
                                    response.TramaZipCdr   = resultado.Item1;
                                    response.Exito         = true;
                                    response.NombreArchivo = nombreArchivo;
                                }
                                catch (Exception ex)
                                {
                                    response.MensajeError = ex.Message;
                                    response.Pila         = ex.StackTrace;
                                    response.Exito        = false;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                response.Exito            = true;
                response.MensajeRespuesta = resultado.Item1;
            }

            return(response);
        }
Exemple #5
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            try {
                if (dgreten.Rows.Count > 0)
                {
                    _documento.DocumentoRetencion.Receptor.NroDocumento  = txtNroCliente.Text;
                    _documento.DocumentoRetencion.Receptor.TipoDocumento = cboTipoDocRec2.SelectedValue.ToString();
                    _documento.DocumentoRetencion.Receptor.NombreLegal   = txtNomCliente.Text;
                    _documento.DocumentoRetencion.IdDocumento            = txtCorrelativo3.Text;
                    _documento.DocumentoRetencion.FechaEmision           = DateTime.Today.ToString(FormatoFecha);
                    _documento.DocumentoRetencion.Moneda           = cboMoneda2.SelectedValue.ToString();
                    _documento.DocumentoRetencion.RegimenRetencion = "01";
                    _documento.DocumentoRetencion.TasaRetencion    = 3;


                    Decimal ImporteRetenido = 0, ImportePagado = 0;
                    foreach (DataGridViewRow row in dgreten.Rows)
                    {
                        ItemRetencion retencion = new ItemRetencion();
                        retencion.NroDocumento  = row.Cells[1].Value.ToString();
                        retencion.TipoDocumento = "01";
                        retencion.MonedaDocumentoRelacionado = row.Cells[3].Value.ToString();
                        retencion.FechaEmision        = DateTime.Today.ToString(FormatoFecha);
                        retencion.ImporteTotal        = Convert.ToDecimal(row.Cells[4].Value);
                        retencion.FechaPago           = row.Cells[2].Value.ToString();
                        retencion.NumeroPago          = Convert.ToInt32(row.Cells[0].Value);
                        retencion.ImporteSinRetencion = Convert.ToDecimal(row.Cells[4].Value) - Convert.ToDecimal(row.Cells[5].Value);
                        retencion.ImporteRetenido     = Convert.ToDecimal(row.Cells[5].Value);
                        retencion.FechaRetencion      = row.Cells[2].Value.ToString();
                        retencion.ImporteTotalNeto    = Convert.ToDecimal(row.Cells[4].Value);;
                        // retencion.TipoCambio = 3.41m;
                        //retencion.FechaTipoCambio = DateTime.Today.ToString(FormatoFecha);
                        ImporteRetenido += Convert.ToDecimal(row.Cells[5].Value);
                        ImportePagado    = Convert.ToDecimal(row.Cells[4].Value);
                        _documento.DocumentoRetencion.DocumentosRelacionados.Add(retencion);


                        //documentoReten.DocumentosRelacionados.Add(retencion);
                    }
                    _documento.DocumentoRetencion.ImporteTotalPagado   = ImportePagado;
                    _documento.DocumentoRetencion.ImporteTotalRetenido = ImporteRetenido;
                    _documento.DocumentoRetencion.Emisor = CrearEmisor();
                    _documento.MontoEnLetras             = ConvertLetras.enletras(_documento.DocumentoRetencion.ImporteTotalRetenido.ToString());

                    var RetenDoc      = GeneradorXML.GenerarRetention(_documento.DocumentoRetencion);
                    var serializador4 = new Serializador();
                    TramaXmlSinFirma = serializador4.GenerarXml(RetenDoc);
                    RutaArchivo      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documentos\\" +
                                                    $"{_documento.DocumentoRetencion.IdDocumento}.xml");
                    File.WriteAllBytes(RutaArchivo, Convert.FromBase64String(TramaXmlSinFirma));
                    IdDocumento  = _documento.DocumentoRetencion.IdDocumento;
                    _documento2  = _documento;
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("No hay Registros para Generar Documento");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #6
0
        private void toolGenerar_Click(object sender, EventArgs e)
        {
            try
            {
                if (cboTipoDoc.SelectedIndex == -1)
                {
                    MessageBox.Show("Seleccione un tipo de Documento Factura/Boleta");
                    return;
                }
                if (cboTipoDocRec.SelectedIndex == -1)
                {
                    MessageBox.Show("Seleccione un tipo de Documento para el Cliente..!");
                    return;
                }

                if (txtNroDocRec.Text == "")
                {
                    MessageBox.Show("Ingrese Tipo Documento Cliente");
                    txtNroDocRec.Focus();
                    return;
                }
                if (txtNombreLegalRec.Text == "")
                {
                    MessageBox.Show("Ingrese Nombre Legal Cliente");
                    txtNombreLegalRec.Focus();
                    return;
                }
                if (cboTipoDocRec.SelectedValue.ToString() == "1")
                {
                    cboTipoDocRec.MaxLength = 8;
                    if ((txtNroDocRec.Text.Length) < 8)
                    {
                        MessageBox.Show("Ingrese DNI Correcto");
                        txtNroDocRec.Focus();
                        return;
                    }
                }
                if (cboTipoDocRec.SelectedValue.ToString() == "6")
                {
                    cboTipoDocRec.MaxLength = 11;
                    if ((txtNroDocRec.Text.Length) < 11)
                    {
                        MessageBox.Show("Ingrese RUC Correcto");
                        txtNroDocRec.Focus();
                        return;
                    }
                }

                if (txtDirRec.Text == "")
                {
                    MessageBox.Show("Ingrese Dirección de Cliente..!");
                    txtDirRec.Focus();
                    return;
                }
                if (textBox17.Text == "")
                {
                    MessageBox.Show("Ingrese Correlativo del Documento..!");
                    textBox17.Focus();
                    return;
                }

                Cursor.Current = Cursors.WaitCursor;

                documentoElectronicoBindingSource.EndEdit();
                totalVentaTextBox.Focus();

                switch (_documento.TipoDocumento)
                {
                case "07":
                    //NotaCredito
                    var notaCredito   = GeneradorXML.GenerarCreditNote(_documento);
                    var serializador1 = new Serializador();
                    TramaXmlSinFirma = serializador1.GenerarXml(notaCredito);
                    break;

                case "08":
                    //GenerarNotaDebito
                    var notaDebito    = GeneradorXML.GenerarDebitNote(_documento);
                    var serializador2 = new Serializador();
                    TramaXmlSinFirma = serializador2.GenerarXml(notaDebito);
                    break;

                default:
                    var invoice       = GeneradorXML.GenerarInvoice(_documento);
                    var serializador3 = new Serializador();
                    TramaXmlSinFirma = serializador3.GenerarXml(invoice);
                    break;
                }



                RutaArchivo = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documentos\\" +
                                           $"{_documento.IdDocumento}.xml");
                File.WriteAllBytes(RutaArchivo, Convert.FromBase64String(TramaXmlSinFirma));



                IdDocumento = _documento.IdDocumento;

                _documento2  = _documento;
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #7
0
        public async void enviar_documentos()
        {
            try
            {
                byte[] archivo_xml = null;
                byte[] archivo_cdr = null;
                int    enviados    = 0;
                byte[] archivo_pdf = null;


                foreach (DataGridViewRow row in dg_repositorio.Rows)
                {
                    //if (!archivo_existe(row.Cells[rutaxml.Index].Value.ToString()))
                    //{
                    descargar_xml(row.Index, 0);
                    descargar_pdf(row.Index, 0);
                    //}
                    var tramaXmlSinFirma = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutaxml.Index].Value.ToString())) ?
                                           Convert.ToBase64String(File.ReadAllBytes(row.Cells[rutaxml.Index].Value.ToString())) :
                                           Convert.ToBase64String(File.ReadAllBytes(herramienta.GetResourcesPath5() + "\\" + dg_repositorio.Rows[row.Index].Cells[nombredocxml.Index].Value.ToString()));
                    var firmadoRequest = new FirmadoRequest
                    {
                        TramaXmlSinFirma    = tramaXmlSinFirma,
                        CertificadoDigital  = Convert.ToBase64String(File.ReadAllBytes(herramienta.GetResourcesPath() + "\\" + empresa.Rutacertificado)),
                        PasswordCertificado = empresa.Clavecertificado,
                        UnSoloNodoExtension = false
                    };

                    ICertificador certificador     = new Certificador();
                    var           respuestaFirmado = await new Firmar(certificador).Post(firmadoRequest);


                    if (!respuestaFirmado.Exito)
                    {
                        MessageBox.Show(respuestaFirmado.MensajeError);
                    }



                    var enviarDocumentoRequest = new EnviarDocumentoRequest
                    {
                        Ruc         = empresa.Ruc,
                        UsuarioSol  = empresa.Usuariosol,
                        ClaveSol    = empresa.Clavesol,
                        EndPointUrl = empresa.Urlenvio,
                        //https://www.sunat.gob.pe/ol-ti-itcpgem-sqa/billService //RETENCION
                        IdDocumento     = row.Cells[comprobante.Index].Value.ToString(),
                        TipoDocumento   = row.Cells[tipocomprobante.Index].Value.ToString(),
                        TramaXmlFirmado = respuestaFirmado.TramaXmlFirmado
                    };


                    /*===================================*/

                    ISerializador            serializador            = new Serializador();
                    IServicioSunatDocumentos servicioSunatDocumentos = new ServicioSunatDocumentos();

                    RespuestaComunConArchivo respuestaEnvio;
                    respuestaEnvio = await new EnviarDocumento(serializador, servicioSunatDocumentos).Post(enviarDocumentoRequest);

                    var rpta = (EnviarDocumentoResponse)respuestaEnvio;


                    if (!respuestaEnvio.Exito)
                    {
                        MessageBox.Show(respuestaEnvio.MensajeError);
                    }

                    /*==============================*/


                    if (rpta != null)
                    {
                        repositorio = new clsRepositorio();
                        repositorio.Repositorioid = Convert.ToInt32(row.Cells[repositorioid.Index].Value.ToString());

                        archivo_xml = Convert.FromBase64String(respuestaFirmado.TramaXmlFirmado);
                        File.WriteAllBytes($"{Program.CarpetaXml}\\{rpta.NombreArchivo}.xml", archivo_xml);

                        if (rpta.Exito)
                        {
                            if (rpta.MensajeRespuesta != null)
                            {
                                if (rpta.MensajeRespuesta.IndexOf("1033") > 0)
                                {
                                    repositorio.Estadosunat  = 0;
                                    repositorio.Mensajesunat = rpta.MensajeRespuesta;
                                }
                                else
                                {
                                    if (rpta.MensajeRespuesta.IndexOf("ha sido aceptada") > 0)
                                    {
                                        repositorio.Estadosunat  = 0;
                                        repositorio.Mensajesunat = rpta.MensajeRespuesta;
                                    }
                                    else
                                    {
                                        repositorio.Estadosunat  = -1;
                                        repositorio.Mensajesunat = rpta.MensajeRespuesta;
                                    }
                                }
                            }
                            else
                            {
                                repositorio.Estadosunat  = -1;
                                repositorio.Mensajesunat = "No Enviado";
                            }


                            if (!string.IsNullOrEmpty(rpta.TramaZipCdr))
                            {
                                archivo_cdr = Convert.FromBase64String(rpta.TramaZipCdr);
                                File.WriteAllBytes($"{Program.CarpetaCdr}\\R-{rpta.NombreArchivo}.zip", archivo_cdr);
                            }

                            if (File.Exists($"{Program.CarpetaXml}\\{rpta.NombreArchivo}.xml") &&
                                File.Exists($"{Program.CarpetaCdr}\\R-{rpta.NombreArchivo}.zip"))
                            {
                                switch (row.Cells[tipocomprobante.Index].Value.ToString())
                                {
                                case "03":
                                    archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                                  File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                                  File.ReadAllBytes(herramienta.GetResourcesPath6() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                    break;

                                case "01":
                                    archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                                  File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                                  File.ReadAllBytes(herramienta.GetResourcesPath3() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                    break;

                                case "07":
                                    archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                                  File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                                  File.ReadAllBytes(herramienta.GetResourcesPath7() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                    break;

                                case "08":
                                    archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                                  File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                                  File.ReadAllBytes(herramienta.GetResourcesPath8() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                    break;
                                }

                                if (!string.IsNullOrEmpty(rpta.TramaZipCdr))
                                {
                                    archivo = new clsArchivo()
                                    {
                                        Xml = File.ReadAllBytes($"{Program.CarpetaXml}\\{rpta.NombreArchivo}.xml"),
                                        Zip = File.ReadAllBytes($"{Program.CarpetaCdr}\\R-{rpta.NombreArchivo}.zip"),
                                        Pdf = archivo_pdf
                                    };

                                    repositorio.Archivo   = archivo;
                                    repositorio.Pcorigen  = SystemInformation.UserDomainName;
                                    repositorio.Usuariopc = SystemInformation.UserName;
                                    if (admrepo.actualizar_repositorio(repositorio) < 0)
                                    {
                                        MessageBox.Show("Problemas para actualizar información el proceso de detuvo...", "Información");
                                        break;
                                    }
                                }
                                else
                                {
                                    archivo = new clsArchivo()
                                    {
                                        Xml = File.ReadAllBytes($"{Program.CarpetaXml}\\{rpta.NombreArchivo}.xml"),
                                        Pdf = archivo_pdf
                                    };

                                    repositorio.Archivo   = archivo;
                                    repositorio.Pcorigen  = SystemInformation.UserDomainName;
                                    repositorio.Usuariopc = SystemInformation.UserName;
                                    if (admrepo.actualizar_repositorio(repositorio) < 0)
                                    {
                                        MessageBox.Show("Problemas para actualizar información el proceso de detuvo...", "Información");
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                switch (row.Cells[tipocomprobante.Index].Value.ToString())
                                {
                                case "03":
                                    archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                                  File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                                  File.ReadAllBytes(herramienta.GetResourcesPath6() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                    break;

                                case "01":
                                    archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                                  File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                                  File.ReadAllBytes(herramienta.GetResourcesPath3() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                    break;

                                case "07":
                                    archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                                  File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                                  File.ReadAllBytes(herramienta.GetResourcesPath7() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                    break;

                                case "08":
                                    archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                                  File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                                  File.ReadAllBytes(herramienta.GetResourcesPath8() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                    break;
                                }

                                archivo = new clsArchivo()
                                {
                                    Xml = File.ReadAllBytes($"{Program.CarpetaXml}\\{rpta.NombreArchivo}.xml"),
                                    Pdf = archivo_pdf
                                };

                                repositorio.Archivo   = archivo;
                                repositorio.Pcorigen  = SystemInformation.UserDomainName;
                                repositorio.Usuariopc = SystemInformation.UserName;
                                if (admrepo.actualizar_repositorio(repositorio) < 0)
                                {
                                    MessageBox.Show("Problemas para actualizar información el proceso de detuvo...", "Información");
                                    break;
                                }
                            }
                        }
                        else
                        {
                            switch (row.Cells[tipocomprobante.Index].Value.ToString())
                            {
                            case "03":
                                archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                              File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                              File.ReadAllBytes(herramienta.GetResourcesPath6() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                break;

                            case "01":
                                archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                              File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                              File.ReadAllBytes(herramienta.GetResourcesPath3() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                break;

                            case "07":
                                archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                              File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                              File.ReadAllBytes(herramienta.GetResourcesPath7() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                break;

                            case "08":
                                archivo_pdf = (File.Exists(dg_repositorio.Rows[row.Index].Cells[rutapdf.Index].Value.ToString())) ?
                                              File.ReadAllBytes(row.Cells[rutapdf.Index].Value.ToString()) :
                                              File.ReadAllBytes(herramienta.GetResourcesPath8() + "\\" + row.Cells[nombredocpdf.Index].Value.ToString());
                                break;
                            }

                            archivo = new clsArchivo()
                            {
                                Xml = File.ReadAllBytes($"{Program.CarpetaXml}\\{rpta.NombreArchivo}.xml"),
                                Pdf = archivo_pdf
                            };

                            if (rpta.MensajeRespuesta != null)
                            {
                                if (rpta.MensajeRespuesta.IndexOf("1033") > 0)
                                {
                                    repositorio.Estadosunat  = 0;
                                    repositorio.Mensajesunat = rpta.MensajeRespuesta;
                                }
                                else
                                {
                                    enviados++;
                                    repositorio.Estadosunat  = -1;
                                    repositorio.Mensajesunat = rpta.MensajeRespuesta;
                                }
                            }
                            else
                            {
                                repositorio.Estadosunat  = -1;
                                repositorio.Mensajesunat = "No Enviado";
                                enviados++;
                            }

                            repositorio.Archivo   = archivo;
                            repositorio.Pcorigen  = SystemInformation.UserDomainName;
                            repositorio.Usuariopc = SystemInformation.UserName;

                            if (admrepo.actualizar_repositorio(repositorio) < 0)
                            {
                                MessageBox.Show("Problemas para actualizar información el proceso de detuvo...", "Información");
                                break;
                            }
                        }
                    }
                    else
                    {
                        enviados++;
                    }
                }

                if (enviados > 0)
                {
                    MessageBox.Show("No todos los documentos se enviaron...", "Información");
                    btn_buscar.PerformClick();
                }
                else
                {
                    MessageBox.Show("Todos los documentos se enviaron...", "Información");
                    btn_buscar.PerformClick();
                }
            }
            catch (Exception a) { MessageBox.Show(a.Message); }
        }