public void ChangeTo(Speciality old, Speciality anew)
        {
            if (old.IdSpeciality != anew.IdSpeciality &&
                base.FindAll(x => x.ToString().Trim() == anew.ToString().Trim()).Count > 0)
            {
                throw new Exception($"Специальность \"{anew}\" уже существует!");
            }
            old.Name   = anew.Name;
            old.Number = anew.Number;
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdSpeciality", "P" + anew.IdSpeciality.ToString() },
                { "Name", anew.Name },
                { "Number", anew.Number }
            };

            server.UpdateInto("Specialities", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 2
0
        public void ChangeTo(Matter old, Matter anew)
        {
            if (old.IdMatter != anew.IdMatter &&
                base.FindAll(x => x.ToString().Trim() == anew.ToString().Trim()).Count > 0)
            {
                throw new Exception($"Предмет \"{anew}\" уже существует!");
            }
            old.Name = anew.Name;
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdMatter", "P" + anew.IdMatter.ToString() },
                { "Name", anew.Name }
            };

            server.UpdateInto("Matters", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 3
0
        public void ChangeTo(Semester old, Semester anew)
        {
            if (old.IdSemester != anew.IdSemester &&
                base.FindAll(x => x.ToString().Trim() == anew.ToString().Trim()).Count > 0)
            {
                throw new Exception($"Семестр \"{anew}\" уже существует!");
            }
            old.Number = anew.Number;
            base.Sort();
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdSemester", "P" + anew.IdSemester.ToString() },
                { "Number", anew.Number }
            };

            server.UpdateInto("Semesters", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
        public new void Add(StudyGroup item)
        {
            if (base.Exists(x => x.ToString().Trim() == item.ToString().Trim()))
            {
                throw new Exception($"Группа \"{item}\" уже существует!");
            }
            base.Add(item);
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdStudyGroup", "P" + item.IdStudyGroup.ToString() },
                { "Number", item.Number },
                { "TrainingPeriod", item.TrainingPeriod },
                { "IdSpeciality", "P" + item.IdSpeciality.ToString() },
                { "IdSpecialization", "P" + item.IdSpecialization.ToString() }
            };

            server.InsertInto("StudyGroups", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
        public void ChangeTo(StudyGroup old, StudyGroup anew)
        {
            if (old.IdStudyGroup != anew.IdStudyGroup &&
                base.FindAll(x => x.ToString().Trim() == anew.ToString().Trim()).Count > 0)
            {
                throw new Exception($"Группа \"{anew}\" уже существует!");
            }
            old.Number           = anew.Number;
            old.TrainingPeriod   = anew.TrainingPeriod;
            old.IdSpeciality     = anew.IdSpeciality;
            old.IdSpecialization = anew.IdSpecialization;
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdStudyGroup", "P" + anew.IdStudyGroup.ToString() },
                { "Number", anew.Number },
                { "TrainingPeriod", anew.TrainingPeriod },
                { "IdSpeciality", "P" + anew.IdSpeciality.ToString() },
                { "IdSpecialization", "P" + anew.IdSpecialization.ToString() }
            };

            server.UpdateInto("StudyGroups", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
        public new void Remove(StudyGroup item)
        {
            if (Helper.StudyGroupUsed(item.IdSpecialization))
            {
                throw new Exception($"Группа \"{item}\" ещё используется!");
            }
            base.Remove(item);

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdStudyGroup", "P" + item.IdStudyGroup.ToString() },
            };

            server.DeleteInto("StudyGroups", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 7
0
        public void ChangeTo(Teacher old, Teacher anew)
        {
            if (old.IdTeacher != anew.IdTeacher &&
                base.FindAll(x => x.ToString().Trim() == anew.ToString().Trim()).Count > 0)
            {
                throw new Exception($"Преподаватель \"{anew}\" уже существует!");
            }
            old.FullName = anew.FullName;
            old.IdMatter = anew.IdMatter;
            old.Login    = anew.Login;
            old.Password = anew.Password;
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdTeacher", "P" + anew.IdTeacher.ToString() },
                { "FullName", anew.FullName },
                { "IdMatter", "P" + anew.IdMatter.ToString() },
                { "Login", anew.Login },
                { "Password", anew.Password }
            };

            server.UpdateInto("Teachers", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 8
0
        public new void Remove(Teacher item)
        {
            if (Helper.MatterUsed(item.IdMatter))
            {
                throw new Exception($"Преподаватель \"{item}\" ещё используется!");
            }
            base.Remove(item);

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdTeacher", "P" + item.IdTeacher.ToString() },
            };

            server.DeleteInto("Teachers", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
        public void ChangeTo(Specialization old, Specialization anew)
        {
            if (old.IdSpecialization != anew.IdSpecialization &&
                base.FindAll(x => x.ToString().Trim() == anew.ToString().Trim()).Count > 0)
            {
                throw new Exception($"Специализация \"{anew}\" уже существует!");
            }
            old.Name         = anew.Name;
            old.IdSpeciality = anew.IdSpeciality;
            base.Sort();
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdSpecialization", "P" + anew.IdSpecialization.ToString() },
                { "Name", anew.Name },
                { "IdSpeciality", "P" + anew.IdSpeciality.ToString() }
            };

            server.UpdateInto("Specializations", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 10
0
        public new void Add(Student item)
        {
            base.Add(item);
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdStudent", "P" + item.IdStudent.ToString() },
                { "FullName", item.FullName },
                { "BirthDay", item.BirthDay },
                { "EducationCertificate", item.EducationCertificate },
                { "ReceiptDate", item.ReceiptDate },
                { "Address", item.Address },
                { "PhoneNumber", item.PhoneNumber },
                { "SocialStatus", item.SocialStatus },
                { "Notes", item.Notes },
                { "Photo", item.Photo ?? new byte[] { } },
                { "IdSpeciality", "P" + item.IdSpeciality.ToString() },
                { "IdSpecialization", "P" + item.IdSpecialization.ToString() },
                { "IdStudyGroup", "P" + item.IdStudyGroup.ToString() }
            };

            server.InsertInto("Students", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 11
0
        public new void Remove(Speciality item)
        {
            if (Helper.SpecialityUsed(item.IdSpeciality))
            {
                throw new Exception($"Специальность \"{item}\" ещё используется!");
            }
            base.Remove(item);

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdSpeciality", "P" + item.IdSpeciality.ToString() },
            };

            server.DeleteInto("Specialities", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 12
0
        public new void Remove(Semester item)
        {
            if (Helper.SemesterUsed(item.IdSemester))
            {
                throw new Exception($"Семестр \"{item}\" ещё используется!");
            }
            base.Remove(item);
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdSemester", "P" + item.IdSemester.ToString() },
            };

            server.DeleteInto("Semesters", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 13
0
        // -- [NonSerialized]
        // -- public bool Changed;

        public new void Add(Semester item)
        {
            if (base.Exists(x => x.ToString().Trim() == item.ToString().Trim()))
            {
                throw new Exception($"Семестр \"{item}\" уже существует!");
            }
            base.Add(item);
            base.Sort();
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdSemester", "P" + item.IdSemester.ToString() },
                { "Number", item.Number }
            };

            server.InsertInto("Semesters", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 14
0
        // -- [NonSerialized]
        // -- public bool Changed;

        public new void Add(Performance item)
        {
            if (base.Exists(x => x.ToString().Trim() == item.ToString().Trim()))
            {
                throw new Exception($"Успеваемость \"{item}\" уже существует!");
            }
            base.Add(item);
            base.Sort();
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdPerformance", "P" + item.IdPerformance.ToString() },
                { "IdSemester", "P" + item.IdSemester.ToString() },
                { "IdMatter", "P" + item.IdMatter.ToString() },
                { "Grade", item.Grade },
                { "IdStudent", "P" + item.IdStudent.ToString() }
            };

            server.InsertInto("Performances", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 15
0
        public new void Add(Semester item)
        {
            if (base.Exists(x => x.ToString().Trim() == item.ToString().Trim()))
            {
                throw new Exception($"Семестр \"{item}\" уже существует!");
            }
            else
            {
                base.Add(item);
            }
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdSemester", "P" + item.IdSemester.ToString() },
                { "Number", item.Number }
            };

            server.InsertInto("Semesters", columns);
        }
Esempio n. 16
0
        public new void Remove(Performance item)
        {
            if (Helper.PerformanceUsed(item.IdPerformance))
            {
                throw new Exception($"Успеваемость \"{item}\" ещё используются!");
            }
            base.Remove(item);
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdPerformance", "P" + item.IdPerformance.ToString() },
            };

            server.DeleteInto("Performances", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 17
0
        // -- [NonSerialized]
        // -- public bool Changed;

        public new void Add(Teacher item)
        {
            if (base.Exists(x => x.ToString().Trim() == item.ToString().Trim()))
            {
                throw new Exception($"Преподаватель \"{item}\" уже существует!");
            }
            base.Add(item);
            base.Sort();
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdTeacher", "P" + item.IdTeacher.ToString() },
                { "FullName", item.FullName },
                { "IdMatter", "P" + item.IdMatter.ToString() },
                { "Login", item.Login },
                { "Password", item.Password }
            };

            server.InsertInto("Teachers", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
        public new void Add(MattersCourse item)
        {
            if (base.Exists(x => x.ToString().Trim() == item.ToString().Trim()))
            {
                throw new Exception($"Курс \"{item}\" уже существует!");
            }
            base.Add(item);
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdMattersCourse", "P" + item.IdMatter.ToString() },
                { "IdSpeciality", "P" + item.IdSpeciality.ToString() },
                { "IdSpecialization", "P" + item.IdSpecialization.ToString() },
                { "IdMatter", "P" + item.IdMatter.ToString() },
                { "CourseType", item.CourseType },
                { "RatingSystem", item.RatingSystem },
                { "HoursCount", item.HoursCount }
            };

            server.InsertInto("MattersCourses", columns);
        }
Esempio n. 19
0
        public new void Remove(Student item)
        {
            if (Helper.StudentUsed(item.IdStudent))
            {
                throw new Exception($"Данные о студенте \"{item}\" ещё используются!");
            }
            base.Remove(item);

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdStudent", "P" + item.IdStudent.ToString() },
            };

            server.DeleteInto("Students", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 20
0
        public new void Add(Speciality item)
        {
            if (base.Exists(x => x.ToString().Trim() == item.ToString().Trim()))
            {
                throw new Exception($"Специальность \"{item}\" уже существует!");
            }
            base.Add(item);
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdSpeciality", "P" + item.IdSpeciality.ToString() },
                { "Name", item.Name },
                { "Number", item.Number }
            };

            server.InsertInto("Specialities", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 21
0
        public new void Add(Matter item)
        {
            if (base.Exists(x => x.ToString().Trim() == item.ToString().Trim()))
            {
                throw new Exception($"Предмет \"{item}\" уже существует!");
            }
            else
            {
                base.Add(item);
            }
            base.Sort();

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdMatter", "P" + item.IdMatter.ToString() },
                { "Name", item.Name }
            };

            server.InsertInto("Matters", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 22
0
        public void ChangeTo(Student old, Student anew)
        {
            if (old.IdStudent != anew.IdStudent &&
                base.FindAll(x => x.ToString().Trim() == anew.ToString().Trim()).Count > 0)
            {
                throw new Exception($"Студент \"{anew}\" уже существует!");
            }
            old.FullName             = anew.FullName;
            old.BirthDay             = anew.BirthDay;
            old.EducationCertificate = anew.EducationCertificate;
            old.ReceiptDate          = anew.ReceiptDate;
            old.Address          = anew.Address;
            old.PhoneNumber      = anew.PhoneNumber;
            old.SocialStatus     = anew.SocialStatus;
            old.Notes            = anew.Notes;
            old.Photo            = anew.Photo.DeepClone();
            old.IdSpeciality     = anew.IdSpeciality;
            old.IdSpecialization = anew.IdSpecialization;
            old.IdStudyGroup     = anew.IdStudyGroup;
            base.Sort();
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdStudent", "P" + anew.IdStudent.ToString() },
                { "FullName", anew.FullName },
                { "BirthDay", anew.BirthDay },
                { "EducationCertificate", anew.EducationCertificate },
                { "ReceiptDate", anew.ReceiptDate },
                { "Address", anew.Address },
                { "PhoneNumber", anew.PhoneNumber },
                { "SocialStatus", anew.SocialStatus },
                { "Notes", anew.Notes },
                { "Photo", anew.Photo ?? new byte[] { } },
                { "IdSpeciality", "P" + anew.IdSpeciality.ToString() },
                { "IdSpecialization", "P" + anew.IdSpecialization.ToString() },
                { "IdStudyGroup", "P" + anew.IdStudyGroup.ToString() }
            };

            server.UpdateInto("Students", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
        public void ChangeTo(MattersCourse old, MattersCourse anew)
        {
            if (old.IdMattersCourse != anew.IdMattersCourse &&
                base.FindAll(x => x.ToString().Trim() == anew.ToString().Trim()).Count > 0)
            {
                throw new Exception($"Курс \"{anew}\" уже существует!");
            }
            old.IdSpeciality     = anew.IdSpeciality;
            old.IdSpecialization = anew.IdSpecialization;
            old.IdMatter         = anew.IdMatter;
            old.CourseType       = anew.CourseType;
            old.RatingSystem     = anew.RatingSystem;
            old.HoursCount       = anew.HoursCount;
            base.Sort();
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdMattersCourse", "P" + anew.IdMatter.ToString() },
                { "IdSpeciality", "P" + anew.IdSpeciality.ToString() },
                { "IdSpecialization", "P" + anew.IdSpecialization.ToString() },
                { "IdMatter", "P" + anew.IdMatter.ToString() },
                { "CourseType", anew.CourseType },
                { "RatingSystem", anew.RatingSystem },
                { "HoursCount", anew.HoursCount }
            };

            server.UpdateInto("MattersCourses", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 24
0
        // -- [NonSerialized]
        // -- public bool Changed;

        public new void Add(Student item)
        {
            // -- Допускаются студенты с одиковым полным именем
            // -- if (base.Exists(x => x.ToString().Trim() == item.ToString().Trim()))
            // --     throw new Exception($"Студент \"{item}\" уже существует!");
            base.Add(item);
            base.Sort();
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdStudent", "P" + item.IdStudent.ToString() },
                { "FullName", item.FullName },
                { "BirthDay", item.BirthDay },
                { "EducationCertificate", item.EducationCertificate },
                { "ReceiptDate", item.ReceiptDate },
                { "Address", item.Address },
                { "PhoneNumber", item.PhoneNumber },
                { "SocialStatus", item.SocialStatus },
                { "Notes", item.Notes },
                { "Photo", item.Photo ?? new byte[] { } },
                { "IdSpeciality", "P" + item.IdSpeciality.ToString() },
                { "IdSpecialization", "P" + item.IdSpecialization.ToString() },
                { "IdStudyGroup", "P" + item.IdStudyGroup.ToString() }
            };

            server.InsertInto("Students", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 25
0
        public new void Remove(Matter item)
        {
            base.Remove(item);

            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdMatter", "P" + item.IdMatter.ToString() },
            };

            server.DeleteInto("Matters", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 26
0
        public void ChangeTo(Performance old, Performance anew)
        {
            if (old.IdPerformance != anew.IdPerformance &&
                base.FindAll(x => x.IdStudent != anew.IdStudent &&
                             x.ToString().Trim() == anew.ToString().Trim()).Count > 0)
            {
                throw new Exception($"Успеваемость \"{anew}\" уже существует!");
            }
            old.IdSemester = anew.IdSemester;
            old.IdMatter   = anew.IdMatter;
            old.Grade      = anew.Grade;
            old.IdStudent  = anew.IdStudent;
            base.Sort();
            // -- Changed = true;
            // добавлено 29.06.2019
            if (!Loaded)
            {
                return;
            }
            var server = new OleDbServer {
                Connection = Helper.ConnectionString
            };
            var columns = new Dictionary <string, object>
            {
                { "IdPerformance", "P" + anew.IdPerformance.ToString() },
                { "IdSemester", "P" + anew.IdSemester.ToString() },
                { "IdMatter", "P" + anew.IdMatter.ToString() },
                { "Grade", anew.Grade },
                { "IdStudent", "P" + anew.IdStudent.ToString() }
            };

            server.UpdateInto("Performances", columns);
            if (!string.IsNullOrWhiteSpace(server.LastError))
            {
                throw new Exception(server.LastError);
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Метод загрузки сохранённой ранее конфигурации из базы данных
        /// </summary>
        /// <param name="connection"></param>
        /// <returns></returns>
        public static Root LoadFromBase(string connection)
        {
            var root   = new Root();
            var server = new OleDbServer {
                Connection = connection
            };
            // предметы
            var dataSet = server.GetRows("Matters");

            if (dataSet.Tables.Count > 0)
            {
                foreach (var row in dataSet.Tables[0].Rows.Cast <DataRow>())
                {
                    if (row.ItemArray.Length != 2)
                    {
                        continue;
                    }
                    root.Matters.Add(new Matter
                    {
                        IdMatter = Guid.Parse(row.ItemArray[0].ToString().Substring(1)),
                        Name     = row.ItemArray[1].ToString()
                    });
                }
            }
            // -- root.Matters.Changed = false;
            root.Matters.Loaded = true; // добавлено 29.06.2019
            OperationResult     = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(root);
            }
            // специальности
            dataSet = server.GetRows("Specialities");
            if (dataSet.Tables.Count > 0)
            {
                foreach (var row in dataSet.Tables[0].Rows.Cast <DataRow>())
                {
                    if (row.ItemArray.Length != 3)
                    {
                        continue;
                    }
                    root.Specialities.Add(new Speciality
                    {
                        IdSpeciality = Guid.Parse(row.ItemArray[0].ToString().Substring(1)),
                        Name         = row.ItemArray[1].ToString(),
                        Number       = int.Parse(row.ItemArray[2].ToString())
                    });
                }
            }
            // -- root.Specialities.Changed = false;
            root.Specialities.Loaded = true; // добавлено 29.06.2019
            OperationResult          = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(root);
            }
            // специализации
            dataSet = server.GetRows("Specializations");
            if (dataSet.Tables.Count > 0)
            {
                foreach (var row in dataSet.Tables[0].Rows.Cast <DataRow>())
                {
                    if (row.ItemArray.Length != 3)
                    {
                        continue;
                    }
                    root.Specializations.Add(new Specialization
                    {
                        IdSpecialization = Guid.Parse(row.ItemArray[0].ToString().Substring(1)),
                        Name             = row.ItemArray[1].ToString(),
                        IdSpeciality     = Guid.Parse(row.ItemArray[2].ToString().Substring(1))
                    });
                }
            }
            // -- root.Specializations.Changed = false;
            root.Specializations.Loaded = true; // добавлено 29.06.2019
            OperationResult             = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(root);
            }
            // курсы предметов
            dataSet = server.GetRows("MattersCourses");
            if (dataSet.Tables.Count > 0)
            {
                foreach (var row in dataSet.Tables[0].Rows.Cast <DataRow>())
                {
                    if (row.ItemArray.Length != 7)
                    {
                        continue;
                    }
                    root.MattersCourses.Add(new MattersCourse
                    {
                        IdMattersCourse  = Guid.Parse(row.ItemArray[0].ToString().Substring(1)),
                        IdSpeciality     = Guid.Parse(row.ItemArray[1].ToString().Substring(1)),
                        IdSpecialization = Guid.Parse(row.ItemArray[2].ToString().Substring(1)),
                        IdMatter         = Guid.Parse(row.ItemArray[3].ToString().Substring(1)),
                        CourseType       = (CourseType)Enum.Parse(typeof(CourseType), row.ItemArray[4].ToString()),
                        RatingSystem     = (RatingSystem)Enum.Parse(typeof(RatingSystem), row.ItemArray[5].ToString()),
                        HoursCount       = float.Parse(row.ItemArray[6].ToString())
                    });
                }
            }
            // -- root.MattersCourses.Changed = false;
            root.MattersCourses.Loaded = true; // добавлено 29.06.2019
            OperationResult            = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(root);
            }
            // семестры
            dataSet = server.GetRows("Semesters");
            if (dataSet.Tables.Count > 0)
            {
                foreach (var row in dataSet.Tables[0].Rows.Cast <DataRow>())
                {
                    if (row.ItemArray.Length != 2)
                    {
                        continue;
                    }
                    root.Semesters.Add(new Semester
                    {
                        IdSemester = Guid.Parse(row.ItemArray[0].ToString().Substring(1)),
                        Number     = int.Parse(row.ItemArray[1].ToString())
                    });
                }
            }
            // -- root.Semesters.Changed = false;
            root.Semesters.Loaded = true; // добавлено 29.06.2019
            OperationResult       = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(root);
            }
            // учебные группы
            dataSet = server.GetRows("StudyGroups");
            if (dataSet.Tables.Count > 0)
            {
                foreach (var row in dataSet.Tables[0].Rows.Cast <DataRow>())
                {
                    if (row.ItemArray.Length != 5)
                    {
                        continue;
                    }
                    root.StudyGroups.Add(new StudyGroup
                    {
                        IdStudyGroup     = Guid.Parse(row.ItemArray[0].ToString().Substring(1)),
                        Number           = row.ItemArray[1].ToString(),
                        TrainingPeriod   = float.Parse(row.ItemArray[2].ToString()),
                        IdSpeciality     = Guid.Parse(row.ItemArray[3].ToString().Substring(1)),
                        IdSpecialization = Guid.Parse(row.ItemArray[4].ToString().Substring(1))
                    });
                }
            }
            // -- root.StudyGroups.Changed = false;
            root.StudyGroups.Loaded = true; // добавлено 29.06.2019
            OperationResult         = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(root);
            }
            // успеваемости
            dataSet = server.GetRows("Performances");
            if (dataSet.Tables.Count > 0)
            {
                foreach (var row in dataSet.Tables[0].Rows.Cast <DataRow>())
                {
                    if (row.ItemArray.Length != 5)
                    {
                        continue;
                    }
                    root.Performances.Add(new Performance
                    {
                        IdPerformance = Guid.Parse(row.ItemArray[0].ToString().Substring(1)),
                        IdSemester    = Guid.Parse(row.ItemArray[1].ToString().Substring(1)),
                        IdMatter      = Guid.Parse(row.ItemArray[2].ToString().Substring(1)),
                        Grade         = (Grade)Enum.Parse(typeof(Grade), row.ItemArray[3].ToString()),
                        IdStudent     = Guid.Parse(row.ItemArray[4].ToString().Substring(1))
                    });
                }
            }
            // -- root.Performances.Changed = false;
            root.Performances.Loaded = true; // добавлено 29.06.2019
            OperationResult          = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(root);
            }
            // студенты
            dataSet = server.GetRows("Students");
            if (dataSet.Tables.Count > 0)
            {
                foreach (var row in dataSet.Tables[0].Rows.Cast <DataRow>())
                {
                    if (row.ItemArray.Length != 13)
                    {
                        continue;
                    }
                    var buff = (byte[])row.ItemArray[9];
                    root.Students.Add(new Student
                    {
                        IdStudent            = Guid.Parse(row.ItemArray[0].ToString().Substring(1)),
                        FullName             = row.ItemArray[1].ToString(),
                        BirthDay             = DateTime.Parse(row.ItemArray[2].ToString()),
                        EducationCertificate = row.ItemArray[3].ToString(),
                        ReceiptDate          = DateTime.Parse(row.ItemArray[4].ToString()),
                        Address          = row.ItemArray[5].ToString(),
                        PhoneNumber      = row.ItemArray[6].ToString(),
                        SocialStatus     = row.ItemArray[7].ToString(),
                        Notes            = row.ItemArray[8].ToString(),
                        Photo            = buff,
                        IdSpeciality     = Guid.Parse(row.ItemArray[10].ToString().Substring(1)),
                        IdSpecialization = Guid.Parse(row.ItemArray[11].ToString().Substring(1)),
                        IdStudyGroup     = Guid.Parse(row.ItemArray[12].ToString().Substring(1))
                    });
                }
            }
            // -- root.Students.Changed = false;
            root.Students.Loaded = true; // добавлено 29.06.2019
            OperationResult      = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(root);
            }
            // преподаватели
            dataSet = server.GetRows("Teachers");
            if (dataSet.Tables.Count > 0)
            {
                foreach (var row in dataSet.Tables[0].Rows.Cast <DataRow>())
                {
                    if (row.ItemArray.Length != 5)
                    {
                        continue;
                    }
                    root.Teachers.Add(new Teacher
                    {
                        IdTeacher = Guid.Parse(row.ItemArray[0].ToString().Substring(1)),
                        FullName  = row.ItemArray[1].ToString(),
                        IdMatter  = Guid.Parse(row.ItemArray[2].ToString().Substring(1)),
                        Login     = row.ItemArray[3].ToString(),
                        Password  = row.ItemArray[4].ToString()
                    });
                }
            }
            // -- root.Teachers.Changed = false;
            root.Teachers.Loaded = true; // добавлено 29.06.2019
            OperationResult      = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(root);
            }

            return(root);
        }