Beispiel #1
0
        static public void Load()
        {
            User selUser = Program.SelectUser;

            Program.SelectUser = null;
            string path = Path.Combine(Directory.GetCurrentDirectory(), "data\\users.hav");

            if (File.Exists(path))
            {
                string   JSONString;
                FileRead JSONRead = new FileRead();

                JSONString = JSONRead.GetJSONString(path);
                UsertCollection usertCollection = JsonConvert.DeserializeObject <UsertCollection>(JSONString);
                Items = usertCollection.Users;
                Items.ForEach(user =>
                {
                    user.ChangeDataEvent += () =>
                    {
                        ChangeDataInListEvent?.Invoke();
                    };
                });
            }
            else
            {
                Save();
                Load();
            }
            if (selUser != null)
            {
                selUser = Users.GetUser(selUser.Login);
            }
            Program.SelectUser = selUser;
        }
Beispiel #2
0
        static public void Load()
        {
            User selUser = Program.SelectUser;

            Program.SelectUser = null;
            string path = Path.Combine(Directory.GetCurrentDirectory(), "data\\students.hav");

            if (File.Exists(path))
            {
                string   JSONString;
                FileRead JSONRead = new FileRead();

                JSONString = JSONRead.GetJSONString(path);
                StudentCollection studentCollection = JsonConvert.DeserializeObject <StudentCollection>(JSONString);
                Items = studentCollection.Students;
                Items.ForEach(student =>
                {
                    student.ChangeDataEvent += () =>
                    {
                        ChangeDataInListEvent?.Invoke();
                    };
                });
            }
            else
            {
                Save();
                Load();
            }
            Program.SelectUser = selUser;
        }
Beispiel #3
0
 static public bool AddUser(string login, string pass)
 {
     if (!Users.Extant(login))
     {
         User user = new User(login, pass);
         user.ChangeDataEvent += () =>
         {
             ChangeDataInListEvent?.Invoke();
         };
         Items.Add(user);
         return(true);
     }
     else
     {
         MessageBox.Show("Такой пользователь уже существует", "Ошибка создания пользователя");
         return(false);
     }
 }
Beispiel #4
0
 static public bool AddGroup()
 {
     if (Program.SelectUser.Role < 2)
     {
         Group group = new Group
         {
             Id = Students.GetNextId()
         };
         group.ChangeDataEvent += () =>
         {
             ChangeDataInListEvent?.Invoke();
         };
         Items.Add(group);
         return(true);
     }
     else
     {
         MessageBox.Show("У вас недостаточно Прав", "Ошибка создания группы");
         return(false);
     }
 }
Beispiel #5
0
 static public bool AddSubject()
 {
     if (Program.SelectUser.Role < 2)
     {
         Subject subject = new Subject
         {
             Id = Students.GetNextId()
         };
         subject.ChangeDataEvent += () =>
         {
             ChangeDataInListEvent?.Invoke();
         };
         Items.Add(subject);
         return(true);
     }
     else
     {
         MessageBox.Show("У вас недостаточно Прав", "Ошибка создания предмета");
         return(false);
     }
 }
Beispiel #6
0
 static public bool AddStudent(Group group)
 {
     if (Program.SelectUser.Role < 2)
     {
         Student student = new Student
         {
             Id_Group = group.Id,
             Id       = GetNextId()
         };
         student.ChangeDataEvent += () =>
         {
             ChangeDataInListEvent?.Invoke();
         };
         Items.Add(student);
         return(true);
     }
     else
     {
         MessageBox.Show("У вас недостаточно Прав", "Ошибка создания студента");
         return(false);
     }
 }