예제 #1
0
        private void Button_Click_4(object sender, RoutedEventArgs e) // Delete selected student
        {
            var selectedIndex = List.SelectedIndex;

            if (students.studentlist[selectedIndex].isHead == "+")
            {
                var rez = students.studentlist[selectedIndex].group;
                rez.head     = null;
                rez.headName = "-";
            }
            students.studentlist.Remove(students.studentlist[selectedIndex]);

            NameBox.Clear();
            SurnameBox.Clear();
            Middlename.Clear();
            YearBox.Clear();
            FileNameTextBox.Clear();
            GroupCombo.SelectedIndex    = -1;
            OldGroupCombo.SelectedIndex = -1;

            List.Items.Refresh();

            mark.marks.Clear();
            Table.ItemsSource = mark.marks;
            Table.Items.Refresh();

            AddButton.IsEnabled    = true;
            HeadCheck.IsChecked    = false;
            ChangeButton.IsEnabled = false;
            DeleteButton.IsEnabled = false;
        }
예제 #2
0
        private void Button_Click_6(object sender, RoutedEventArgs e)
        {
            NameBox.Clear();
            SurnameBox.Clear();
            Middlename.Clear();
            YearBox.Clear();
            GroupCombo.SelectedIndex    = -1;
            OldGroupCombo.SelectedIndex = -1;
            FileNameTextBox.Clear();

            mark.marks.Clear();
            Table.ItemsSource = mark.marks;
            Table.Items.Refresh();

            AddButton.IsEnabled    = true;
            HeadCheck.IsChecked    = false;
            ChangeButton.IsEnabled = false;
            DeleteButton.IsEnabled = false;
        }
예제 #3
0
        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            GroupEnum   new_groups   = new GroupEnum();
            StudentEnum new_students = new StudentEnum();


            OpenFileDialog dialog = new OpenFileDialog();

            dialog.DefaultExt = ".zip";
            dialog.Filter     = "zip|*.zip";

            string selectedArchive = "";
            bool?  result          = dialog.ShowDialog();

            if (result == true)
            {
                selectedArchive = dialog.FileName;
            }
            else
            {
                return;
            }
            try
            {
                if (!Directory.Exists(Directory.GetCurrentDirectory() + @"\Buffer") && selectedArchive != "")
                {
                    ZipFile.ExtractToDirectory(selectedArchive, Directory.GetCurrentDirectory());
                }
                else
                {
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please, select another folder ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            FileStream   connector = new FileStream(Directory.GetCurrentDirectory() + @"\Buffer\Temp.txt", FileMode.Open);;
            StreamReader reader    = new StreamReader(connector);

            int groupsNumber = Convert.ToInt32(reader.ReadLine());

            reader.ReadLine();
            for (int i = 0; i < groupsNumber; i++)
            {
                reader.ReadLine();
                Group new_group = new Group();

                new_group.Number   = Convert.ToInt32(reader.ReadLine());
                new_group.Actual   = reader.ReadLine();
                new_group.headName = reader.ReadLine();
                int teachersNumber = Convert.ToInt32(reader.ReadLine());

                Group subject = new Group();
                if (teachersNumber != 0)
                {
                    reader.ReadLine();
                    for (int j = 0; j < teachersNumber; j++)
                    {
                        Group.struct_teachers new_teacher = new Group.struct_teachers();
                        new_teacher.Name    = reader.ReadLine();
                        new_teacher.Subject = reader.ReadLine();
                        subject.teachers.Add(new_teacher);
                    }
                    reader.ReadLine();
                    new_group.teachers = new List <Group.struct_teachers>(subject.teachers);
                }
                else
                {
                    reader.ReadLine();
                }

                reader.ReadLine();
                new_groups.groupList.Add(new_group);
            }
            reader.ReadLine();

            int studentsNumber = Convert.ToInt32(reader.ReadLine());

            reader.ReadLine();
            for (int i = 0; i < studentsNumber; i++)
            {
                reader.ReadLine();
                Student new_student = new Student();

                new_student.Name             = reader.ReadLine();
                new_student.Surname          = reader.ReadLine();
                new_student.Middlename       = reader.ReadLine();
                new_student.Year             = Convert.ToInt32(reader.ReadLine());
                new_student.isHead           = reader.ReadLine();
                new_student.groupHeading     = reader.ReadLine();
                new_student.group_number     = reader.ReadLine();
                new_student.old_group_number = reader.ReadLine();

                new_student.photoPath = reader.ReadLine();
                if (new_student.photoPath != "")
                {
                    BitmapImage StudentPhoto = new BitmapImage();
                    StudentPhoto.BeginInit();
                    StudentPhoto.UriSource   = new Uri(new_student.photoPath, UriKind.Absolute);
                    StudentPhoto.CacheOption = BitmapCacheOption.OnLoad;
                    StudentPhoto.EndInit();
                    new_student.studentPhoto = StudentPhoto;
                }

                int     marksNumber = Convert.ToInt32(reader.ReadLine());
                Student mark        = new Student();
                if (marksNumber != 0)
                {
                    reader.ReadLine();
                    for (int j = 0; j < marksNumber; j++)
                    {
                        Student.struct_marks new_mark = new Student.struct_marks();
                        new_mark.Mark    = Convert.ToInt32(reader.ReadLine());
                        new_mark.Subject = reader.ReadLine();
                        mark.marks.Add(new_mark);
                    }
                    reader.ReadLine();
                    new_student.marks = new List <Student.struct_marks>(mark.marks);
                }
                else
                {
                    reader.ReadLine();
                }

                reader.ReadLine();
                new_students.studentlist.Add(new_student);
            }

            for (int i = 0; i < new_groups.groupList.Count(); i++)
            {
                for (int j = 0; j < new_students.studentlist.Count(); j++)
                {
                    if (new_students.studentlist[j].group_number == Convert.ToString(new_groups.groupList[i].Number))
                    {
                        new_students.studentlist[j].group = new_groups.groupList[i];
                        if (new_students.studentlist[j].groupHeading == Convert.ToString(new_groups.groupList[i].Number))
                        {
                            new_groups.groupList[i].head = new_students.studentlist[j];
                        }
                    }
                    if (new_students.studentlist[j].old_group_number == Convert.ToString(new_groups.groupList[i].Number))
                    {
                        new_students.studentlist[j].oldGroup = new_groups.groupList[i];
                    }
                }
            }
            reader.Close();
            connector.Close();

            groups.groupList     = new_groups.groupList;
            students.studentlist = new_students.studentlist;

            List.ItemsSource = students.studentlist;
            List.Items.Refresh();
            mark.marks.Clear();
            Table.ItemsSource = mark.marks;
            Table.Items.Refresh();

            NameBox.Clear();
            SurnameBox.Clear();
            Middlename.Clear();
            YearBox.Clear();

            GroupCombo.SelectedIndex    = -1;
            OldGroupCombo.SelectedIndex = -1;
            HeadCheck.IsChecked         = false;
            FileNameTextBox.Text        = "";

            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Buffer"))
            {
                Directory.Delete(Directory.GetCurrentDirectory() + @"\Buffer", true);
            }

            MessageBox.Show("File loaded", "", MessageBoxButton.OK, MessageBoxImage.Information);
        }
예제 #4
0
        private void Button_Click_3(object sender, RoutedEventArgs e) // Change information
        {
            if (String.IsNullOrWhiteSpace(NameBox.Text) || String.IsNullOrWhiteSpace(SurnameBox.Text) || String.IsNullOrWhiteSpace(Middlename.Text) || String.IsNullOrWhiteSpace(YearBox.Text))
            {
                MessageBox.Show("Please, fill all fields", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (NameBox.Text.Length > 16 || SurnameBox.Text.Length > 16 || Middlename.Text.Length > 16)
            {
                MessageBox.Show("Name, Surname and Middlename must not contain more than 16 letters ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (Convert.ToInt32(YearBox.Text) > 2017 || Convert.ToInt32(YearBox.Text) < 1950)
            {
                MessageBox.Show("In the year selection field number should be between 1950 to 2017", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                YearBox.Clear();
                return;
            }

            if (GroupCombo.SelectedItem != null && GroupCombo.SelectedItem == OldGroupCombo.SelectedItem)
            {
                MessageBox.Show("Old group and current group must be different", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                GroupCombo.SelectedItem    = null;
                OldGroupCombo.SelectedItem = null;
                return;
            }

            var selectedIndex = List.SelectedIndex;

            students.studentlist[selectedIndex].Name       = NameBox.Text;
            students.studentlist[selectedIndex].Surname    = SurnameBox.Text;
            students.studentlist[selectedIndex].Middlename = Middlename.Text;
            students.studentlist[selectedIndex].Year       = Convert.ToInt32(YearBox.Text);

            if (GroupCombo.SelectedItem == null)
            {
                students.studentlist[selectedIndex].group_number = "-";
                students.studentlist[selectedIndex].groupHeading = "-";
                students.studentlist[selectedIndex].isHead       = "-";
                students.studentlist[selectedIndex].group        = null;
            }
            else
            {
                students.studentlist[selectedIndex].group_number = GroupCombo.Text;
                var rez = (Group)GroupCombo.SelectedItem;

                if (HeadCheck.IsChecked == true)
                {
                    if (students.studentlist[selectedIndex].groupHeading != Convert.ToString(rez.Number))
                    {
                        if (rez != students.studentlist[selectedIndex].group)
                        {
                            if (students.studentlist[selectedIndex].isHead == "+")
                            {
                                var rez1 = students.studentlist[selectedIndex].group;
                                rez1.headName = "-";
                                rez1.head     = null;
                            }
                        }

                        if (rez.head == null)
                        {
                            students.studentlist[selectedIndex].isHead       = "+";
                            students.studentlist[selectedIndex].group_number = Convert.ToString(rez.Number);
                            students.studentlist[selectedIndex].groupHeading = students.studentlist[selectedIndex].group_number;
                            students.studentlist[selectedIndex].group        = rez;

                            rez.headName = students.studentlist[selectedIndex].Surname + " " + students.studentlist[selectedIndex].Name;
                            rez.head     = students.studentlist[selectedIndex];
                        }
                        else
                        {
                            students.studentlist[selectedIndex].group_number = Convert.ToString(rez.Number);
                            students.studentlist[selectedIndex].isHead       = "-";
                            students.studentlist[selectedIndex].groupHeading = "-";
                            students.studentlist[selectedIndex].group        = rez;
                            MessageBox.Show("This group already has a head. This student was not appointed head", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }
                    else
                    {
                        rez.headName = students.studentlist[selectedIndex].Surname + " " + students.studentlist[selectedIndex].Name;
                    }
                }
                else
                {
                    if (rez.head == students.studentlist[selectedIndex])
                    {
                        rez.head     = null;
                        rez.headName = "-";
                    }
                    students.studentlist[selectedIndex].isHead       = "-";
                    students.studentlist[selectedIndex].groupHeading = "-";
                }
                students.studentlist[selectedIndex].group = (Group)GroupCombo.SelectedItem;
            }

            if (students.studentlist[selectedIndex].isHead == "+")
            {
                students.studentlist[selectedIndex].groupHeading = students.studentlist[selectedIndex].group_number;
            }
            else
            {
                students.studentlist[selectedIndex].groupHeading = "-";
            }

            if (OldGroupCombo.SelectedItem == null)
            {
                students.studentlist[selectedIndex].old_group_number = "-";
            }
            else
            {
                students.studentlist[selectedIndex].old_group_number = OldGroupCombo.Text;
            }

            students.studentlist[selectedIndex].oldGroup = (Group)OldGroupCombo.SelectedItem;

            if (students.studentlist[selectedIndex].studentPhoto != null)
            {
                if ("file:///" + FileNameTextBox.Text != Convert.ToString(students.studentlist[selectedIndex].studentPhoto.UriSource))
                {
                    if (FileNameTextBox.Text != "")
                    {
                        BitmapImage StudentPhoto = new BitmapImage();
                        StudentPhoto.BeginInit();
                        StudentPhoto.UriSource   = new Uri(FileNameTextBox.Text, UriKind.Absolute);
                        StudentPhoto.CacheOption = BitmapCacheOption.OnLoad;
                        StudentPhoto.EndInit();
                        students.studentlist[selectedIndex].studentPhoto = StudentPhoto;
                        students.studentlist[selectedIndex].photoPath    = Convert.ToString(students.studentlist[selectedIndex].studentPhoto.UriSource);
                    }
                }
            }

            students.studentlist[selectedIndex].marks = new List <Student.struct_marks>(mark.marks);
            List.Items.Refresh();

            NameBox.Clear();
            SurnameBox.Clear();
            Middlename.Clear();
            YearBox.Clear();
            FileNameTextBox.Clear();
            GroupCombo.SelectedIndex    = -1;
            OldGroupCombo.SelectedIndex = -1;

            mark.marks.Clear();
            Table.ItemsSource = mark.marks;
            Table.Items.Refresh();

            AddButton.IsEnabled    = true;
            HeadCheck.IsChecked    = false;
            ChangeButton.IsEnabled = false;
            DeleteButton.IsEnabled = false;
        }