예제 #1
0
        public List <ParticipantsData> SelectAllParticipants()
        {
            ResultsManager resultsManager = new ResultsManager();

            cmd    = new SqlCommand("SELECT * FROM Participants Order by parPointsSum DESC", conn);
            reader = cmd.ExecuteReader();

            List <ParticipantsData> result = new List <ParticipantsData>();

            while (reader.Read())
            {
                ParticipantsData data = new ParticipantsData();
                data.Id           = Convert.ToInt32(reader["Id"]);
                data.parName      = Convert.ToString(reader["parName"]);
                data.parSurname   = Convert.ToString(reader["parSurname"]);
                data.parNumber    = Convert.ToInt32(reader["parNumber"]);
                data.parAgeGroup  = Convert.ToString(reader["parAgeGroup"]);
                data.parPoints1   = Convert.ToInt32(reader["parPoints1"]);
                data.parPoints2   = Convert.ToInt32(reader["parPoints2"]);
                data.parPoints3   = Convert.ToInt32(reader["parPoints3"]);
                data.parPoints4   = Convert.ToInt32(reader["parPoints4"]);
                data.parPoints5   = Convert.ToInt32(reader["parPoints5"]);
                data.parPoints6   = Convert.ToInt32(reader["parPoints6"]);
                data.parPoints7   = Convert.ToInt32(reader["parPoints7"]);
                data.parPoints8   = Convert.ToInt32(reader["parPoints8"]);
                data.parPointsSum = Convert.ToInt32(reader["parPointsSum"]);
                result.Add(data);
            }
            reader.Close();

            return(result);
        }
예제 #2
0
        public void UpdateParSumPoints()
        {
            ResultsManager          resultsManager = new ResultsManager();
            List <ParticipantsData> participants   = new List <ParticipantsData>();

            participants = resultsManager.SelectAllParticipants();

            foreach (var participant in participants)
            {
                int[] pointArray = new int[]
                {
                    participant.parPoints1,
                    participant.parPoints2,
                    participant.parPoints3,
                    participant.parPoints4,
                    participant.parPoints5,
                    participant.parPoints6,
                    participant.parPoints7,
                    participant.parPoints8
                };

                Array.Sort(pointArray);
                Array.Reverse(pointArray);

                int pointSumToUpload = 0;


                for (int i = 0; i < 5; i++)
                {
                    pointSumToUpload += pointArray[i];
                }

                cmd = new SqlCommand("UPDATE Participants SET parPointsSum = @p1 WHERE id = @p2", conn);
                cmd.Parameters.Add("@p1", SqlDbType.Int).Value = pointSumToUpload;
                cmd.Parameters.Add("@p2", SqlDbType.Int).Value = participant.Id;

                cmd.ExecuteNonQuery();
            }
        }