Ejemplo n.º 1
0
        public void ShowGrid(Grid grid, List <Product> productsList, bool IsOrientationPortrait, int countColumn)
        {
            bool isGridChildrenZero = grid.Children.Count == 0;

            bool isInExistence;

            if (productsList == null || productsList.Count == 0)
            {
                IsCompleteShowGrid = true;
                return;
            }
            int i = 0;

            Task.Run(() => {
                foreach (Product product in productsList)
                {
                    if (CancelTSProduct.IsCancellationRequested)
                    {
                        CancelTSProduct    = new CancellationTokenSource();
                        IsCompleteShowGrid = true;
                        return;
                    }
                    if (product.productsAttributes.Count > 0)
                    {
                        isInExistence = false;
                        for (int j = 0; j < product.productsAttributes.Count; j++)
                        {
                            if (product.productsAttributes[j].Quantity > 0)
                            {
                                isInExistence = true;
                            }
                        }
                    }
                    else
                    {
                        isInExistence = true;
                    }

                    if (!isInExistence || product.productsDescription == null)
                    {
                        continue;
                    }

                    ProductInCategoryTemplate productItem = null;
                    if (i <= grid.Children.Count - 1)
                    {
                        productItem = grid.Children[i] as ProductInCategoryTemplate;                        //.Take();
                        Device.BeginInvokeOnMainThread(() => {
                            productItem.IsVisible = true;
                            productItem.ShowProduct(product, isInExistence);
                        });
                        if (isGridChildrenZero)
                        {
                            AddProduct(productItem, i, countColumn, grid);
                        }
                    }
                    else
                    {
                        //productItem = new ProductInCategoryTemplate();
                        //productItem.EventClick += ClickProduct;
                        ////OnePage.mainPage.productItemsList.Add(productItem);


                        //productItem.ShowProduct(product, isInExistence);
                        //AddProduct(productItem, i, countColumn, grid);
                    }
                    i++;
                }
                IsCompleteShowGrid = true;

                Device.BeginInvokeOnMainThread(() => {
                    grid.HeightRequest = Math.Ceiling((double)productsList.Count / 2) * (210 + 10);
                    //if (CancelTSProduct.IsCancellationRequested) {
                    //	CancelTSProduct = new CancellationTokenSource();

                    //	indicator.IsVisible = false;
                    //	layoutProductGrid.IsVisible = false;
                    //}

                    if (contentAndHeads1 != null && contentAndHeads1.countPage > 1)
                    {
                        SetPagination(paginationBegin, contentAndHeads1);
                        SetPagination(paginationEnd, contentAndHeads1);
                    }
                    else
                    {
                        paginationBegin.IsVisible = false;
                        paginationEnd.IsVisible   = false;
                    }
                    indicator.IsVisible         = false;
                    layoutProductGrid.IsVisible = true;
                });
            });
        }