Beispiel #1
0
        private void participates_Click(object sender, EventArgs e)
        {
            string lookUpAthlete = String.Format("SELECT age,gender FROM athlete" +
                                                 " WHERE athleteNo={0}" +
                                                 "   AND teamAccNo='{1}'",
                                                 participatesAthleteNo.Text, teamAccNo);
            NpgsqlCommand cmd = new NpgsqlCommand(lookUpAthlete);

            cmd.Connection = conn;
            NpgsqlDataReader r = cmd.ExecuteReader();

            if (!r.HasRows)
            {
                noticeLabelParticipate.Text = "此运动员未登记";
                r.Close();
                return;
            }
            r.Read();
            string ageG   = ProgramCore.ageGroup(r.GetValue(0).ToString());
            bool   gender = (r.GetValue(1).ToString() == "True");

            noticeLabelParticipate.Text = ageG + ":" + r.GetValue(0).ToString();
            r.Close();
            string validate = String.Format("SELECT * FROM competitions" +
                                            " WHERE gameType='{0}'" +
                                            "   AND ageGroup={1}" +
                                            "   AND gender={2}",
                                            gameTypeUpDown.SelectedItem.ToString(),
                                            ageG, gender);

            cmd            = new NpgsqlCommand(validate);
            cmd.Connection = conn;
            r = cmd.ExecuteReader();
            if (!r.HasRows)
            {
                r.Close();
                noticeLabelParticipate.Text += " 该运动员不具有资格参加此项目";
                return;
            }
            r.Close();
            string insertParticipates = String.Format("INSERT INTO participates(athleteNo,tournamentId,finalScore)" +
                                                      " SELECT {0},gameId,0" +
                                                      " FROM competitions,games" +
                                                      " WHERE games.compId=competitions.compId" +
                                                      "   AND gameType='{1}'" +
                                                      "   AND ageGroup={2}" +
                                                      "   AND gender={3}" +
                                                      " ON CONFLICT DO NOTHING",
                                                      participatesAthleteNo.Text,
                                                      gameTypeUpDown.Text,
                                                      ageG, gender);

            cmd            = new NpgsqlCommand(insertParticipates);
            cmd.Connection = conn;
            cmd.ExecuteNonQuery();
            refreshParticipateInfo();
        }