private void Enter_Click(object sender, RoutedEventArgs e)
        {
            if ((Sername.Text == "") || (Name.Text == "") || (Patronymic.Text == "") || (Subject.Text == "") || (Login.Text == "") || (Password.Text == ""))
            {
                MessageBox.Show("Заполните все поля!", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }

            else
            {
                if ((Sername.Text == "") || (Name.Text == "") || (Patronymic.Text == "") || (Subject.Text == "") || (Login.Text == "") || (Password.Text == ""))
                {
                    MessageBox.Show("Заполните все поля!", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }

                else
                {
                    Serialization        ser  = new Serialization();
                    List <Authorization> list = ser.Deserialize();
                    foreach (Authorization x in list)
                    {
                        if (x.Login == Login.Text)
                        {
                            MessageBox.Show("Введённый логин уже используется", "", MessageBoxButton.OK);
                            return;
                        }
                    }
                    var      hash = CalculateHash(Password.Text);
                    Teacher  t    = new Teacher(Sername.Text, Name.Text, Patronymic.Text, Subject.Text);
                    Students s    = new Students("-1", "-1", "-1", "-1", t.Subject, -1);
                    t.History = new List <HistoryOfChanges>();
                    Authorization    aut  = new Authorization("-1", "-1", s);
                    HistoryOfChanges hist = new HistoryOfChanges(aut, aut);
                    t.History.Add(hist);
                    Authorization a = new Authorization(Login.Text, hash, t);
                    list.Add(a);
                    ser.Serialize(list);
                    MessageBox.Show("Регистрация прошла успешно!", "", MessageBoxButton.OK);
                }
            }
            Name.Text       = "";
            Sername.Text    = "";
            Patronymic.Text = "";
            Subject.Text    = "";
            Login.Text      = "";
            Password.Text   = "";
            NavigationService.GoBack();
        }
Example #2
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            if ((FIO.Text == "") || (Group.Text == ""))
            {
                MessageBox.Show("Заполните все поля!", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                Serialization        ser  = new Serialization();
                List <Authorization> list = ser.Deserialize();
                string[]             mas  = FIO.Text.Split(new char[] { ' ' });
                if (mas.Length < 3)
                {
                    MessageBox.Show("Заполните поле 'ФИО' должным образом.", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                if (mas.Length > 3)
                {
                    MessageBox.Show("Заполните поле 'ФИО' должным образом. \nСлишком много данных в одной строке.", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                bool t = false;
                foreach (Authorization student in list)
                {
                    try
                    {
                        Students st = (Students)student.User;
                        if ((mas[0] == st.Sername) && (mas[1] == st.Name) && (mas[2] == st.Patronymic) && (Group.Text == st.Group))
                        {
                            Object           stud = new Students("-1", "-1", "-1", "-1", "-1", -1);
                            Authorization    x    = new Authorization("-1", "-1", stud);
                            HistoryOfChanges hist = new HistoryOfChanges(student, x);
                            P.History.Add(hist);
                            P.MakeIt10();
                            foreach (Authorization X in list)
                            {
                                try
                                {
                                    Teacher te = (Teacher)X.User;
                                    if (P.Name == te.Name && P.Sername == te.Sername && P.Subject == te.Subject && P.Patronymic == te.Patronymic)
                                    {
                                        te.History = P.History;
                                    }
                                }
                                catch { }
                            }
                            list.Remove(student);
                            ser.Serialize(list);
                            MessageBox.Show("Удаление завершено", "-", MessageBoxButton.OK);
                            FIO.Text   = "";
                            Group.Text = "";

                            t = true;
                            break;
                        }
                    }
                    catch { }
                }
                if (t == false)
                {
                    MessageBox.Show("Студент не найден", "-", MessageBoxButton.OK);
                }
            }
        }
Example #3
0
        private void SaveChanges_Click(object sender, RoutedEventArgs e)
        {
            //try
            //{
            if (P == null)
            {
                NavigationService.Navigate(new Entrance()); return;
            }
            Serialization        ser            = new Serialization();
            List <Authorization> list           = ser.Deserialize();
            List <Students>      listOfStudents = new List <Students>();

            foreach (Authorization el in list)
            {
                try
                {
                    Students student = (Students)el.User;
                    if (group != "")
                    {
                        if (student.Group == group)
                        {
                            listOfStudents.Add(student);
                        }
                    }
                    else
                    {
                        if (fio != null && mark == -1)
                        {
                            if (student.Sername == fio[0] && student.Name == fio[1] && student.Patronymic == fio[2])
                            {
                                listOfStudents.Add(student);
                            }
                        }
                        else
                        {
                            if (fio == null && mark >= 0 && mark == student.GetMark(P.Subject))
                            {
                                listOfStudents.Add(student);
                            }
                            else
                            {
                                if (fio != null && mark >= 0 && student.Sername == fio[0] && student.Name == fio[1] && student.Patronymic == fio[2] && mark == student.GetMark(P.Subject))
                                {
                                    listOfStudents.Add(student);
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            int t = 1;
            int m;

            for (int i = 0; i < listOfStudents.Count; i++)
            {
                if ((arj[i].Group == "ББИ161" || arj[i].Group == "ББИ162" || arj[i].Group == "ББИ163" || arj[i].Group == "ББИ164" || arj[i].Group == "ББИ165" || arj[i].Group == "ББИ166" || arj[i].Group == "ББИ167" || arj[i].Group == "ББИ168") == false || (0 <= arj[i].Mark && arj[i].Mark <= 10) == false)
                {
                    MessageBox.Show("Изменения должны быть корректными", "!", MessageBoxButton.OK, MessageBoxImage.Exclamation); return;
                }
                if (arj[i].Name == "" || arj[i].Sername == "" || arj[i].Patronymic == "")
                {
                    MessageBox.Show("Не оставляйте поля пустыми", "!", MessageBoxButton.OK, MessageBoxImage.Exclamation); return;
                }
                try
                {
                    m = int.Parse(arj[i].Name);
                    t = 0;
                }
                catch
                {
                }
                try
                {
                    m = int.Parse(arj[i].Sername);
                    t = 0;
                }
                catch
                {
                }
                try
                {
                    m = int.Parse(arj[i].Patronymic);
                    t = 0;
                }
                catch
                {
                }
                if (t == 0)
                {
                    MessageBox.Show("ФИО должны быть записаны буквами", "!", MessageBoxButton.OK, MessageBoxImage.Exclamation); return;
                }
                int _mark;
                switch (P.Subject)
                {
                case "Программирование":
                    _mark = listOfStudents[i].marks.Programming;
                    break;

                case "Экономика":
                    _mark = listOfStudents[i].marks.Economics;
                    break;

                case "Математический анализ":
                    _mark = listOfStudents[i].marks.Mathematical_analysis;
                    break;

                default:
                    _mark = 0;
                    break;
                }
                Authorization StudentBefore;
                Authorization StudentAfter;
                if (listOfStudents[i].Name != arj[i].Name || listOfStudents[i].Sername != arj[i].Sername || listOfStudents[i].Patronymic != arj[i].Patronymic || listOfStudents[i].Group != arj[i].Group || _mark != arj[i].Mark)
                {
                    for (int x = 0; x < list.Count; x++)
                    {
                        try
                        {
                            Students s = (Students)list[x].User;
                            if (listOfStudents[i] == s)
                            {
                                StudentBefore = list[x];
                                Students st = new Students(arj[i].Sername, arj[i].Name, arj[i].Patronymic, arj[i].Group, P.Subject, arj[i].Mark);
                                switch (P.Subject)
                                {
                                case "Программирование":
                                    st.marks.Economics             = s.marks.Economics;
                                    st.marks.Mathematical_analysis = s.marks.Mathematical_analysis;
                                    break;

                                case "Экономика":
                                    st.marks.Programming           = s.marks.Programming;
                                    st.marks.Mathematical_analysis = s.marks.Mathematical_analysis;
                                    break;

                                case "Математический анализ":
                                    st.marks.Programming = s.marks.Programming;
                                    st.marks.Economics   = s.marks.Economics;
                                    break;

                                default:

                                    break;
                                }
                                StudentAfter = new Authorization(list[x].Login, list[x].Password, st);
                                HistoryOfChanges hist = new HistoryOfChanges(StudentBefore, StudentAfter);
                                P.History.Add(hist);
                                P.MakeIt10();
                                list.Remove(StudentBefore);
                                list.Add(StudentAfter);

                                //int g=-1;
                                //for(int h=0; h<list.Count; h++)
                                //{
                                //    try
                                //    {

                                //        Students stud = (Students)list[i].User;
                                //        Students stu = StudentBefore.User as Students;
                                //        if (stud.Name == stu.Name && stud.Sername == stu.Sername && stud.Group == stu.Group && stud.Patronymic == stu.Patronymic)
                                //        {

                                //            g = h;

                                //        }
                                //    }
                                //    catch { }
                                //}
                                //if (g==-1)
                                //{
                                //    MessageBox.Show("Всё плохо");
                                //    return;
                                //}

                                foreach (Authorization X in list)
                                {
                                    try
                                    {
                                        Teacher te = (Teacher)X.User;
                                        if (P.Name == te.Name && P.Sername == te.Sername && P.Subject == te.Subject && P.Patronymic == te.Patronymic)
                                        {
                                            te.History = P.History;
                                        }
                                    }
                                    catch { }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }


                int pr = listOfStudents[i].marks.Programming, ec = listOfStudents[i].marks.Economics, ma = listOfStudents[i].marks.Mathematical_analysis;
                listOfStudents[i] = new Students(arj[i].Sername, arj[i].Name, arj[i].Patronymic, arj[i].Group, P.Subject, arj[i].Mark);
                switch (P.Subject)
                {
                case "Программирование":
                    listOfStudents[i].marks.Mathematical_analysis = ma;
                    listOfStudents[i].marks.Economics             = ec;
                    break;

                case "Экономика":
                    listOfStudents[i].marks.Programming           = pr;
                    listOfStudents[i].marks.Mathematical_analysis = ma;
                    break;

                case "Математический анализ":
                    listOfStudents[i].marks.Programming = pr;
                    listOfStudents[i].marks.Economics   = ec;
                    break;
                }

                //    listOfStudents[i].Name = arj[i].Name;
                //    listOfStudents[i].Sername = arj[i].Sername;
                //    listOfStudents[i].Patronymic = arj[i].Patronymic;
                //    listOfStudents[i].Group = arj[i].Group;
                //    switch (P.Subject)
                //    {
                //        case "Программирование":
                //            listOfStudents[i].marks.Programming = arj[i].Mark;
                //            break;
                //        case "Экономика":
                //            listOfStudents[i].marks.Economics = arj[i].Mark;
                //            break;
                //        case "Математический анализ":
                //            listOfStudents[i].marks.Mathematical_analysis = arj[i].Mark;
                //            break;
                //        default:
                //            break;
                //    }
            }
            List <string> sername = new List <string>();
            Authorization a;

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    Students st = (Students)list[i].User;
                    sername.Add(st.Sername);
                }
                catch { }
            }
            sername.Sort();
            for (int i = 0; i < sername.Count; i++)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    try
                    {
                        Students st = (Students)list[j].User;
                        if (st.Sername == sername[i])
                        {
                            a       = list[j];
                            list[j] = list[i];
                            list[i] = a;
                        }
                    }
                    catch { }
                }
            }
            ser.Serialize(list);
            //}
            //catch
            //{
            //    MessageBox.Show("Произошла ошибка, возможно, Вы неккоректно ввели данные","Ошибка", MessageBoxButton.OK,MessageBoxImage.Error);
            //}
        }
Example #4
0
        private void Del_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int selectedindex = DataGrid.SelectedIndex;
                if (selectedindex == -1)

                {
                    MessageBox.Show("Для удаления нужно что-то выбрать");
                }
                else
                {
                    Serialization        ser  = new Serialization();
                    List <Authorization> list = ser.Deserialize();

                    List <int> index = new List <int>();
                    for (int i = 0; i < list.Count; i++)
                    {
                        try
                        {
                            Students s = list[i].User as Students;
                            foreach (var row in DataGrid.SelectedItems)
                            {
                                Student st = row as Student;
                                if (st.Sername == s.Sername && st.Name == s.Name && s.Group == st.Group && st.Patronymic == s.Patronymic)
                                {
                                    Object           stud = new Students("-1", "-1", "-1", "-1", "-1", -1);
                                    Authorization    x    = new Authorization("-1", "-1", stud);
                                    HistoryOfChanges hist = new HistoryOfChanges(list[i], x);
                                    P.History.Add(hist);
                                    P.MakeIt10();
                                    foreach (Authorization X in list)
                                    {
                                        try
                                        {
                                            Teacher te = (Teacher)X.User;
                                            if (P.Name == te.Name && P.Sername == te.Sername && P.Subject == te.Subject && P.Patronymic == te.Patronymic)
                                            {
                                                te.History = P.History;
                                            }
                                        }
                                        catch { }
                                    }
                                    arj.Remove(st);
                                    index.Add(i);
                                    break;
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    for (int i = 0; i < index.Count; i++)
                    {
                        list.RemoveAt(index[i]);
                    }
                    DataGrid.ItemsSource = null;
                    DataGrid.ItemsSource = arj;

                    ser.Serialize(list);
                }
            }catch { MessageBox.Show("Что-то пошло не так.. Попробуйте удалить данные в отдельном окне.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); }
        }
Example #5
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            if ((FIO.Text == "") || (Group.Text == "") || (Mark.Text == "") || (Login.Text == "") || (Password.Text == ""))
            {
                MessageBox.Show("Заполните все поля!", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                string[] mas = FIO.Text.Split(new char[] { ' ' });
                if (mas.Length < 3)
                {
                    MessageBox.Show("Заполните поле 'ФИО' должным образом.", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                if (mas.Length > 3)
                {
                    MessageBox.Show("Заполните поле 'ФИО' должным образом. \nСлишком много данных в одной строке.", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                Serialization        ser  = new Serialization();
                Students             s    = new Students(mas[0], mas[1], mas[2], Group.Text, subject, int.Parse(Mark.Text));
                List <Authorization> list = ser.Deserialize();
                foreach (Authorization x in list)
                {
                    if (x.Login == Login.Text)
                    {
                        MessageBox.Show("Введённый логин уже используется", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                }
                var           hash   = CalculateHash(Password.Text);
                Authorization Leysan = new Authorization(Login.Text, hash, s);
                list.Add(Leysan);
                List <string> sername = new List <string>();
                Authorization a;
                for (int i = 0; i < list.Count; i++)
                {
                    try
                    {
                        Students st = (Students)list[i].User;
                        sername.Add(st.Sername);
                    }
                    catch { }
                }
                sername.Sort();
                for (int i = 0; i < sername.Count; i++)
                {
                    for (int j = 0; j < list.Count; j++)
                    {
                        try
                        {
                            Students st = (Students)list[j].User;
                            if (st.Sername == sername[i])
                            {
                                a       = list[j];
                                list[j] = list[i];
                                list[i] = a;
                            }
                        }
                        catch { }
                    }
                }
                Object           stud = new Students("-1", "-1", "-1", "-1", "-1", -1);
                Authorization    aut  = new Authorization("-1", "-1", stud);
                HistoryOfChanges hist = new HistoryOfChanges(aut, Leysan);
                P.History.Add(hist);
                P.MakeIt10();
                foreach (Authorization X in list)
                {
                    try
                    {
                        Teacher t = (Teacher)X.User;
                        if (P.Name == t.Name && P.Sername == t.Sername && P.Subject == t.Subject && P.Patronymic == t.Patronymic)
                        {
                            t.History = P.History;
                        }
                    }
                    catch { }
                }
                ser.Serialize(list);
                MessageBox.Show("Студент добавлен", "-", MessageBoxButton.OK);

                FIO.Text = "";
                FIO.Focus();
                Group.Text    = "";
                Mark.Text     = "";
                Login.Text    = "";
                Password.Text = "";
            }
        }