Beispiel #1
0
        static void Main(string[] args)
        {
            string[]           lines    = File.ReadAllLines("../../input.txt");
            SomeList <Angajat> angajati = new SomeList <Angajat>();

            foreach (string line in lines)
            {
                string[] data    = line.Split(' ');
                Angajat  angajat = new Angajat();
                angajat.Nume         = data[0];
                angajat.Prenume      = data[1];
                angajat.DataAngajare = DateTime.Parse(data[2]);
                angajati.Add(angajat);
            }

            angajati.Sort((a, b) => a.Nume.CompareTo(b.Nume));
            string[] output = new string[lines.Length];
            for (int i = 0; i < output.Length; i++)
            {
                output[i] = $"{angajati[i].Nume} {angajati[i].Prenume} {angajati[i].DataAngajare.ToShortDateString()}";
            }
            File.WriteAllLines("../../outputAlfabetic.txt", output);

            angajati.Sort((a, b) => (DateTime.Now.Year - b.DataAngajare.Year).CompareTo(DateTime.Now.Year - a.DataAngajare.Year));
            for (int i = 0; i < output.Length; i++)
            {
                output[i] = $"{angajati[i].Nume} {angajati[i].Prenume} {DateTime.Now.Year - angajati[i].DataAngajare.Year}";
            }
            File.WriteAllLines("../../outputVechime.txt", output);
        }
        public AngajatRepo()
        {
            lista = new List <Angajat>();
            try
            {
                using (StreamReader sr = new StreamReader(@"C:\Users\gaido\source\repos\ClasaAngajat\input.txt"))
                {
                    string   line;
                    string[] separated = new string[5];
                    while ((line = sr.ReadLine()) != null)
                    {
                        separated = line.Split(' ');

                        Angajat a = new Angajat(separated[0], separated[1], separated[2]);

                        lista.Add(a);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("FIle could not be read!");
                Console.WriteLine(e.ToString());
            }
        }
        static void Main(string[] args)
        {
            AngajatRepo ar = new AngajatRepo();

            ar.print(AngajatRepo.DATA);

            Angajat a = new Angajat("Harrison", "Ford", "11-11-1989");

            ar.Add(a);
            ar.Remove(2);

            ar.print(AngajatRepo.NUME);
        }
        public static List <Angajat> FileReader()
        {
            List <Angajat> Angajati = new List <Angajat>();

            string[] linesfromfile = File.ReadAllLines(@"..\..\Angajati.txt");
            char[]   sep           = { ' ', ';', ',', '.', ':', '!', '?', ' ', '*' };
            for (int i = 0; i < linesfromfile.Length; i++)
            {
                string[] eachline  = linesfromfile[i].Split(sep);
                string   lastname  = eachline[0];
                string   firstname = eachline[1];
                DateTime data      = new DateTime(int.Parse(eachline[4]), int.Parse(eachline[3]), int.Parse(eachline[2]));

                Angajat a1 = new Angajat(lastname, firstname, data);
                Angajati.Add(a1);
            }
            return(Angajati);
        }
 public void Add(Angajat a)
 {
     lista.Add(a);
 }