private void DeleteCurrent(object sender, RoutedEventArgs e)
        {
            if (SelectedItem.GetType().Name == SelectedFaculty.GetType().Name)
            {
                SelectedFaculty = (FacultyViewModel)SelectedItem;
                Collection.Remove(SelectedFaculty.Key, true);
                CollectionView.Remove(SelectedFaculty);
            }

            if (SelectedItem.GetType().Name == SelectedGroup.GetType().Name)
            {
                SelectedGroup = (GroupViewModel)SelectedItem;
                Faculty <int, Group <int, Student> > faculty;
                Collection.TryGetValue(SelectedGroup.Parent.Key, out faculty, true);
                faculty.Remove(SelectedGroup.Key, true);
                SelectedGroup.Parent.Groups.Remove(SelectedGroup);
            }

            if (SelectedItem.GetType().Name == SelectedStudent.GetType().Name)
            {
                SelectedStudent = (StudentViewModel)SelectedItem;
                Faculty <int, Group <int, Student> > faculty;
                Collection.TryGetValue(SelectedStudent.Parent.Parent.Key, out faculty, true);
                Group <int, Student> group;
                faculty.TryGetValue(SelectedStudent.Parent.Key, out group, true);
                group.Remove(SelectedStudent.Key, true);
                SelectedStudent.Parent.Students.Remove(SelectedStudent);
            }

            TreeViewAll.ItemsSource = null;
            TreeViewAll.ItemsSource = CollectionView;
        }
        private void ModifyCurrent(object sender, RoutedEventArgs e)
        {
            if (SelectedItem.GetType().Name == SelectedFaculty.GetType().Name)
            {
                InputPage ip = new InputPage((FacultyViewModel)SelectedItem, "Modify");
                ip.Owner = this;
                ip.Resources["BorderColor"]    = Resources["BorderColor"];
                ip.Resources["ButtonColor"]    = Resources["ButtonColor"];
                ip.Resources["BGColor"]        = Resources["BGColor"];
                ip.Resources["TextColor"]      = Resources["TextColor"];
                ip.Resources["FontStyle"]      = Resources["FontStyle"];
                ip.Resources["FontFamily"]     = Resources["FontFamily"];
                ip.Resources["FontSizeSmall"]  = Resources["FontSizeSmall"];
                ip.Resources["FontSizeMedium"] = Resources["FontSizeMedium"];
                ip.Resources["FontSizeLarge"]  = Resources["FontSizeLarge"];

                ip.Show();

                TreeViewAll.ItemsSource = null;
                TreeViewAll.ItemsSource = CollectionView;
            }

            if (SelectedItem.GetType().Name == SelectedGroup.GetType().Name)
            {
                InputPage ip = new InputPage((GroupViewModel)SelectedItem, "Modify");
                ip.Owner = this;
                ip.Resources["BorderColor"]    = Resources["BorderColor"];
                ip.Resources["ButtonColor"]    = Resources["ButtonColor"];
                ip.Resources["BGColor"]        = Resources["BGColor"];
                ip.Resources["TextColor"]      = Resources["TextColor"];
                ip.Resources["FontStyle"]      = Resources["FontStyle"];
                ip.Resources["FontFamily"]     = Resources["FontFamily"];
                ip.Resources["FontSizeSmall"]  = Resources["FontSizeSmall"];
                ip.Resources["FontSizeMedium"] = Resources["FontSizeMedium"];
                ip.Resources["FontSizeLarge"]  = Resources["FontSizeLarge"];

                ip.Show();

                TreeViewAll.ItemsSource = null;
                TreeViewAll.ItemsSource = CollectionView;
            }

            if (SelectedItem.GetType().Name == SelectedStudent.GetType().Name)
            {
                SelectedStudent = (StudentViewModel)SelectedItem;
                StudentInput si = new StudentInput((StudentViewModel)SelectedItem);
                si.Owner = this;
                si.Resources["BorderColor"]    = Resources["BorderColor"];
                si.Resources["ButtonColor"]    = Resources["ButtonColor"];
                si.Resources["BGColor"]        = Resources["BGColor"];
                si.Resources["TextColor"]      = Resources["TextColor"];
                si.Resources["FontStyle"]      = Resources["FontStyle"];
                si.Resources["FontFamily"]     = Resources["FontFamily"];
                si.Resources["FontSizeSmall"]  = Resources["FontSizeSmall"];
                si.Resources["FontSizeMedium"] = Resources["FontSizeMedium"];
                si.Resources["FontSizeLarge"]  = Resources["FontSizeLarge"];

                si.Show();

                TreeViewAll.ItemsSource = null;
                TreeViewAll.ItemsSource = CollectionView;
            }
        }
        private void Add(object sender, RoutedEventArgs e)
        {
            if (SelectedItem == null)
            {
                InputPage ip = new InputPage(new FacultyViewModel(), "Add");
                ip.Owner = this;

                ip.Resources["BorderColor"]    = Resources["BorderColor"];
                ip.Resources["ButtonColor"]    = Resources["ButtonColor"];
                ip.Resources["BGColor"]        = Resources["BGColor"];
                ip.Resources["TextColor"]      = Resources["TextColor"];
                ip.Resources["FontStyle"]      = Resources["FontStyle"];
                ip.Resources["FontFamily"]     = Resources["FontFamily"];
                ip.Resources["FontSizeSmall"]  = Resources["FontSizeSmall"];
                ip.Resources["FontSizeMedium"] = Resources["FontSizeMedium"];
                ip.Resources["FontSizeLarge"]  = Resources["FontSizeLarge"];

                ip.Show();

                TreeViewAll.ItemsSource     = null;
                TreeViewAll.ItemsSource     = CollectionView;
                Delete_All_Button.IsEnabled = true;
                Delete_All_Button.Opacity   = 1;
                return;
            }

            if (SelectedItem.GetType().Name == SelectedFaculty.GetType().Name)
            {
                SelectedFaculty = (FacultyViewModel)SelectedItem;
                InputPage ip = new InputPage(new GroupViewModel()
                {
                    Parent = SelectedFaculty
                }, "Add");
                ip.Owner = this;

                ip.Resources["BorderColor"]    = Resources["BorderColor"];
                ip.Resources["ButtonColor"]    = Resources["ButtonColor"];
                ip.Resources["BGColor"]        = Resources["BGColor"];
                ip.Resources["TextColor"]      = Resources["TextColor"];
                ip.Resources["FontStyle"]      = Resources["FontStyle"];
                ip.Resources["FontFamily"]     = Resources["FontFamily"];
                ip.Resources["FontSizeSmall"]  = Resources["FontSizeSmall"];
                ip.Resources["FontSizeMedium"] = Resources["FontSizeMedium"];
                ip.Resources["FontSizeLarge"]  = Resources["FontSizeLarge"];

                ip.Show();
                TreeViewAll.ItemsSource = null;
                TreeViewAll.ItemsSource = CollectionView;
                return;
            }

            if (SelectedItem.GetType().Name == SelectedGroup.GetType().Name)
            {
                SelectedGroup = (GroupViewModel)SelectedItem;
                StudentInput si = new StudentInput("Add new student to group \"" + SelectedGroup.Name + "\"");
                si.Owner = this;

                si.Resources["BorderColor"]    = Resources["BorderColor"];
                si.Resources["ButtonColor"]    = Resources["ButtonColor"];
                si.Resources["BGColor"]        = Resources["BGColor"];
                si.Resources["TextColor"]      = Resources["TextColor"];
                si.Resources["FontStyle"]      = Resources["FontStyle"];
                si.Resources["FontFamily"]     = Resources["FontFamily"];
                si.Resources["FontSizeSmall"]  = Resources["FontSizeSmall"];
                si.Resources["FontSizeMedium"] = Resources["FontSizeMedium"];
                si.Resources["FontSizeLarge"]  = Resources["FontSizeLarge"];

                si.Show();
                TreeViewAll.ItemsSource = null;
                TreeViewAll.ItemsSource = CollectionView;
                return;
            }

            if (SelectedItem.GetType().Name == SelectedStudent.GetType().Name)
            {
                SelectedStudent = (StudentViewModel)SelectedItem;
                Info si = new Info(SelectedStudent);
                si.Resources["BorderColor"]    = Resources["BorderColor"];
                si.Resources["ButtonColor"]    = Resources["ButtonColor"];
                si.Resources["BGColor"]        = Resources["BGColor"];
                si.Resources["TextColor"]      = Resources["TextColor"];
                si.Resources["FontStyle"]      = Resources["FontStyle"];
                si.Resources["FontFamily"]     = Resources["FontFamily"];
                si.Resources["FontSizeSmall"]  = Resources["FontSizeSmall"];
                si.Resources["FontSizeMedium"] = Resources["FontSizeMedium"];
                si.Resources["FontSizeLarge"]  = Resources["FontSizeLarge"];

                si.Show();
                return;
            }
        }
        private void TreeViewSelected(object sender, RoutedEventArgs e)
        {
            TreeViewItem tvi = e.OriginalSource as TreeViewItem;

            if (tvi != null)
            {
                if (tvi.DataContext.GetType().Name == SelectedFaculty.GetType().Name)
                {
                    Add_Info_Button.Content = "_Add group...";
                    Delete_Button.Content   = "_Delete faculty";
                    Modify_Button.Content   = "_Modify faculty...";
                    Delete_Button.IsEnabled = true;
                    Delete_Button.Opacity   = 1;
                    Modify_Button.Opacity   = 1;
                    Modify_Button.IsEnabled = true;

                    SelectedItem    = (FacultyViewModel)tvi.DataContext;
                    SelectedFaculty = (FacultyViewModel)tvi.DataContext;
                    bool hasstuds = false;
                    foreach (var group in SelectedFaculty.Groups)
                    {
                        if (group.Students.Count != 0)
                        {
                            hasstuds = true;
                        }
                    }
                    AM_TB.Content = (hasstuds) ? "Faculty average mark: " + SelectedFaculty.AM
                        : "";
                }
                if (tvi.DataContext.GetType().Name == SelectedGroup.GetType().Name)
                {
                    Add_Info_Button.Content = "_Add student...";
                    Delete_Button.Content   = "_Delete group";
                    Modify_Button.Content   = "_Modify group...";
                    Delete_Button.IsEnabled = true;
                    Delete_Button.Opacity   = 1;
                    Modify_Button.Opacity   = 1;
                    Modify_Button.IsEnabled = true;
                    SSListButton.IsEnabled  = true;
                    SSListButton.Opacity    = 1;

                    SelectedItem  = (GroupViewModel)tvi.DataContext;
                    SelectedGroup = (GroupViewModel)tvi.DataContext;
                    AM_TB.Content = (SelectedGroup.Students.Count != 0) ? "Group average mark: " + SelectedGroup.AM : "";
                }
                if (tvi.DataContext.GetType().Name == SelectedStudent.GetType().Name)
                {
                    Add_Info_Button.Content = "_More info...";
                    Delete_Button.Content   = "_Delete student";
                    Modify_Button.Content   = "_Modify student...";
                    Delete_Button.IsEnabled = true;
                    Delete_Button.Opacity   = 1;
                    Modify_Button.Opacity   = 1;
                    Modify_Button.IsEnabled = true;


                    SelectedItem    = (StudentViewModel)tvi.DataContext;
                    SelectedStudent = (StudentViewModel)tvi.DataContext;
                    AM_TB.Content   = "Student average mark: " + SelectedStudent.AM;
                }
            }
        }