Example #1
0
        private static void AppendNewScheduleRecord(DayDto dayDto, string time, Row row)
        {
            try
            {
                string       subject   = row[2].Value.ToString();
                TeacherDto   teacher   = GetTeacherData(row[3].Value.ToString());
                ClassRoomDto classRoom = new ClassRoomDto {
                    Number = row[6].Value.ToString().Replace(" ", String.Empty)
                };

                var weeksString = row[5].Value.ToString();

                if (string.IsNullOrEmpty(teacher.LastName))
                {
                    teacher.LastName = "Вакансія"; // in case of null
                }


                var groupStr = row[4].Value.ToString(); //either number or 'lecture'

                if (string.IsNullOrEmpty(subject) || subject.Length <= 2)
                {
                    return;
                }

                if (string.IsNullOrEmpty(classRoom.Number) ||
                    string.IsNullOrEmpty(weeksString) || string.IsNullOrEmpty(groupStr))
                {
                    throw new InvalidInputException("Некоректні дані: " + dayDto.DayName + ", " + time + " у файлі " + _currentFilePath);
                }

                LessonTimeDto lessonTime = new LessonTimeDto {
                    Number = LessonTimeDto.GetNumberFromPeriod(time)
                };
                string group = string.Empty;

                if (groupStr.Any(char.IsDigit))
                {
                    group = groupStr.Replace(" ", "");
                }
                else
                {
                    group = string.Empty;
                }

                LessonTypeDto lessonType = new LessonTypeDto();
                lessonType.Id = LessonTypeDto.GetIdByType(group == string.Empty ? LessonType.Лекція : LessonType.Практика);

                ScheduleRecordDto scheduleRecord = new ScheduleRecordDto
                {
                    YearOfStudying = _yearOfStudying,
                    LessonTime     = lessonTime,
                    Subject        = subject,
                    LessonType     = lessonType,
                    Group          = group,
                    Day            = dayDto,
                    Specialty      = _specialty,
                    ClassRoom      = classRoom,
                    Teacher        = teacher,
                    Weeks          = weeksString
                };

                var weeksStr  = row[5].Value.ToString().Replace(".", ","); //replace 6.9 to 6,9
                var weeksList = Utils.Utils.ParseWeeks(weeksStr);

                _weekScheduleRecords.Add(scheduleRecord, new List <int>());
                foreach (var weekNumber in weeksList)
                {
                    _weekScheduleRecords[scheduleRecord].Add(weekNumber);
                }
            }
            catch (InvalidInputException e)
            {
                Logger.LogException(e);
                throw e;
            }
            catch (Exception e)
            {
                Logger.LogException(e);
            }
        }
Example #2
0
        public static bool AddIfNotExists(ScheduleRecordDto scheduleRecord)
        {
            var specialtyId = SpecialtyDao.AddIfNotExists(scheduleRecord.Specialty);
            var teacherId   = TeacherDao.AddIfNotExists(scheduleRecord.Teacher);

            ClassRoomsDao.AddIfNotExists(scheduleRecord.ClassRoom);
            scheduleRecord.Id = scheduleRecord.GetHashCode();

            if (IsStoredInDb(scheduleRecord.Id))
            {
                return(false);
            }
            try
            {
                using (OleDbCommand oleDbCommand = new OleDbCommand())
                {
                    // Set the command object properties
                    oleDbCommand.Connection  = new OleDbConnection(ConnectionConfig.ConnectionString);
                    oleDbCommand.CommandType = CommandType.Text;
                    oleDbCommand.CommandText = insertScheduleRecord;

                    // Add the input parameters to the parameter collection
                    oleDbCommand.Parameters.AddWithValue("@Id", scheduleRecord.Id);
                    oleDbCommand.Parameters.AddWithValue("@YearOfStudying", scheduleRecord.YearOfStudying);
                    oleDbCommand.Parameters.AddWithValue("@Subject", scheduleRecord.Subject);
                    oleDbCommand.Parameters.AddWithValue("@LessonTypeId", scheduleRecord.LessonType.Id);
                    if (scheduleRecord.Group == string.Empty)
                    {
                        oleDbCommand.Parameters.AddWithValue("@Group", DBNull.Value);
                    }
                    else
                    {
                        oleDbCommand.Parameters.AddWithValue("@Group", scheduleRecord.Group);
                    }
                    oleDbCommand.Parameters.AddWithValue("@TeacherId", teacherId);
                    oleDbCommand.Parameters.AddWithValue("@DayNumber", scheduleRecord.Day.DayNumber);
                    oleDbCommand.Parameters.AddWithValue("@ClassRoomNumber", scheduleRecord.ClassRoom.Number);
                    oleDbCommand.Parameters.AddWithValue("@LessonTimeNumber", scheduleRecord.LessonTime.Number);
                    oleDbCommand.Parameters.AddWithValue("@SpecialtyId", specialtyId);
                    oleDbCommand.Parameters.AddWithValue("@Weeks", scheduleRecord.Weeks);

                    // Open the connection, execute the query and close the connection
                    oleDbCommand.Connection.Open();
                    var rowsAffected = oleDbCommand.ExecuteNonQuery();

                    oleDbCommand.Connection.Close();

                    if (rowsAffected > 0)
                    {
                        return(true);
                    }

                    Logger.LogException("Could not add schedule record");
                    return(false);
                }
            }
            catch (OleDbException ex)
            {
                Logger.LogException(ex);
                return(false);
            }
        }