private void ImportTimetable(string[] fields) { //return $"\"Timetables\"{sep}\"Id\"{sep}\"TimetableName\"{sep}\"TimetableAbbreviation\"{sep}" + // $"\"TimetableDescription\"{sep}\"IsMultiDirection\"{sep}\"ServiceDirectionId\"{sep}\"RouteId\"\r\n"; var timetable = new TimetableModel(); timetable.Id = int.Parse(fields[1]); timetable.TimetableName = fields[2]; timetable.TimetableAbbreviation = fields[3]; timetable.TimetableDescription = fields[4]; timetable.IsMultiDirection = bool.Parse(fields[5]); var oldServiceDirectionId = int.Parse(fields[6]); timetable.ServiceDirectionId = ServiceDirectionKeys.GetValueOrDefault(oldServiceDirectionId, 0); timetable.RouteId = newRouteId; var newTimetableId = TimetableDataAccess.InsertTimetableForRoute(timetable); TimetableKeys.Add(timetable.Id, newTimetableId); }
public string ExportTimetableTable() { List <TimetableModel> timetableList = TimetableDataAccess.GetAllTimetablesPerRoute(RouteId); return(WriteTimetableHeader() + WriteTimetableData(timetableList)); }
public static TimetableMatrixModel ReadTimetableMatrix(int timetableId, bool csvTarget) { // TODO wrap this all in a transaction, for better performance TimetableMatrixModel matrixModel = new TimetableMatrixModel(); // Get TimetableMode to retrieve name var timetable = TimetableDataAccess.GetTimetableById(timetableId); matrixModel.TimetableName = timetable.TimetableName; matrixModel.TimetableId = timetable.Id; matrixModel.RouteId = timetable.RouteId; var direction = ServiceDirectionDataAccess.GetServiceDirectionById(timetable.ServiceDirectionId); matrixModel.IsDescending = direction.IsDescending; // Now get a view, representing Services List <ServiceModel> serviceList = ServicesDataAccess.GetServicesPerTimetable(timetable.Id); serviceList = serviceList.OrderBy(x => x.StartTime).ToList(); var locationsList = LocationDataAccess.GetAllLocationsPerRoute(matrixModel.RouteId); if (matrixModel.IsDescending) { locationsList = locationsList.OrderByDescending(x => x.Order).ToList(); } else { locationsList = locationsList.OrderBy(x => x.Order).ToList(); } var locationsCount = locationsList.Count; matrixModel.Matrix = new string[locationsList.Count + 1][]; var columncount = serviceList.Count + 1; string[] columnheaders = new string[columncount]; columnheaders[0] = "---"; for (int i = 0; i < columncount - 1; i++) { columnheaders[i + 1] = serviceList[i].ServiceAbbreviation; } matrixModel.Matrix[0] = columnheaders; for (int i = 0; i < locationsCount; i++) { string[] row = new string[columncount]; row[0] = locationsList[i].LocationName; matrixModel.Matrix[i + 1] = row; } for (int index = 0; index < serviceList.Count; index++) { int actualTime = serviceList[index].StartTime; List <ServiceTimingModel> Timing; if (matrixModel.IsDescending) { Timing = GetServiceTiming(serviceList[index].Id, locationsList).OrderByDescending(x => x.LocationsOrder).ToList(); } else { Timing = GetServiceTiming(serviceList[index].Id, locationsList); } int j = 0; for (int i = 0; i < locationsCount;) { if (j < Timing.Count && locationsList[i].Order == Timing[j].LocationsOrder) { i++; j++; } else { var Insert = new ServiceTimingModel(); Insert.LocationId = locationsList[i].Id; Insert.LocationName = locationsList[i].LocationName; Insert.LocationAbbrev = locationsList[i].LocationAbbreviation; Insert.EventType = ""; Insert.ArrivalTime = 0; Insert.WaitTime = 0; Insert.TimeString = "--"; Insert.LocationsOrder = locationsList[i].Order; Insert.TimeEventId = -1; // TimeEvent is not valid! Timing.Insert(j, Insert); i++; j++; } } matrixModel.TimingList.Add(Timing); } for (int i = 0; i < columncount - 1; i++) // for each service { int actualTime = serviceList[i].StartTime; var timing = matrixModel.TimingList[i]; for (int j = 0; j < locationsCount; j++) // for each location { if (timing[j].TimeEventId > 0) { actualTime += timing[j].ArrivalTime; timing[j].TimeString = TimeConverters.TimeEventToString(actualTime, timing[j].WaitTime, csvTarget); actualTime += timing[j].WaitTime; } matrixModel.Matrix[j + 1][i + 1] = timing[j].TimeString; } } return(matrixModel); }