protected async void OnIdentChanged(object sender, SelectionChangedEventArgs args)
        {
            try
            {
                var selected = args.CurrentSelection[0] as AccountInfo;
                //(sender as CollectionView).UpdateSelectedItems(new List<Object> { selected });
                await Task.Delay(TimeSpan.FromMilliseconds(100));

                Device.BeginInvokeOnMainThread(() =>
                {
                    try
                    {
                        foreach (var acc in Accounts)
                        {
                            acc.Selected = false;
                        }
                        selected.Selected = true;
                        var newmeters     = _meterInfoAll.Where(x => x.Ident == selected.Ident).ToList();

                        if (selected.Ident == AppResources.All)
                        {
                            newmeters = _meterInfoAll;
                        }

                        baseForCounters.Children.Clear();

                        if (newmeters.Count == 0 && Accounts.Count > 0)
                        {
                            baseForCounters.Children.Add(new Label
                            {
                                VerticalTextAlignment   = TextAlignment.Center,
                                HorizontalTextAlignment = TextAlignment.Center,
                                FontSize          = 18,
                                Text              = AppResources.NoMetersIdent,
                                VerticalOptions   = LayoutOptions.FillAndExpand,
                                HorizontalOptions = LayoutOptions.FillAndExpand,
                                HeightRequest     = 400
                            });
                        }

                        foreach (var mi in newmeters)
                        {
                            var mtc = new MetersThreeCell(mi);
                            TapGestureRecognizer tap = new TapGestureRecognizer();
                            tap.Tapped += Tap_Tapped;
                            mtc.GestureRecognizers.Add(tap);

                            baseForCounters.Children.Add(mtc);
                        }
                    }
                    catch { }
                });
            }
            catch { }
        }
예제 #2
0
        private static bool CheckPeriod(int currDay, MeterInfo meterInfo)
        {
//#if DEBUG
//            return true;
//#endif
            if (meterInfo.ValuesEndDay < meterInfo.ValuesStartDay)
            {
                return(MetersThreeCell.GetPeriodEnabled() || (meterInfo.ValuesStartDay == 0 &&
                                                              meterInfo.ValuesEndDay == 0));
            }

            return((meterInfo.ValuesStartDay <= currDay &&
                    meterInfo.ValuesEndDay >= currDay) ||
                   (meterInfo.ValuesStartDay == 0 &&
                    meterInfo.ValuesEndDay == 0));
        }
        public async Task RefreshCountersData()
        {
            if (Xamarin.Essentials.Connectivity.NetworkAccess != Xamarin.Essentials.NetworkAccess.Internet)
            {
                Device.BeginInvokeOnMainThread(async() =>
                                               await DisplayAlert(AppResources.ErrorTitle, AppResources.ErrorNoInternet, "OK"));
                return;
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                if (!IsRefreshing)
                {
                    aIndicator.IsVisible = true;
                }
            });

            try
            {
                ItemsList <MeterInfo> info = await _server.GetThreeMeters();

                if (info.Error == null && info.Data != null)
                {
                    if (string.IsNullOrEmpty(account) || string.IsNullOrWhiteSpace(account))
                    {
                        account = "Все";
                    }
                    _meterInfoAll = info.Data;
                    if (account == "Все")
                    {
                        _meterInfo = _meterInfoAll;
                    }
                    else
                    {
                        List <MeterInfo> meters = new List <MeterInfo>();
                        foreach (var meterInfo in _meterInfoAll)
                        {
                            if (meterInfo.Ident == account)
                            {
                                meters.Add(meterInfo);
                            }
                        }

                        _meterInfo = meters;
                    }

                    if (info.Data.Count == 0)
                    {
                        baseForCounters.Children.Clear();
                        if (Accounts.Count > 1)
                        {
                            baseForCounters.Children.Add(new Label
                            {
                                VerticalTextAlignment   = TextAlignment.Center,
                                HorizontalTextAlignment = TextAlignment.Center,
                                FontSize          = 18,
                                Text              = AppResources.NoMetersIdent,
                                VerticalOptions   = LayoutOptions.FillAndExpand,
                                HorizontalOptions = LayoutOptions.FillAndExpand,
                                HeightRequest     = 400
                            });
                        }
                    }
                    else
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            await Task.Delay(TimeSpan.FromMilliseconds(100));
                            //var idents = _meterInfo.Select(x => x.Ident);
                            //foreach (var account in Settings.Person.Accounts)
                            //{

                            //    if (!Accounts.Contains(Accounts.FirstOrDefault(x => x.Ident == account.Ident)))
                            //    {
                            //        Accounts.Add(account);
                            //    }
                            //}
                            //var all = Accounts.Where(x => x.Ident == AppResources.All).ToList();
                            //if (all.Count > 1)
                            //{
                            //    foreach (var account in all)
                            //    {
                            //        Accounts.Remove(account);
                            //    }
                            //    //Accounts.Insert(0, new AccountInfo() { Ident = AppResources.All, Selected = true });
                            //}

                            if (SelectedAccount == null)
                            {
                                //Accounts.Insert(0, new AccountInfo() { Ident = AppResources.All, Selected = true });
                                if (Accounts.Count > 0)
                                {
                                    SelectedAccount = Accounts[0];
                                }
                            }
                            else if (SelectedAccount.Ident == AppResources.All)
                            {
                                SelectedAccount = Accounts[0];
                            }
                            else if (!Accounts.Contains(SelectedAccount))
                            {
                                SelectedAccount = Accounts[0];
                                foreach (var account in Accounts)
                                {
                                    account.Selected = false;
                                }
                                SelectedAccount.Selected = true;
                            }
                            //addIdentLbl.IsVisible = false;

                            List <MeterInfo> meters_ = new List <MeterInfo>();
                            if (SelectedAccount != null && SelectedAccount.Ident != AppResources.All)
                            {
                                meters_ = _meterInfo.Where(x => x.Ident == SelectedAccount.Ident).ToList();
                            }
                            else
                            {
                                meters_ = _meterInfo;
                            }
                            baseForCounters.Children.Clear();

                            if (meters_.Count == 0 && Accounts.Count > 0)
                            {
                                baseForCounters.Children.Add(new Label
                                {
                                    VerticalTextAlignment   = TextAlignment.Center,
                                    HorizontalTextAlignment = TextAlignment.Center,
                                    FontSize          = 18,
                                    Text              = AppResources.NoMetersIdent,
                                    VerticalOptions   = LayoutOptions.FillAndExpand,
                                    HorizontalOptions = LayoutOptions.FillAndExpand,
                                    HeightRequest     = 400
                                });
                            }

                            foreach (var mi in meters_)
                            {
                                var mtc = new MetersThreeCell(mi);
                                TapGestureRecognizer tap = new TapGestureRecognizer();
                                tap.Tapped += Tap_Tapped;
                                mtc.GestureRecognizers.Add(tap);

                                baseForCounters.Children.Add(mtc);
                            }
                        });
                    }
                }
                OSAppTheme currentTheme = Application.Current.RequestedTheme;
                SetHeader(currentTheme);

                Device.BeginInvokeOnMainThread(async() =>
                {
                    aIndicator.IsVisible = false;
                    IsRefreshing         = false;
                });
            }
            catch (Exception e)
            {
                Microsoft.AppCenter.Crashes.Crashes.TrackError(e);
            }
            finally
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    aIndicator.IsVisible = false;
                    IsRefreshing         = false;
                });
            }



            //countersList.ItemsSource = null;
            //countersList.ItemsSource = _meterInfo;
        }