/*
		private void PopulateGrid()
		{
			SetGrid2Definitions ();


			//Populate a list with all products 
			//To be able to define product index
			var valueList = mProductDictionary.Values.Cast<List<Product>> ().ToList();
			//var tempProductList = new List<Product> ();
			foreach (var products in valueList) {
				if (products.Count > 0) {
					mCategoryIndexList.Add (mProductList.Count);
					foreach (var tempProduct in products) {					
						mProductList.Add (tempProduct);	
					}
				}
			}
			//PopulateSubCategoryButtons ();
			//LoadLimitedNumberOfProducts (1000);
			LoadAllProducts();
			ManageQueuesInBackground ();
			PopulateProductCellInBackground ();
			EraseProductCellInBackground ();
			CheckIfLastIndexChanged ();

			//LoadInitialImages ();
		}

		private async void CheckIfLastIndexChanged(){

			while (true) {
				if (mLastLoadedIndex != mLastScrollIndex) {
					lock (_ListLock) {
						mManagerProductCellQueue.Clear ();
					}

					mLastScrollIndex = mLastLoadedIndex;
					bIsImagesProduced = false;
				} else {
					if (!bIsImagesProduced) {
						bIsImagesProduced = true;
						for (int i = 0; i < 8; i++) {
							int next = mLastLoadedIndex + i;
							int prev = mLastLoadedIndex - i;
							if (next < mProductCellList.Count ) {							
								lock (_ListLock) {									
									mManagerProductCellQueue.Enqueue (mProductCellList [next]);
								}
							}
							if (prev > 0 ) {							
								lock (_ListLock) {									
									mManagerProductCellQueue.Enqueue (mProductCellList [prev]);
								}
							}
						}
					}
				}
				await Task.Delay (100);
			}
		}

		private async void ManageQueuesInBackground()
		{
			while (true) {
				while (mManagerProductCellQueue.Count > mLoadSize) {
					lock (_ListLock) {
						mManagerProductCellQueue.Dequeue ();
					}
				}

				if( mManagerProductCellQueue.Count > 0 ){
					ProductCell productCell;

					lock (_ListLock) {
						productCell = mManagerProductCellQueue.Dequeue ();
					}

					if (!mPopulaterProductCellQueue.Contains (productCell)) {
						mPopulaterProductCellQueue.Enqueue (productCell);	
					}
				}

				await Task.Delay (100);	
			}
		}

		private async void EraseProductCellInBackground()
		{
			while (true) {
				if (mTrashProductCellQueue.Count > mLoadSize) {
					var	productCell = mTrashProductCellQueue.Dequeue ();

					if (productCell.bIsImageSet) {
						productCell.bIsImageSet = false;
						productCell.ClearStreamsAndImages ();
						productCell.mProductImage.Source = null;
					}

				}
				await Task.Delay (100);	
			}
		}

		private async void PopulateProductCellInBackground()
		{
			while (true) {				

				if (mPopulaterProductCellQueue.Count > 0) {
					var productCell = mPopulaterProductCellQueue.Dequeue ();	
					if (!productCell.bIsImageSet) {	
						productCell.bIsImageSet = true;
						mTrashProductCellQueue.Enqueue (productCell);
						productCell.ProduceProductImages ();
					}
				}

				await Task.Delay (100);				

			}
		}

		private async void LoadLimitedNumberOfProducts(int count)
		{	
			foreach (var product in mProductList) {
				int productIndex = mProductList.IndexOf (product);
				if (productIndex == count)
					break;

				ProductCell productCell = new ProductCell (ProductGrid, product, this);

				mProductCellList.Add (productCell);					

				ProductGrid.Children.Add (productCell.View, productIndex % 2, productIndex / 2);			
				productCell.ProduceStreamsAndImages ();

				await Task.Delay (100);
			}
		}
*/
		private int CheckIfProductIsInTopSellingListAndReturnIndex(Product p)
		{			
			int counter = 0;
			foreach (var product in mTopSellingProductList) {				
				if (p.ProductID == product.ProductID)
					return counter;
				counter++;
			}

			return counter;
		}
Exemple #2
0
        public CartCell(Product product,Page parent)
        {
            //change PriceLabel
            //mQuantity = Convert.ToInt32 (product.Quantity.Split (' ') [0]);
            //mQuantityLabel = product.Quantity.Split (' ') [1];
            mProduct = product;
            mParentPage = parent;
            bIsFavorite = mFavoriteModel.IsProductFavorite (product.ProductID);

            Grid mainCellView = new Grid (){
                RowSpacing = 0,
                ColumnSpacing = 0,
                Padding = 0,
                BackgroundColor=Color.FromRgb(51,51,51),
                HorizontalOptions = LayoutOptions.Center,
                HeightRequest = MyDevice.GetScaledSize(150),
                WidthRequest = MyDevice.GetScaledSize(535)
            };

            //mainCellView.BackgroundColor = Color.Red;
            mainCellView.ColumnDefinitions.Add (new ColumnDefinition (){ Width = MyDevice.GetScaledSize(535) } );
            mainCellView.RowDefinitions.Add (new RowDefinition (){ Height = MyDevice.GetScaledSize(148) } );
            mainCellView.RowDefinitions.Add (new RowDefinition (){ Height = MyDevice.GetScaledSize(2) } );

            var mainLayout = new RelativeLayout () {
                HeightRequest = MyDevice.GetScaledSize(148),
                WidthRequest = MyDevice.GetScaledSize(535),
                Padding = 0,
                BackgroundColor = Color.FromRgb(253,59,47)
            };

            var cellLayout = new MR.Gestures.RelativeLayout () {
                HeightRequest = MyDevice.GetScaledSize(148),
                WidthRequest = MyDevice.GetScaledSize(535),
                Padding = 0,
                BackgroundColor=Color.FromRgb(51,51,51)
            };

            var productImage = new CachedImage () {
                WidthRequest = MyDevice.GetScaledSize(126),
                HeightRequest = MyDevice.GetScaledSize(122),
                CacheDuration = TimeSpan.FromDays(30),
                DownsampleToViewSize = true,
                RetryCount = 10,
                RetryDelay = 250,
                TransparencyEnabled = false,
                FadeAnimationEnabled = false
            };

            /*PCLStorage.IFolder folder=null;

            if (mParentPage is BrowseProductsPage) {
                folder = (mParentPage as BrowseProductsPage).mParent.mFolder;
            } else if (mParentPage is FavoritesPage) {
                folder = (mParentPage as FavoritesPage).mParent.mFolder;
            } else if (mParentPage is SearchPage) {
                folder = (mParentPage as SearchPage).mParent.mFolder;
            }*/
            /*
            if( folder.CheckExistsAsync(ProductModel.mRootFolderPath + "/" + ParseConstants.IMAGE_FOLDER_NAME + "/" + mProduct.ProductImageName).Result != PCLStorage.ExistenceCheckResult.NotFound)
                productImage.Source = ProductModel.mRootFolderPath + "/" + ParseConstants.IMAGE_FOLDER_NAME + "/" + mProduct.ProductImageName;
            else
                productImage.Source = ImageSource.FromResource("bluemart.SavedImages."+mProduct.ProductImageName);
            */
            productImage.Source = mProduct.ProductImagePath;

            var imageMask = new CachedImage () {
                WidthRequest = MyDevice.GetScaledSize(126),
                HeightRequest = MyDevice.GetScaledSize(122),
                CacheDuration = TimeSpan.FromDays(30),
                DownsampleToViewSize = true,
                RetryCount = 10,
                RetryDelay = 250,
                TransparencyEnabled = false,
                FadeAnimationEnabled = false,
                Source = "CartPage_ImageMask.png"
            };

            mFavoriteImage = new CachedImage () {
                WidthRequest = MyDevice.GetScaledSize(39),
                HeightRequest = MyDevice.GetScaledSize(32),
                CacheDuration = TimeSpan.FromDays(30),
                DownsampleToViewSize = true,
                RetryCount = 10,
                RetryDelay = 250,
                TransparencyEnabled = false,
                FadeAnimationEnabled = false
            };

            var favoriteButton = new RelativeLayout () {
                WidthRequest = MyDevice.GetScaledSize(84),
                HeightRequest = MyDevice.GetScaledSize(71),
                BackgroundColor = Color.Transparent
            };

            if (!bIsFavorite) {
                mFavoriteImage.Source = "CartPage_AddFavorites.png";
            } else {
                mFavoriteImage.Source = "CartPage_RemoveFavorites.png";
            }

            mProductPriceLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize(102),
                HeightRequest = MyDevice.GetScaledSize(40),
                HorizontalTextAlignment = TextAlignment.End,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.White,
                FontSize = MyDevice.FontSizeMedium
            };

            UpdatePriceLabel();

            var productNameLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize(225),
                HeightRequest = MyDevice.GetScaledSize(40),
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment = TextAlignment.Start,
                TextColor = Color.White,
                FontSize = MyDevice.FontSizeMicro,
                Text = product.Name
            };

            var productQuantityLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize(225),
                HeightRequest = MyDevice.GetScaledSize(26),
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment = TextAlignment.Start,
                TextColor = Color.FromRgb(152,152,152),
                FontSize = MyDevice.FontSizeMicro,
                Text = product.Quantity
            };

            mRemoveImage = new CachedImage () {
                WidthRequest = MyDevice.GetScaledSize(27),
                HeightRequest = MyDevice.GetScaledSize(21),
                CacheDuration = TimeSpan.FromDays(30),
                DownsampleToViewSize = true,
                RetryCount = 10,
                RetryDelay = 250,
                TransparencyEnabled = false,
                FadeAnimationEnabled = false,
                Source = "CartPage_RemoveProduct.png"
            };

            var removeProductButton = new RelativeLayout () {
                WidthRequest = MyDevice.GetScaledSize(59),
                HeightRequest = MyDevice.GetScaledSize(49),
                BackgroundColor = Color.Transparent
            };

            mProductNumberLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize(120),
                HeightRequest = MyDevice.GetScaledSize(47),
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment = TextAlignment.Center,
                BackgroundColor = Color.FromRgb(152,152,152),
                TextColor = Color.FromRgb(51,51,51),
                FontSize = MyDevice.FontSizeSmall
            };

            UpdateNumberLabel ();

            mAddImage = new CachedImage () {
                WidthRequest = MyDevice.GetScaledSize(27),
                HeightRequest = MyDevice.GetScaledSize(21),
                CacheDuration = TimeSpan.FromDays(30),
                DownsampleToViewSize = true,
                RetryCount = 10,
                RetryDelay = 250,
                TransparencyEnabled = false,
                FadeAnimationEnabled = false,
                Source = "CartPage_AddProduct.png"
            };

            var addProductButton = new RelativeLayout () {
                WidthRequest = MyDevice.GetScaledSize(59),
                HeightRequest = MyDevice.GetScaledSize(49),
                BackgroundColor = Color.Transparent
            };

            var deleteButton = new Label () {
                WidthRequest = MyDevice.GetScaledSize(167),
                HeightRequest = MyDevice.GetScaledSize(147),
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment = TextAlignment.Center,
                BackgroundColor = Color.FromRgb(253,59,47),
                TextColor = Color.White,
                FontSize = MyDevice.FontSizeSmall,
                Text = "DELETE"
            };

            var cartTapRecogniser = new TapGestureRecognizer ();

            cartTapRecogniser.Tapped += (sender, e) => {
                if( !IsOpen )
                    cellLayout.TranslateTo( MyDevice.GetScaledSize(-164),0,300,Easing.Linear);
                else
                    cellLayout.TranslateTo( MyDevice.GetScaledSize(0),0,300,Easing.Linear);
                IsOpen = !IsOpen;
            };

            cellLayout.GestureRecognizers.Add (cartTapRecogniser);

            cellLayout.Swiped += (object sender, MR.Gestures.SwipeEventArgs e) =>
            {
                if( !IsOpen && e.Direction == MR.Gestures.Direction.Left )
                    cellLayout.TranslateTo( MyDevice.GetScaledSize(-164),0,300,Easing.Linear);
                else if( IsOpen && e.Direction == MR.Gestures.Direction.Right )
                    cellLayout.TranslateTo( MyDevice.GetScaledSize(0),0,300,Easing.Linear);
                IsOpen = !IsOpen;
            };

            var deleteButtonTapRecogniser = new TapGestureRecognizer ();
            deleteButtonTapRecogniser.Tapped += (sender, e) => {
                Cart.ProductTotalPrice -= (mProduct.ProductNumberInCart-1)*mProduct.Price;
                mProduct.ProductNumberInCart = 1;

                if (mParentPage is BrowseProductsPage) {
                    foreach (var productCell in (mParentPage as BrowseProductsPage).mProductCellList) {
                        if (productCell.mProduct.ProductID == mProduct.ProductID) {

                            productCell.DeactivateAddMenu ();
                        }
                    }
                }
                else if (mParentPage is SearchPage) {
                    foreach (var productCell in (mParentPage as SearchPage).mProductCellList) {
                        if (productCell.mProduct.ProductID == mProduct.ProductID) {
                            productCell.DeactivateAddMenu ();
                        }
                    }
                }
                else if (mParentPage is FavoritesPage) {
                    foreach (var productCell in (mParentPage as FavoritesPage).mProductCellList) {
                        if (productCell.mProduct.ProductID == mProduct.ProductID) {
                            productCell.DeactivateAddMenu ();
                        }
                    }
                }

                RemoveProductFromCart();
            };
            deleteButton.GestureRecognizers.Add (deleteButtonTapRecogniser);

            var removeProductTapRecogniser = new TapGestureRecognizer ();
            removeProductTapRecogniser.Tapped += (sender, e) => {
                RemoveProductFromCart();
            };
            removeProductButton.GestureRecognizers.Add (removeProductTapRecogniser);

            var addProductTapRecogniser = new TapGestureRecognizer ();
            addProductTapRecogniser.Tapped += (sender, e) => {
                AddProductInCart();
            };
            addProductButton.GestureRecognizers.Add (addProductTapRecogniser);

            var favoriteTapRecogniser = new TapGestureRecognizer ();
            favoriteTapRecogniser.Tapped += (sender, e) => {
                if( !bIsFavorite )
                {
                    mFavoriteModel.AddProductID(mProduct.ProductID);
                    mFavoriteImage.Source = "CartPage_RemoveFavorites.png";
                    bIsFavorite = true;
                }
                else
                {
                    mFavoriteModel.RemoveProductID(mProduct.ProductID);
                    mFavoriteImage.Source = "CartPage_AddFavorites.png";
                    bIsFavorite = false;
                }
            };
            favoriteButton.GestureRecognizers.Add (favoriteTapRecogniser);

            mainLayout.Children.Add (deleteButton,
                Constraint.Constant (MyDevice.GetScaledSize (368)),
                Constraint.Constant (0)
            );

            mainLayout.Children.Add (cellLayout,
                Constraint.Constant (0),
                Constraint.Constant (0)
            );

            cellLayout.Children.Add (productImage,
                Constraint.Constant (MyDevice.GetScaledSize(12)),
                Constraint.Constant (MyDevice.GetScaledSize(12))
            );

            cellLayout.Children.Add (imageMask,
                Constraint.RelativeToView (productImage, (p,sibling) => {
                    return sibling.Bounds.Left;
                }),
                Constraint.RelativeToView (productImage, (p,sibling) => {
                    return sibling.Bounds.Top;
                })
            );

            cellLayout.Children.Add (mFavoriteImage,
                Constraint.Constant (MyDevice.GetScaledSize(479)),
                Constraint.Constant (MyDevice.GetScaledSize(27))
            );

            cellLayout.Children.Add (favoriteButton,
                Constraint.RelativeToView(mFavoriteImage, (p,sibling) => {
                    return sibling.Bounds.Left - MyDevice.GetScaledSize(24);
                }),
                Constraint.Constant(0)
            );

            cellLayout.Children.Add (mProductPriceLabel,
                Constraint.RelativeToView(mFavoriteImage, (p,sibling) => {
                    return sibling.Bounds.Right - MyDevice.GetScaledSize(102);
                }),
                Constraint.RelativeToView(mFavoriteImage, (p,sibling) => {
                    return sibling.Bounds.Bottom + MyDevice.GetScaledSize(30);
                })
            );

            cellLayout.Children.Add (productNameLabel,
                Constraint.RelativeToView(mFavoriteImage, (p,sibling) => {
                    return sibling.Bounds.Left - MyDevice.GetScaledSize(278);
                }),
                Constraint.RelativeToView(mFavoriteImage, (p,sibling) => {
                    return sibling.Bounds.Top - MyDevice.GetScaledSize(8);
                })
            );

            cellLayout.Children.Add (productQuantityLabel,
                Constraint.RelativeToView(productNameLabel, (p,sibling) => {
                    return sibling.Bounds.Left;
                }),
                Constraint.RelativeToView(productNameLabel, (p,sibling) => {
                    return sibling.Bounds.Bottom;
                })
            );

            cellLayout.Children.Add (mRemoveImage,
                Constraint.RelativeToView(productQuantityLabel, (p,sibling) => {
                    return sibling.Bounds.Left - MyDevice.GetScaledSize(7);
                }),
                Constraint.RelativeToView(productQuantityLabel, (p,sibling) => {
                    return sibling.Bounds.Bottom + MyDevice.GetScaledSize(15);
                })
            );

            cellLayout.Children.Add (removeProductButton,
                Constraint.RelativeToView(mRemoveImage, (p,sibling) => {
                    return sibling.Bounds.Left - MyDevice.GetScaledSize(11);
                }),
                Constraint.RelativeToView(mRemoveImage, (p,sibling) => {
                    return sibling.Bounds.Top - MyDevice.GetScaledSize(14);
                })
            );

            cellLayout.Children.Add (mProductNumberLabel,
                Constraint.RelativeToView(mRemoveImage, (p,sibling) => {
                    return sibling.Bounds.Right + MyDevice.GetScaledSize(18);
                }),
                Constraint.RelativeToView(mRemoveImage, (p,sibling) => {
                    return sibling.Bounds.Top - MyDevice.GetScaledSize(14);
                })
            );

            cellLayout.Children.Add (mAddImage,
                Constraint.RelativeToView(mProductNumberLabel, (p,sibling) => {
                    return sibling.Bounds.Right + MyDevice.GetScaledSize(18);
                }),
                Constraint.RelativeToView(mRemoveImage, (p,sibling) => {
                    return sibling.Bounds.Top;
                })
            );

            cellLayout.Children.Add (addProductButton,
                Constraint.RelativeToView(mAddImage, (p,sibling) => {
                    return sibling.Bounds.Left - MyDevice.GetScaledSize(11);
                }),
                Constraint.RelativeToView(mAddImage, (p,sibling) => {
                    return sibling.Bounds.Top - MyDevice.GetScaledSize(14);
                })
            );

            var bottomLayout = new RelativeLayout () {
                HeightRequest = MyDevice.GetScaledSize(2),
                WidthRequest = MyDevice.GetScaledSize(535),
                BackgroundColor = Color.FromRgb(129,129,129),
                Padding = 0
            };

            mainCellView.Children.Add (mainLayout, 0, 0);
            mainCellView.Children.Add (bottomLayout, 0, 1);

            this.View = mainCellView;
        }
Exemple #3
0
        private void InitializeReceiptLayout(Object obj = null)
        {
            mReceiptLayout = new Image () {
                WidthRequest = MyDevice.GetScaledSize(600),
                HeightRequest = MyDevice.GetScaledSize(477),
                Source = "ReceiptPage_ReceiptBackground.png"
            };

            var quantityLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (109),
                HeightRequest = MyDevice.GetScaledSize(25),
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.FromRgb(98,98,98),
                Text = "Quantity",
                FontSize = MyDevice.FontSizeMicro
            };

            var productLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (187),
                HeightRequest = MyDevice.GetScaledSize(25),
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.FromRgb(98,98,98),
                Text = "Product",
                FontSize = MyDevice.FontSizeMicro
            };

            var descriptionLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (169),
                HeightRequest = MyDevice.GetScaledSize(25),
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.FromRgb(98,98,98),
                Text = "Description",
                FontSize = MyDevice.FontSizeMicro
            };

            var costLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (117),
                HeightRequest = MyDevice.GetScaledSize(25),
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.FromRgb(98,98,98),
                Text = "Cost (AED)",
                FontSize = MyDevice.FontSizeMicro
            };

            var receiptStackLayout = new StackLayout {
                Orientation = StackOrientation.Vertical,
                Padding = 0,
                Spacing = 0
            };

            var totalAmountLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (259),
                HeightRequest = MyDevice.GetScaledSize(32),
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.FromRgb(98,98,98),
                Text = "TOTAL AMOUNT: ",
                FontSize = MyDevice.FontSizeSmall
            };

            var totalAmountPriceLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (117),
                HeightRequest = MyDevice.GetScaledSize(32),
                HorizontalTextAlignment = TextAlignment.End,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.FromRgb(98,98,98),
                Text = Cart.ProductTotalPrice.ToString(),
                FontSize = MyDevice.FontSizeSmall
            };

            if (obj == null) {
                totalAmountPriceLabel.Text = Cart.ProductTotalPrice.ToString ();
            } else {
                if (obj is StatusClass) {
                    totalAmountPriceLabel.Text = (obj as StatusClass).TotalPrice.ToString ();
                } else if (obj is HistoryClass) {
                    totalAmountPriceLabel.Text = (obj as HistoryClass).TotalPrice.ToString ();
                }
            }

            var agreeLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (168),
                HeightRequest = MyDevice.GetScaledSize(46),
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.White,
                Text = "AGREE",
                FontSize = MyDevice.FontSizeSmall
            };

            var disagreeLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (173),
                HeightRequest = MyDevice.GetScaledSize(46),
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.White,
                Text = "CANCEL",
                FontSize = MyDevice.FontSizeSmall
            };

            if (mObject != null) {
                agreeLabel.Text = "OK";
                disagreeLabel.Text = "";
                disagreeLabel.BackgroundColor = Color.White;
            }

            var thankyouLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (589),
                HeightRequest = MyDevice.GetScaledSize(57),
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment = TextAlignment.Center,
                TextColor = Color.FromRgb(192,192,192),
                Text = "THANK YOU\nFOR SHOPPING WITH US",
                FontSize = MyDevice.FontSizeSmall
            };

            var rightsReservedLabel = new Label () {
                WidthRequest = MyDevice.GetScaledSize (589),
                HeightRequest = MyDevice.GetScaledSize(24),
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment = TextAlignment.Start,
                TextColor = Color.FromRgb(192,192,192),
                Text = "ALL RIGHTS RESERVED TO BLUEMART",
                FontSize = MyDevice.FontSizeMicro
            };

            var agreeTapRecognizer = new TapGestureRecognizer ();
            agreeTapRecognizer.Tapped += async (sender, e) => {
                if (mObject == null) {
                    if (MyDevice.GetNetworkStatus () != "NotReachable") {
                        if(mAddressModel.GetActiveAddress (mUserModel.ActiveRegion)==null)
                        {
                            await DisplayAlert ("No Address", "Please Add An Address.", "OK");
                        }
                        else
                        {
                            bool OrderSucceeded = OrderModel.SendOrderToRemote (mUserModel).Result;

                            if (OrderSucceeded)
                            {
                                await DisplayAlert ("Order Sent", "Please check the quality of the fresh produce you receive before you pay to the delivery boy. Your satisfaction is our top priority at all times.", "OK");
                                //mParent.mBrowseCategoriesPage.CartStackLayout.Children.Clear();
                                Cart.ProductTotalPrice = 0;
                                Cart.ProductsInCart.Clear();
                                mParent.LoadTrackPage();
                            }
                            else
                            {
                                await DisplayAlert ("Connection Error", "Your order couldn't be delivered. Check your internet connection and try again.", "OK");
                                mParent.SwitchTab ("BrowseCategories");
                            }
                        }
                    } else {
                        await DisplayAlert ("Connection Error", "Your order couldn't be delivered. Check your internet connection and try again.", "OK");
                    }
                } else {
                    if (mObject is HistoryClass) {
                        //mParent.mFooter.ChangeColorOfLabel (mParent.mFooter.mCartLabel);
                        mParent.LoadTrackPage ();
                    } else if (mObject is StatusClass) {
                        //mParent.mFooter.ChangeColorOfLabel (mParent.mFooter.mTrackLabel);
                        //mParent.SwitchTab ("Track");
                        mParent.LoadTrackPage ();
                    }
                }
            };
            agreeLabel.GestureRecognizers.Add (agreeTapRecognizer);

            var disagreeTapRecognizer = new TapGestureRecognizer ();
            disagreeTapRecognizer.Tapped += (sender, e) => {
                if (mObject == null) {
                    mParent.SwitchTab ("BrowseCategories");
                }
            };
            disagreeLabel.GestureRecognizers.Add (disagreeTapRecognizer);

            int receiptCellCount = 0;

            if (obj == null) {
                foreach (var product in Cart.ProductsInCart) {
                    receiptStackLayout.Children.Add (new ReceiptCell (receiptCellCount++, product).View);
                }
            }
            else {
                //Product product = new Product(
                if (obj is HistoryClass) {
                    foreach (var productString in (obj as HistoryClass).ProductOrderList) {
                        string quantity = productString.Split (';') [0].Split (':') [1];
                        string name = productString.Split (';') [1].Split (':') [1];
                        string description = productString.Split (';') [2].Split (':') [1];
                        string price = productString.Split (';') [3].Split (':') [1];

                        var product = new Product ("", name, "", decimal.Parse (price), "", description,true);
                        product.ProductNumberInCart = int.Parse (quantity);
                        receiptStackLayout.Children.Add (new ReceiptCell (receiptCellCount++, product).View);
                    }
                } else if (obj is StatusClass) {
                    foreach (var productString in (obj as StatusClass).ProductOrderList) {
                        string quantity = productString.Split (';') [0].Split (':') [1];
                        string name = productString.Split (';') [1].Split (':') [1];
                        string description = productString.Split (';') [2].Split (':') [1];
                        string price = productString.Split (';') [3].Split (':') [1];

                        var product = new Product ("", name, "", decimal.Parse (price), "", description,true);
                        product.ProductNumberInCart = int.Parse (quantity);
                        receiptStackLayout.Children.Add (new ReceiptCell (receiptCellCount++, product).View);
                    }
                }

            }

            var receiptScrollView = new ScrollView {
                Orientation = ScrollOrientation.Vertical,
                Content = receiptStackLayout
            };

            mMidLayout.Children.Add (mReceiptLayout,
                Constraint.RelativeToView (mAddressLayout, (p, sibling) => {
                    return sibling.Bounds.Left;
                }),
                Constraint.RelativeToView (mAddressLayout, (p, sibling) => {
                    return sibling.Bounds.Bottom + MyDevice.GetScaledSize(25);
                })
            );

            mMidLayout.Children.Add (quantityLabel,
                Constraint.RelativeToView (mReceiptLayout, (p, sibling) => {
                    return sibling.Bounds.Left + MyDevice.GetScaledSize(22);
                }),
                Constraint.RelativeToView (mReceiptLayout, (p, sibling) => {
                    return sibling.Bounds.Top + MyDevice.GetScaledSize(37);
                })
            );

            mMidLayout.Children.Add (productLabel,
                Constraint.RelativeToView (quantityLabel, (p, sibling) => {
                    return sibling.Bounds.Right;
                }),
                Constraint.RelativeToView (quantityLabel, (p, sibling) => {
                    return sibling.Bounds.Top;
                })
            );

            mMidLayout.Children.Add (descriptionLabel,
                Constraint.RelativeToView (productLabel, (p, sibling) => {
                    return sibling.Bounds.Right;
                }),
                Constraint.RelativeToView (productLabel, (p, sibling) => {
                    return sibling.Bounds.Top;
                })
            );

            mMidLayout.Children.Add (costLabel,
                Constraint.RelativeToView (descriptionLabel, (p, sibling) => {
                    return sibling.Bounds.Right;
                }),
                Constraint.RelativeToView (descriptionLabel, (p, sibling) => {
                    return sibling.Bounds.Top;
                })
            );

            double receiptHeight = MyDevice.GetScaledSize (24)*(receiptCellCount);

            if (receiptHeight > MyDevice.GetScaledSize (238))
                receiptHeight = MyDevice.GetScaledSize (238);

            mMidLayout.Children.Add (receiptScrollView,
                Constraint.RelativeToView (quantityLabel, (parent,sibling) => {
                    return sibling.Bounds.Left;
                }),
                Constraint.RelativeToView (quantityLabel, (parent,sibling) => {
                    return sibling.Bounds.Bottom + MyDevice.GetScaledSize(16);
                }),
                Constraint.Constant(MyDevice.GetScaledSize(571)),
                Constraint.Constant(receiptHeight)
            );

            mMidLayout.Children.Add (totalAmountLabel,
                Constraint.RelativeToView (mReceiptLayout, (p, sibling) => {
                    return sibling.Bounds.Left + MyDevice.GetScaledSize(206);
                }),
                Constraint.RelativeToView (mReceiptLayout, (p, sibling) => {
                    return sibling.Bounds.Bottom - MyDevice.GetScaledSize(138);
                })
            );

            mMidLayout.Children.Add (totalAmountPriceLabel,
                Constraint.RelativeToView (totalAmountLabel, (p, sibling) => {
                    return sibling.Bounds.Right;
                }),
                Constraint.RelativeToView (totalAmountLabel, (p, sibling) => {
                    return sibling.Bounds.Top;
                })
            );

            mMidLayout.Children.Add (agreeLabel,
                Constraint.RelativeToView (mReceiptLayout, (p, sibling) => {
                    return sibling.Bounds.Left + MyDevice.GetScaledSize(84);
                }),
                Constraint.RelativeToView (mReceiptLayout, (p, sibling) => {
                    return sibling.Bounds.Bottom - MyDevice.GetScaledSize(75);
                })
            );

            mMidLayout.Children.Add (disagreeLabel,
                Constraint.RelativeToView (agreeLabel, (p, sibling) => {
                    return sibling.Bounds.Right + MyDevice.GetScaledSize(90);
                }),
                Constraint.RelativeToView (agreeLabel, (p, sibling) => {
                    return sibling.Bounds.Top;
                })
            );

            mMidLayout.Children.Add (thankyouLabel,
                Constraint.RelativeToView (mReceiptLayout, (p, sibling) => {
                    return sibling.Bounds.Left;
                }),
                Constraint.RelativeToView (mReceiptLayout, (p, sibling) => {
                    return sibling.Bounds.Bottom + MyDevice.GetScaledSize(5);
                })
            );

            mMidLayout.Children.Add (rightsReservedLabel,
                Constraint.RelativeToView (thankyouLabel, (p, sibling) => {
                    return sibling.Bounds.Left;
                }),
                Constraint.RelativeToView (thankyouLabel, (p, sibling) => {
                    return sibling.Bounds.Bottom + MyDevice.GetScaledSize(5);
                })
            );
        }
Exemple #4
0
        protected override void SetupCell(bool isRecycled)
        {
            if (product != null)
            {
                mParent = MyDevice.currentPage;
                //SetRootPage ();
                if (Cart.ProductsInCart.Count != 0) {
                    foreach (Product p in Cart.ProductsInCart) {
                        if (p.ProductID == product.ProductID) {
                            mProduct = p;
                            break;
                        }
                        else
                            mProduct = product;
                    }
                } else
                    mProduct = product;
                //System.Diagnostics.Debug.WriteLine (mProduct.ProductImagePath);
                mProductImage.Source = mProduct.ProductImagePath;

                /*
                PCLStorage.IFolder folder=null;

                if (mParent is BrowseProductsPage) {
                    folder = (mParent as BrowseProductsPage).mParent.mFolder;
                } else if (mParent is FavoritesPage) {
                    folder = (mParent as FavoritesPage).mParent.mFolder;
                } else if (mParent is SearchPage) {
                    folder = (mParent as SearchPage).mParent.mFolder;
                }

                if( folder.CheckExistsAsync(ProductModel.mRootFolderPath + "/" + ParseConstants.IMAGE_FOLDER_NAME + "/" + mProduct.ProductImageName).Result != PCLStorage.ExistenceCheckResult.NotFound)
                    mProductImage.Source = ProductModel.mRootFolderPath + "/" + ParseConstants.IMAGE_FOLDER_NAME + "/" + mProduct.ProductImageName;
                else
                    mProductImage.Source = ImageSource.FromResource("bluemart.SavedImages."+mProduct.ProductImageName);
            */

                productNameLabel.Text = mProduct.Name;
                productQuantityLabel.Text = mProduct.Quantity.Replace (",",".");
                productPriceLabel.Text = "AED " + String.Format("{0:0.00}", mProduct.Price);  //mProduct.Price.ToString ();
                mFavoriteModel = new FavoritesClass ();
                bIsFavorite = mFavoriteModel.IsProductFavorite (mProduct.ProductID);

                UpdateNumberLabel ();

                if (mProduct.ProductNumberInCart > 0)
                    ActivateAddMenu ();
                else
                    DeactivateAddMenu ();
                if (bIsFavorite)
                    AddFavorite ();
                else
                    RemoveFavorite ();

                if (mProduct.ProductIsInStock)
                    DeActivateOutOfStock ();
                else
                    ActivateOutOfStock ();
            }
        }
Exemple #5
0
        protected override void SetupCell(bool isRecycled)
        {
            //System.Diagnostics.Debug.WriteLine ("SetupCell");

            if (product == null)
                return;
            mProduct = product;

            bIsFavorite = mFavoriteModel.IsProductFavorite (product.ProductID);

            productImage.Source = mProduct.ProductImagePath;

            if (!bIsFavorite) {
                mFavoriteImage.Source = "CartPage_AddFavorites.png";
            } else {
                mFavoriteImage.Source = "CartPage_RemoveFavorites.png";
            }

            if( ( !deleteIsOpenDictionary.ContainsKey(product.ProductID) || !deleteIsOpenDictionary[product.ProductID]))
            {
                cellLayout.TranslationX = 0;
            }
            else if( deleteIsOpenDictionary.ContainsKey(product.ProductID) && deleteIsOpenDictionary[product.ProductID])
            {
                cellLayout.TranslationX = MyDevice.GetScaledSize (-164);
            }

            UpdatePriceLabel();
            productNameLabel.Text = product.Name;
            productQuantityLabel.Text = product.Quantity;
            UpdateNumberLabel ();
        }