public ProductsSortView(FilterParam _filterParam)
        {
            filterParamDefault = _filterParam;
            VerticalOptions    = LayoutOptions.FillAndExpand;

            indicator = new ActivityIndicator {
                Color           = Device.OnPlatform(Color.Black, Color.Gray, Color.Default),
                IsRunning       = true,
                VerticalOptions = LayoutOptions.CenterAndExpand,
            };

            Label lblSort = new Label {
                Text            = "Сортировать по:",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            StackLayout titleSortLayout = new StackLayout {
                BackgroundColor = ApplicationStyle.LineColor,
                HeightRequest   = Utils.GetSize(22),
                Padding         = new Thickness(8, 0),
                Children        =
                {
                    lblSort
                }
            };

            sortList = new ListView {
                ItemTemplate    = new DataTemplate(typeof(SortItemCell)),
                ItemsSource     = ParamSort.ParamsList,
                VerticalOptions = LayoutOptions.Start,
                RowHeight       = Utils.GetSize(43),
            };
            sortList.SizeChanged += (sender, e) => {
                sortList.HeightRequest = (sortList.RowHeight + 0.5) * ParamSort.ParamsList.Count;
            };
            sortList.ItemTapped += OnClickSort;
            Sorted(sortList, _filterParam.paramForSort);

            Label lblFilter = new Label {
                Text            = "Фильтровать по:",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            StackLayout titleFilterLayout = new StackLayout {
                BackgroundColor = ApplicationStyle.LineColor,
//				VerticalOptions = LayoutOptions.Start,
                HeightRequest = Utils.GetSize(22),
                Padding       = new Thickness(8, 0),
                Children      =
                {
                    lblFilter
                }
            };

            sizesCell = new CellTemplate("Размеру")
            {
                HeightRequest = Utils.GetSize(43)
            };
            TapGestureRecognizer tapOrderStatusList = new TapGestureRecognizer();

            tapOrderStatusList.Tapped += OnSelectSize;;
            sizesCell.GestureRecognizers.Add(tapOrderStatusList);

            listSizes = new ListView {
                ItemTemplate = new DataTemplate(typeof(RadioButtonItemCell)),
            };
            listSizes.ItemTapped += OnClickSize;

            layoutSize = new StackLayout {
                Spacing  = 0,
                Children =
                {
                    sizesCell,
                    new BoxView(),
                    listSizes
                }
            };

            entPriceBegin = new MyEntry {
                VerticalOptions         = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.Center,
                Padding           = new Thickness(5),
                BorderColor       = ApplicationStyle.LineColor,
                BorderRadius      = Utils.GetSize(3),
                BorderWidth       = Utils.GetSize(1),
                HeightRequest     = Utils.GetSize(26),
                WidthRequest      = Utils.GetSize(80),
                Placeholder       = "от",
                HorizontalOptions = LayoutOptions.EndAndExpand,
                Keyboard          = Keyboard.Numeric
            };
            entPriceEnd = new MyEntry {
                VerticalOptions         = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.Center,
                Padding       = new Thickness(5),
                BorderColor   = ApplicationStyle.LineColor,
                BorderRadius  = Utils.GetSize(3),
                BorderWidth   = Utils.GetSize(1),
                HeightRequest = Utils.GetSize(26),
                WidthRequest  = Utils.GetSize(80),
                Placeholder   = "до",
                Keyboard      = Keyboard.Numeric
            };

            Label lblPriceBegin = new Label {
                VerticalOptions = LayoutOptions.CenterAndExpand,
                TextColor       = ApplicationStyle.TextColor,
                Text            = "Цене"
            };

            Label lblPriceEnd = new Label {
                VerticalOptions = LayoutOptions.CenterAndExpand,
                Text            = " — "
            };

            StackLayout layoutPrice = new StackLayout {
                Orientation   = StackOrientation.Horizontal,
                Padding       = new Thickness(16, 0, 24, 0),
                HeightRequest = Utils.GetSize(43),
                Children      =
                {
                    lblPriceBegin,
                    entPriceBegin,
                    lblPriceEnd,
                    entPriceEnd,
                }
            };

            Button btnClear = new Button {
                BackgroundColor = Color.Transparent,
                TextColor       = ApplicationStyle.GreenColor,
                BorderColor     = ApplicationStyle.GreenColor,
                BorderWidth     = 1,
                WidthRequest    = Utils.GetSize(150),
                Text            = "СБРОСИТЬ ВСЕ",
            };

            btnClear.Clicked += OnClearClick;

            btnOk = new Button {
                BackgroundColor   = ApplicationStyle.RedColor,
                TextColor         = Color.White,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                WidthRequest      = Utils.GetSize(150),
                Text = "ПРИМЕНИТЬ",
            };
            btnOk.Clicked += OnOkClick;

            StackLayout layoutBtn = new StackLayout {
                Padding       = new Thickness(8, 16),
                HeightRequest = Utils.GetSize(35),
                Orientation   = StackOrientation.Horizontal,
                Children      =
                {
                    btnClear,
                    btnOk,
                }
            };

            mainLayout = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Spacing         = 0,
                Children        =
                {
                    titleSortLayout,
                    sortList,
                    titleFilterLayout,
                    layoutSize,
                    layoutPrice,
                    new BoxView(),
                    layoutBtn,
                }
            };
            Content = mainLayout;
        }
Exemple #2
0
        public static async Task <ContentAndHeads> GetProductsByCategoryIDAsync(int[] catogoriesIDList, int currentPage, int countItems, FilterParam paramForCheck)
        {
            if (paramForCheck == null)
            {
                return(await Product.GetProductsByCategoryIDAsync(catogoriesIDList, currentPage, countItems));
            }
            string strCategoryID        = string.Join(",", catogoriesIDList);
            string formatAdvancedFilter = string.Format(AdvancedFiltersList.ProductToListCategoryIDAndSortToProductDescrioption);

            formatAdvancedFilter += "," + AdvancedFiltersList.ProductToListFilterProductsQuantity;
            formatAdvancedFilter += "," + string.Format(AdvancedFiltersList.ProductToListFilterCategories, strCategoryID);

            if (paramForCheck.Sizes != null)
            {
                string strSizes = string.Join(",", paramForCheck.Sizes);
                formatAdvancedFilter += "," + string.Format(AdvancedFiltersList.ProductToListFilterSizes, strSizes);
            }
            if (paramForCheck.PriceBegin != 0)
            {
                formatAdvancedFilter += "," + string.Format(AdvancedFiltersList.ProductToListFilterPriceBegin, paramForCheck.PriceBegin);
            }
            if (paramForCheck.PriceEnd != 0)
            {
                formatAdvancedFilter += "," + string.Format(AdvancedFiltersList.ProductToListFilterPriceEnd, paramForCheck.PriceEnd);
            }

            formatAdvancedFilter = "[" + formatAdvancedFilter + "]&distinct=1";


            string advancedSort = null;

            if (paramForCheck.paramForSort != null)
            {
                string desc = paramForCheck.paramForSort.IsDesc ? "desc" : "asc";
                if (paramForCheck.paramForSort.FieldSort == ProductsSort.products_name)
                {
                    advancedSort = string.Format(AdvancedSort.ProductToListCategoryIDAndSortToProductDescrioption,
                                                 paramForCheck.paramForSort.FieldSort, desc);
                }
                else
                {
                    advancedSort = string.Format(AdvancedSort.ProductToListCategoryIDAndSort, paramForCheck.paramForSort.FieldSort, desc);
                }
            }


            string expandList = ExpandList.ProductsAttributesFullInfo + "," + ExpandList.ProductsDescription + "," + ExpandList.ProductsSchedule + "," + ExpandList.ProductsExpress;
            string url        = WebRequestUtils.GetUrl(Constants.UrlProducts, expandList, formatAdvancedFilter, advancedSort);

            url = WebRequestUtils.GetUrlPage(url, currentPage, countItems);

            ContentAndHeads contentAndHeads = await WebRequestUtils.GetJsonAndHeadsAsync(url, isCancelable : true);

            if (contentAndHeads.requestStatus != System.Net.HttpStatusCode.OK)
            {
                throw new Exception();
            }

            if (contentAndHeads.Content == null)
            {
                return(contentAndHeads);
            }
            string json = contentAndHeads.Content[0];

            if (string.IsNullOrEmpty(json))
            {
                return(contentAndHeads);
            }

            contentAndHeads.productsList = new List <Product>();
            contentAndHeads.productsList.AddRange(JsonConvert.DeserializeObject <List <Product> > (json));

            return(contentAndHeads);
        }