コード例 #1
0
        static void Eliminar(string path, Jag set)
        {
            Persona persona = Buscar(set);

            if (persona.Cedula == "")
            {
                return;
            }

            while (true)
            {
                WriteLine("¿Desea eliminarlo (Y/N)?");
                string opt = ReadLine().ToUpper();

                if (opt == "Y")
                {
                    bool remove = set.Remove(persona);
                    if (remove)
                    {
                        WriteLine("Borrado completado satisfactoriamente!!");
                    }
                    else
                    {
                        WriteLine("==> Borrado no realizado <==");
                    }
                    break;
                }
                else if (opt == "N")
                {
                    break;
                }
            }
        }
コード例 #2
0
        static void Listar(Jag set)
        {
            Persona[] order = set.toSortedArray();

            foreach (var i in order)
            {
                if (i != null)
                {
                    WriteLine(i);
                }
            }
        }
コード例 #3
0
        static void Save(string path, Jag set)
        {
            Persona[] order = set.toSortedArray();

            File.Delete(path);

            foreach (var i in order)
            {
                if (i != null)
                {
                    StreamWriter writer = File.AppendText(path);
                    writer.WriteLine(i.ToWrite());
                    writer.Close();
                }
            }
        }
コード例 #4
0
        static Persona Buscar(Jag set)
        {
            string ced = ReadCedula("\nIntroduzca la cédula a buscar: ");

            WriteLine();
            Write("Introduzca el apellido: ");
            string  last    = ReadLine();
            Persona persona = new Persona(ced, "", last, 0, 0, "");

            if (set.Contains(persona))
            {
                int pos = set.BinarySearch(persona);
                if (pos == -1)
                {
                    WriteLine("==> No se ha encontrado <==");
                    persona.Cedula   = "";
                    persona.LastName = "";
                }
                else
                {
                    int buck = Math.Abs(persona.GetHashCode() % set.Buckets);
                    if (set.Set[buck][pos] != null)
                    {
                        persona = set.Set[buck][pos];
                        WriteLine(persona);
                    }
                }
            }
            else
            {
                WriteLine("==> No se ha encontrado <==");
                persona.Cedula   = "";
                persona.LastName = "";
            }

            return(persona);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Environment.Exit(0);
            }

            FileExists(args[0]);

            StreamReader reader = new StreamReader(args[0]);

            string[] read = reader.ReadToEnd().Split(Environment.NewLine);
            reader.Close();

            List <Persona> people = new List <Persona>();

            foreach (var i in read)
            {
                if (i != "")
                {
                    people.Add(Persona.CreateFromLine(i));
                }
            }

            Jag Set = new Jag(2, 2, people);

            while (true)
            {
                FileExists(args[0]);

                WriteLine("\n[1] = Capturar\n[2] = Listar\n[3] = Buscar\n[4] = Editar\n[5] = Eliminar\n[6] = Guardar\n[7] = Salir");
                string opt = ReadLine();

                switch (opt)
                {
                case "1":
                    Capturar(args[0], Set);
                    break;

                case "2":
                    Listar(Set);
                    break;

                case "3":
                    Buscar(Set);
                    break;

                case "4":
                    Editar(args[0], Set);
                    break;

                case "5":
                    Eliminar(args[0], Set);
                    break;

                case "6":
                    Save(args[0], Set);
                    break;

                case "7":
                    Environment.Exit(0);
                    break;

                default:
                    WriteLine("\nLa opción elegida no es válida.");
                    break;
                }
            }
        }
コード例 #6
0
        static void Capturar(string path, Jag set)
        {
            while (true)
            {
                string ced = ReadCedula("\nCedula: ");
                Write("\nNombre: ");
                string name = ReadLine();
                Write("Apellidos: ");
                string ape = ReadLine();

                if (name == "" && ape == "")
                {
                    break;
                }

                int age = ReadAge("Edad (7 - 120): ");;
                while (age < 7 || age > 120)
                {
                    age = ReadAge("\nEdad (7 - 120): ");
                }

                char gender, state, grade;
                do
                {
                    gender = ReadChar("\nGénero (M/F): ");
                } while (gender != 'M' && gender != 'F');

                do
                {
                    state = ReadChar("\nEstado Civil (S/C): ");
                } while (state != 'S' && state != 'C');

                do
                {
                    grade = ReadChar("\nGrado Académico (I/M/G/P): ");
                } while (grade != 'I' && grade != 'M' && grade != 'G' && grade != 'P');

                decimal ahorros  = ReadMoney("\nAhorros: ");
                string  password = ReadPassword("\nContraseña: ");

                bool success = password == ReadPassword("\nConfirme contraseña: ");

                int datos = ToBits(age, gender, state, grade);

                Console.WriteLine();
                if (!success)
                {
                    continue;
                }

                while (true)
                {
                    WriteLine("\nGuardar (G); Rehacer (R); Salir (S)");
                    string opt = ReadLine().ToUpper();

                    if (opt == "G")
                    {
                        Persona nuevo = new Persona(ced, name, ape, datos, ahorros, password);
                        bool    add   = set.Add(nuevo);
                        if (add)
                        {
                            WriteLine("Agregado satisfactoriamente!!");
                        }
                        else
                        {
                            WriteLine("==> No se ha agregado <==");
                        }
                        break;
                    }
                    else if (opt == "R")
                    {
                        break;
                    }
                    else if (opt == "S")
                    {
                        Environment.Exit(0);
                    }
                }
            }
        }
コード例 #7
0
        static void Editar(string path, Jag set)
        {
            Persona persona = Buscar(set);

            if (persona.Cedula == "")
            {
                return;
            }

            while (true)
            {
                string ced = ReadCedula("\nCedula: ");
                Write("\nNombre: ");
                string name = ReadLine();
                Write("Apellidos: ");
                string ape = ReadLine();

                if (name == "" && ape == "")
                {
                    break;
                }

                int age = ReadAge("Edad (7 - 120): ");;
                while (age < 7 || age > 120)
                {
                    age = ReadAge("\nEdad (7 - 120): ");
                }

                char gender, state, grade;
                do
                {
                    gender = ReadChar("\nGénero (M/F): ");
                } while (gender != 'M' && gender != 'F');

                do
                {
                    state = ReadChar("\nEstado Civil (S/C): ");
                } while (state != 'S' && state != 'C');

                do
                {
                    grade = ReadChar("\nGrado Académico (I/M/G/P): ");
                } while (grade != 'I' && grade != 'M' && grade != 'G' && grade != 'P');

                decimal ahorros  = ReadMoney("\nAhorros: ");
                string  password = ReadPassword("\nContraseña: ");

                bool success = password == ReadPassword("\nConfirme contraseña: ");

                int datos = ToBits(age, gender, state, grade);

                Console.WriteLine();
                if (!success)
                {
                    continue;
                }

                Persona nuevo   = new Persona(ced, name, ape, datos, ahorros, password);
                bool    replace = set.Replace(persona, nuevo);
                if (replace)
                {
                    WriteLine("Edición completada satisfactoriamente!!");
                }
                else
                {
                    WriteLine("==> Edición no realizada <==");
                }
                break;
            }
        }