Exemplo n.º 1
0
        private static void ReadAndSaveSubject(SubjectsStorage dataStorage)
        {
            string name, surname, patronymic, passportNumber, birthday;

            Console.WriteLine(@"enter name: ");
            name = Console.ReadLine();
            Console.WriteLine(@"enter surname: ");
            surname = Console.ReadLine();
            Console.WriteLine(@"enter patronymic: ");
            patronymic = Console.ReadLine();
            Console.WriteLine(@"enter passport serial and number (without spaces): ");
            passportNumber = Console.ReadLine();
            Console.WriteLine(@"enter birth day (dd/mm/yyyy): ");
            birthday = Console.ReadLine();
            try
            {
                //Subject nextSubj = Subject.CreateSubject(name, surname, patronymic, passportNumber, birthday);
                //dataStorage.PutSubject(nextSubj);
                Subject nextSubj = new Subject(name, surname, patronymic, passportNumber, birthday);
                _subjects.Add(nextSubj);
            }
            catch (System.Exception exc)
            {
                Console.WriteLine("Error: {0}", exc.Data["Bad input"]);
            }
        }
Exemplo n.º 2
0
        // TODO: Split Main() into a few methods (in switch clause at least)
        static void Main()
        {
            var path = @"db.txt";

            using (var dataStorage = new SubjectsStorage(path))
            {
                _subjects = new ObservableCollection <Subject>(dataStorage.GetAllSubjects());
                // TODO: To think a little bit more about [0]-element or null
                _subjects.CollectionChanged += (o, args) => dataStorage.PutSubject(args.NewItems[0] as Subject);
                do
                {
                    Console.WriteLine();
                    Console.WriteLine(@"Type '/help' for help or enter some command:");
                    Console.Write(">> ");
                    var inputStr = Console.ReadLine();

                    while (true)
                    {
                        // TODO: Extract method to dictionary with commands
                        // (to think about dictionary<string, Action>)?
                        switch (inputStr)
                        {
                        case @"/exit":
                            Console.WriteLine("Exit");
                            return;

                        case @"/help":
                            WriteHelp();
                            break;

                        case @"/new":
                            ReadAndSaveSubject(dataStorage);
                            break;

                        case @"/show":
                            foreach (var subj in _subjects)
                            {
                                Console.WriteLine(subj);
                            }
                            break;

                        case @"/save":
                            SaveSubjects(_subjects);
                            break;

                        case @"/save sort":
                            SortAndSaveSubjects();
                            break;

                        default:
                            break;
                        }
                        Console.Write(">> ");
                        inputStr = Console.ReadLine();
                    }
                }while (true);
            }
        }