public static bool ChangePassword(ref string password, int startY = 0)
        {
            var passEditor = new PasswordEditor(password);
            ClassEditor <PasswordEditor> editor = new ClassEditor <PasswordEditor>(
                passEditor,
                startY
                );
            bool changed = editor.Edit();

            editor.Clear();
            if (changed)
            {
                password = passEditor.Password;
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        void ShowAccountAddMenu()
        {
            menu.Update(accountAddMenu);
            Account account;
            int     selectedIndex = menu.Choice(
                (ConsoleKeyInfo key, int selectedIndex) =>
            {
                if (key.Key == ConsoleKey.Escape)
                {
                    return(-1);
                }
                return(null);
            }
                );

            if (selectedIndex >= 0)
            {
                menu.Clear();
                switch (selectedIndex)
                {
                case 0:     //Admin
                {
                    account = new Admin("", "");
                    ClassEditor <Admin> editor = new ClassEditor <Admin>(
                        (Admin)account,
                        validateAdmin
                        );
                    if (editor.Edit())
                    {
                        settings.AddAccount(account);
                    }
                    editor.Clear();
                }
                break;

                case 1:     //Teacher
                {
                    account = new Teacher("", "", "", "", "", DateTime.Today, new string[0], new string[0]);
                    ClassEditor <Teacher> editor = new ClassEditor <Teacher>(
                        (Teacher)account,
                        validateTeacher
                        );
                    if (editor.Edit())
                    {
                        settings.AddAccount(account);
                    }
                    editor.Clear();
                }
                break;

                case 2:     //Student
                {
                    account = new Student("", "", "", "", "", DateTime.Today, "");
                    Student student = (Student)account;

                    ClassEditor <Student> editor = new ClassEditor <Student>(
                        (Student)account,
                        validateStudent
                        );
                    if (editor.Edit())
                    {
                        settings.AddAccount(account);
                    }
                    editor.Clear();

                    if (student.Group != "" && groupsList.Contains(student.Group))
                    {
                        Group group = new Group(settings, student.Group);
                        group.Students.Add(student.Login);
                        group.Export(settings);
                    }
                }
                break;
                }
            }
        }
Beispiel #3
0
        void ShowAccountEditMenu(int index)
        {
            Account account = settings.LoadAccount(accountsList[index]);
            string  _login  = account.Login;

            menu.Clear();

            BinaryWriter RewriteFile() => settings.GetAccountFileWriter(_login);

            switch (account.Type)
            {
            case AccountType.Admin:
            {
                ClassEditor <Admin> editor = new ClassEditor <Admin>(
                    (Admin)account,
                    validateAdmin
                    );
                if (editor.Edit())
                {
                    using (var writer = RewriteFile())
                        account.Export(writer);
                }
                editor.Clear();
            }
            break;

            case AccountType.Teacher:
            {
                Teacher teacher = (Teacher)account;
                ClassEditor <Teacher> editor = new ClassEditor <Teacher>(
                    (Teacher)account,
                    validateTeacher
                    );
                if (editor.Edit())
                {
                    using (var writer = RewriteFile())
                        account.Export(writer);
                }
                editor.Clear();

                if (_login != teacher.Login)
                {
                    foreach (string groupName in teacher.Groups)
                    {
                        Group group = new Group(settings, groupName);
                        group.Teachers[Array.IndexOf(group.Teachers.ToArray(), _login)] = teacher.Login;
                        group.ExportInfo(settings);
                    }
                }
            }
            break;

            case AccountType.Student:
            {
                Student student = (Student)account;
                string  _group  = student.Group;
                ClassEditor <Student> editor = new ClassEditor <Student>(
                    student,
                    validateStudent
                    );
                if (editor.Edit())
                {
                    using (var writer = RewriteFile())
                        account.Export(writer);
                }
                editor.Clear();

                if (_group != "" && student.Group != _group)
                {
                    Group previousGroup = new Group(settings, _group);
                    if (previousGroup.Students.Contains(_login))
                    {
                        previousGroup.Students.Remove(_login);
                        previousGroup.Export(settings);
                    }
                    if (student.Group != "" && groupsList.Contains(student.Group))
                    {
                        Group newGroup = new Group(settings, student.Group);
                        newGroup.Students.Add(student.Login);
                        newGroup.Export(settings);
                    }
                }
                if (_login != student.Login)
                {
                    Group group = new Group(settings, student.Group);
                    group.Students[Array.IndexOf(group.Students.ToArray(), _login)] = student.Login;
                    group.ExportInfo(settings);
                }
            }
            break;
            }

            if (_login != account.Login)
            {
                settings.RenameAccount(_login, account.Login);
            }
        }