Exemple #1
0
        void ReleaseDesignerOutlets()
        {
            if (BtnDeliveryAddress != null)
            {
                BtnDeliveryAddress.Dispose();
                BtnDeliveryAddress = null;
            }

            if (BtnDeliveryTime != null)
            {
                BtnDeliveryTime.Dispose();
                BtnDeliveryTime = null;
            }

            if (BtnPay != null)
            {
                BtnPay.Dispose();
                BtnPay = null;
            }

            if (deliveryDatePicker != null)
            {
                deliveryDatePicker.Dispose();
                deliveryDatePicker = null;
            }

            if (lblTotalAmount != null)
            {
                lblTotalAmount.Dispose();
                lblTotalAmount = null;
            }
        }
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title       = "My Cart";
            restActions = new RestActions();
            _minprice   = UserSession.MinPrice();
            var bounds = UIScreen.MainScreen.Bounds;

            if (_unpaidOrder == false)
            {
                _loadingOverlay = new LoadingOverlay(bounds, "Refreshing Cart...");
                View.Add(_loadingOverlay);
                cartItemList = await LoadCartItems(UserSession.GetUserId());

                _loadingOverlay.Hide(0);
            }

            _loadingOverlay = new LoadingOverlay(bounds, "Loading Locations and Delivery times...");
            View.Add(_loadingOverlay);
            locationStingList = await LoadLocationList();

            deliveryTimeList = await LoadDeliveryTimeList();

            _loadingOverlay.Hide();


#pragma warning disable 618
            _deliveryAddressActionSheet = new UIActionSheet("Select Delivery Address", null, cancelTitle: "Cancel", destroy: null, other: locationStingList);

            _deliveryTimeActionSheet = new UIActionSheet("Select Delivery Time", null, cancelTitle: "Cancel", destroy: null, other: deliveryTimeList);
#pragma warning restore 618

            //set minimum date
            DateTime date = DateTime.Now;
            currentNsDate = (NSDate)DateTime.SpecifyKind(date, DateTimeKind.Utc);
            deliveryDate  = currentNsDate.ToString(); //set as default date
            if (_unpaidOrder)
            {
                deliveryDate = _order.ORDER_DATE_TIME.ToString("dd/MM/yyyy"); //"09:35:37"

                deliveryTime = _order.ORDER_TIME;

                deliveryLocation    = _order.LOCATION.LOCATION_NAME;
                _selectedLocationId = _order.LOCATION_ID;

                NSDate orderNsDate = (NSDate)DateTime.SpecifyKind(_order.ORDER_DATE_TIME, DateTimeKind.Utc);
                ;

                //set the current values

                BtnDeliveryAddress.SetTitle(deliveryLocation, UIControlState.Normal);
                BtnDeliveryTime.SetTitle(deliveryTime, UIControlState.Normal);
                deliveryDatePicker.SetDate(orderNsDate, true);
                deliveryDatePicker.MaximumDate = orderNsDate;

                //btnViewItems.Hidden = true;
            }



            /*btnViewItems.TouchUpInside += (e, s) =>
             * {
             *  // create the view controller for your initial view - using storyboard, code, etc
             *  CartItemsViewController cartItemsViewController = this.Storyboard.InstantiateViewController(controllerName) as CartItemsViewController;
             *  if (cartItemsViewController != null)
             *  {
             *      cartItemsViewController.SetCartItems(cartItemList);
             *      NavigationController.PushViewController(cartItemsViewController, true);
             *  }
             * };*/

            BtnDeliveryAddress.TouchUpInside += (e, s) => { _deliveryAddressActionSheet.ShowInView(View); };

            BtnDeliveryTime.TouchUpInside += (e, s) => { _deliveryTimeActionSheet.ShowInView(View); };

            deliveryDatePicker.ValueChanged += (e, s) =>
            {
                deliveryDatePicker.MinimumDate = currentNsDate; //set minimum date to current date
                deliveryDate = deliveryDatePicker.Date.ToString();
            };

            _deliveryAddressActionSheet.Clicked += (btn_sender, args) =>
            {
                try
                {
                    if (args.ButtonIndex >= 0)
                    {
                        var selectedIndex = args.ButtonIndex;

                        deliveryLocation = locationStingList[selectedIndex];

                        BtnDeliveryAddress.SetTitle(deliveryLocation, UIControlState.Normal);

                        _selectedLocationId = GetLocationId(locationList, deliveryLocation);
                    }

                    Console.WriteLine("{0} Clicked", args.ButtonIndex);
                }
                catch (Exception e)
                {
                    AppCenterLog.Error("ERROR", e.Message, e);
                }
            };

            _deliveryTimeActionSheet.Clicked += (btn_sender, args) =>
            {
                try
                {
                    if (args.ButtonIndex >= 0)
                    {
                        var selectedIndex = args.ButtonIndex;

                        deliveryTime = deliveryTimeList[selectedIndex];
                        BtnDeliveryTime.SetTitle(deliveryTime, UIControlState.Normal);
                    }

                    Console.WriteLine("{0} Clicked", args.ButtonIndex);
                }
                catch (Exception e)
                {
                    AppCenterLog.Error("ERROR", e.Message, e);
                }
            };

            BtnPay.TouchUpInside += async(e, s) =>
            {
                //let us validate the data
                if (IsLocationSelected() && IsTimeSelected() && IsDateSelected())
                {
                    //check minimum purchase price
                    if (_total >= _minprice)
                    {
                        //create new order
                        if (_unpaidOrder)
                        {
                            //let us update the order and proceed
                            OpenCheckout(_order);
                        }
                        else
                        {
                            await CreateOrderFromCart();
                        }
                    }
                    else
                    {
                        var least = _minprice.ToString("C", CultureInfo.CreateSpecificCulture("en-US"));
                        MessagingActions.ShowAlert("Minimum Price",
                                                   $"Please make a purchase of at least {least} to be eligible for delivery");
                    }
                }
                else
                {
                    MessagingActions.ShowAlert("Incomplete Info", "Ensure delivery location,date and time are specified");
                }
            };
        }