Пример #1
0
        public bool InitWndControls()
        {
            using (var wrapper = new DisposableWrapper <ShowAsyncResult>(CWaitingWnd.ShowAsync(Title,
                                                                                               Properties.Resources.resFillingGenerationFromOnlineBDWnd,
                                                                                               this,
                                                                                               CheckAccess()),
                                                                         asyncResult =>
            {
                if (asyncResult?.hFinishedSearchEvent != null)
                {
                    asyncResult.hFinishedSearchEvent.Set();
                }
            }))
            {
                EndYears.Clear();
                StartYears.Clear();
                EndYears.Add((int)enEndYearSpecVals.AndYounger);
                EndYears.Add((int)enEndYearSpecVals.AndElder);
                for (int i = DateTime.Now.Year - 7; i > DateTime.Now.Year - 100; i--)
                {
                    StartYears.Add(i);
                    EndYears.Add(i);
                }


                GroupNames.Clear();
                lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj)
                {
                    foreach (var groupNameDesc in DBManagerApp.m_AppSettings.m_Settings.AvailableGroupNames)
                    {
                        GroupNames.Add(groupNameDesc.GroupName);
                    }
                }

                // Заполняем выпадающие списки текущими значениями
                LocalDBComps.Clear();

                try
                {
                    foreach (var comp in DBManagerApp.m_Entities.descriptions.ToList())
                    {
                        var item = new CompDescLocalWorkbook()
                        {
                            ID        = comp.id_desc,
                            Name      = comp.name,
                            StartDate = DateTime.Today,
                            EndDate   = DateTime.Today.AddDays(2)
                        };
                        item.DestCompFolder   = GetDefaultDestCompFolderName(item);
                        item.PropertyChanged += comp_PropertyChanged;

                        LocalDBComps.Add(item);
                    }
                    SelectedComp = LocalDBComps.LastOrDefault();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this,
                                    string.Format(Properties.Resources.resfmtErrorDuringReadingDataFromOnlineDB, ex.Message),
                                    Title,
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return(false);
                }

                cmbMainJudge.Items.Clear();
                foreach (var mainJudge in DBManagerApp
                         .m_Entities
                         .groups
                         .Select(arg => arg.main_judge)
                         .Where(arg => !string.IsNullOrEmpty(arg))
                         .Distinct())
                {
                    cmbMainJudge.Items.Add(mainJudge);
                }

                cmbMainSecretary.Items.Clear();
                foreach (var mainSecretary in DBManagerApp
                         .m_Entities
                         .groups
                         .Select(arg => arg.main_secretary)
                         .Where(arg => !string.IsNullOrEmpty(arg))
                         .Distinct())
                {
                    cmbMainSecretary.Items.Add(mainSecretary);
                }

                cmbRow6.Items.Clear();
                foreach (var row6 in DBManagerApp
                         .m_Entities
                         .groups
                         .Select(arg => arg.row6)
                         .Where(arg => !string.IsNullOrEmpty(arg))
                         .Distinct())
                {
                    cmbRow6.Items.Add(row6);
                }
            }

            return(true);
        }
        public bool InitWndControls()
        {
            using (var wrapper = new DisposableWrapper <ShowAsyncResult>(CWaitingWnd.ShowAsync(Title,
                                                                                               Properties.Resources.resFillingGenerationFromOnlineBDWnd,
                                                                                               this,
                                                                                               CheckAccess()),
                                                                         asyncResult =>
            {
                if (asyncResult?.hFinishedSearchEvent != null)
                {
                    asyncResult.hFinishedSearchEvent.Set();
                }
            }))
            {
                EndYears.Clear();
                StartYears.Clear();
                EndYears.Add((int)enEndYearSpecVals.AndYounger);
                EndYears.Add((int)enEndYearSpecVals.AndElder);
                for (int i = DateTime.Now.Year - 7; i > DateTime.Now.Year - 100; i--)
                {
                    StartYears.Add(i);
                    EndYears.Add(i);
                }

                // Заполняем выпадающие списки текущими значениями
                RemoteDBComps.Clear();
                if (OnlineDBManager.Instance.IsConnectedToRemoteDB)
                {
                    try
                    {
                        var speedGroups = m_DBManager
                                          .Entities
                                          .group
                                          .Where(gr =>
                                                 gr
                                                 .participants
                                                 .SelectMany(part => part.participants_kind)
                                                 .Any(kind => kind.kind_id == (int)enOnlineDBKind.Speed))
                                          .ToList();

                        // Выбираем только соревы на скорость
                        foreach (var comp in speedGroups.SelectMany(gr => gr.events).Distinct().ToList())
                        {
                            var item = new CompItemRemoteDB()
                            {
                                Desc = new CompDescRemoteDB()
                            };
                            (item.Desc as CompDescRemoteDB).ID              = comp.id;
                            (item.Desc as CompDescRemoteDB).Name            = comp.name;
                            (item.Desc as CompDescRemoteDB).RemoteStartDate = comp.date1;
                            (item.Desc as CompDescRemoteDB).RemoteEndDate   = comp.date2;
                            (item.Desc as CompDescRemoteDB).UpdateDatesFromRemoteOnes();

                            foreach (var group in speedGroups.Where(gr => gr.events.Any(ev => ev.id == comp.id)))
                            {
                                if (DBManagerApp.m_AppSettings.m_Settings.AvailableGroupNames.Any(arg => string.Compare(arg.GroupName, group.name, true) == 0))
                                {
                                    var groupItem = new GroupItemRemoteDB((item.Desc as CompDescRemoteDB))
                                    {
                                        ID        = group.id,
                                        Name      = group.name,
                                        Sex       = ((enOnlineSex)(group.sex ? 1 : 0)).ToLocalSexValue(),
                                        StartYear = DateTime.Now.Year - group.year2,
                                        EndYear   = group.year1.HasValue ? DateTime.Now.Year - group.year1 : null,
                                        StartDate = item.Desc.StartDate,
                                        EndDate   = item.Desc.EndDate
                                    };
                                    item.Groups.Add(groupItem);
                                }
                            }

                            RemoteDBComps.Add(item);
                        }
                        SelectedComp = RemoteDBComps.LastOrDefault();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this,
                                        string.Format(Properties.Resources.resfmtErrorDuringReadingDataFromOnlineDB, ex.Message),
                                        Title,
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                        return(false);
                    }
                }

                cmbMainJudge.Items.Clear();
                foreach (var mainJudge in DBManagerApp
                         .m_Entities
                         .groups
                         .Select(arg => arg.main_judge)
                         .Where(arg => !string.IsNullOrEmpty(arg))
                         .Distinct())
                {
                    cmbMainJudge.Items.Add(mainJudge);
                }

                cmbMainSecretary.Items.Clear();
                foreach (var mainSecretary in DBManagerApp
                         .m_Entities
                         .groups
                         .Select(arg => arg.main_secretary)
                         .Where(arg => !string.IsNullOrEmpty(arg))
                         .Distinct())
                {
                    cmbMainSecretary.Items.Add(mainSecretary);
                }

                cmbRow6.Items.Clear();
                foreach (var row6 in DBManagerApp
                         .m_Entities
                         .groups
                         .Select(arg => arg.row6)
                         .Where(arg => !string.IsNullOrEmpty(arg))
                         .Distinct())
                {
                    cmbRow6.Items.Add(row6);
                }
            }

            return(true);
        }