Example #1
0
    void Update()
    {
        if (!_isUpdated && isMaster)
        {
            _isUpdated = true;
            set        = _receivedData.Dequeue();
            var flightIds = set.Flights.Select(p => p.Id).ToList();

            var aircraftToDelete =
                _aircrafts.Keys.Where(p => !flightIds.Contains(p)).ToList();
            DeleteAircraft(aircraftToDelete);

            var aircraftToAdd =
                set.Flights.Where(p => !_aircrafts.Keys.Contains(p.Id)).ToList();
            CreateAircraft(aircraftToAdd);
        }

#if UNITY_UWP
        foreach (var flight in set.Flights)
        {
            if ((flight.lastUpdate - DateTimeOffset.Now).Duration() > _waitTime)
            {
                flight.lastUpdate = DateTimeOffset.Now;
                OnElapsed(flight);
            }
        }
#endif
    }
Example #2
0
 public UploadLoggerData(DataAccess Client, FlightSet ct)
 {
     this.Client = Client;
     this.ct     = ct;
     InitializeComponent();
     textBoxDate.Enabled = false;
 }
Example #3
0
        public static void CalculateAndPersistPenaltyPoints(Client.DataAccess c, FlightSet f)
        {
            // IntersectionPoints: points where the competitor crosses a border
            // for Channel type : channel borders
            // for PROHZONE type: entering/leaving a prohibited area
            List <IntersectionPoint> intersectionPoints = new List <IntersectionPoint>();
            List <PenaltySet>        penalties          = CalculatePenaltyPoints(f, out intersectionPoints);

            c.DBContext.PenaltySet.RemoveRange(f.PenaltySet);
            if (f.IntersectionPointSet != null)
            {
                c.DBContext.IntersectionPointSet.RemoveRange(f.IntersectionPointSet);
                f.IntersectionPointSet.Clear();
            }
            f.PenaltySet.Clear();
            c.DBContext.PenaltySet.AddRange(penalties);
            f.PenaltySet = penalties;

            foreach (IntersectionPoint p in intersectionPoints)
            {
                p.Flight_Id = f.Id; // must add the Flight Id
            }

            c.DBContext.IntersectionPointSet.AddRange(intersectionPoints);
            f.IntersectionPointSet = intersectionPoints;
            c.DBContext.SaveChanges();
        }
Example #4
0
        public async Task <ActionResult <FlightSet> > PostFlightSet(FlightSet flightSet)
        {
            flightSet.RemainingSeats -= 1;
            FlightSet dbFlightSet = _context.FlightSet.Find(flightSet.FlightNo);

            flightSet.Price = dbFlightSet.Price;
            _context.FlightSet.Update(flightSet);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFlightSet", new { id = flightSet.FlightNo }, flightSet));
        }
        //private int ParcourLength;
        //private int TakeOffStartgate;
        //private int TakeOffIntervall;
        //private int ParcourIntervall;

        public StartListDialog(
            List <TeamSet> lstTeams,
            FlightSet selectedFlt,
            int maxStartId,
            long dateQRDate,
            long timeTKOF0,
            long timeStart0,
            long timeEnd0,
            int nrOfRoutes)
        {
            InitializeComponent();
            // BindingSource bs = new BindingSource();
            // bs.DataSource = lstTeams;
            // comboBoxTKOFLines.DataSource = bs;
            if (selectedFlt == null)
            {
                SelectedFlight = new FlightSet();
            }
            else
            {
                SelectedFlight = selectedFlt;
            }
            SelectedTeam = SelectedFlight.TeamSet;

            List <ComboTeamExtension> lstCboTeam = new List <ComboTeamExtension>();

            foreach (TeamSet t in lstTeams)
            {
                comboBoxCrew.Items.Add(new ComboTeamExtension(t, getTeamDsc(t)));
            }

            for (int i = 1; i <= nrOfRoutes; i++)
            {
                Route r = (Route)i;
                comboBoxRoute.Items.Add(new ComboRoute(r));
            }

            if (SelectedFlight.Id == 0)
            {
                textBoxStartId.Text       = maxStartId.ToString();
                comboBoxCrew.SelectedItem = null;
                date.Value        = new DateTime(dateQRDate);
                timeTakeOff.Value = new DateTime(timeTKOF0);
                timeStart.Value   = new DateTime(timeStart0);
                timeEnd.Value     = new DateTime(timeEnd0);
                // select first item id we have only one route
                comboBoxRoute.SelectedIndex = (nrOfRoutes == 1) ? 0: -1;
            }
            else
            {
                ComboTeamExtension comboTeam = null;
                foreach (Object o in comboBoxCrew.Items)
                {
                    if ((o as ComboTeamExtension).p == SelectedTeam)
                    {
                        comboTeam = o as ComboTeamExtension;
                        comboBoxCrew.SelectedItem = comboTeam;
                        break;
                    }
                }
                ComboRoute route = null;
                foreach (Object o in comboBoxRoute.Items)
                {
                    ComboRoute r = o as ComboRoute;
                    if ((int)r.p == SelectedFlight.Route)
                    {
                        route = r;
                        comboBoxRoute.SelectedItem = route;
                        break;
                    }
                }
                comboBoxRoute.SelectedItem = route;

                textBoxStartId.Text = SelectedFlight.StartID.ToString();
                DateTime takeOff = new DateTime(SelectedFlight.TimeTakeOff);
                date.Value          = takeOff;
                timeTakeOff.Value   = takeOff;
                timeStart.Value     = new DateTime(SelectedFlight.TimeStartLine);
                timeEnd.Value       = new DateTime(SelectedFlight.TimeEndLine);
                textBoxStartId.Tag  = SelectedFlight;
                textBoxStartId.Text = SelectedFlight.StartID.ToString();
            }
            UpdateEnablement();
            errorProvider1.Clear();
        }
Example #6
0
    private void ProcessData(List <Flight> flightData)
    {
        var set = new FlightSet(flightData);

        _receivedData.Enqueue(set);
    }
 public RankedTeam(FlightSet t, TeamSet team, int points)
 {
     this.t      = t;
     this.team   = team;
     this.points = points;
 }
Example #8
0
        public static List <PenaltySet> CalculatePenaltyPoints(FlightSet flight, out List <IntersectionPoint> lstIntersectionPoints)
        {
            bool useProhZoneCalculation = false;

            Point             last             = null;
            List <PenaltySet> result           = new List <PenaltySet>();
            List <LineP>      PenaltyZoneLines = new List <LineP>();
            // intersectionPoints will contain the intersection poinst of the flight path with SP, FP, PROH areas
            List <IntersectionPoint> intersectionPoints = new List <IntersectionPoint>();
            QualificationRoundSet    qr = flight.QualificationRoundSet;
            ParcourSet parcour          = flight.QualificationRoundSet.ParcourSet;

            useProhZoneCalculation = (parcour.PenaltyCalcType != (int)ParcourType.CHANNELS);


            List <LineP> ChannelZoneLines = getAssignedChannelLineP(parcour, (Route)flight.Route);

            foreach (Line nl in parcour.Line.Where(p => p.Type == (int)LineType.PENALTYZONE))
            {
                PenaltyZoneLines.Add(getLine(nl));
            }

            // add also all channel-specific prohibited zones assigned channel
            PenaltyZoneLines.AddRange(getAssignedProhZonelLines(parcour, (Route)flight.Route));

            List <LineP> dataLines = new List <LineP>();

            foreach (Point g in flight.Point)
            {
                if (last != null)
                {
                    LineP l = new LineP();
                    l.end           = new Vector(g.longitude, g.latitude, 0);
                    l.TimestamEnd   = g.Timestamp;
                    l.start         = new Vector(last.longitude, last.latitude, 0);
                    l.TimestamStart = last.Timestamp;
                    dataLines.Add(l);
                }
                last = g;
            }
            LineP startLine = getStartLine(parcour, (Route)flight.Route);
            LineP endLine   = getEndLine(parcour, (Route)flight.Route);

            if (startLine == null || endLine == null)
            {
                lstIntersectionPoints = intersectionPoints;
                return(result);
            }
            LineP takeOffLine = new LineP();

            takeOffLine.start       = new Vector(qr.TakeOffLine.A.longitude, qr.TakeOffLine.A.latitude, 0);
            takeOffLine.end         = new Vector(qr.TakeOffLine.B.longitude, qr.TakeOffLine.B.latitude, 0);
            takeOffLine.orientation = Vector.Orthogonal(takeOffLine.end - takeOffLine.start);

            long maxTimestamp = 0;

            maxTimestamp = flight.Point.Max(x => x.Timestamp);

            // For TakeOff-, Start- and End Line, we obviously(?) assume that these lines should have been passed two minutes before the end of recording
            // below values are used in case they are not passed
            bool shouldHaveCrossedTakeOff = (maxTimestamp - 2 * tickOfMinute) > flight.TimeTakeOff;
            bool shouldHaveCrossedStart   = (maxTimestamp - 2 * tickOfMinute) > flight.TimeStartLine;
            bool shouldHaveCrossedEnd     = (maxTimestamp - 2 * tickOfMinute) > flight.TimeEndLine;

            bool haveCrossedTakeOff         = false;
            bool haveCrossedStart           = false;
            bool haveCrossedEnd             = false;
            bool insidePenalty              = false;
            long timeSinceInsidePenalty     = 0;
            bool outsideOwnChannel          = true;
            long timeSinceOutsideOwnChannel = 0;
            bool isFirstTimeIntoChannel     = true;

            IntersectionPoint ipTakeOff = new IntersectionPoint();
            IntersectionPoint ipStart   = new IntersectionPoint();
            IntersectionPoint ipEnd     = new IntersectionPoint();

            foreach (LineP l in dataLines)
            {
                double            intersectionTakeOff = getIntersection(l, takeOffLine);
                double            intersectionStart   = getIntersection(l, startLine);
                double            intersectionEnd     = getIntersection(l, endLine);
                IntersectionPoint ip = new IntersectionPoint();

                #region crossing takeOff line
                if (getIntersection(l, takeOffLine, out ip) && !haveCrossedTakeOff)
                {
                    haveCrossedTakeOff = true;
                    intersectionPoints.Add(ip);
                    long crossTime = ip.Timestamp;
                    crossTime = ((crossTime + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // round
                    ipTakeOff = ip;
                    long       diff    = crossTime - flight.TimeTakeOff;
                    PenaltySet penalty = new PenaltySet();
                    penalty.Points = (diff > C_TKOF_TimeUpper * tickOfSecond || diff < C_TKOF_TimeLower * tickOfSecond) ? C_TKOF_MaxPenalty : 0;
                    penalty.Reason = string.Format("Take-off Line planned: {1}, actual: {0}", new DateTime((Int64)crossTime).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime((Int64)flight.TimeTakeOff).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                    result.Add(penalty);
                }
                #endregion

                #region crossing start line
                if (getIntersection(l, startLine, out ip) & !haveCrossedStart)
                {
                    haveCrossedStart = true;
                    intersectionPoints.Add(ip);
                    long crossTime = ip.Timestamp;
                    ipStart = ip;
                    long diff = Math.Abs(crossTime - flight.TimeStartLine);
                    crossTime = ((crossTime + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // round
                    int        sec     = (int)((diff + (tickOfSecond / 2) + 1) / tickOfSecond);
                    PenaltySet penalty = new PenaltySet();
                    penalty.Points = (diff > C_SPFP_TimeTolerance * tickOfSecond) ? Math.Min((sec - C_SPFP_TimeTolerance) * C_PointsPerSec, C_SPFP_MaxPenalty) : 0;
                    penalty.Reason = string.Format("SP Line planned: {1}, actual: {0}", new DateTime((Int64)crossTime).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime((Int64)flight.TimeStartLine).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                    result.Add(penalty);
                }
                #endregion

                if (useProhZoneCalculation || ChannelZoneLines.Count == 0)
                {
                    #region entering or leaving prohibited zone

                    bool stateChanged = false;
                    //IntersectionPoint ip = new IntersectionPoint();
                    if (intersectsProhAreaPoint(PenaltyZoneLines, l, out stateChanged, out ip))
                    {
                        if (stateChanged)
                        {
                            intersectionPoints.Add(ip);
                            if (!insidePenalty)
                            {
                                insidePenalty          = true;
                                timeSinceInsidePenalty = ip.Timestamp;
                            }
                            else
                            {
                                insidePenalty = false;
                                long diff = ip.Timestamp - timeSinceInsidePenalty;
                                if (diff > tickOfSecond * C_PROH_TimeTolerance)
                                {
                                    PenaltySet penalty = new PenaltySet();
                                    // round times for entering/leaving penalty zone to nearest full second
                                    long pstart = ((timeSinceInsidePenalty + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // rounded
                                    long pend   = ((ip.Timestamp + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond;           // rounded
                                    int  sec    = (int)((pend - pstart) / tickOfSecond);
                                    penalty.Points = (sec - C_PROH_TimeTolerance) * C_PointsPerSec;
                                    // Max penalty inside PROH zone: ======>> NOTE: acc FAI rules disabled after NOV 2017; zero means no maximum per event
                                    penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - C_PROH_TimeTolerance) * C_PointsPerSec, C_MaxPenaltyPerEvent) : penalty.Points;
                                    //penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - 5) * 3, C_MaxPenaltyPerEvent) : penalty.Points;
                                    penalty.Reason = string.Format("Penalty zone for {0} sec, [{1} - {2}]", sec, new DateTime(pstart).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime(pend).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                                    result.Add(penalty);
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region entering or leaving channel

                    bool stateChanged = false;
                    if (intersectsOwnChannel(ChannelZoneLines, l, out stateChanged, out ip))
                    {
                        if (stateChanged)
                        {
                            intersectionPoints.Add(ip);
                            if (!outsideOwnChannel)
                            {
                                outsideOwnChannel          = true;
                                timeSinceOutsideOwnChannel = ip.Timestamp;
                            }
                            else
                            {
                                if (isFirstTimeIntoChannel)
                                {
                                    isFirstTimeIntoChannel = false;
                                    if (haveCrossedStart)
                                    {
                                        timeSinceOutsideOwnChannel = ipStart.Timestamp;
                                    }
                                    else
                                    {
                                        timeSinceOutsideOwnChannel = flight.TimeStartLine;
                                    }
                                }
                                outsideOwnChannel = false;
                                long diff = ip.Timestamp - timeSinceOutsideOwnChannel;
                                if (diff > tickOfSecond * C_PROH_TimeTolerance)
                                {
                                    PenaltySet penalty = new PenaltySet();
                                    // round times for entering/leaving penalty zone to nearest full second
                                    long pstart = ((timeSinceOutsideOwnChannel + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // rounded
                                    long pend   = ((ip.Timestamp + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond;               // rounded
                                    int  sec    = (int)((pend - pstart) / tickOfSecond);
                                    penalty.Points = (sec - C_PROH_TimeTolerance) * C_PointsPerSec;
                                    penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - C_PROH_TimeTolerance) * C_PointsPerSec, C_MaxPenaltyPerEvent) : penalty.Points;
                                    //penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - 5) * 3, C_MaxPenaltyPerEvent) : penalty.Points;
                                    penalty.Reason = string.Format("outside channel for {0} sec, [{1} - {2}]", sec, new DateTime(pstart).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime(pend).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                                    result.Add(penalty);
                                }
                            }
                        }
                    }
                    else
                    {
                        // check if end line is passed now but outside the cannel. if yes, set outSideOwnChannel = false
                        if (getIntersection(l, endLine, out ip))
                        {
                            outsideOwnChannel = false;
                            long diff = ip.Timestamp - timeSinceOutsideOwnChannel;
                            if (diff > tickOfSecond * C_PROH_TimeTolerance)
                            {
                                PenaltySet penalty = new PenaltySet();
                                // round times for entering/leaving penalty zone to nearest full second
                                long pstart = ((timeSinceOutsideOwnChannel + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // rounded
                                long pend   = ((ip.Timestamp + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond;               // rounded
                                int  sec    = (int)((pend - pstart) / tickOfSecond);
                                penalty.Points = (sec - C_PROH_TimeTolerance) * C_PointsPerSec;
                                // Max penalty outside channel; zero value means no Max penalty
                                penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - C_PROH_TimeTolerance) * C_PointsPerSec, C_MaxPenaltyPerEvent) : penalty.Points;
                                //penalty.Points = C_MaxPenaltyPerEvent > 0 ? Math.Min((sec - 5) * 3, C_MaxPenaltyPerEvent) : penalty.Points;
                                penalty.Reason = string.Format("outside channel for {0} sec, [{1} - {2}]", sec, new DateTime(pstart).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime(pend).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                                result.Add(penalty);
                            }
                        }
                    }

                    #endregion
                }

                #region crossing end line
                if (getIntersection(l, endLine, out ip) & !haveCrossedEnd)
                {
                    haveCrossedEnd = true;
                    intersectionPoints.Add(ip);
                    long crossTime = ip.Timestamp;
                    ipEnd = ip;
                    long diff = Math.Abs(crossTime - flight.TimeEndLine);
                    crossTime = ((crossTime + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // round
                    int        sec     = (int)((diff + (tickOfSecond / 2) + 1) / tickOfSecond);
                    PenaltySet penalty = new PenaltySet();
                    penalty.Points = (diff > C_SPFP_TimeTolerance * tickOfSecond) ? Math.Min((sec - C_SPFP_TimeTolerance) * C_PointsPerSec, C_SPFP_MaxPenalty) : 0;
                    penalty.Reason = string.Format("FP Line planned: {1}, actual: {0}", new DateTime((Int64)crossTime).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime((Int64)flight.TimeEndLine).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                    result.Add(penalty);
                }
                #endregion
            }

            #region handling cases where Takeoff-, Start- or End line are not observed/never crossed

            if (shouldHaveCrossedStart && !haveCrossedStart)
            {
                PenaltySet penalty = new PenaltySet();
                penalty.Points = C_SPFP_MaxPenalty;
                penalty.Reason = "SP Line not passed";
                result.Insert(0, penalty); // add to begin of list
            }
            ;
            if (shouldHaveCrossedTakeOff && !haveCrossedTakeOff)
            {
                PenaltySet penalty = new PenaltySet();
                penalty.Points = C_TKOF_MaxPenalty;
                penalty.Reason = "Takeoff Line not passed";
                result.Insert(0, penalty); // add to begin of list
            }
            ;
            if (shouldHaveCrossedEnd && !haveCrossedEnd)
            {
                PenaltySet penalty = new PenaltySet();
                // TODO: handle the case where we have channel calculation but no FP line
                if (!(useProhZoneCalculation || ChannelZoneLines.Count == 0) && outsideOwnChannel)
                {
                    outsideOwnChannel = false;
                    long crossTime = flight.TimeEndLine;
                    long diff      = Math.Abs(crossTime - timeSinceOutsideOwnChannel);
                    if (diff > C_SPFP_TimeTolerance * tickOfSecond)
                    {
                        crossTime = ((crossTime + (tickOfSecond / 2) + 1) / tickOfSecond) * tickOfSecond; // round
                        int sec = (int)((diff + (tickOfSecond / 2) + 1) / tickOfSecond);
                        penalty.Points = Math.Min((sec - C_SPFP_TimeTolerance) * C_PointsPerSec, C_SPFP_MaxPenalty);
                        penalty.Reason = string.Format("outside channel for {0} sec, [{1} - {2}]", sec, new DateTime(timeSinceOutsideOwnChannel).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo), new DateTime(crossTime).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                        result.Add(penalty);
                    }
                }
                penalty        = new PenaltySet();
                penalty.Points = C_SPFP_MaxPenalty;
                penalty.Reason = "FP Line not passed";
                result.Add(penalty);
            }
            ;
            #endregion



            lstIntersectionPoints = intersectionPoints;
            return(result);
        }
        private void ImportFromExcel(ComboQRExtension item, string filename)
        {
            // this has not been tested after changes in version 2.0.0
            // therefore unsupported UFN
            return;

            FileInfo newFile = new FileInfo(filename);

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            //ExcelPackage pck = new ExcelPackage(newFile);
            using (var pck = new ExcelPackage(newFile))
            {
                ExcelWorksheet Participants = pck.Workbook.Worksheets.First(p => p.Name == "Participants");
                ExcelWorksheet Teams        = pck.Workbook.Worksheets.First(p => p.Name == "Crews");
                ExcelWorksheet StartList    = pck.Workbook.Worksheets.First(p => p.Name == "StartList");
                int            i            = 2;
                while (i < 200)
                {
                    string LastName  = Participants.Cells[("A" + i)].Value as string;
                    string FirstName = Participants.Cells[("B" + i)].Value as string;
                    if (LastName != null && FirstName != null && LastName != "" && FirstName != "")
                    {
                        if (!Client.SelectedCompetition.SubscriberSet.Any(p => p.LastName == LastName && p.FirstName == FirstName))
                        {
                            SubscriberSet sub = new SubscriberSet();
                            sub.CompetitionSet = Client.SelectedCompetition;
                            sub.LastName       = LastName;
                            sub.FirstName      = FirstName;
                            Client.DBContext.SubscriberSet.Add(sub);
                        }
                    }
                    else
                    {
                        break;
                    }
                    i++;
                }
                Client.DBContext.SaveChanges();
                i = 2;
                while (i < 200)
                {
                    double?cNumber     = Teams.Cells[("A" + i)].Value as double?;
                    string nationality = Teams.Cells[("B" + i)].Value as string;
                    string pilot       = Teams.Cells[("C" + i)].Value as string;
                    string navigator   = Teams.Cells[("D" + i)].Value as string;
                    string ac          = Teams.Cells[("E" + i)].Value as string;
                    if (cNumber.HasValue && pilot != null && pilot != "")
                    {
                        SubscriberSet pilotS     = Client.SelectedCompetition.SubscriberSet.First(p => pilot.Contains(p.FirstName) && pilot.Contains(p.LastName));
                        SubscriberSet navigatorS = null;
                        if (navigator != null && navigator != "")
                        {
                            navigatorS = Client.SelectedCompetition.SubscriberSet.First(p => navigator.Contains(p.FirstName) && navigator.Contains(p.LastName));
                        }
                        TeamSet t = null;
                        if (Client.SelectedCompetition.TeamSet.Any(p => p.CNumber == ((int)cNumber.Value).ToString()))
                        {
                            t = Client.SelectedCompetition.TeamSet.First(p => p.CNumber == ((int)cNumber.Value).ToString());
                        }
                        else
                        {
                            t = new TeamSet();
                            t.CompetitionSet = Client.SelectedCompetition;
                            Client.DBContext.TeamSet.Add(t);
                        }
                        t.Pilot       = pilotS;
                        t.Navigator   = navigatorS;
                        t.CNumber     = ((int)cNumber.Value).ToString();
                        t.Nationality = nationality;
                        t.AC          = ac;
                    }
                    else
                    {
                        break;
                    }
                    i++;
                }
                Client.DBContext.SaveChanges();
                i = 2;
                DateTime?date = null;
                while (i < 200)
                {
                    if (i == 2)
                    {
                        date = StartList.Cells[("K" + i)].Value as DateTime?;
                    }
                    double?startId = StartList.Cells[("A" + i)].Value as double?;
                    double?cNumber = StartList.Cells[("B" + i)].Value as double?;
                    double?takeOff = StartList.Cells[("G" + i)].Value as double?;
                    double?start   = StartList.Cells[("H" + i)].Value as double?;
                    double?end     = StartList.Cells[("I" + i)].Value as double?;
                    string route   = StartList.Cells[("J" + i)].Value as string;
                    if (date != null && date.HasValue && takeOff != null && start != null && end != null && startId.HasValue && cNumber.HasValue && takeOff.HasValue && start.HasValue && end.HasValue && route != null)
                    {
                        FlightSet f = null;
                        if (item.q.FlightSet.Any(p => p.StartID == startId.Value))
                        {
                            f = item.q.FlightSet.First(p => p.StartID == startId.Value);
                        }
                        else
                        {
                            f = new FlightSet();
                            f.QualificationRoundSet = item.q;
                            f.StartID = ((int)startId.Value);
                            Client.DBContext.FlightSet.Add(f);
                        }
                        f.TeamSet = Client.SelectedCompetition.TeamSet.First(p => p.CNumber == ((int)cNumber.Value).ToString());
                        f.Route   = (int)Enum.Parse(typeof(Route), route, true);
                        DateTime d  = date.Value;
                        DateTime to = DateTime.FromOADate(takeOff.Value);
                        DateTime st = DateTime.FromOADate(start.Value);
                        DateTime en = DateTime.FromOADate(end.Value);
                        f.TimeTakeOff   = new DateTime(d.Year, d.Month, d.Day, to.Hour, to.Minute, to.Second).Ticks;
                        f.TimeStartLine = new DateTime(d.Year, d.Month, d.Day, st.Hour, st.Minute, st.Second).Ticks;
                        f.TimeEndLine   = new DateTime(d.Year, d.Month, d.Day, en.Hour, en.Minute, en.Second).Ticks;
                    }
                    else
                    {
                        break;
                    }
                    i++;
                }
                Client.DBContext.SaveChanges();
            }
        }