Example #1
0
        public TeachersAndSubjectsVM(TeachersAndSubjects teachersAndSubjects, Subject[] subjects, DayOfWeek[] days)
        {
            HashSet <int>       sj = new HashSet <int>(teachersAndSubjects.SubjectList.Select(s => s.CodeOfSubject));
            HashSet <DayOfWeek> dw = new HashSet <DayOfWeek>(teachersAndSubjects.DayList);

            Subjects = subjects.Where(d => d.Department.CodeOfDepartment == teachersAndSubjects.Teacher.Department.CodeOfDepartment).OrderBy(n => n.NameOfSubject).Select(s => new ChooseViewHelper <Subject>
            {
                IsSelected = sj.Contains(s.CodeOfSubject),
                Value      = s
            }).ToArray();
            Days = days.Select(d => new ChooseViewHelper <DayOfWeek>
            {
                IsSelected = dw.Count == 0 || dw.Contains(d),
                Value      = d
            }).ToArray();

            saveTeachersAndSubjects = this.Factory.CommandSyncParam <Window>(SaveAndClose);
        }
Example #2
0
        public TeachersAndSubjects[] ReadTeacherAndSubjects()
        {
            List <TeachersAndSubjects> tands    = new List <TeachersAndSubjects>();
            List <Subject>             subjlist = new List <Subject>();

            if (Open())
            {
                using (FbTransaction dbtran = conn.BeginTransaction())
                {
                    using (FbCommand selectCommand = new FbCommand())
                    {
                        selectCommand.CommandText = "select TeachersAndSubjects.id_teacher, fio, post, mail, TeachersAndSubjects.id_department, d1.name_of_department, id_subject, name_of_subject, subjects.id_department, d2.name_of_department, daylist, isreadlecture, f1.id_faculty, f1.name_of_faculty " +
                                                    " from (TeachersAndSubjects join Teachers on TeachersAndSubjects.id_teacher = teachers.id_teacher join departments d1 on d1.id_department = TeachersAndSubjects.id_department join Subjects using(id_subject) join departments d2 on d2.id_department = subjects.id_department join faculty f1 on d1.id_faculty = f1.id_faculty join teachersanddepartments on teachersanddepartments.id_department = d1.id_department and teachersanddepartments.id_teacher = TeachersAndSubjects.id_teacher)";
                        selectCommand.Connection  = conn;
                        selectCommand.Transaction = dbtran;
                        FbDataReader reader = selectCommand.ExecuteReader();
                        while (reader.Read())
                        {
                            if (!tands.Exists(t => t.Teacher.CodeOfTeacher == reader.GetInt32(0) && t.Teacher.Department.CodeOfDepartment == reader.GetInt32(4)))
                            {
                                var ld   = JsonConvert.DeserializeObject <DayOfWeek[]>(reader.GetString(10));
                                var subj = new Subject
                                {
                                    CodeOfSubject = reader.GetInt32(6),
                                    NameOfSubject = reader.GetString(7),
                                    Department    = new Department
                                    {
                                        CodeOfDepartment = reader.GetInt32(8),
                                        NameOfDepartment = reader.GetString(9)
                                    }
                                };
                                subjlist.Add(subj);

                                var TeacherSubjects = new TeachersAndSubjects
                                {
                                    Teacher = new Teacher
                                    {
                                        CodeOfTeacher = reader.GetInt32(0),
                                        FIO           = reader.GetString(1),
                                        Post          = reader.GetString(2),
                                        Mail          = reader.GetString(3),
                                        IsReadLecture = Convert.ToBoolean(reader.GetInt32(11)),
                                        Department    = new Department
                                        {
                                            CodeOfDepartment = reader.GetInt32(4),
                                            NameOfDepartment = reader.GetString(5),
                                            Faculty          = new Faculty
                                            {
                                                CodeOfFaculty = reader.GetInt32(12),
                                                NameOfFaculty = reader.GetString(13)
                                            }
                                        }
                                    },
                                    SubjectList = subjlist.ToArray(),
                                    DayList     = ld
                                };
                                tands.Add(TeacherSubjects);
                                subjlist.Clear();
                            }
                            else
                            {
                                var subj = new Subject
                                {
                                    CodeOfSubject = reader.GetInt32(6),
                                    NameOfSubject = reader.GetString(7),
                                    Department    = new Department
                                    {
                                        CodeOfDepartment = reader.GetInt32(8),
                                        NameOfDepartment = reader.GetString(9)
                                    }
                                };
                                foreach (var teacher in tands)
                                {
                                    if (teacher.Teacher.CodeOfTeacher == reader.GetInt32(0) && teacher.Teacher.Department.CodeOfDepartment == reader.GetInt32(4))
                                    {
                                        var temp = teacher.SubjectList.Append(subj);
                                        teacher.SubjectList = temp.ToArray();
                                    }
                                }
                            }
                        }
                    }
                    dbtran.Commit();
                    return(tands.ToArray());
                }
            }
            return(null);
        }