Пример #1
0
        private void initializeVariablesDone()
        {
            if (hadException)
            {
                return;
            }

            this.lbClasses.ItemCheck -= new ItemCheckEventHandler(onClassesCheckstateChanged);
            this.lbClasses.SelectedIndexChanged -= new EventHandler(onSelectedClassChanged);
            this.lbSubjects.ItemCheck -= new ItemCheckEventHandler(onSubjectsCheckstateChanged);

            foreach (JsonLesson jsonLesson in jsonLessons)
            {
                if (!classesWithLessons.Any(p => p.Name.Equals(jsonLesson.ClassToken)))
                {
                    Lesson lesson = new Lesson(jsonLesson.Teachers, new Subject(jsonLesson.SubjectToken));
                    Class newClass = new Class(jsonLesson.ClassToken);
                    newClass.addLesson(lesson);
                    classesWithLessons.Add(newClass);
                }
                else
                {
                    int index = classesWithLessons.FindIndex(p => p.Name.Equals(jsonLesson.ClassToken));
                    Lesson lesson = new Lesson(jsonLesson.Teachers, new Subject(jsonLesson.SubjectToken));
                    classesWithLessons.ElementAt(index).addLesson(lesson);
                }
            }

            oldClasses = (List<Class>)ObjectCloner.DeepClone(classesWithLessons);

            lbClasses.InvokeIfRequired(() => { lbClasses.Items.Clear(); });
            lbSubjects.InvokeIfRequired(() => { lbSubjects.Items.Clear(); });

            foreach (Class newClass in classes)
            {
                if (classesWithLessons.Any(p => p.Name.Equals(newClass.Name)))
                    lbClasses.InvokeIfRequired(() => { lbClasses.Items.Add(newClass.Name, CheckState.Checked); });
                else
                    lbClasses.InvokeIfRequired(() => { lbClasses.Items.Add(newClass.Name, CheckState.Unchecked); });
            }

            foreach (Subject subject in subjects)
            {
                if (classesWithLessons.Any(p => p.Name.Equals(classes.ElementAt(0).Name) && p.Lessons.Any(q => q.Subject.Token.Equals(subject.Token))))
                    lbSubjects.InvokeIfRequired(() => { lbSubjects.Items.Add(subject.Token + " - " + subject.Name, CheckState.Checked); });
                else
                    lbSubjects.InvokeIfRequired(() => { lbSubjects.Items.Add(subject.Token + " - " + subject.Name, CheckState.Unchecked); });
            }

            lbClasses.InvokeIfRequired(() => { lbClasses.SelectionMode = SelectionMode.One; });
            lbSubjects.InvokeIfRequired(() => { lbSubjects.SelectionMode = SelectionMode.One; });

            lbClasses.InvokeIfRequired(() => { lbClasses.SelectedIndex = 0; });

            btSaveChanges.InvokeIfRequired(() => { btSaveChanges.Enabled = true; });

            lbClasses.InvokeIfRequired(() =>
                {
                    lbClasses.ItemCheck += new ItemCheckEventHandler(onClassesCheckstateChanged);
                    lbClasses.SelectedIndexChanged += new EventHandler(onSelectedClassChanged);
                }
            );
            lbSubjects.InvokeIfRequired(() => { lbSubjects.ItemCheck += new ItemCheckEventHandler(onSubjectsCheckstateChanged); });
        }
Пример #2
0
 /// <summary>
 /// Adds a new <see cref="ExcelAllGrade.model.Lesson"/> to <see cref="Lessons"/>.
 /// </summary>
 /// <param name="lesson"></param>
 public void addLesson(Lesson lesson)
 {
     this.Lessons.Add(lesson);
 }