Example #1
0
        private void button1_Click_2(object sender, EventArgs e)
        {
            String       usu, pass;
            StreamReader Lectura;
            string       cadena, usuario, password;

            string[] campo      = new string[4];
            char[]   separador  = { '-' };
            bool     encontrado = false;

            try
            {
                usu      = "admin";
                pass     = "******";
                Lectura  = File.OpenText("BDUsuarios.txt");
                usuario  = Usuario_TextBox.Text;
                password = Password_TexBox.Text;
                cadena   = Lectura.ReadLine();

                while (cadena != null && encontrado == false)
                {
                    campo = cadena.Split(separador);
                    if (campo[0].Trim().Equals(usuario) && campo[1].Trim().Equals(password))
                    {
                        VentanaPrincipal principal_windows = new VentanaPrincipal();
                        MessageBox.Show("Usuario y Contraseña Correcta", "Inicio Correcto", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        encontrado = true;
                        principal_windows.Show();
                        this.Hide();
                    }
                    else
                    {
                        cadena = Lectura.ReadLine();
                    }
                }
                if (encontrado == false)
                {
                    Log llamada_log = new Log();
                    MessageBox.Show("Usuario o Contraseña Incorrecta", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    llamada_log.log();
                }
                Lectura.Close();
            }
            catch (FileNotFoundException fi)
            {
                MessageBox.Show("Error" + fi.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message);
            }
        }
Example #2
0
        public void Consulta(string path)
        {
            Console.Clear();
            Console.BackgroundColor = ConsoleColor.DarkBlue;
            StreamReader Lectura;
            string       Busqueda, Line;

            Busqueda = " ";
            Line     = " ";
            bool ValorBuscado;

            ValorBuscado = false;
            string[] tabla     = new string[6];
            char[]   indicador = { ';' };
            try
            {
                using (Lectura = File.OpenText(path))
                {
                    Console.WriteLine("Ingrese el numero de control a consultar");
                    Busqueda = Console.ReadLine();
                    Line     = Lectura.ReadLine();
                    while (Line != null && ValorBuscado == false)
                    {
                        tabla = Line.Split(indicador);
                        if (tabla[0].Trim().Equals(Busqueda))
                        {
                            Console.WriteLine("Número de control: {0}", tabla[0].Trim());
                            Console.WriteLine("Nombre: {0}", tabla[1].Trim());
                            Console.WriteLine("Carrea: {0}", tabla[2].Trim());
                            Console.WriteLine("Direccion: {0}", tabla[3].Trim());
                            Console.WriteLine("Número Telefonico: {0}", tabla[4].Trim());
                            Console.WriteLine("Email: {0}", tabla[5].Trim());
                            ValorBuscado = true;
                        }
                        else
                        {
                            Line = Lectura.ReadLine();
                        }
                    }
                    if (ValorBuscado == false)
                    {
                        Console.WriteLine("EL alumno con número de control {0} no está en la base ", Busqueda);
                    }
                    Lectura.Close();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("No se puede leer el archivo");
            }
        }
Example #3
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            StreamReader Lectura;
            StreamWriter escribir;
            String       cadena, libro;
            bool         encontrado = false;;

            string[] campo     = new string[5];
            char[]   separador = { ',' };

            try
            {
                Lectura  = File.OpenText("Historia.txt");
                escribir = File.CreateText("tmp.txt");
                libro    = txtEliminar.Text;
                cadena   = Lectura.ReadLine();
                while (cadena != null)
                {
                    campo = cadena.Split(separador);
                    if (campo[1].Trim().Equals(libro))
                    {
                        encontrado = true;
                    }
                    else
                    {
                        escribir.WriteLine(cadena);
                    }
                    cadena = Lectura.ReadLine();
                }

                if (encontrado == false)
                {
                    labelNombre.Text = "No existe";
                }
                else
                {
                    labelNombre.Text = "Libro eliminado";
                }
                Lectura.Close();
                escribir.Close();

                File.Delete("Historia.txt");
                File.Move("tmp.txt", "Historia.txt");
            }
            catch (FileNotFoundException fe)
            {
                labelNombre.Text = ("¡ERROR!" + fe.Message);
            }
        }
Example #4
0
        private void DatosContacto_Boton_Click(object sender, EventArgs e)
        {
            StreamReader Lectura;
            string       cadena, usuario;

            string[] campo      = new string[4];
            char[]   separador  = { '-' };
            bool     encontrado = false;

            try
            {
                Lectura = File.OpenText("BDRegistros.txt");
                usuario = Usuario_txtDatos.Text;
                cadena  = Lectura.ReadLine();

                while (cadena != null && encontrado == false)
                {
                    campo = cadena.Split(separador);
                    if (campo[3].Trim().Equals(usuario))
                    {
                        StreamReader leer = new StreamReader("BDRegistros.txt");
                        if (!leer.EndOfStream)
                        {
                            MessageBox.Show("Usuario Encontrado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            DatosMostrar_txt.AppendText("Nombre" + campo[0] + "Apellido" + campo[1] + "Edad" + campo[2] + "Usuario" + campo[3] + "\n ");
                            encontrado = true;
                        }
                    }
                    else
                    {
                        cadena = Lectura.ReadLine();
                    }
                }
                if (encontrado == false)
                {
                    MessageBox.Show("Usuario no Encontrado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                Lectura.Close();
            }
            catch (FileNotFoundException fi)
            {
                MessageBox.Show("Error" + fi.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            StreamReader Lectura;
            String       cadena, libro;
            bool         encontrado = false;;

            string[] campo     = new string[5];
            char[]   separador = { ',' };

            try
            {
                Lectura = File.OpenText("Espiritual.txt");
                libro   = txtBuscarCodigo.Text;
                cadena  = Lectura.ReadLine();
                while (cadena != null && encontrado == false)
                {
                    campo = cadena.Split(separador);
                    if (campo[0].Trim().Equals(libro))
                    {
                        txtEspiritualCodigo.Text = campo[0];
                        txtEspiritualNombre.Text = campo[1];
                        txtEspiritualAutor.Text  = campo[2];
                        txtEspiritualYear.Text   = campo[3];
                        txtEspiritualPagina.Text = campo[4];
                        labelMensaje.Visible     = false;
                        panelContenedorBCodigoEspiritual.Visible = true;
                        encontrado = true;
                    }
                    else
                    {
                        cadena = Lectura.ReadLine();
                    }
                }

                if (encontrado == false)
                {
                    labelMensaje.Text = "No existe el libro en nuestra libreria";
                }
                Lectura.Close();
            }
            catch (FileNotFoundException fe)
            {
                labelMensaje.Text = ("¡ERROR!" + fe.Message);
            }
        }
Example #6
0
        private void btnMas2_Click(object sender, EventArgs e)
        {
            StreamReader Lectura;
            String       cadena, libro;
            bool         encontrado = false;;

            string[] campo     = new string[5];
            char[]   separador = { ',' };

            try
            {
                Lectura = File.OpenText("Animacion.txt");
                libro   = labelSegunda.Text;
                cadena  = Lectura.ReadLine();
                while (cadena != null && encontrado == false)
                {
                    campo = cadena.Split(separador);
                    if (campo[1].Trim().Equals(libro))
                    {
                        txtAnimacionCodigo.Text             = campo[0];
                        txtAnimacionNombre.Text             = campo[1];
                        txtAnimacionAutor.Text              = campo[2];
                        txtAnimacionYear.Text               = campo[3];
                        txtAnimacionPagina.Text             = campo[4];
                        panelContenedorAnimacionMas.Visible = true;
                        encontrado = true;
                    }
                    else
                    {
                        cadena = Lectura.ReadLine();
                    }
                }

                if (encontrado == false)
                {
                    labelSegunda.Text = "No existe el libro en nuestra libreria";
                }
                Lectura.Close();
            }
            catch (FileNotFoundException fe)
            {
                labelSegunda.Text = ("¡ERROR!" + fe.Message);
            }
        }
Example #7
0
        private void Consultar_Boton_Click(object sender, EventArgs e)
        {
            StreamReader Lectura;
            string       cadena, usuario;

            string[] campo      = new string[4];
            char[]   separador  = { '-' };
            bool     encontrado = false;

            try
            {
                Lectura = File.OpenText("BDUsuarios.txt");
                usuario = Usuario_txtconsulta.Text;
                cadena  = Lectura.ReadLine();

                while (cadena != null && encontrado == false)
                {
                    campo = cadena.Split(separador);
                    if (campo[0].Trim().Equals(usuario))
                    {
                        MessageBox.Show("Usuario Encontrado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Usuario_txtconsulta.Clear();
                        encontrado = true;
                    }
                    else
                    {
                        cadena = Lectura.ReadLine();
                    }
                }
                if (encontrado == false)
                {
                    MessageBox.Show("Usuario no Encontrado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                Lectura.Close();
            }
            catch (FileNotFoundException fi)
            {
                MessageBox.Show("Error" + fi.Message);
            }
        }
Example #8
0
        public void Editar(string path)
        {
            Console.Clear();
            Console.BackgroundColor = ConsoleColor.DarkYellow;
            StreamReader Lectura;
            StreamWriter Tmp;
            int          op;
            string       Busqueda, Line, res, CampoNuevo;

            CampoNuevo = " ";
            Busqueda   = " ";
            Line       = " ";
            res        = " ";
            op         = 0;
            bool ValorBuscado;

            ValorBuscado = false;
            string[] tabla     = new string[6];
            char[]   indicador = { ';' };
            try
            {
                using (Lectura = File.OpenText(path))
                {
                    Tmp = File.CreateText("Tmp.txt");
                    Console.WriteLine("Ingrese el numero de control a modificar");
                    Busqueda = Console.ReadLine();
                    Line     = Lectura.ReadLine();

                    while (Line != null)
                    {
                        tabla = Line.Split(indicador);
                        if (tabla[0].Trim().Equals(Busqueda))
                        {
                            Console.WriteLine("0.Número de control: {0}", tabla[0].Trim());
                            Console.WriteLine("1.Nombre: {0}", tabla[1].Trim());
                            Console.WriteLine("2.Carrea: {0}", tabla[2].Trim());
                            Console.WriteLine("3.Direccion: {0}", tabla[3].Trim());
                            Console.WriteLine("4.Número Telefonico: {0}", tabla[4].Trim());
                            Console.WriteLine("5.Email: {0}", tabla[5].Trim());
                            ValorBuscado = true;
                            Console.WriteLine("Desea editar este registro?");
                            res = Console.ReadLine();
                            if ((res.ToUpper()) == "S")
                            {
                                try{
                                    Console.WriteLine("Ingrese el numero del campo que desea editar");
                                    op = Convert.ToInt32(Console.ReadLine());
                                    switch (op)
                                    {
                                    case 0:
                                        Console.WriteLine("El numero de control no es editable");
                                        Tmp.WriteLine(tabla[0] + "; " + tabla[1] + ";" + tabla[2] + ";" + tabla[3] + ";" + tabla[4] + ";" + tabla[5]);
                                        break;

                                    case 1:
                                        Console.WriteLine("Ingrese el nuevo nombre");
                                        CampoNuevo = Console.ReadLine();
                                        Tmp.WriteLine(tabla[0] + ";" + CampoNuevo + ";" + tabla[2] + ";" + tabla[3] + ";" + tabla[4] + ";" + tabla[5]);
                                        Console.WriteLine("Registro editado con exito!");
                                        break;

                                    case 2:
                                        Console.WriteLine("Ingrese la nueva carrera");
                                        CampoNuevo = Console.ReadLine();
                                        Tmp.WriteLine(tabla[0] + ";" + tabla[1] + ";" + CampoNuevo + ";" + tabla[3] + ";" + tabla[4] + ";" + tabla[5]);
                                        Console.WriteLine("Registro editado con exito!");
                                        break;

                                    case 3:
                                        Console.WriteLine("Ingrese la nueva dirección");
                                        CampoNuevo = Console.ReadLine();
                                        Tmp.WriteLine(tabla[0] + ";" + tabla[1] + "; " + tabla[2] + ";" + CampoNuevo + ";" + tabla[4] + "; " + tabla[5]);
                                        Console.WriteLine("Registro editado con exito!");
                                        break;

                                    case 4:
                                        Console.WriteLine("Ingrese el nuevo número telefonico");
                                        CampoNuevo = Console.ReadLine();
                                        Tmp.WriteLine(tabla[0] + ";" + tabla[1] + ";" + tabla[2] + ";" + tabla[3] + ";" + CampoNuevo + ";" + tabla[5]);
                                        Console.WriteLine("Registro editado con exito!");
                                        break;

                                    case 5:
                                        Console.WriteLine("Ingrese el nuevo número email");
                                        CampoNuevo = Console.ReadLine();
                                        Tmp.WriteLine(tabla[0] + ";" + tabla[1] + ";" + tabla[2] + ";" + tabla[3] + ";" + tabla[4] + ";" + CampoNuevo);
                                        Console.WriteLine("Registro editado con exito!");
                                        break;

                                    default:
                                        Console.WriteLine("No existe el campo ingresado");
                                        break;
                                    }
                                }catch (FormatException e) {
                                    Console.WriteLine("Entrada invalida: {0}", e.Message);
                                }
                            }
                            else
                            {
                                Tmp.WriteLine(Line);
                            }
                        }
                        else
                        {
                            Tmp.WriteLine(Line);
                        }
                        Line = Lectura.ReadLine();
                    }
                    if (ValorBuscado == false)
                    {
                        Console.WriteLine("EL alumno con número de control {0} no está en la base ", Busqueda);
                    }

                    Lectura.Close();
                    Tmp.Close();
                    File.Delete("miarchivo.txt");
                    File.Move("Tmp.txt", "miarchivo.txt");
                }
            }
            catch (Exception)
            {
                Console.WriteLine("No se puede leer el archivo");
            }
        }
Example #9
0
        public void Eliminar(string path)
        {
            Console.Clear();
            Console.BackgroundColor = ConsoleColor.DarkMagenta;
            StreamReader Lectura;
            StreamWriter Tmp;
            string       Busqueda, Line, res;

            Busqueda = " ";
            Line     = " ";
            res      = " ";
            bool ValorBuscado;

            ValorBuscado = false;
            string[] tabla     = new string[6];
            char[]   indicador = { ';' };
            try
            {
                using (Lectura = File.OpenText(path))
                {
                    Tmp = File.CreateText("Tmp.txt");
                    Console.WriteLine("Ingrese el numero de control a eliminar");
                    Busqueda = Console.ReadLine();
                    Line     = Lectura.ReadLine();

                    while (Line != null)
                    {
                        tabla = Line.Split(indicador);
                        if (tabla[0].Trim().Equals(Busqueda))
                        {
                            Console.WriteLine("Deseas eliminar el registro?");
                            res = Console.ReadLine();
                            if ((res.ToUpper()) == "S")
                            {
                                ValorBuscado = true;
                            }
                            else
                            {
                                return;
                            }
                        }
                        else
                        {
                            Tmp.WriteLine(Line);
                        }
                        Line = Lectura.ReadLine();
                    }
                    if (ValorBuscado == false)
                    {
                        Console.WriteLine("EL alumno con número de control {0} no está en la base ", Busqueda);
                    }
                    else
                    {
                        Console.WriteLine("EL alumno con número de control {0} ha sido eliminado ", Busqueda);
                    }
                    Lectura.Close();
                    Tmp.Close();
                    File.Delete("miarchivo.txt");
                    File.Move("Tmp.txt", "miarchivo.txt");
                }
            }
            catch (Exception)
            {
                Console.WriteLine("No se puede leer el archivo");
            }
        }