static void Main(string[] args)
        {
            
            Person[] malta; 
            malta = new Person[10];
//            int mx = 3;
//            for (int ix = 0; ix < mx; ix++)
//                malta[ix] = readPerson();
            
            int max = readFilePersons(malta, "pessoas.txt");
            
            malta[max] = new Student("Zé", new DateTime(2001,1,1), 10);
            
            Console.WriteLine("Lista de Pessoas");

            foreach(Person p in malta)
            {
             
                if (p != null)
                   Console.WriteLine("{0} Idade = {1}", p, p.Age);

            }

            int i;
            
            Console.Write("Introduza o indice: ");
            string line = Console.ReadLine();
            i = int.Parse(line);

            // if (malta[i] is Student) pergunta se é do tipo student 
            // Student s = (student) malta[i];  se quisermos forçar o tipo student
            Student s = malta[i] as Student; // se quisermos que assuma null se n for do tipo student

            if (s!=null)
                Console.WriteLine("number = {0}", s.Number);
            else
                Console.WriteLine("not student");

             //Console.WriteLine("Pessoa : {0}", p.ToString());
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Student a = new Student();

            a.Announcement();
        }
Exemplo n.º 3
0
 public void PrintBasicInfo(Student student)
 {
     Console.WriteLine(student.ToString());
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var listOfStudents = new HashSet <Student>(new CustomComparer());

            //error log
            using var streamWriter = new StreamWriter(@"log.txt");
            string path, outpath, format;

            //default xml, dane/dane.csv , result.xml
            format = args.Length > 2 ? args[2] : "xml";
            // path = args.Length > 0 ? args[0] : @"Dane/dane.csv"; TODO: UNCOMMENT
            path    = @"C:\Users\Weronika Wawrzyniak\Desktop\APBD-tut2\ConsoleApp1\ConsoleApp1\Dane\dane.csv";
            outpath = args.Length > 1 ? args[1] : $"output/result.{format}";



            if (!File.Exists(path))
            {
                streamWriter.WriteLine("Data source doesnt exist");
            }
            if (!File.Exists(outpath))
            {
                streamWriter.WriteLine("Output file doesnt exist - creating a new one ");
            }
            else
            {
                streamWriter.WriteLine("Output file exists - override");
            }


            var fi = new FileInfo(path);

            using (var stream = new StreamReader(fi.OpenRead()))
            {
                string line = null;
                //creating a new student from the stream
                while ((line = stream.ReadLine()) != null)
                {
                    string[] columns = line.Split(',');
                    //only if number of columns is 9
                    if (columns.GetLength(0) == 9)
                    {
                        Boolean allGood = true;
                        //and if none of the columns is empty
                        foreach (string c in columns)
                        {
                            if (string.IsNullOrWhiteSpace(c))
                            {
                                allGood = false;
                            }
                        }
                        if (allGood == true)
                        {
                            var buffStudent = new Student
                            {
                                FirstName = columns[0],
                                LastName  = columns[1],
                                BirthDate = DateTime.Parse(columns[5]),
                                Studies   = new Studies
                                {
                                    mode = columns[3],
                                    name = columns[2]
                                },
                                Email        = columns[6],
                                MothersName  = columns[7],
                                FathersName  = columns[8],
                                StudentIndex = columns[4]
                            };
                            //will be added to the list only if there are no duplicates
                            if (listOfStudents.Contains(buffStudent))
                            {
                                //duplicate error into log.txt

                                streamWriter.WriteLine($"Student with the firstName: {buffStudent.FirstName} was not added due to duplicate");
                            }
                            else
                            {
                                listOfStudents.Add(buffStudent);
                            }
                        }
                        else
                        {  //empty columns error into log.txt
                            streamWriter.WriteLine("One or more columns empty");
                        }
                    }
                    else
                    {  //not 9 columns error into log.txt
                        streamWriter.WriteLine("Not described by 9 data columns.");
                    }
                }
            }
            activeStudies ac = new activeStudies()
            {
                studentsList = listOfStudents,
            };
            University uni = new University()
            {
                students = listOfStudents, pary = ac.countSubjects()
            };

            uni.random();
            string   author  = "Weronika_Wawrzyniak_s19515";
            DateTime time    = DateTime.Now;
            string   message = ($"university_created_at_{time}_author_{author}");

            switch (format)
            {
            case "xml":
                //  var writer = new FileStream(outpath, FileMode.Create);
                var writer      = new FileStream("result.xml", FileMode.Create);
                var serialaizer = new XmlSerializer(typeof(University), new XmlRootAttribute(message));
                serialaizer.Serialize(writer, uni);
                break;

            case "json":
                var jsonString = JsonSerializer.Serialize(listOfStudents);
                File.WriteAllText("data.json", jsonString);
                break;

            default:
                streamWriter.WriteLine("Invalid path");
                break;
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            //////11111111
            Student   Andrey = new Student();
            Random    rand   = new Random();
            ArrayList First  = new ArrayList();

            First.Add(rand.Next(100));
            First.Add(rand.Next(100));
            First.Add(rand.Next(100));
            First.Add(rand.Next(100));
            First.Add(rand.Next(100));
            First.Add(Andrey);
            First.Remove(Andrey);

            foreach (int ch in First)
            {
                Console.WriteLine(ch);
            }
            Console.WriteLine("Количество элементов в коллекции " + First.Count);
            if (First.Contains(84))
            {
                Console.WriteLine("Колекция содержит элемент : 84");
            }
            else
            {
                Console.WriteLine("Колекция не содержит элемент : 84");
            }

            ///////2222222

            SortedList <string, long> Second = new SortedList <string, long>();

            Second.Add("1 first", 1);
            Second.Add("2 second", 2);
            Second.Add("3 third", 3);
            Second.Add("4 fourth", 4);
            Second.Add("5 five", 5);
            Second.Add("6 six", 6);

            foreach (KeyValuePair <string, long> ch in Second)
            {
                Console.WriteLine($"Key : {ch.Key}, Value : {ch.Value}");
            }
            for (int i = 0; i < 3; i++)
            {
                Second.RemoveAt(i);
            }
            Console.WriteLine("После удаления элементов");
            foreach (KeyValuePair <string, long> ch in Second)
            {
                Console.WriteLine($"Key : {ch.Key}, Value : {ch.Value}");
            }

            IList <long> list = Second.Values;
            Stack <long> stak = new Stack <long>();

            for (int i = 0; i < list.Count; i++)
            {
                stak.Push(list[i]);
            }
            foreach (long ch in stak)
            {
                Console.WriteLine(ch);
            }
            if (stak.Contains(6))
            {
                Console.WriteLine(stak.Peek());
            }


            ///////3333333

            SortedList <int, Film> film = new SortedList <int, Film>();
            Film Titanik   = new Film(25);
            Film SpanchBob = new Film(16);

            film.Add(1, Titanik);
            film.Add(2, SpanchBob);
            foreach (KeyValuePair <int, Film> ch in film)
            {
                Console.WriteLine(ch.Value);
            }

            IList <Film> spis = film.Values;
            Stack <Film> st   = new Stack <Film>();

            for (int i = 0; i < spis.Count; i++)
            {
                st.Push(spis[i]);
            }
            foreach (Film ch in st)
            {
                Console.WriteLine(ch);
            }
            if (st.Contains(Titanik))
            {
                Console.WriteLine(st.Peek());
            }


            //////444444
            ///



            void ColectionChange(object sender, NotifyCollectionChangedEventArgs e)
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    Student newStud = e.NewItems[0] as Student;
                    Console.WriteLine($"Добавлен новый объект: {newStud.Name}");
                    break;

                case NotifyCollectionChangedAction.Remove:
                    Student OldStud = e.OldItems[0] as Student;
                    Console.WriteLine($"Удален объект: {OldStud.Name}");
                    break;
                }
            }

            ObservableCollection <Student> Stud = new ObservableCollection <Student>();

            Stud.CollectionChanged += ColectionChange;
            Stud.Add(new Student {
                Name = "Andrey"
            });
            Stud.Add(new Student {
                Name = "Igor"
            });
            Stud.Add(new Student {
                Name = "Kesha"
            });
            Stud.Add(new Student {
                Name = "Tanyusha"
            });
            foreach (Student stud in Stud)
            {
                Console.WriteLine(stud.Name);
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            //arrlist =  list
            //set  = hashset
            //map = dictionary


            string fileStart     = CheckArgument1(args);
            string fileResult    = CheckArgument2(args);
            string fileExtension = CheckArgument3(args);
            string fileLogs      = "data/łog.txt";

            StreamWriter streamWriter = new StreamWriter(fileLogs);
            FileInfo     file         = new FileInfo(fileStart);

            List <Student>           studentList = new List <Student>();
            Dictionary <string, int> stundetMap  = new Dictionary <string, int>();

            try
            {
                using (StreamReader stream = new StreamReader(file.OpenRead()))
                {
                    string line = "";
                    while ((line = stream.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                        string[] student = line.Split(",");
                        Console.WriteLine(line);

                        if (checkData(student))
                        {
                            var kierunek = new Kierunek
                            {
                                nazwa = student[2],
                                tryb  = student[3],
                            };
                            Student student1 = new Student
                            {
                                Imie          = student[0],
                                Nazwisko      = student[1],
                                Index         = int.Parse(student[4]),
                                Kierunek      = kierunek,
                                DataUrodzenia = student[5],
                                Email         = student[6],
                                Ojciec        = student[8],
                                Matka         = student[7]
                            };
                            studentList.Add(student1);

                            if (stundetMap.ContainsKey(kierunek.nazwa))
                            {
                                stundetMap[kierunek.nazwa]++;
                            }
                            else
                            {
                                stundetMap.Add(kierunek.nazwa, 1);
                            }
                        }
                        else
                        {
                            streamWriter.WriteLine("Zle podane dane : " + line);
                        }
                    }
                }
            }catch (FileNotFoundException)
            {
                Console.WriteLine("Plik nazwa nie istnieje");
                streamWriter.WriteLine("Plik nazwa nie istnieje");
                return;
            }catch (ArgumentException)
            {
                Console.WriteLine("Podana ścieżka jest niepoprawna");
                streamWriter.WriteLine("Podana ścieżka jest niepoprawna");
                return;
            }catch (Exception e3)
            {
                Console.WriteLine(e3.Message);
                streamWriter.WriteLine(e3.Message);
                return;
            }

            streamWriter.Flush();
            streamWriter.Close();


            ActiveStudies activeSt = new ActiveStudies()
            {
                activeStudies = new List <ActiveStudie>()
            };

            foreach (KeyValuePair <string, int> entry in stundetMap)
            {
                activeSt.activeStudies.Add(new ActiveStudie {
                    name = entry.Key, number = entry.Value
                });
            }

            Students students = new Students
            {
                Student = studentList.Distinct(new EqualityComp()).ToList <Student>()
            };

            Uczelnia uczelnia = new Uczelnia
            {
                data          = "14.03.2020",
                autor         = "Alvan Maksym",
                student       = students,
                activeStudies = activeSt,
            };


            FileStream writer = new FileStream(fileExtension, FileMode.Create);

            XmlSerializer           serializer = new XmlSerializer(typeof(Uczelnia));
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add("", "");

            serializer.Serialize(writer, uczelnia, namespaces);
        }
Exemplo n.º 7
0
        static void ShowHandleStudentsMenu()
        {
            CurrentOption = "a";
            Console.WriteLine("Menu de gestionar alumnos.");
            Console.WriteLine("Opciones: a - para añadir un nuevo almuno");
            Console.WriteLine("Opciones: e + dni - para editar un alumno existente");
            Console.WriteLine("Opciones: n - ver información del alumno");
            Console.WriteLine("Opciones: n/e - ver exámenes de alumno");
            Console.WriteLine("Opciones: n/e - ver asignaturas de alumno");
            Console.WriteLine("Presione m para acabar y volver al menú principal");

            while (true)
            {
                var option = Console.ReadLine();

                if (option == "m")
                {
                    break;
                }
                else if (option == "a")
                {
                    Console.WriteLine("Para volver sin guardar alumno escriba  *.");
                    Console.WriteLine("escriba el dni:");

                    #region read dni
                    var dni = Console.ReadLine();

                    if (dni == "*")
                    {
                        break;
                    }

                    ValidationResult <string> vrDni;
                    while (!(vrDni = Student.ValidateDni(dni)).IsSuccess)
                    {
                        Console.WriteLine(vrDni.AllErrors);
                        dni = Console.ReadLine();
                    }

                    if (dni == "*")
                    {
                        break;
                    }

                    #endregion

                    #region read name
                    Console.WriteLine("escriba el nombre y apellidos:");
                    var name = Console.ReadLine();

                    if (name == "*")
                    {
                        break;
                    }

                    ValidationResult <string> vrName;
                    while (!(vrName = Student.ValidateName(name)).IsSuccess)
                    {
                        Console.WriteLine(vrName.AllErrors);
                        name = Console.ReadLine();
                    }

                    #endregion

                    #region read chair number
                    Console.WriteLine("escriba el número de silla:");
                    var chairNumberText = Console.ReadLine();

                    if (chairNumberText == "*")
                    {
                        break;
                    }

                    ValidationResult <int> vrChair;
                    while (!(vrChair = Student.ValidateChairNumber(chairNumberText)).IsSuccess)
                    {
                        Console.WriteLine(vrChair.AllErrors);
                        chairNumberText = Console.ReadLine();
                    }

                    #endregion

                    if (vrDni.IsSuccess && vrName.IsSuccess && vrChair.IsSuccess)
                    {
                        var student = new Student
                        {
                            Dni         = vrDni.ValidatedResult,
                            Name        = vrName.ValidatedResult,
                            ChairNumber = vrChair.ValidatedResult
                        };

                        var sr = student.Save();
                        if (sr.IsSuccess)
                        {
                            Console.WriteLine($"alumno guardado correctamente");
                        }
                        else
                        {
                            Console.WriteLine($"uno o más errores han ocurrido y el almuno no se guardado correctamente: {sr.AllErrors}");
                        }
                    }
                }
            }

            ClearCurrentConsoleLine();
            Console.WriteLine();
            ShowMainMenu();
        }