Esempio n. 1
0
        //async void SetCarusel()
        //{
        //    int i = 0;
        //    var itemTemplate = new DataTemplate(() =>
        //    {
        //        Label text = new Label();
        //        text.FontSize = 20;
        //        text.TextColor = Color.Black;
        //        text.SetBinding(Label.TextProperty, "Name");

        //        StackLayout rootStackLayout = new StackLayout();

        //        StackLayout stackLayout = new StackLayout();
        //        //Frame stackLayoutFrame = new Frame();
        //        //stackLayoutFrame.CornerRadius = 10;
        //        PancakeView pancake = new PancakeView();
        //        pancake.CornerRadius = new CornerRadius(30, 30, 0, 0);
        //        pancake.BackgroundColor = Color.White;

        //        stackLayout.BackgroundColor = Color.White;

        //        foreach (var each in Keys[i].Goodses)
        //        {
        //            Frame frame = new Frame();
        //            frame.HorizontalOptions = LayoutOptions.FillAndExpand;
        //            frame.VerticalOptions = LayoutOptions.Start;
        //            frame.BackgroundColor = Color.White;
        //            frame.Margin = new Thickness(0, 0, 0, 10);
        //            frame.Padding = new Thickness(15, 15, 15, 15);
        //            //frame.CornerRadius = 10;

        //            StackLayout list = new StackLayout();
        //            list.Orientation = StackOrientation.Horizontal;

        //            Image imageGoods = new Image();
        //            imageGoods.HeightRequest = 50;
        //            imageGoods.WidthRequest = 50;
        //            //imageGoods.Source = ImageSource.FromFile("ic_no_photo");
        //            if (each.HasImage)
        //            {
        //                imageGoods.Source =
        //                    ImageSource.FromUri(new Uri(GOODS_IMAGE_URI +
        //                                                each.ID.ToString()));
        //            }
        //            else
        //            {
        //                imageGoods.Source = ImageSource.FromFile("ic_no_photo");
        //            }


        //            Label LabelName = new Label();
        //            LabelName.TextColor = Color.Black;
        //            LabelName.FontSize = 15;
        //            LabelName.Text = each.Name;
        //            LabelName.Margin = new Thickness(10, 0, 0, 0);
        //            LabelName.HorizontalOptions = LayoutOptions.FillAndExpand;
        //            LabelName.VerticalTextAlignment = TextAlignment.Start;

        //            StackLayout stackLayoutprice = new StackLayout();

        //            Label LabelPrice = new Label();
        //            LabelPrice.TextColor = Color.Black;
        //            LabelPrice.FontSize = 15;
        //            LabelPrice.Text = each.Price.ToString() + " \u20BD";
        //            LabelPrice.HorizontalOptions = LayoutOptions.EndAndExpand;
        //            LabelPrice.VerticalTextAlignment = TextAlignment.Start;

        //            Label labelCount = new Label();
        //            labelCount.TextColor = Color.Gray;
        //            labelCount.FontSize = 15;
        //            labelCount.HorizontalOptions = LayoutOptions.Center;
        //            labelCount.Text = each.ColBusket.ToString() + " " + each.Units;

        //            StackLayout stackLayoutAddAndMin = new StackLayout();
        //            stackLayoutAddAndMin.Orientation = StackOrientation.Horizontal;

        //            IconView iconViewPlus = new IconView();
        //            iconViewPlus.Source = "ic_plus";
        //            iconViewPlus.Foreground = (Color)Application.Current.Resources["MainColor"];
        //            iconViewPlus.HeightRequest = 15;
        //            iconViewPlus.WidthRequest = 15;


        //            var addItem = new TapGestureRecognizer();
        //            addItem.Tapped += async (s, e) =>
        //            {
        //                if (each.Rest != 0)
        //                {
        //                    each.Rest--;
        //                    each.ColBusket++;
        //                    labelCount.Text = each.ColBusket.ToString() + " " + each.Units;
        //                    each.priceBusket = (decimal) (each.Price * each.ColBusket);
        //                    each.weightBusket = (decimal) (each.Weight * each.ColBusket);

        //                    Price += each.priceBusket;
        //                    Weight += each.weightBusket;

        //                    try
        //                    {
        //                        Goodset.Add(each.ID.ToString(), each);
        //                    }
        //                    catch (Exception ex)
        //                    {
        //                        Goodset[each.ID.ToString()] = each;
        //                    }

        //                    isUpdate = true;
        //                    // await DisplayAlert("Добавление", "Товар: " + each.Name + " добавили в корзину", "OK");
        //                }
        //                else
        //                {
        //                    await DisplayAlert(AppResources.ErrorTitle, "Товар: " + each.Name + " закончился", "OK");
        //                }

        //                SetPriceAndWeight();
        //            };
        //            iconViewPlus.GestureRecognizers.Add(addItem);

        //            IconView iconViewMinus = new IconView();
        //            iconViewMinus.Source = "ic_minus";
        //            iconViewMinus.Foreground = (Color)Application.Current.Resources["MainColor"];
        //            iconViewMinus.HeightRequest = 15;
        //            iconViewMinus.WidthRequest = 15;


        //            var dellItem = new TapGestureRecognizer();
        //            dellItem.Tapped += async (s, e) =>
        //            {
        //                if (each.ColBusket != 0)
        //                {
        //                    each.Rest++;
        //                    each.ColBusket--;
        //                    labelCount.Text = each.ColBusket.ToString() + " " + each.Units;
        //                    each.priceBusket = (decimal) (each.Price * each.ColBusket);
        //                    each.weightBusket = (decimal) (each.Weight * each.ColBusket);

        //                    Price += each.priceBusket;
        //                    Weight += each.weightBusket;

        //                    if (each.ColBusket > 0)
        //                    {
        //                        Goodset[each.ID.ToString()] = each;
        //                    }
        //                    else
        //                    {
        //                        Goodset.Remove(each.ID.ToString());
        //                    }

        //                    isUpdate = true;
        //                    // await DisplayAlert("Добавление", "Товар: " + each.Name + " убрали из корзины", "OK");
        //                }
        //                else
        //                {
        //                    await DisplayAlert(AppResources.ErrorTitle, "Товара: " + each.Name + " в корзине больше нет", "OK");
        //                }

        //                SetPriceAndWeight();
        //            };
        //            iconViewMinus.GestureRecognizers.Add(dellItem);

        //            stackLayoutAddAndMin.HorizontalOptions = LayoutOptions.Center;
        //            stackLayoutAddAndMin.Children.Add(iconViewMinus);
        //            stackLayoutAddAndMin.Children.Add(iconViewPlus);

        //            stackLayoutprice.Children.Add(LabelPrice);
        //            stackLayoutprice.Children.Add(labelCount);
        //            stackLayoutprice.Children.Add(stackLayoutAddAndMin);

        //            list.Children.Add(imageGoods);
        //            list.Children.Add(LabelName);
        //            list.Children.Add(stackLayoutprice);
        //            frame.Content = list;
        //            stackLayout.Children.Add(frame);
        //        }

        //        i++;

        //        //stackLayoutFrame.Content = stackLayout;

        //        rootStackLayout.Children.Add(text);
        //        ScrollView scrollView = new ScrollView();
        //        scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Never;
        //        scrollView.Content = stackLayout;
        //        //scrollView.Content = stackLayoutFrame;
        //        rootStackLayout.Children.Add(scrollView);
        //        pages.Add(scrollView);
        //        pancake.Content = rootStackLayout;
        //        return pancake;
        //    });
        //    //CarouselViewShop.ItemTemplate = itemTemplate;
        //}

        public void updateGoods(int i)
        {
            //Frame content = new Frame() ;
            //content.BackgroundColor = Color.White;
            //content.CornerRadius = 30;

            StackLayout stackLayout = new StackLayout();

            GoodsLayot.Content = null;
            SetCategories();
            return;

            foreach (var each in Keys[i].Goodses)
            {
                Frame frame = new Frame();
                frame.HorizontalOptions = LayoutOptions.FillAndExpand;
                frame.VerticalOptions   = LayoutOptions.Start;
                frame.BackgroundColor   = Color.White;
                frame.Margin            = new Thickness(0, 0, 0, 10);
                frame.Padding           = new Thickness(15, 15, 15, 15);
                //frame.CornerRadius = 10;

                StackLayout list = new StackLayout();
                list.Orientation = StackOrientation.Horizontal;

                Image imageGoods = new Image();
                imageGoods.HeightRequest = 50;
                imageGoods.WidthRequest  = 50;
                imageGoods.Source        = ImageSource.FromFile("ic_no_photo");
                if (each.HasImage)
                {
                    imageGoods.Source =
                        ImageSource.FromUri(new Uri(GOODS_IMAGE_URI +
                                                    each.ID.ToString()));
                }


                Label LabelName = new Label();
                LabelName.TextColor             = Color.Black;
                LabelName.FontSize              = 15;
                LabelName.Text                  = each.Name;
                LabelName.Margin                = new Thickness(10, 0, 0, 0);
                LabelName.HorizontalOptions     = LayoutOptions.FillAndExpand;
                LabelName.VerticalTextAlignment = TextAlignment.Start;

                StackLayout stackLayoutprice = new StackLayout();

                Label LabelPrice = new Label();
                LabelPrice.TextColor             = Color.Black;
                LabelPrice.FontSize              = 15;
                LabelPrice.Text                  = each.Price.ToString() + " \u20BD";
                LabelPrice.HorizontalOptions     = LayoutOptions.EndAndExpand;
                LabelPrice.VerticalTextAlignment = TextAlignment.Start;

                Label labelCount = new Label();
                labelCount.TextColor         = Color.Gray;
                labelCount.FontSize          = 15;
                labelCount.HorizontalOptions = LayoutOptions.Center;
                labelCount.Text = each.ColBusket.ToString() + " " + each.Units;
                if (Goodset.ContainsKey(each.ID.ToString()))
                {
                    labelCount.Text = Goodset[each.ID.ToString()].ColBusket + " " + each.Units;
                }

                StackLayout stackLayoutAddAndMin = new StackLayout();
                stackLayoutAddAndMin.Orientation = StackOrientation.Horizontal;

                IconView iconViewPlus = new IconView();
                iconViewPlus.Source        = "ic_plus";
                iconViewPlus.Foreground    = (Color)Application.Current.Resources["MainColor"];
                iconViewPlus.HeightRequest = 15;
                iconViewPlus.WidthRequest  = 15;


                var addItem = new TapGestureRecognizer();
                addItem.Tapped += async(s, e) =>
                {
                    if (each.Rest != 0)
                    {
                        each.Rest--;
                        each.ColBusket++;
                        labelCount.Text   = each.ColBusket.ToString() + " " + each.Units;
                        each.priceBusket  = (decimal)(each.Price * each.ColBusket);
                        each.weightBusket = (decimal)(each.Weight * each.ColBusket);

                        Price  += each.priceBusket;
                        Weight += each.weightBusket;

                        try
                        {
                            Goodset.Add(each.ID.ToString(), each);
                        }
                        catch (Exception ex)
                        {
                            Goodset[each.ID.ToString()] = each;
                        }

                        isUpdate = true;
                        // await DisplayAlert("Добавление", "Товар: " + each.Name + " добавили в корзину", "OK");
                    }
                    else
                    {
                        await DisplayAlert(AppResources.ErrorTitle, "Товар: " + each.Name + " закончился", "OK");
                    }

                    SetPriceAndWeight();
                };
                iconViewPlus.GestureRecognizers.Add(addItem);

                IconView iconViewMinus = new IconView();
                iconViewMinus.Source        = "ic_minus";
                iconViewMinus.Foreground    = (Color)Application.Current.Resources["MainColor"];
                iconViewMinus.HeightRequest = 15;
                iconViewMinus.WidthRequest  = 15;


                var dellItem = new TapGestureRecognizer();
                dellItem.Tapped += async(s, e) =>
                {
                    if (each.ColBusket != 0)
                    {
                        each.Rest++;
                        each.ColBusket--;
                        labelCount.Text   = each.ColBusket.ToString() + " " + each.Units;
                        each.priceBusket  = (decimal)(each.Price * each.ColBusket);
                        each.weightBusket = (decimal)(each.Weight * each.ColBusket);

                        Price  += each.priceBusket;
                        Weight += each.weightBusket;

                        if (each.ColBusket > 0)
                        {
                            Goodset[each.ID.ToString()] = each;
                        }
                        else
                        {
                            Goodset.Remove(each.ID.ToString());
                        }

                        isUpdate = true;
                        // await DisplayAlert("Добавление", "Товар: " + each.Name + " убрали из корзины", "OK");
                    }
                    else
                    {
                        await DisplayAlert(AppResources.ErrorTitle, "Товара: " + each.Name + " в корзине больше нет", "OK");
                    }

                    SetPriceAndWeight();
                };
                iconViewMinus.GestureRecognizers.Add(dellItem);

                stackLayoutAddAndMin.HorizontalOptions = LayoutOptions.Center;
                stackLayoutAddAndMin.Children.Add(iconViewMinus);
                stackLayoutAddAndMin.Children.Add(iconViewPlus);

                stackLayoutprice.Children.Add(LabelPrice);
                stackLayoutprice.Children.Add(labelCount);
                stackLayoutprice.Children.Add(stackLayoutAddAndMin);

                list.Children.Add(imageGoods);
                list.Children.Add(LabelName);
                list.Children.Add(stackLayoutprice);
                frame.Content = list;
                stackLayout.Children.Add(frame);
            }

            try
            {
                //pages[i].Content = stackLayout;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 2
0
        StackLayout GetOrderedGoodsList(List <Goods> goods)
        {
            StackLayout stackLayout = new StackLayout();

            stackLayout.BackgroundColor = Color.White;

            foreach (var each in goods)
            {
                StackLayout list = new StackLayout();
                list.Orientation       = StackOrientation.Horizontal;
                list.Padding           = new Thickness(10, 10, 10, 10);
                list.HorizontalOptions = LayoutOptions.FillAndExpand;
                list.VerticalOptions   = LayoutOptions.Start;

                Image imageGoods = new Image();

                imageGoods.HeightRequest = 35;
                imageGoods.WidthRequest  = 35;
                if (each.HasImage)
                {
                    imageGoods.Source = new UriImageSource
                    {
                        CachingEnabled = true,
                        CacheValidity  = new TimeSpan(2, 0, 0, 0),
                        Uri            = new Uri(GOODS_IMAGE_URI + each.ID.ToString())
                    };
                }
                else
                {
                    imageGoods.Source = ImageSource.FromFile("ic_no_photo");
                }

                Frame imgFrame = new Frame();
                imgFrame.CornerRadius    = 10;
                imgFrame.HeightRequest   = 40;
                imgFrame.WidthRequest    = 40;
                imgFrame.VerticalOptions = LayoutOptions.Start;
                imgFrame.BackgroundColor = Color.FromHex("#e7e7e7");
                imgFrame.Padding         = new Thickness(5, 5, 5, 5);
                imgFrame.Content         = imageGoods;
                imgFrame.HasShadow       = false;

                Label LabelName = new Label();
                LabelName.TextColor      = Color.Black;
                LabelName.FontSize       = 15;
                LabelName.FontAttributes = FontAttributes.Bold;

                FormattedString LabelNameFormattedString = new FormattedString();

                Span name = new Span();
                name.Text           = each.Name;
                name.TextColor      = Color.Black;
                name.FontAttributes = FontAttributes.Bold;
                name.FontSize       = 15;

                LabelNameFormattedString.Spans.Add(name);

                if (each.Weight != 0)
                {
                    Span weigt = new Span();
                    weigt.Text      = "\n" + each.Weight.ToString() + " гр";
                    weigt.TextColor = Color.Gray;
                    weigt.FontSize  = 10;
                    LabelNameFormattedString.Spans.Add(weigt);
                }

                LabelName.FormattedText = LabelNameFormattedString;

                LabelName.Margin                = new Thickness(10, 0, 0, 0);
                LabelName.HorizontalOptions     = LayoutOptions.FillAndExpand;
                LabelName.VerticalTextAlignment = TextAlignment.Start;

                StackLayout stackLayoutprice = new StackLayout();

                Label LabelPrice = new Label();
                LabelPrice.HorizontalOptions     = LayoutOptions.EndAndExpand;
                LabelPrice.VerticalTextAlignment = TextAlignment.Start;

                FormattedString LabelPriceFormattedString = new FormattedString();

                Span price = new Span();
                price.Text           = each.Price.ToString();
                price.TextColor      = Color.Black;
                price.FontAttributes = FontAttributes.Bold;
                price.FontSize       = 15;
                LabelPriceFormattedString.Spans.Add(price);

                Span rub = new Span();
                rub.Text      = " руб";
                rub.TextColor = Color.Gray;
                rub.FontSize  = 10;
                LabelPriceFormattedString.Spans.Add(rub);

                LabelPrice.FormattedText = LabelPriceFormattedString;


                Label labelCount = new Label();
                labelCount.Margin            = new Thickness(10, 0);
                labelCount.TextColor         = Color.Gray;
                labelCount.FontSize          = 15;
                labelCount.HorizontalOptions = LayoutOptions.Center;
                labelCount.Text = each.ColBusket.ToString();

                StackLayout stackLayoutAddAndMin = new StackLayout();// { Margin = new Thickness(0, 5, 0, 0) };
                stackLayoutAddAndMin.Orientation = StackOrientation.Horizontal;

                var icViewPlusMinusSize = 22;

                IconView iconViewPlus = new IconView();
                iconViewPlus.Source        = "ic_shop_plus";
                iconViewPlus.Foreground    = colorFromMobileSettings;
                iconViewPlus.HeightRequest = icViewPlusMinusSize;
                iconViewPlus.WidthRequest  = icViewPlusMinusSize;


                var addItem = new TapGestureRecognizer();
                addItem.Tapped += async(s, e) =>
                {
                    if (each.Rest != 0)
                    {
                        each.Rest--;
                        each.ColBusket++;
                        labelCount.Text      = each.ColBusket.ToString();
                        labelCount.TextColor = Color.Black;

                        each.priceBusket  = (decimal)(each.Price * each.ColBusket);
                        each.weightBusket = (decimal)(each.Weight * each.ColBusket);

                        Price  += each.priceBusket;
                        Weight += each.weightBusket;

                        try
                        {
                            Goodset.Add(each.ID.ToString(), each);
                        }
                        catch (Exception ex)
                        {
                            Goodset[each.ID.ToString()] = each;
                        }

                        isUpdate = true;
                        // await DisplayAlert("Добавление", "Товар: " + each.Name + " добавили в корзину", "OK");
                    }
                    else
                    {
                        await DisplayAlert(AppResources.ErrorTitle, $"{AppResources.BasketProduct} {AppResources.BasketProductNoLeft}", "OK");
                    }

                    SetPriceAndWeight();
                };
                iconViewPlus.GestureRecognizers.Add(addItem);

                IconView iconViewMinus = new IconView();
                iconViewMinus.Source        = "ic_shop_minus";
                iconViewMinus.Foreground    = colorFromMobileSettings;
                iconViewMinus.HeightRequest = icViewPlusMinusSize;
                iconViewMinus.WidthRequest  = icViewPlusMinusSize;


                var dellItem = new TapGestureRecognizer();
                dellItem.Tapped += async(s, e) =>
                {
                    if (each.ColBusket != 0)
                    {
                        each.Rest++;
                        each.ColBusket--;
                        labelCount.Text = each.ColBusket.ToString();
                        if (each.ColBusket == 0)
                        {
                            labelCount.TextColor = Color.Gray;
                        }
                        each.priceBusket  = (decimal)(each.Price * each.ColBusket);
                        each.weightBusket = (decimal)(each.Weight * each.ColBusket);

                        Price  += each.priceBusket;
                        Weight += each.weightBusket;

                        if (each.ColBusket > 0)
                        {
                            Goodset[each.ID.ToString()] = each;
                        }
                        else
                        {
                            Goodset.Remove(each.ID.ToString());
                        }

                        isUpdate = true;
                        // await DisplayAlert("Добавление", "Товар: " + each.Name + " убрали из корзины", "OK");
                    }
                    else
                    {
                        await DisplayAlert(AppResources.ErrorTitle, $"{AppResources.BasketProduct} {AppResources.BasketProductNotInBasket}", "OK");
                    }

                    SetPriceAndWeight();
                };
                iconViewMinus.GestureRecognizers.Add(dellItem);

                stackLayoutAddAndMin.HorizontalOptions = LayoutOptions.Center;
                stackLayoutAddAndMin.Children.Add(iconViewMinus);
                stackLayoutAddAndMin.Children.Add(labelCount);
                stackLayoutAddAndMin.Children.Add(iconViewPlus);

                StackLayout l1 = new StackLayout()
                {
                    Orientation = StackOrientation.Vertical
                };

                l1.Children.Add(stackLayoutAddAndMin);

                var b1 = new BoxView()
                {
                    Color = colorFromMobileSettings, HeightRequest = 1, Margin = new Thickness(0, -5, 0, 0)
                };
                l1.Children.Add(b1);

                stackLayoutprice.Children.Add(LabelPrice);
                stackLayoutprice.Children.Add(l1);

                list.Children.Add(imgFrame);
                list.Children.Add(LabelName);
                list.Children.Add(stackLayoutprice);

                stackLayout.Children.Add(list);

                //разделитель
                BoxView b = new BoxView()
                {
                    Color = Color.FromHex("#e7e7e7"), HeightRequest = 1, Margin = new Thickness(10, 0)
                };
                stackLayout.Children.Add(b);
            }
            return(stackLayout);
        }