public override void Load()
        {
            if (reading)
            {
                try
                {
                    const string path = @"E:\BACHELORS WORK\TIMETABLE\DataCollectionApp\BugsReport.txt";

                    int departmentID = dbo.getDepartmentID(departmentShortName);

                    for (int i = 0; i < disciplines.Count; i++)
                    {
                        int disciplineID = dbo.getDisciplineID(disciplines[i].ToString());

                        dbo.insertLesson(disciplineID, lessonsType[i].ToString(), Convert.ToInt32(hours[i]),
                                         lessonsControl[i].ToString(), departmentID);

                        int lastLessonID = dbo.getLastLessonID();

                        string suggestedAuditories = auditories[i].ToString();

                        if (suggestedAuditories.Length != 0)
                        {
                            suggestedAuditories = ccc.correctAuditories(suggestedAuditories);

                            string [] separatedAuditories = suggestedAuditories.Split(new char[] { ',', ';' });

                            for (int j = 0; j < separatedAuditories.Length; j++)
                            {
                                ArrayList auditoriesInDB = dbo.getAuditoryNames();

                                if (auditoriesInDB.Contains(separatedAuditories[j]) == false)
                                {
                                    dbo.insertAuditory(departmentID, separatedAuditories[j]);
                                    using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default))
                                    {
                                        sw.WriteLine("{0:g}", DateTime.Now);
                                        sw.Write("Аудиторію \"" + separatedAuditories[j] + "\" кафедри \"" + departmentShortName +
                                                 "\" завантажено до бази даних з файлу \"" + FileName + "\"");
                                        sw.WriteLine();
                                    }
                                }

                                int auditoryID = dbo.getAuditoryID(separatedAuditories[j]);
                                dbo.insertLesson_Auditory(lastLessonID, auditoryID);
                            }
                        }

                        string teachersRecord = teachers[i].ToString();
                        teachersRecord = ccc.correctTeachers(teachersRecord);

                        string [] separatedTeachers = teachersRecord.Split(new char[] { ',', ';' });

                        for (int j = 0; j < separatedTeachers.Length; j++)
                        {
                            separatedTeachers[j] = separatedTeachers[j].Trim();

                            int teacherID = dbo.getTeacherID(separatedTeachers[j]);

                            dbo.insertLesson_Teacher(lastLessonID, teacherID);
                        }

                        string groupsInCell = groups[i].ToString();
                        if (groupsInCell.Length != 0)
                        {
                            groupsInCell = ccc.correctGroups(groupsInCell);

                            string [] separatedGroups = groupsInCell.Split(new char[] { ',', ';' });

                            ArrayList studyGroups = dbo.getStudy_groups();

                            for (int j = 0; j < separatedGroups.Length; j++)
                            {
                                if (studyGroups.Contains(separatedGroups[j]) == false)
                                {
                                    GroupCode gc   = new GroupCode();
                                    string    code = gc.getGroupCode(separatedGroups[j]);

                                    dbo.insertStudy_group(departmentID, separatedGroups[j], code);
                                    using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default))
                                    {
                                        sw.WriteLine("{0:g}", DateTime.Now);
                                        sw.Write("Учбову групу \"" + separatedGroups[j] + "\" кафедри \"" + departmentShortName +
                                                 "\" завантажено до бази даних з файлу \"" + FileName + "\"");
                                        sw.WriteLine();
                                    }
                                }
                                int groupID = dbo.getStudy_groupID(separatedGroups[j]);
                                dbo.insertLesson_group(lastLessonID, groupID);
                            }
                        }

                        string daysInCell = days[i].ToString();
                        if (daysInCell.Length != 0)
                        {
                            daysInCell = ccc.correctTime(daysInCell);
                            string [] separatedDays = daysInCell.Split(new char[] { ',', ';' });
                            for (int j = 0; j < separatedDays.Length; j++)
                            {
                                dbo.insertLesson_time(lastLessonID, separatedDays[j]);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Виникла помилка під час завантаження відомостей доручень до бази даних!" + "\n" + ex.Message);
                }
            }
        }
示例#2
0
        public override void Load()
        {
            if (reading)
            {
                try
                {
                    DbOperations          dbo = new DbOperations();
                    CellContentCorrection ccc = new CellContentCorrection();


                    int departmentID = dbo.getDepartmentID("ПМ");

                    for (int i = 0; i < disciplines.Count; i++)
                    {
                        int disciplineID = dbo.getDisciplineID(disciplines[i].ToString());

                        dbo.insertLesson(disciplineID, lessonsType[i].ToString(), Convert.ToInt32(hours[i]),
                                         lessonsControl[i].ToString(), departmentID);

                        int lastLessonID = dbo.getLastLessonID();

                        string suggestedAuditories = auditories[i].ToString();

                        if (suggestedAuditories.Length != 0)
                        {
                            suggestedAuditories = ccc.correctAuditories(suggestedAuditories);

                            string [] separatedAuditories = suggestedAuditories.Split(new char[] { ',', ';' });

                            for (int j = 0; j < separatedAuditories.Length; j++)
                            {
                                int auditoryID = dbo.getAuditoryID(separatedAuditories[j]);
                                dbo.insertLesson_Auditory(lastLessonID, auditoryID);
                            }
                        }

                        string teachersRecord = teachers[i].ToString();
                        teachersRecord = ccc.correctTeachers(teachersRecord);

                        string [] separatedTeachers = teachersRecord.Split(new char[] { ',', ';' });

                        for (int j = 0; j < separatedTeachers.Length; j++)
                        {
                            separatedTeachers[j] = separatedTeachers[j].Trim();

                            int teacherID = dbo.getTeacherID(separatedTeachers[j]);

                            dbo.insertLesson_Teacher(lastLessonID, teacherID);
                        }

                        string groupsInCell = groups[i].ToString();
                        if (groupsInCell.Length != 0)
                        {
                            groupsInCell = ccc.correctGroups(groupsInCell);

                            string [] separatedGroups = groupsInCell.Split(new char[] { ',', ';' });

                            ArrayList studyGroups = dbo.getStudy_groups();

                            for (int j = 0; j < separatedGroups.Length; j++)
                            {
                                if (studyGroups.Contains(separatedGroups[j]) == false)
                                {
                                    GroupCode gc   = new GroupCode();
                                    string    code = gc.getGroupCode(separatedGroups[j]);

                                    dbo.insertStudy_group(departmentID, separatedGroups[j], code);
                                }

                                int groupID = dbo.getStudy_groupID(separatedGroups[j]);
                                dbo.insertLesson_group(lastLessonID, groupID);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Виникла помилка під час завантаження відомостей доручень до бази даних!" + "\n" + ex.Message);
                }
            }
        }