public CMainExportTab(CExportToExcelWnd ParentWnd, ObservableDictionary <long, CKeyValuePairEx <long, CCompSettings> > CompGroups) :
            base(ParentWnd, CompGroups)
        {
            InitializeComponent();

            CreateReport = true; // Эта вкладка по умолчанию будет активной

            if (CompDesc != null)
            {
                // Добавляем группы в колекцию
                foreach (KeyValuePair <long, CKeyValuePairEx <long, CCompSettings> > Group in CompGroups)
                {
                    CGroupItem GroupItem = new CGroupItem(Group.Key)
                    {
                        Name = Group.Value.Value.AgeGroup.FullGroupName,
                        Sex  = Group.Value.Value.AgeGroup.SexInEnum
                    };
                    CRoundItem RoundItem = null;

                    if (Group.Value.Value.AgeGroup.GroupType == CAgeGroup.enGroupType.Children)
                    {   // Есть года рождения
                        if (Group.Value.Value.AgeGroup.StartYear == GlobalDefines.DEFAULT_XML_INT_VAL ||
                            Group.Value.Value.AgeGroup.wEndYear == GlobalDefines.DEFAULT_XML_INT_VAL)
                        {   // Но пока их почему-то не ввели
                            GroupItem.CanSelectYears = false;
                        }
                        else
                        {
                            int EndYear = 0, StartYear = 0;
                            switch (Group.Value.Value.AgeGroup.wEndYear)
                            {
                            case (int)DBManager.Scanning.XMLDataClasses.CAgeGroup.enEndYearSpecVals.AndElder:
                                StartYear = GlobalDefines.MIN_GROUP_YEAR;
                                EndYear   = Group.Value.Value.AgeGroup.StartYear;
                                break;

                            case (int)DBManager.Scanning.XMLDataClasses.CAgeGroup.enEndYearSpecVals.AndYounger:
                                StartYear = Group.Value.Value.AgeGroup.StartYear;
                                EndYear   = GlobalDefines.MAX_GROUP_YEAR;
                                break;

                            default:
                                StartYear = Group.Value.Value.AgeGroup.StartYear;
                                EndYear   = Group.Value.Value.AgeGroup.wEndYear;
                                break;
                            }
                            for (int i = StartYear; i <= EndYear; i++)
                            {
                                GroupItem.YearsOfBirth.Add(i);
                            }
                            GroupItem.StartYearIndToExport = 0;
                            GroupItem.EndYearIndToExport   = GroupItem.YearsOfBirth.Count - 1;
                        }
                    }
                    else
                    {   // Годов рождения нет
                        for (int i = GlobalDefines.MIN_GROUP_YEAR; i <= GlobalDefines.MAX_GROUP_YEAR; i++)
                        {
                            GroupItem.YearsOfBirth.Add(i);
                        }
                        GroupItem.StartYearIndToExport = 0;
                        GroupItem.EndYearIndToExport   = GroupItem.YearsOfBirth.Count - 1;
                    }

                    // Список всех раундов без итогового протокола
                    foreach (dynamic RoundInfo in from result in DBManagerApp.m_Entities.results_speed
                             join part in DBManagerApp.m_Entities.participations on result.participation equals part.id_participation
                             where part.Group == Group.Key
                             group result by result.round into groupRounds
                             orderby groupRounds.Key
                             select new
                    {
                        RoundID = groupRounds.Key,
                        RoundName = (from round in DBManagerApp.m_Entities.rounds
                                     join groupRound in groupRounds on round.id_round equals groupRound.round
                                     where round.id_round == groupRounds.Key
                                     select round.name).FirstOrDefault()
                    })
                    {
                        if (RoundInfo.RoundName == null)
                        {
                            continue;
                        }

                        RoundItem = new CRoundItem((enRounds)RoundInfo.RoundID)
                        {
                            SheetName = GroupItem.Name + " " + RoundInfo.RoundName
                        };
                        RoundItem.SheetName = RoundItem.SheetName.Left(m_ParentWnd.MaxSheetNameLen);

                        GroupItem.Rounds.Add(RoundItem);
                    }

                    RoundItem = new CRoundItem(enRounds.Total)
                    {
                        SheetName = GroupItem.Name // По умолчанию для итогового протокола
                                                   // название листа будет равно названию группы
                    };
                    RoundItem.SheetName = RoundItem.SheetName.Left(m_ParentWnd.MaxSheetNameLen);

                    GroupItem.Rounds.Add(RoundItem);

                    Groups.Add(GroupItem);
                }
            }
        }
        public CPersonalExportTab(CExportToExcelWnd ParentWnd, ObservableDictionary <long, CKeyValuePairEx <long, CCompSettings> > CompGroups) :
            base(ParentWnd, CompGroups)
        {
            InitializeComponent();

            lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj)
            {
                AppSettings settings = DBManagerApp.m_AppSettings.m_Settings;

                if (CompDesc != null)
                {
                    // Добавляем группы в колекцию
                    foreach (KeyValuePair <long, CKeyValuePairEx <long, CCompSettings> > Group in CompGroups)
                    {
                        CGroupItem GroupItem = new CGroupItem(Group.Key)
                        {
                            Name      = Group.Value.Value.AgeGroup.FullGroupName,
                            SheetName = Properties.Resources.resPersonalReport + " " + Group.Value.Value.AgeGroup.FullGroupName,
                            Sex       = Group.Value.Value.AgeGroup.SexInEnum
                        };
                        GroupItem.SheetName = GroupItem.SheetName.Left(m_ParentWnd.MaxSheetNameLen);
                        if (Group.Value.Value.AgeGroup.GroupType == CAgeGroup.enGroupType.Children)
                        {       // Есть года рождения
                            if (Group.Value.Value.AgeGroup.StartYear == GlobalDefines.DEFAULT_XML_INT_VAL ||
                                Group.Value.Value.AgeGroup.wEndYear == GlobalDefines.DEFAULT_XML_INT_VAL)
                            {   // Но пока их почему-то не ввели
                                GroupItem.CanSelectYears = false;
                            }
                            else
                            {
                                int EndYear = 0, StartYear = 0;
                                switch (Group.Value.Value.AgeGroup.wEndYear)
                                {
                                case (int)DBManager.Scanning.XMLDataClasses.CAgeGroup.enEndYearSpecVals.AndElder:
                                    StartYear = GlobalDefines.MIN_GROUP_YEAR;
                                    EndYear   = Group.Value.Value.AgeGroup.StartYear;
                                    break;

                                case (int)DBManager.Scanning.XMLDataClasses.CAgeGroup.enEndYearSpecVals.AndYounger:
                                    StartYear = Group.Value.Value.AgeGroup.StartYear;
                                    EndYear   = GlobalDefines.MAX_GROUP_YEAR;
                                    break;

                                default:
                                    StartYear = Group.Value.Value.AgeGroup.StartYear;
                                    EndYear   = Group.Value.Value.AgeGroup.wEndYear;
                                    break;
                                }
                                for (int i = StartYear; i <= EndYear; i++)
                                {
                                    GroupItem.YearsOfBirth.Add(i);
                                }
                                GroupItem.StartYearIndToExport = 0;
                                GroupItem.EndYearIndToExport   = GroupItem.YearsOfBirth.Count - 1;
                            }
                        }
                        else
                        {       // Годов рождения нет
                            for (int i = GlobalDefines.MIN_GROUP_YEAR; i <= GlobalDefines.MAX_GROUP_YEAR; i++)
                            {
                                GroupItem.YearsOfBirth.Add(i);
                            }
                            GroupItem.StartYearIndToExport = 0;
                            GroupItem.EndYearIndToExport   = GroupItem.YearsOfBirth.Count - 1;
                        }

                        GroupsForReport.Add(GroupItem);
                    }
                }

                CCompSpecificSets CompSettings;
                if (settings.dictCompSettings.TryGetValue(CompDesc.id_desc, out CompSettings))
                {
                    PlaceAggregationMethod  = CompSettings.PersRepPlaceAggregationMethod;
                    WinnerDetection         = CompSettings.PersRepWinnerDetection;
                    PriorityCompetitionKind = CompSettings.PriorityCompetitionKind;
                }
                else
                {
                    PlaceAggregationMethod  = settings.DefaultCompSettings.PersRepPlaceAggregationMethod;
                    WinnerDetection         = settings.DefaultCompSettings.PersRepWinnerDetection;
                    PriorityCompetitionKind = settings.DefaultCompSettings.PriorityCompetitionKind;
                }
            }

            GlobalDefines.TuneComboboxWidth2(cmbPlaceAggregationMethod);
            GlobalDefines.TuneComboboxWidth2(cmbWinnerDetection);

            cmbPlaceAggregationMethod.Width = cmbWinnerDetection.Width = Math.Max(cmbPlaceAggregationMethod.Width, cmbWinnerDetection.Width);
            foreach (ComboBoxItem cmbi in cmbPlaceAggregationMethod.Items)
            {
                cmbi.Width = Math.Max(cmbi.Width, (cmbWinnerDetection.Items[0] as ComboBoxItem).Width);
            }
            foreach (ComboBoxItem cmbi in cmbWinnerDetection.Items)
            {
                cmbi.Width = (cmbPlaceAggregationMethod.Items[0] as ComboBoxItem).Width;
            }
        }
        public CLeadReportInfoTab(CExportToExcelWnd ParentWnd, ObservableDictionary <long, CKeyValuePairEx <long, CCompSettings> > CompGroups) :
            base(ParentWnd, CompGroups)
        {
            InitializeComponent();

            lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj)
            {
                AppSettings settings = DBManagerApp.m_AppSettings.m_Settings;

                if (CompDesc != null)
                {
                    CCompSpecificSets CompSettings = null;
                    if (settings.dictCompSettings.TryGetValue(CompDesc.id_desc, out CompSettings))
                    {
                        if (CompSettings.FirstMemberRow != GlobalDefines.DEFAULT_XML_INT_VAL)
                        {
                            FirstMemberRow = CompSettings.FirstMemberRow;
                        }
                        else
                        {
                            FirstMemberRow = settings.DefaultCompSettings.FirstMemberRow;
                        }

                        if (CompSettings.PlaceColumnIndex != GlobalDefines.DEFAULT_XML_INT_VAL)
                        {
                            PlaceColumnIndex = CompSettings.PlaceColumnIndex;
                        }
                        else
                        {
                            PlaceColumnIndex = settings.DefaultCompSettings.PlaceColumnIndex;
                        }

                        if (CompSettings.PersonalDataColumnIndex != GlobalDefines.DEFAULT_XML_INT_VAL)
                        {
                            PersonalDataColumnIndex = CompSettings.PersonalDataColumnIndex;
                        }
                        else
                        {
                            PersonalDataColumnIndex = settings.DefaultCompSettings.PersonalDataColumnIndex;
                        }

                        if (CompSettings.YearOfBirthColumnIndex != GlobalDefines.DEFAULT_XML_INT_VAL)
                        {
                            YearOfBirthColumnIndex = CompSettings.YearOfBirthColumnIndex;
                        }
                        else
                        {
                            YearOfBirthColumnIndex = settings.DefaultCompSettings.YearOfBirthColumnIndex;
                        }

                        if (CompSettings.TeamColumnIndex != GlobalDefines.DEFAULT_XML_INT_VAL)
                        {
                            TeamColumnIndex = CompSettings.TeamColumnIndex;
                        }
                        else
                        {
                            TeamColumnIndex = settings.DefaultCompSettings.TeamColumnIndex;
                        }

                        if (CompSettings.LeadReportXlsPath != GlobalDefines.DEFAULT_XML_STRING_VAL)
                        {
                            XlsPath = CompSettings.LeadReportXlsPath;
                        }
                        else
                        {
                            XlsPath = settings.DefaultCompSettings.LeadReportXlsPath;
                        }
                    }
                    else
                    {
                        FirstMemberRow          = settings.DefaultCompSettings.FirstMemberRow;
                        PlaceColumnIndex        = settings.DefaultCompSettings.PlaceColumnIndex;
                        PersonalDataColumnIndex = settings.DefaultCompSettings.PersonalDataColumnIndex;
                        YearOfBirthColumnIndex  = settings.DefaultCompSettings.YearOfBirthColumnIndex;
                        TeamColumnIndex         = settings.DefaultCompSettings.TeamColumnIndex;
                        XlsPath = settings.DefaultCompSettings.LeadReportXlsPath;
                    }
                    HasLeadReport = !string.IsNullOrWhiteSpace(XlsPath);
                    CheckPathSettings();

                    // Добавляем группы в колекцию
                    foreach (KeyValuePair <long, CKeyValuePairEx <long, CCompSettings> > Group in CompGroups)
                    {
                        CGroupItem GroupItem = new CGroupItem(Group.Key)
                        {
                            Name = Group.Value.Value.AgeGroup.FullGroupName,
                            Sex  = Group.Value.Value.AgeGroup.SexInEnum
                        };
                        if (Group.Value.Value.AgeGroup.GroupType == CAgeGroup.enGroupType.Children)
                        {       // Есть года рождения
                            if (Group.Value.Value.AgeGroup.StartYear == GlobalDefines.DEFAULT_XML_INT_VAL ||
                                Group.Value.Value.AgeGroup.wEndYear == GlobalDefines.DEFAULT_XML_INT_VAL)
                            {   // Но пока их почему-то не ввели
                                GroupItem.CanSelectYears = false;
                            }
                            else
                            {
                                int EndYear = 0, StartYear = 0;
                                switch (Group.Value.Value.AgeGroup.wEndYear)
                                {
                                case (int)DBManager.Scanning.XMLDataClasses.CAgeGroup.enEndYearSpecVals.AndElder:
                                    StartYear = GlobalDefines.MIN_GROUP_YEAR;
                                    EndYear   = Group.Value.Value.AgeGroup.StartYear;
                                    break;

                                case (int)DBManager.Scanning.XMLDataClasses.CAgeGroup.enEndYearSpecVals.AndYounger:
                                    StartYear = Group.Value.Value.AgeGroup.StartYear;
                                    EndYear   = GlobalDefines.MAX_GROUP_YEAR;
                                    break;

                                default:
                                    StartYear = Group.Value.Value.AgeGroup.StartYear;
                                    EndYear   = Group.Value.Value.AgeGroup.wEndYear;
                                    break;
                                }
                                for (int i = StartYear; i <= EndYear; i++)
                                {
                                    GroupItem.YearsOfBirth.Add(i);
                                }
                                GroupItem.StartYearIndToExport = 0;
                                GroupItem.EndYearIndToExport   = GroupItem.YearsOfBirth.Count - 1;
                            }
                        }
                        else
                        {       // Годов рождения нет
                            for (int i = GlobalDefines.MIN_GROUP_YEAR; i <= GlobalDefines.MAX_GROUP_YEAR; i++)
                            {
                                GroupItem.YearsOfBirth.Add(i);
                            }
                            GroupItem.StartYearIndToExport = 0;
                            GroupItem.EndYearIndToExport   = GroupItem.YearsOfBirth.Count - 1;
                        }

                        Groups.Add(GroupItem);
                    }

                    if (CompSettings != null && CompSettings.dictGroupsLeadSheetsInfos != null)
                    {
                        List <long> Keys = CompSettings.dictGroupsLeadSheetsInfos.Keys.ToList();
                        foreach (long Key in Keys)
                        {
                            if (Groups.FirstOrDefault(arg => arg.id == Key) == null)
                            {   // Такой группы больше нет
                                CompSettings.dictGroupsLeadSheetsInfos.Remove(Key);
                            }
                        }
                    }

                    OnLeadReportRefreshed();

                    // Присваивать LeadSheetIndex нужно только после OnLeadReportRefreshed
                    foreach (CGroupItem GroupItem in Groups)
                    {
                        if (CompSettings != null && CompSettings.dictGroupsLeadSheetsInfos != null)
                        {
                            CLeadSheetInfo LeadSheetInfo;
                            if (CompSettings.dictGroupsLeadSheetsInfos.TryGetValue(GroupItem.id, out LeadSheetInfo))
                            {
                                GroupItem.LeadSheetIndex = LeadSheetInfo.SheetIndex;
                                GroupItem.StartDate      = LeadSheetInfo.StartDate;
                                GroupItem.EndDate        = LeadSheetInfo.EndDate;
                            }
                        }
                    }
                }
            }
        }