Exemplo n.º 1
0
        private void AddLabel(SigaretsBrands NewSigaret)
        {
            if (id == frames.Length)
            {
                Frame[] Newframes = new Frame[frames.Length * 2];
                for (int i = 0; i < id; ++i)
                {
                    Newframes[i] = frames[i];
                }

                frames = Newframes;
            }

            Label label = new Label
            {
                Text                    = NewSigaret.Name,
                TextColor               = Color.FromHex("#FFC4C4C4"),
                FontSize                = Device.GetNamedSize(NamedSize.Medium, typeof(Button)),
                VerticalOptions         = LayoutOptions.CenterAndExpand,
                HorizontalOptions       = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.Center
            };

            frames[id] = new Frame
            {
                Content         = label,
                BackgroundColor = Color.FromHex("#424242"),
                Padding         = new Thickness(8)
            };

            stackLayout.Children.Add(frames[id]);
            id++;
        }
Exemplo n.º 2
0
        private void AddButton(SigaretsBrands NewSigaret)
        {
            if (id == buttons.Length)
            {
                Button[] Newbuttons = new Button[buttons.Length * 2];
                for (int i = 0; i < id; ++i)
                {
                    Newbuttons[i] = buttons[i];
                }

                buttons = Newbuttons;
            }

            buttons[id] = new Button
            {
                Text            = NewSigaret.Name,
                TextColor       = Color.FromHex("#FFC4C4C4"),
                BackgroundColor = Color.FromHex("#ff5916"),
                FontSize        = Device.GetNamedSize(NamedSize.Medium, typeof(Button)),
                BorderWidth     = 1
                                  //VerticalOptions = LayoutOptions.Start,
                                  //HorizontalOptions = LayoutOptions.Start
            };
            buttons[id].Clicked += (object sender, EventArgs e) =>
            {
                Brand.Text = "Выбранный бренд: " + ((Button)sender).Text;

                var config = new RealmConfiguration()
                {
                    SchemaVersion = 1
                };
                Realm _realm    = Realm.GetInstance(config);
                var   AllMemory = _realm.All <Memory>().ToList();
                if (AllMemory.Count != 0)
                {
                    var NewMemory = AllMemory[0];
                    _realm.Write(() => _realm.Remove(NewMemory));
                }

                _realm.Write(() => _realm.Add(new Memory {
                    SigaretBrand = ((Button)sender).Text
                }));

                var config1 = new RealmConfiguration()
                {
                    SchemaVersion = 1
                };
                Realm _Realm   = Realm.GetInstance(config1);
                var   TopBrand = _Realm.All <TopBrands>().ToList();
                if (((Button)sender).Text != TopBrand[0].First && ((Button)sender).Text != TopBrand[0].Second &&
                    ((Button)sender).Text != TopBrand[0].Third && ((Button)sender).Text != TopBrand[0].Fourth &&
                    ((Button)sender).Text != TopBrand[0].Fifth)
                {
                    _Realm.Write(() => TopBrand[0].Fifth  = TopBrand[0].Fourth);
                    _Realm.Write(() => TopBrand[0].Fourth = TopBrand[0].Third);
                    _Realm.Write(() => TopBrand[0].Third  = TopBrand[0].Second);
                    _Realm.Write(() => TopBrand[0].Second = TopBrand[0].First);
                    _Realm.Write(() => TopBrand[0].First  = ((Button)sender).Text);
                }

                DisplayAlert("", "Бренд сигарет изменён!", "ОK");
            };
            stackLayout.Children.Add(buttons[id]);
            id++;
        }