public FlightServices(IRepository <Flight> flightsRepository, IRepository <Airport> airportRepository, IRepository <Aircraft> aircrafttRepository, IMapperWrapper mapper) { _flightsRepository = flightsRepository ?? throw new ArgumentNullException("flightsRepository"); _airportRepository = airportRepository ?? throw new ArgumentNullException("airportRepository"); _aircrafttRepository = aircrafttRepository ?? throw new ArgumentNullException("aircrafttRepository"); _mapper = mapper ?? throw new ArgumentNullException("autoMapper"); _flightHelper = new FlightHelper(); }
public int DrawFlight(FlightHelper flightHelper, VehicleModel vehicle) { try { return(DrawFlightUnsafe(flightHelper, vehicle)); } catch (Exception ex) { var msg = ex.Message; return(0); } }
private int DrawFlightUnsafe(FlightHelper flightHelper, VehicleModel vehicle) { var flight = flightHelper.Flight; var rowDefinition = _planRows.GetValueOrDefault(flight.RowIndex ?? 0); var startDate = flight.StartDate.Date; var endDate = flight.EndDate.AddDays(-1).Date; var startColumn = _columnsLookup[startDate] + flightHelper.StartCorrection; var endColumn = _columnsLookup[endDate] + flightHelper.EndCorrection; if (startColumn > endColumn) { return(rowDefinition.EndExcelRowIndex); } var appearance = AppearanceHelper.GetAppearance(flight, vehicle); DrawAboveCaptions(flight, rowDefinition, startColumn, endColumn, appearance); var flightCells = _worksheet.Cells[rowDefinition.PrimaryExcelRowIndex, startColumn, rowDefinition.PrimaryExcelRowIndex, endColumn]; DrawBelowCaptions(flight, rowDefinition, startColumn, endColumn, appearance); FormatFlight(flightCells, appearance); var insideCaptions = flight.FlightCaption?.Inside ?? new List <FlightCaptionPosition>(); var captions = insideCaptions.Select(x => { var a = AppearanceHelper.GetAppearance(x.Appearance); return(a.GetValue(x.FormattedValue, _currencies)); }); flightCells.Value = string.Join(' ', captions); return(rowDefinition.EndExcelRowIndex); }
private void FillGrid(ExcelWorksheet worksheet) { int?mRowIndex = 0; var flightPainter = new FlightPainter(worksheet, _columnsLookup, _planRows, _exportPlanRequest.Currencies); if (_chartData.Objects.LinkedFlights != null) { if (_chartData.Objects.Flights == null) { _chartData.Objects.Flights = new List <Flight>(); } _chartData.Objects.Flights.AddRange(_chartData.Objects.LinkedFlights); } if (_chartData.Objects.Flights != null) { List <Flight> flights = _chartData.Objects.Flights; List <FlightHelper> intersectFlights = new List <FlightHelper>(); if (_viewMode == FormattedPlanViewMode.Weekly) { if (flights.Any()) { flights = flights.OrderBy(x => x.RowIndex).ThenBy(x => x.StartDate).ToList(); mRowIndex = flights.First().RowIndex; } } FlightHelper lastFlightHelper = null; int fc = 0; foreach (var flight in flights) { fc++; VehicleModel vehicle = null; if (flight.VehicleID.HasValue) { vehicle = _chartData.Vehicles.FirstOrDefault(x => x.ID == flight.VehicleID); } int flightRowIndex = -1; if (_viewMode == FormattedPlanViewMode.Weekly) { if (lastFlightHelper != null) { if (flight != lastFlightHelper.Flight) { continue; } } int index = flights.IndexOf(flight); Flight nextFlight = flights.ElementAtOrDefault(index + 1); int currIndex = 0; int nextIndex = 0; mRowIndex = flight.RowIndex; while ((nextFlight != null) && (nextFlight.RowIndex == mRowIndex) && (currIndex == nextIndex)) { currIndex = _columnsLookup[flight.EndDate.AddDays(-1).Date]; nextIndex = _columnsLookup[nextFlight.StartDate]; if (currIndex == nextIndex && nextFlight.RowIndex == flight.RowIndex) { if (!intersectFlights.Any()) { var firstFlightHelper = new FlightHelper(flight); if (lastFlightHelper != null) { firstFlightHelper.StartCorrection = lastFlightHelper.StartCorrection; firstFlightHelper.EndCorrection = lastFlightHelper.EndCorrection; } intersectFlights.Add(firstFlightHelper); } intersectFlights.Add(new FlightHelper(nextFlight)); } index += 1; nextFlight = flights.ElementAtOrDefault(index + 1); } if ((nextFlight != null) && (nextFlight.RowIndex > mRowIndex)) { mRowIndex = nextFlight.RowIndex; } if (intersectFlights.Any()) { int daysInWeek = 0; int flightIndex = 0; int maxDaysFlightIndex = 0; foreach (var fl in intersectFlights) { int currDaysInWeek = 1; int weekNumber = 0; if (flightIndex == 0) { weekNumber = _columnsLookup[fl.Flight.EndDate.AddDays(-1).Date]; DateTime dateTime = fl.Flight.EndDate.AddDays(-1 * currDaysInWeek - 1).Date; while ((_columnsLookup[dateTime] == weekNumber) && (dateTime >= fl.Flight.StartDate)) { currDaysInWeek += 1; dateTime = fl.Flight.EndDate.AddDays(-1 * currDaysInWeek - 1).Date; } currDaysInWeek -= 1; } else { weekNumber = _columnsLookup[fl.Flight.StartDate.Date]; DateTime dateTime = fl.Flight.StartDate.AddDays(currDaysInWeek).Date; while ((currDaysInWeek < 7) && (dateTime <= fl.Flight.EndDate.AddDays(-1).Date) && (_columnsLookup[dateTime] == weekNumber)) { currDaysInWeek += 1; dateTime = fl.Flight.StartDate.AddDays(currDaysInWeek).Date; } } if (daysInWeek < currDaysInWeek) { daysInWeek = currDaysInWeek; maxDaysFlightIndex = flightIndex; } flightIndex += 1; } foreach (var fl in intersectFlights) { if (intersectFlights.IndexOf(fl) < maxDaysFlightIndex) { fl.EndCorrection -= 1; } if (intersectFlights.IndexOf(fl) > maxDaysFlightIndex) { fl.StartCorrection += 1; } if (fl != intersectFlights.Last()) { flightRowIndex = flightPainter.DrawFlight(fl, vehicle); } } lastFlightHelper = intersectFlights.Last(); currIndex = 0; nextIndex = 0; intersectFlights.Clear(); } else { if (lastFlightHelper != null) { flightRowIndex = flightPainter.DrawFlight(lastFlightHelper, vehicle); lastFlightHelper = null; } else { flightRowIndex = flightPainter.DrawFlight(new FlightHelper(flight), vehicle); } } } else { flightRowIndex = flightPainter.DrawFlight(new FlightHelper(flight), vehicle); } } } }
public FlightController(IService <FlightDTO> flightService) { this.flightService = flightService; helper = new FlightHelper(flightService); }