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); } } }
public override void EvaluateData() { if (reading) { const string path = @"E:\BACHELORS WORK\TIMETABLE\DataCollectionApp\BugsReport.txt"; if (missingValuesOfNames.Count != 0 || missingValuesOfTypes.Count != 0 || missingValuesOfDepartments.Count != 0 || duplicatesOfNames.Count != 0) { using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default)) { sw.WriteLine("{0:g}", DateTime.Now); sw.WriteLine("АУДИТОРІЇ."); sw.WriteLine("Файл: " + FileName); } } if (missingValuesOfNames.Count != 0) { using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default)) { sw.WriteLine("Пропущено назви аудиторій в рядках: "); foreach (int value in missingValuesOfNames) { sw.Write(value + "|"); } sw.WriteLine(); } } if (missingValuesOfTypes.Count != 0) { using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default)) { sw.WriteLine("Пропущено типи аудиторій в рядках: "); foreach (int value in missingValuesOfTypes) { sw.Write(value + "|"); } sw.WriteLine(); } } if (missingValuesOfDepartments.Count != 0) { using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default)) { sw.WriteLine("Пропущено назви кафедр в рядках: "); foreach (int value in missingValuesOfDepartments) { sw.Write(value + "|"); } sw.WriteLine(); } } if (duplicatesOfNames.Count != 0) { using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default)) { sw.WriteLine("Є дублікати назв аудиторій: "); foreach (KeyValuePair <int, string> duplicate in duplicatesOfNames) { sw.WriteLine("В рядку номер " + duplicate.Key + ": " + duplicate.Value); } sw.WriteLine(); } } bool noSensetoReload = true; ArrayList auditoriesInDB = dbo.getAuditoryNames(); foreach (string name in names) { if (!auditoriesInDB.Contains(name)) { noSensetoReload = false; break; } } if (noSensetoReload) { reading = false; MessageBox.Show("Дані про аудиторії вже містяться в базі даних!"); } } }