public bool uploadArchivos(clsArchivo objArchivo)
 {
     try
     {
         this.objRequest.cmd    = "microtexto";
         this.objRequest.log    = "upload";
         this.objRequest.origin = Environment.MachineName;
         this.objRequest.token  = Sesion.objUsuario.token;
         this.objRequest.param  = JsonConvert.SerializeObject(objArchivo);
         string json    = JsonConvert.SerializeObject(this.objRequest);
         string mensaje = HttpPostRequest(url, JsonToDictionary(json, "request"));
         this.objResponse = JsonConvert.DeserializeObject <Response>(mensaje);
         string[] var = objResponse.data.Split(',');
         //if (objResponse.result == "OK" && objResponse.data.Split(':')[1].Substring(0, objResponse.data.Split(':')[1].Length - 1) == "true")
         string a = var[0].Split(':')[1].Substring(0, var[0].Split(':')[1].Length);
         string b = var[1].Split(':')[1].Substring(0, var[1].Split(':')[1].Length - 1);
         if (objResponse.result == "OK" && a == "true" && b == "true")
         {
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         throw new Exception("Error al subir la imagen de microtexto. ", ex);
     }
 }
Esempio n. 2
0
        private bool CargarArchivoExterno()
        {
            try
            {
                string     fuente = @"C:\Users\georg\source\repos\PARCIAL II\crudDB.csv";
                clsArchivo ar     = new clsArchivo();

                //obtener todo el archivo en un arreglo
                string[] arregloNotas = ar.LeerArchivo(fuente);

                string sentencia_sql = "";
                int    NumeroLinea   = 0;


                //Iterando el arreglo, linea x linea para luego convertirlo en datos indivuales
                foreach (string linea in arregloNotas)
                {
                    string[] datos = linea.Split(';');
                    if (NumeroLinea > 0)
                    {
                        sentencia_sql += $"INSERT INTO tb_alumnos VALUES({datos[0]},'{datos[1]}',{datos[2]},{datos[3]},{datos[4]},{datos[5]},'{datos[6]}');\n";
                    }
                    NumeroLinea++;
                } //end foreach
                NumeroLinea = 0;
                sqlconexion.EjecutaSQLDirecto(sentencia_sql); //mandar todo a la BD

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 3
0
        private bool uploadImagen(clsMicrotexto objMicrotexto)
        {
            ConsumeWS  objWS      = new ConsumeWS();
            clsArchivo objArchivo = new clsArchivo();

            objArchivo.IdDocumento = 19;
            objArchivo.IdPersona   = objMicrotexto.idPersona;
            objArchivo.Nombre      = objMicrotexto.nombreArchivoSalida.Substring(0, objMicrotexto.nombreArchivoSalida.Length - 4) + "_" + DateTime.Now.ToString("yy_MM_dd_HHmmss") + ".BMP";
            //objArchivo.StrImagen = getBase64StringByImagen(Image.FromFile("micro_" + objMicrotexto.idPersona + ".BMP"));
            objArchivo.StrImagen = getBase64StringByImagen(Image.FromFile(objMicrotexto.nombreArchivoSalida));
            for (int i = 0; i < 5; i++)
            {
                if (objWS.uploadArchivos(objArchivo))
                {
                    try
                    {
                        using (PictureBox pb = new PictureBox())
                        {
                            pb.Load(ConfigurationManager.AppSettings["SistemaURL"] + objWS.getRutaMicrotexto(objArchivo.IdPersona));
                            //pb.Image.Save("calis.jpg");
                        }
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        objWS.updatePersonaDocumentoMicrotexto(objArchivo.IdPersona);
                    }
                }
            }
            return(false);
            //  return objWS.uploadArchivos(objArchivo);
        }
Esempio n. 4
0
 public int AgregarArchivo(clsArchivo archivo)
 {
     using (var conn = new PortalNoticiasEntities())
     {
         Archivo archivoBd = new Archivo
         {
             IdNoticia = archivo.IdNoticia,
             Ruta      = archivo.Ruta,
             Tipo      = archivo.Tipo
         };
         conn.Archivo.Add(archivoBd);
         return(conn.SaveChanges());
     }
 }
Esempio n. 5
0
        public JsonResult Actualizar([Bind] clsArchivo archivo)
        {
            if (archivo.Tipo)
            {
                modeloArchivo bd = new modeloArchivo();
                if (bd.ActualizarArchivo(archivo) > 0)
                {
                    return(Json(new { ok = true, mensaje = archivo }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { ok = false, mensaje = "No se agregó el archivo" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                if (Request.Files.Count > 0)
                {
                    try
                    {
                        HttpFileCollectionBase files = Request.Files;

                        HttpPostedFileBase file = files[0];
                        string             fname;
                        fname = file.FileName;

                        fname = Path.Combine(Server.MapPath("~/Archivos/"), fname);
                        var flocalName = "../Archivos/" + file.FileName;
                        file.SaveAs(fname);
                        archivo.Ruta = flocalName;

                        modeloArchivo bd = new modeloArchivo();
                        if (bd.ActualizarArchivo(archivo) > 0)
                        {
                            return(Json(new { ok = true, mensaje = archivo }, JsonRequestBehavior.AllowGet));
                        }
                        return(Json(new { ok = false, mensaje = "No se agregó el archivo" }, JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception ex)
                    {
                        return(Json(new { ok = false, mensaje = "No se agregó el archivo" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { ok = false, mensaje = "No se agregó el archivo. Intenta con otro, este probablemente ya existe en la base de datos" }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Esempio n. 6
0
        private void btncargarArchivo_Click(object sender, EventArgs e)
        {
            clsArchivo     ar  = new clsArchivo();
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title            = "porfa selecciona el archivo";
            ofd.InitialDirectory = @"C:\Users\USER\Desktop\alumnos";
            ofd.Filter           = "archivo plano (*.csv)|*.csv";


            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var    archivo   = ofd.FileName;
                string resultado = ar.leerTodoArchivo(archivo);
                ArregloNotas      = ar.leerArchivo(archivo);
                txtresultado.Text = resultado;
            }
        }
Esempio n. 7
0
        private void cargararchivo()
        {
            string      pell = @"C:\Users\alumno\Documents\Archivo cvs\crudDB.csv";
            clsArchivo  an   = new clsArchivo();
            clsconexion fn   = new clsconexion();

            string[] arreglonotas = an.LeerArchivo(pell);
            string   jefer_sql    = "";
            int      numlinea     = 0;

            foreach (string linea in arreglonotas)
            {
                string[] datos = linea.Split(';');
                if (numlinea > 0)
                {
                    jefer_sql = $"insert into Estudiantes values({datos[0]},'{datos[1]}',{datos[2]},{datos[3]},{datos[4]},{datos[5]},'{datos[6]}'";
                    fn.EjecutaSQLDirecto(jefer_sql);
                }
                numlinea++;
            }
            numlinea = 0;
        }
Esempio n. 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            string ruta = this.txtRuta.Text;

            clsArchivo    archivo = new clsArchivo(ruta);
            List <alumno> datos   = archivo.leerArchivo();



            List <alumno> arreglo         = datos;
            List <alumno> ArregloTemporal = arreglo;
            alumno        datosTemporal;


            for (int i = 0; i < arreglo.Count - 1; i++)
            {
                for (int j = i + 1; j < arreglo.Count; j++)
                {
                    /**
                     *  COMO NO ES UN NUMERO SE UTILIZA EL COMPARE.TO
                     *  PARA COMPARAR LOS 2 STRING POR ORDEN ALFABETICO
                     */
                    if (ArregloTemporal[i].ParcialUno > ArregloTemporal[j].ParcialUno)
                    {
                        datosTemporal      = ArregloTemporal[i];
                        ArregloTemporal[i] = ArregloTemporal[j];
                        ArregloTemporal[j] = datosTemporal;
                    }
                }
            }

            foreach (alumno info in arreglo)
            {
                this.listAlumnos.Items.Add(info.ParcialUno);
            }
        }
Esempio n. 9
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); }
        }