コード例 #1
0
        private void btnCalcPlaces_Click(object sender, RoutedEventArgs e)
        {
            // Присвоение разрядов
            IEnumerable <CMemberInTotal> MembersForGradesCalc = from member in m_CompMembers
                                                                where member.MemberInfo.InitGrade.HasValue && SelectedYears.Contains(member.MemberInfo.YearOfBirth.Value)
                                                                where member.Place.HasValue
                                                                select member;

            if (chkOnly75PercentForCalcGrades.IsChecked.Value)
            {   // Учитываем только 75% участников
                MembersForGradesCalc = (from member in MembersForGradesCalc
                                        orderby member.Place
                                        select member).Take((int)(Math.Floor(MembersForGradesCalc.Count() * 0.75)));
            }
            Dictionary <enGrade?, int> GradesStat = (from member in MembersForGradesCalc
                                                     group member by member.MemberInfo.InitGrade into MembersGrades
                                                     select new Scanning.CGroupResultsManager.CGradeStat
            {
                Grade = (enGrade?)MembersGrades.Key,
                MembersWithGrade = MembersGrades.Count(arg => arg.MemberInfo.InitGrade == MembersGrades.Key)
            }).ToDictionary(key => key.Grade, item => item.MembersWithGrade);
            int tmp = 0;

            for (enGrade grade = enGrade.WithoutGrade; grade <= enGrade.Master; grade++)
            {
                if (!GradesStat.TryGetValue(grade, out tmp))
                {
                    GradesStat[grade] = 0;
                }
            }

            m_MinPlaceForNewGrade.Clear();

            // 1 разряд
            tmp = GlobalDefines.CalcMinPlaceForNewGrade((enResultGradeCalcMethod)cmbResultGradeCalcMethod.SelectedIndex,
                                                        1.0 * GradesStat[enGrade.Master] +
                                                        0.8 * GradesStat[enGrade.BeforeMaster] +
                                                        0.4 * GradesStat[enGrade.Adult1] +
                                                        0.2 * GradesStat[enGrade.Adult2]);
            m_MinPlaceForNewGrade.Add(new KeyValuePair <enGrade, int>(enGrade.Adult1, tmp));
            m_dictLblsPlaces[enGrade.Adult1].Content = tmp == 0 ? null : tmp.ToString();

            // 2 разряд
            tmp += GlobalDefines.CalcMinPlaceForNewGrade((enResultGradeCalcMethod)cmbResultGradeCalcMethod.SelectedIndex,
                                                         0.2 * GradesStat[enGrade.Adult1] +
                                                         0.4 * GradesStat[enGrade.Adult2] +
                                                         0.2 * GradesStat[enGrade.Adult3]);
            m_MinPlaceForNewGrade.Add(new KeyValuePair <enGrade, int>(enGrade.Adult2, tmp));
            m_dictLblsPlaces[enGrade.Adult2].Content = tmp == 0 ? null : tmp.ToString();

            // 3 разряд
            tmp += GlobalDefines.CalcMinPlaceForNewGrade((enResultGradeCalcMethod)cmbResultGradeCalcMethod.SelectedIndex,
                                                         0.2 * GradesStat[enGrade.Adult2] +
                                                         0.4 * GradesStat[enGrade.Adult3] +
                                                         0.3 * GradesStat[enGrade.Young1]);
            m_MinPlaceForNewGrade.Add(new KeyValuePair <enGrade, int>(enGrade.Adult3, tmp));
            m_dictLblsPlaces[enGrade.Adult3].Content = tmp == 0 ? null : tmp.ToString();

            // 1 ю разряд
            tmp += GlobalDefines.CalcMinPlaceForNewGrade((enResultGradeCalcMethod)cmbResultGradeCalcMethod.SelectedIndex,
                                                         0.2 * GradesStat[enGrade.Adult3] +
                                                         0.4 * GradesStat[enGrade.Young1] +
                                                         0.2 * GradesStat[enGrade.Young2]);
            m_MinPlaceForNewGrade.Add(new KeyValuePair <enGrade, int>(enGrade.Young1, tmp));
            m_dictLblsPlaces[enGrade.Young1].Content = tmp == 0 ? null : tmp.ToString();

            // 2 ю разряд
            tmp += GlobalDefines.CalcMinPlaceForNewGrade((enResultGradeCalcMethod)cmbResultGradeCalcMethod.SelectedIndex,
                                                         0.2 * GradesStat[enGrade.Young1] +
                                                         0.4 * GradesStat[enGrade.Young2] +
                                                         0.2 * GradesStat[enGrade.Young3]);
            m_MinPlaceForNewGrade.Add(new KeyValuePair <enGrade, int>(enGrade.Young2, tmp));
            m_dictLblsPlaces[enGrade.Young2].Content = tmp == 0 ? null : tmp.ToString();

            // 3 ю разряд
            tmp += GlobalDefines.CalcMinPlaceForNewGrade((enResultGradeCalcMethod)cmbResultGradeCalcMethod.SelectedIndex,
                                                         0.2 * GradesStat[enGrade.Young2] +
                                                         0.4 * GradesStat[enGrade.Young3] +
                                                         0.3 * GradesStat[enGrade.WithoutGrade]);
            m_MinPlaceForNewGrade.Add(new KeyValuePair <enGrade, int>(enGrade.Young3, tmp));
            m_dictLblsPlaces[enGrade.Young3].Content = tmp == 0 ? null : tmp.ToString();
        }