private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            if (dataGridView1.SelectedRows[0].Tag == null)
            {
                return;
            }
            SubscriberSet pilot = dataGridView1.SelectedRows[0].Tag as SubscriberSet;

            textBoxLastname.Text  = pilot.LastName;
            textBoxFirstName.Text = pilot.FirstName;
            selectedSubscriber    = pilot;
            if (pilot.PictureSet != null)
            {
                MemoryStream ms = new MemoryStream(pilot.PictureSet.Data);
                PictureBox.Image = System.Drawing.Image.FromStream(ms);
            }
            else
            {
                PictureBox.Image = global::AirNavigationRaceLive.Properties.Resources._default;
            }
        }
Beispiel #2
0
        private string getPilNavNames(SubscriberSet pilot, SubscriberSet navigator)
        {
            string pilName = pilot != null ? pilot.LastName + " " + pilot.FirstName : " - ";
            string navName = navigator != null ? "|" + navigator.LastName + " " + navigator.FirstName : " - ";

            return(pilName + navName);
        }
        void savePicture(Boolean isResetMode)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            SubscriberSet pilot = dataGridView1.SelectedRows[0].Tag as SubscriberSet;

            if (pilot == null)
            {
                return;
            }

            if (PictureBox.Tag == null)
            {
                MemoryStream ms = new MemoryStream();
                PictureBox.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                PictureSet pic = new PictureSet();
                pic.Data         = ms.ToArray();
                pilot.PictureSet = pic;
            }
            if (pilot.Id == 0)
            {
                Client.DBContext.SubscriberSet.Add(pilot);
            }
            if (isResetMode)
            {
                pilot.PictureSet = null;
                PictureBox.Image = global::AirNavigationRaceLive.Properties.Resources._default;
            }
            Client.DBContext.SaveChanges();
            this.BeginInvoke(new MethodInvoker(UpdateEnablement));
        }
 private void ResetFields()
 {
     textBoxLastname.Text  = "";
     textBoxFirstName.Text = "";
     selectedSubscriber    = null;
     PictureBox.Image      = global::AirNavigationRaceLive.Properties.Resources._default;
     UpdateEnablement();
 }
        private string getTeamDsc(TeamSet team)
        {
            SubscriberSet pilot = team.Pilot;
            StringBuilder sb    = new StringBuilder();

            sb.Append(pilot.LastName).Append(" ").Append(pilot.FirstName);
            if (team.Navigator != null)
            {
                SubscriberSet navi = team.Navigator;
                sb.Append(" - ").Append(navi.LastName).Append(" ").Append(navi.FirstName);
            }
            return(sb.ToString());
        }
 private void dataGridView1_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
 {
     if (subscrDeleted != null)
     {
         //cscDel = e.Row.Tag as Subscriber;
         Client.DBContext.SubscriberSet.Remove(subscrDeleted);
         subscrDeleted = null;
         Client.DBContext.SaveChanges();
         textBoxLastname.Clear();
         textBoxFirstName.Clear();
         this.BeginInvoke(new MethodInvoker(LoadData));
     }
 }
Beispiel #7
0
        private static string getTeamDsc(Client.DataAccess c, FlightSet flight)
        {
            TeamSet       team  = flight.TeamSet;
            SubscriberSet pilot = team.Pilot;
            StringBuilder sb    = new StringBuilder();

            sb.Append(team.CNumber).Append(" ");
            sb.Append(pilot.LastName).Append(" ").Append(pilot.FirstName);
            if (team.Navigator != null)
            {
                SubscriberSet navi = team.Navigator;
                sb.Append(" - ").Append(navi.LastName).Append(" ").Append(navi.FirstName);
            }
            return(sb.ToString());
        }
 private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 {
     if (!e.Row.IsNewRow)
     {
         string str =
             "(" + e.Row.Cells[0].Value.ToString() + ") " + e.Row.Cells[1].Value.ToString() + " " + e.Row.Cells[2].Value.ToString();
         if (MessageBox.Show(string.Format("Delete the selected Participant:\n {0} ?", str), "Delete Participant", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.No)
         {
             e.Cancel = true;
             return;
         }
         SubscriberSet pilot = e.Row.Tag as SubscriberSet;
         subscrDeleted = pilot;
     }
 }
        private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (!dataGridView1.IsCurrentRowDirty)
            {
                return;
            }
            var           lastNameVal  = dataGridView1.Rows[e.RowIndex].Cells[1].FormattedValue;
            var           firstNameVal = dataGridView1.Rows[e.RowIndex].Cells[2].FormattedValue;
            var           iDval        = dataGridView1.Rows[e.RowIndex].Cells[0].FormattedValue;
            SubscriberSet subsc        = new SubscriberSet();

            if (string.IsNullOrEmpty(lastNameVal.ToString().Trim()) || string.IsNullOrEmpty(firstNameVal.ToString().Trim()))
            {
                dataGridView1.Rows[e.RowIndex].ErrorText = "Empty values are not allowed";
                e.Cancel = true;
                return;
            }

            if (isDuplicateParticipant(firstNameVal.ToString().Trim(), lastNameVal.ToString().Trim(), iDval.ToString()))
            {
                dataGridView1.Rows[e.RowIndex].ErrorText = "This name exists already in the list of participants";
                e.Cancel = true;
                return;
            }
            dataGridView1.Rows[e.RowIndex].ErrorText = string.Empty;

            if (string.IsNullOrEmpty(iDval.ToString()))
            {
                subsc.LastName       = lastNameVal.ToString().Trim();
                subsc.FirstName      = firstNameVal.ToString().Trim();
                subsc.CompetitionSet = Client.SelectedCompetition;
                dataGridView1.Rows[e.RowIndex].Tag = subsc;
                Client.DBContext.SubscriberSet.Add(subsc);
                Client.DBContext.SaveChanges();
            }
            else
            {
                subsc           = dataGridView1.Rows[e.RowIndex].Tag as SubscriberSet;
                subsc.LastName  = lastNameVal.ToString().Trim();
                subsc.FirstName = firstNameVal.ToString().Trim();
                Client.DBContext.SaveChanges();
            }

            this.BeginInvoke(new MethodInvoker(LoadData));
        }
Beispiel #10
0
 private void comboBoxNavigator_SelectedIndexChanged(object sender, EventArgs e)
 {
     NavigatorId = -1;
     if (comboBoxNavigator.SelectedIndex >= 0)
     {
         if (Navigator == null)
         {
             Navigator = new SubscriberSet();
         }
         int _id = -1;
         NavigatorName = comboBoxNavigator.Text;
         if (int.TryParse(comboBoxNavigator.SelectedValue.ToString(), out _id))
         {
             NavigatorId = _id;
             Navigator   = ListParticipants.FirstOrDefault(r => r.Id == _id);
         }
     }
     UpdateEnablement();
 }
Beispiel #11
0
 private void comboBoxPilot_SelectedIndexChanged(object sender, EventArgs e)
 {
     PilotId = -1;
     if (Pilot == null)
     {
         Pilot = new SubscriberSet();
     }
     if (comboBoxPilot.SelectedIndex > 0)
     {
         int _id = -1;
         PilotName = comboBoxPilot.Text;
         if (int.TryParse(comboBoxPilot.SelectedValue.ToString(), out _id))
         {
             PilotId = _id;
             Pilot   = ListParticipants.Find(r => r.Id == _id);
         }
     }
     UpdateEnablement();
 }
Beispiel #12
0
        internal static void CreateStartListPDF(QualificationRoundSet qRnd, Client.DataAccess Client, string pathToPDF)
        {
            Document doc = new Document();

            doc.Info.Author   = "*****@*****.**";
            doc.Info.Comment  = "Generated from ANRL Client on " + DateTime.Now.ToString();
            doc.Info.Keywords = "ANRL Start List";
            doc.Info.Subject  = "Start List";
            doc.Info.Title    = "Start List";
            doc.UseCmykColor  = true;
            doc.DefaultPageSetup.PageFormat  = PageFormat.A4;
            doc.DefaultPageSetup.Orientation = Orientation.Landscape;

            Section sec = doc.AddSection();

            AddCompetitionAndLogo(Client, sec);

            sec.AddParagraph("Qualification Round: " + qRnd.Name);
            sec.AddParagraph("Starting List");
            sec.AddParagraph("Printed (UTC): " + System.DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ssZ", DateTimeFormatInfo.InvariantInfo));
            sec.AddParagraph("");

            Table table = sec.AddTable();

            table.Borders.Visible = true;

            table.AddColumn(Unit.FromCentimeter(1));
            table.AddColumn(Unit.FromCentimeter(1));
            table.AddColumn(Unit.FromCentimeter(2));
            table.AddColumn(Unit.FromCentimeter(9));
            table.AddColumn(Unit.FromCentimeter(2.1));
            table.AddColumn(Unit.FromCentimeter(2.1));
            table.AddColumn(Unit.FromCentimeter(2.1));
            table.AddColumn(Unit.FromCentimeter(2.1));
            table.AddColumn(Unit.FromCentimeter(2.1));
            table.AddColumn(Unit.FromCentimeter(1.3));

            Row row = table.AddRow();

            row.Shading.Color = Colors.Gray;
            row.Cells[0].AddParagraph("Start ID");
            row.Cells[1].AddParagraph("Crew ID");
            row.Cells[2].AddParagraph("AC");
            row.Cells[3].AddParagraph("Pilot - Navigator");
            row.Cells[4].AddParagraph("Start Planning [UTC]");
            row.Cells[5].AddParagraph("End Planning [UTC]");
            row.Cells[6].AddParagraph("Take-Off [UTC]");
            row.Cells[7].AddParagraph("SP Gate [UTC]");
            row.Cells[8].AddParagraph("FP Gate [UTC]");
            row.Cells[9].AddParagraph("Route");

            foreach (FlightSet ct in qRnd.FlightSet.OrderBy(x => x.TimeTakeOff).ThenBy(x => x.Route))
            {
                Row r = table.AddRow();
                if ((table.Rows.Count - 1) % 2 == 0)
                {
                    r.Shading.Color = Colors.LightGray;
                }
                r.Cells[0].AddParagraph(ct.StartID.ToString());
                TeamSet teams = ct.TeamSet;
                r.Cells[1].AddParagraph(teams.CNumber);
                r.Cells[2].AddParagraph(teams.AC);
                SubscriberSet pilot = teams.Pilot;
                if (teams.Navigator != null)
                {
                    SubscriberSet navigator = teams.Navigator;
                    r.Cells[3].AddParagraph(pilot.LastName + " " + pilot.FirstName + " - " + navigator.LastName + " " + navigator.FirstName);
                }
                else
                {
                    r.Cells[3].AddParagraph(pilot.LastName + " " + pilot.FirstName);
                }
                DateTime dt = new DateTime(ct.TimeTakeOff);

                r.Cells[4].AddParagraph(dt.AddMinutes(-C_Timespan_StartPlanningToTKOF).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                r.Cells[5].AddParagraph(dt.AddMinutes(-C_Timespan_EndPlanningToTKOF).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                //                r.Cells[6].Shading.Color = Colors.LightGray;
                r.Cells[6].AddParagraph(dt.ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                r.Cells[7].AddParagraph(new DateTime(ct.TimeStartLine).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                r.Cells[8].AddParagraph(new DateTime(ct.TimeEndLine).ToString(C_TimeFormat, DateTimeFormatInfo.InvariantInfo));
                r.Cells[9].AddParagraph(Enum.GetName(Route.A.GetType(), ct.Route));
                r.Cells[9].Format.Alignment = ParagraphAlignment.Center;
            }

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(pathToPDF);
            Process.Start(pathToPDF);
        }
Beispiel #13
0
        public static void CreateTeamsPDF(List <TeamSet> teams, Client.DataAccess c, String pathToPDF)
        {
            Document doc = new Document();

            doc.Info.Author   = "*****@*****.**";
            doc.Info.Comment  = "Generated from ANRL Client on " + DateTime.Now.ToString();
            doc.Info.Keywords = "ANRL Crewlist";
            doc.Info.Subject  = "Crewlist";
            doc.Info.Title    = "Crewlist";
            doc.UseCmykColor  = true;
            doc.DefaultPageSetup.PageFormat   = PageFormat.A4;
            doc.DefaultPageSetup.Orientation  = Orientation.Landscape;
            doc.DefaultPageSetup.BottomMargin = Unit.FromCentimeter(1);
            doc.DefaultPageSetup.TopMargin    = Unit.FromCentimeter(1);
            doc.DefaultPageSetup.LeftMargin   = Unit.FromCentimeter(1.5);
            doc.DefaultPageSetup.RightMargin  = Unit.FromCentimeter(1);


            Section sec = doc.AddSection();

            AddCompetitionAndLogo(c, sec);
            sec.AddParagraph("");
            sec.AddParagraph("Participants list");
            sec.AddParagraph("");

            Table table = sec.AddTable();

            table.Borders.Visible = true;

            //table.AddColumn(Unit.FromCentimeter(0.7));
            table.AddColumn(Unit.FromCentimeter(2.5));
            table.AddColumn();
            table.AddColumn(Unit.FromCentimeter(4));
            table.AddColumn(Unit.FromCentimeter(4));
            table.AddColumn(Unit.FromCentimeter(4));
            table.AddColumn(Unit.FromCentimeter(4));
            table.AddColumn();

            Row row = table.AddRow();

            row.Shading.Color = Colors.Gray;
            //row.Cells[0].AddParagraph("ID");
            row.Cells[0].AddParagraph("CNumber");
            row.Cells[1].AddParagraph("Nationality");
            row.Cells[2].AddParagraph("Pilot Lastname");
            row.Cells[3].AddParagraph("Pilot Firstname");
            row.Cells[4].AddParagraph("Navigator Lastname");
            row.Cells[5].AddParagraph("Navigator Firstname");
            row.Cells[6].AddParagraph("AC");

            foreach (TeamSet t in teams)
            {
                Row r = table.AddRow();
                //r.Cells[0].AddParagraph(t.ID.ToString());
                r.Cells[0].AddParagraph(t.CNumber);
                r.Cells[1].AddParagraph(t.Nationality);
                SubscriberSet pilot = t.Pilot;
                r.Cells[2].AddParagraph(pilot.LastName);
                r.Cells[3].AddParagraph(pilot.FirstName);
                if (t.Navigator != null)
                {
                    SubscriberSet navigator = t.Navigator;
                    r.Cells[4].AddParagraph(navigator.LastName);
                    r.Cells[5].AddParagraph(navigator.FirstName);
                }
                r.Cells[6].AddParagraph(t.AC);
            }

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(pathToPDF);

            Process.Start(pathToPDF);
        }
Beispiel #14
0
        public static void CreateRankingListPDF(Client.DataAccess c, QualificationRoundSet qRnd, List <ComboBoxFlights> qRndFlights, String pathToPDF)
        {
            List <Toplist> toplist = new List <Toplist>();

            foreach (ComboBoxFlights cbct in qRndFlights)
            {
                int sum = 0;
                foreach (PenaltySet penalty in cbct.flight.PenaltySet)
                {
                    sum += penalty.Points;
                }
                toplist.Add(new Toplist(cbct.flight, sum));
            }
            toplist.Sort();

            Document doc = new Document();

            doc.Info.Author   = "*****@*****.**";
            doc.Info.Comment  = "Generated from ANRL Client on " + DateTime.Now.ToString();
            doc.Info.Keywords = "ANRL Toplist";
            doc.Info.Subject  = "Toplist";
            doc.Info.Title    = "Toplist";
            doc.UseCmykColor  = true;
            doc.DefaultPageSetup.PageFormat   = PageFormat.A4;
            doc.DefaultPageSetup.Orientation  = Orientation.Landscape;
            doc.DefaultPageSetup.BottomMargin = Unit.FromCentimeter(1);
            doc.DefaultPageSetup.TopMargin    = Unit.FromCentimeter(1);
            doc.DefaultPageSetup.LeftMargin   = Unit.FromCentimeter(1.5);
            doc.DefaultPageSetup.RightMargin  = Unit.FromCentimeter(1);


            Section sec = doc.AddSection();

            AddCompetitionAndLogo(c, sec);
            sec.AddParagraph("");
            sec.AddParagraph("Ranking List: " + qRnd.Name);
            sec.AddParagraph("");

            Table table = sec.AddTable();

            table.Borders.Visible = true;

            table.AddColumn(Unit.FromCentimeter(2));
            table.AddColumn(Unit.FromCentimeter(2));
            table.AddColumn(Unit.FromCentimeter(2.5));
            table.AddColumn(Unit.FromCentimeter(4));
            table.AddColumn(Unit.FromCentimeter(4));
            table.AddColumn(Unit.FromCentimeter(4));
            table.AddColumn(Unit.FromCentimeter(4));

            Row row = table.AddRow();

            row.Shading.Color = Colors.Gray;
            row.Cells[0].AddParagraph("Rank");
            row.Cells[1].AddParagraph("Points");
            row.Cells[2].AddParagraph("Nationality");
            row.Cells[3].AddParagraph("Pilot Lastname");
            row.Cells[4].AddParagraph("Pilot Firstname");
            row.Cells[5].AddParagraph("Navigator Lastname");
            row.Cells[6].AddParagraph("Navigator Firstname");

            int oldsum   = -1;
            int prevRank = 0;
            int rank     = 0;

            foreach (Toplist top in toplist)
            {
                rank++;
                TeamSet t = top.ct.TeamSet;
                Row     r = table.AddRow();
                if (rank > 1 && oldsum == top.sum)  // we have a shared rank
                {
                    r.Cells[0].AddParagraph(prevRank + "");
                }
                else  // the normal case
                {
                    prevRank = rank;
                    r.Cells[0].AddParagraph(rank + "");
                }
                r.Cells[1].AddParagraph(top.sum.ToString());
                r.Cells[2].AddParagraph(t.Nationality);
                SubscriberSet pilot = t.Pilot;
                r.Cells[3].AddParagraph(pilot.LastName);
                r.Cells[4].AddParagraph(pilot.FirstName);
                if (t.Navigator != null)
                {
                    SubscriberSet navigator = t.Navigator;
                    r.Cells[5].AddParagraph(navigator.LastName);
                    r.Cells[6].AddParagraph(navigator.FirstName);
                }
                oldsum = top.sum;
            }

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(pathToPDF);

            Process.Start(pathToPDF);
        }
        public static void CreateRankingListExcel(string CompName, string QRName, List <ComboBoxFlights> qRndFlights, String filename)
        {
            List <Toplist> toplist = new List <Toplist>();

            foreach (ComboBoxFlights cbct in qRndFlights)
            {
                int sum = 0;
                foreach (PenaltySet penalty in cbct.flight.PenaltySet)
                {
                    sum += penalty.Points;
                }
                toplist.Add(new Toplist(cbct.flight, sum));
            }
            toplist.Sort();

            var newFile = new FileInfo(filename);

            if (newFile.Exists)
            {
                newFile.Delete();
            }
            using (var pck = new ExcelPackage(newFile))
            {
                ExcelWorksheet ResultList = pck.Workbook.Worksheets.Add("ResultList");
                ResultList.Cells[1, 1].Value = String.Format("Competition: {0}", CompName);
                ResultList.Cells[2, 1].Value = String.Format("Qualification Round: {0}", QRName);

                string[] colNamesValues = { "Rank", "Points", "Nationality", "Pilot Lastname", "Pilot Firstname", "Navigator Lastname", "Navigator Firstname" };

                for (int jCol = 0; jCol < colNamesValues.Length; jCol++)
                {
                    ResultList.Cells[3, jCol + 1].Value = colNamesValues[jCol];
                }

                int oldsum   = -1;
                int prevRank = 0;
                int rank     = 0;
                int i        = 0;
                int iBase    = 3;

                foreach (Toplist top in toplist)
                {
                    rank++;
                    i++;
                    TeamSet t = top.ct.TeamSet;
                    if (i > 0 && oldsum == top.sum)  // we have a shared rank
                    {
                        ResultList.Cells[i + iBase, 1].Value = prevRank;
                    }
                    else  // the normal case
                    {
                        prevRank = rank;
                        ResultList.Cells[i + iBase, 1].Value = rank;
                    }
                    ResultList.Cells[i + iBase, 2].Value = top.sum.ToString();
                    ResultList.Cells[i + iBase, 3].Value = t.Nationality;
                    SubscriberSet pilot = t.Pilot;
                    ResultList.Cells[i + iBase, 4].Value = pilot.LastName;
                    ResultList.Cells[i + iBase, 5].Value = pilot.FirstName;
                    if (t.Navigator != null)
                    {
                        SubscriberSet navigator = t.Navigator;
                        ResultList.Cells[i + iBase, 6].Value = navigator.LastName;
                        ResultList.Cells[i + iBase, 7].Value = navigator.FirstName;
                    }
                    oldsum = top.sum;
                }
                pck.Save();
            }
        }
        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();
            }
        }