示例#1
0
文件: Form1.cs 项目: sycns/WDSF-API
        private void listBoxAthletes_DoubleClick(object sender, EventArgs e)
        {
            PersonWrapper p = this.listBoxAthletes.SelectedItem as PersonWrapper;

            API_Models.PersonDetail person = this.apiClient.GetPerson(p.person.Min);
            this.model.Person = person;

            if (model.Person.Licenses == null)
            {
                MessageBox.Show("No licenses.");
                return;
            }

            API_Models.License license = person.Licenses.FirstOrDefault(l => l.Type == "Athlete");
            if (license == null)
            {
                return;
            }

            this.textBoxAthleteMin.Text = person.Min.ToString();
            this.comboBoxAthleteDivision.SelectedIndex = this.comboBoxCoupleDivision.Items.IndexOf(license.Division);
            this.comboBoxAthleteStatus.SelectedIndex   = this.comboBoxAthleteStatus.Items.IndexOf(license.Status);
            this.labelAthleteWrlBlocked.Text           = license.WrlBlockedUntil;
            this.labelAthleteChBlocked.Text            = license.CupOrChampionshipBlockedUntil;
            if (string.IsNullOrEmpty(license.ExpiresOn))
            {
                this.dateTimePickerAthleteRetireOn.Value = new DateTime(1800, 1, 1);
            }
            else
            {
                this.dateTimePickerAthleteRetireOn.Value = DateTime.Parse(license.ExpiresOn);
            }
        }
示例#2
0
文件: Form1.cs 项目: sycns/WDSF-API
        private void buttonCreateRandomCouples_Click(object sender, EventArgs e)
        {
            if (this.model.Athletes.Count == 0)
            {
                return;
            }

            var           men    = this.model.Athletes.Where(a => a.person.Sex == "Male").ToList();
            var           women  = this.model.Athletes.Where(a => a.person.Sex == "Female");
            int           total  = int.Parse(this.textBoxRandomCoupleCount.Text);
            Random        rnd    = new Random();
            List <string> result = new List <string>();

            for (int index = 0; index < total; index++)
            {
                API_Models.PersonDetail man = this.apiClient.GetPerson(men[rnd.Next(0, men.Count() - 1)].person.Min);
                var others = women.Where(a => a.person.Country == man.Country);
                API_Models.PersonDetail woman = this.apiClient.GetPerson(others.Skip(rnd.Next(0, others.Count() - 1)).First().person.Min);

                API_Models.CoupleDetail couple = new API_Models.CoupleDetail()
                {
                    ManMin   = man.Min,
                    WomanMin = woman.Min,
                    Country  = man.Country,
                    Division = man.Licenses.First().Division,
                    Status   = "Active"
                };

                try
                {
                    Uri coupleUri = this.apiClient.SaveCouple(couple);
                    result.Add(coupleUri.ToString());
                }
                catch (Exception ex)
                {
                    result.Add(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
                }
            }

            MessageBox.Show(string.Join("\n", result));
        }
示例#3
0
文件: Form1.cs 项目: sycns/WDSF-API
        private void buttonUpdatePerson_Click(object sender, EventArgs e)
        {
            API_Models.PersonDetail person = this.model.Person;
            if (person == null)
            {
                return;
            }
            API_Models.License license = person.Licenses.First(l => l.Type == "Athlete");
            if (license == null)
            {
                return;
            }

            license.Division = (string)this.comboBoxAthleteDivision.SelectedItem;
            license.Status   = (string)this.comboBoxAthleteStatus.SelectedItem;
            if (this.dateTimePickerAthleteRetireOn.Value.Year != 1800)
            {
                license.ExpiresOn = this.dateTimePickerAthleteRetireOn.Value.ToString("yyyy-MM-dd");
            }

            try
            {
                if (!this.apiClient.UpdatePerson(person))
                {
                    MessageBox.Show(this.apiClient.LastApiMessage);
                }
                else
                {
                    MessageBox.Show("License updated");
                }
            }
            catch (Api.Client.Exceptions.ApiException ex)
            {
                MessageBox.Show(ex.InnerException.Message);
            }

            listBoxAthletes_DoubleClick(null, null);
        }