Esempio n. 1
0
        private void listBoxCouples_DoubleClick(object sender, EventArgs e)
        {
            CoupleWrapper c = this.listBoxCouples.SelectedItem as CoupleWrapper;

            var couple = this.apiClient.GetCouple(c.couple.Id);

            this.model.Couple = couple;

            var country = this.model.Countries.First(co => co.country.Name == couple.Country);

            this.textBoxManMin.Text   = couple.ManMin.ToString();
            this.textBoxWomanMin.Text = couple.WomanMin.ToString();
            this.comboBoxCoupleCountry.SelectedIndex  = this.comboBoxCoupleCountry.Items.IndexOf(country);
            this.comboBoxCoupleDivision.SelectedIndex = this.comboBoxCoupleDivision.Items.IndexOf(couple.Division);
            this.comboBoxCoupleStatus.SelectedIndex   = this.comboBoxCoupleStatus.Items.IndexOf(couple.Status);
            this.labelCoupleWrlBlocked.Text           = couple.WrlBlockedUntil;
            this.labelCoupleChBlocked.Text            = couple.CupOrChampionshipBlockedUntil;
            if (string.IsNullOrEmpty(couple.RetiredOn))
            {
                this.dateTimePickerCoupleRetireOn.Value = new DateTime(1800, 1, 1);
            }
            else
            {
                this.dateTimePickerCoupleRetireOn.Value = DateTime.Parse(couple.RetiredOn);
            }
        }
Esempio n. 2
0
 private void textBoxCoupleId_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(typeof(CoupleWrapper)))
     {
         CoupleWrapper a = (CoupleWrapper)e.Data.GetData(typeof(CoupleWrapper));
         textBoxCoupleId.Text = ((CoupleWrapper)e.Data.GetData(typeof(CoupleWrapper))).couple.Id;
     }
 }
Esempio n. 3
0
        private void textBoxCoupleId_DragEnter(object sender, DragEventArgs e)
        {
            CoupleWrapper a = (CoupleWrapper)e.Data.GetData(typeof(CoupleWrapper));

            if (a != null)
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
Esempio n. 4
0
        private void buttonFillWithParticipants_Click(object sender, EventArgs e)
        {
            List <Task> tasks         = new List <Task>();
            Random      random        = new Random();
            int         competitionId = (this.listBoxCompetitions.SelectedItem as CompetitionWrapper).competition.Id;
            int         total         = int.Parse(this.textBoxParticipantCount.Text);
            int         start         = int.Parse(this.textBoxFirstStartNumber.Text);
            int         max           = listBoxCouples.Items.Count - 1;
            List <int>  steps         = new List <int> {
                192, 96, 48, 24, 12, 6, 0
            };
            int maxRounds = 7 - steps.IndexOf(steps.First(s => s < total));

            if (this.model.CompetitionOfficials.Count == 0)
            {
                MessageBox.Show("No officils loaded.");
                return;
            }

            string scoreType = this.checkBoxIncludeScores.Checked ? this.comboBoxScoreType.SelectedItem.ToString() : string.Empty;

            SetProgressBar(this.progressBarParticipants, 0, total);
            for (int i = start; i < start + total; i++)
            {
                tasks.Add(new Task(new Action <object>((state) =>
                {
                    int startNumber      = (int)state;
                    int rank             = startNumber - start + 1;
                    CoupleWrapper couple = listBoxCouples.Items[random.Next(0, max)] as CoupleWrapper;
                    int rounds           = steps.IndexOf(steps.First(s => s < rank)) + 1;

                    var model = new Api.Client.Models.ParticipantCoupleDetail()
                    {
                        CoupleId      = couple.couple.Id,
                        CompetitionId = competitionId,
                        Status        = "Present",
                        StartNumber   = startNumber,
                        Rank          = rank.ToString()
                    };
                    ModelFiller.Fill(model, scoreType, rounds, maxRounds, this.model.CompetitionOfficials);

                    try
                    {
                        Uri participantUrl = apiClient.SaveCoupleParticipant(model);
                        var participant    = apiClient.Get <API_Models.ParticipantCoupleDetail>(participantUrl);
                        lock (this.model.Participants)
                        {
                            this.model.Participants.Add(new ParticipantWrapper(participant));
                        }
                    }
                    catch (Exception ex)
                    {
                        lock (this.model.Participants)
                        {
                            this.model.Participants.Add(new ParticipantWrapper(ex.InnerException, couple.ToString()));
                        }
                    }

                    SetProgressBar(this.progressBarParticipants);
                }), i));
            }

            foreach (var t in tasks)
            {
                t.Start();
            }

            Task.Factory.ContinueWhenAll(tasks.ToArray(), new Action <Task[]>(t =>
            {
                SetProgressBar(this.progressBarParticipants, -1, -1);
                MessageBox.Show("All participants created.");
            }));
        }