private static Event dataAfterProcessing(EventusRow row) { EventType eventType; int index; getEventType(row.Name, out index, out eventType); switch (eventType) { case EventType.P: return(new LectureEvent() { Id = row.Id, DateFrom = row.DateFrom, DateTo = row.DateTo, TimeFrom = row.TimeFrom, TimeTo = row.TimeTo, Subject = new Subject() { Name = row.Name.Substring(0, index).Trim() }, Groups = getGroupForEvent(row.Name, index) }); case EventType.V: return(new PracticeEvent() { Id = row.Id, DateFrom = row.DateFrom, DateTo = row.DateTo, TimeFrom = row.TimeFrom, TimeTo = row.TimeTo, Subject = new Subject() { Name = row.Name.Substring(0, index).Trim() }, Groups = getGroupForEvent(row.Name, index) }); case EventType.N: return(new OtherEvent() { Id = row.Id, DateFrom = row.DateFrom, DateTo = row.DateTo, TimeFrom = row.TimeFrom, TimeTo = row.TimeTo, Subject = new Subject() { Name = row.Name.Trim() } }); } return(null); }
private static void readFromExcelFile(string originalFileName) { var file = new FileInfo(originalFileName); using ( var stream = File.Open(originalFileName, FileMode.Open, FileAccess.Read)) { IExcelDataReader reader; if (file.Extension.Equals(".xls")) { reader = ExcelDataReader.ExcelReaderFactory.CreateBinaryReader(stream); } else if (file.Extension.Equals(".xlsx")) { reader = ExcelDataReader.ExcelReaderFactory.CreateOpenXmlReader(stream); } else { throw new Exception("Invalid FileName"); } reader.Read(); while (reader.Read()) { EventusRow row = new EventusRow(); for (int i = 0; i < reader.FieldCount; i++) { switch (i) { case 0: row.Id = reader.GetDouble(i); break; case 1: row.Created = reader.GetDateTime(i); break; case 2: row.UidCreated = reader.GetDouble(i); break; case 3: row.UidUpdated = reader.GetValue(i) != null ? (double?)reader.GetDouble(i) : null; break; case 4: row.Updated = reader.GetValue(i) != null ? (DateTime?)reader.GetDateTime(i) : null; break; case 5: row.Version = reader.GetDouble(i); break; case 6: row.DateFrom = reader.GetDateTime(i).Date; break; case 7: row.DateTo = reader.GetDateTime(i).Date; break; case 8: row.Description = reader.GetString(i); break; case 9: row.Name = reader.GetString(i); break; case 10: row.Status = reader.GetDouble(i); break; case 11: row.TimeFrom = reader.GetDateTime(i).TimeOfDay; break; case 12: row.TimeTo = reader.GetDateTime(i).TimeOfDay; break; case 13: row.Type = reader.GetDouble(i); break; case 14: row.ExternalCode = reader.GetValue(i) != null?reader.GetString(i) : null; break; default: continue; } } eventusData.Add(row); } } }