Beispiel #1
0
        /// <summary>
        /// Afters the list.
        /// </summary>
        protected override void AfterList()
        {
            Button addButton = new Button {
                Text            = "Add",
                TextColor       = Color.White,
                BackgroundColor = Color.Blue
            };

            addButton.Clicked += (sender, e) => {
                PositionSelectorPage page = new PositionSelectorPage(Position.PositionFlag.None, (position) => {
                    EntitySelected(Manager, position);
                });
                RootPage.Root.NextPageModal(page);
            };

            PageLayout.Children.Add(addButton);
        }
Beispiel #2
0
        private void AddOrdersTab()
        {
            AddContentTab("Orders", "icon_orders.png");
            ordersTab = currentTab;

            ListView ordersList = null;

            Button clearOrdersButton = new Button {
                Text              = "Clear Orders",
                TextColor         = Color.White,
                BackgroundColor   = Color.Red,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            clearOrdersButton.Clicked += async(sender, e) => {
                bool confirm = await currentTab.DisplayAlert("Clear Orders", "Are you sure?", "Yes", "No");

                if (confirm)
                {
                    Phoenix.Application.OrderManager.ClearOrders(CurrentPosition.Id, (results) => {
                        Orders = new ObservableCollection <Order> (results);
                        Device.BeginInvokeOnMainThread(() => {
                            ordersList.ItemsSource = Orders;
                        });
                        SwitchToOrdersTab();
                    });
                }
            };

            Button copyOrdersButton = new Button {
                Text              = "Copy Orders",
                TextColor         = Color.White,
                BackgroundColor   = Color.Blue,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            copyOrdersButton.Clicked += (sender, e) => {
                PositionSelectorPage page = new PositionSelectorPage((Position.PositionFlag)CurrentPosition.PositionType, (position) => {
                    Phoenix.Application.OrderManager.CopyOrders(CurrentPosition.Id, position.Id, (results) => {
                        EntityPageBuilderFactory.ShowEntityPage <Position>(Manager, position.Id, (int)PositionPageBuilder.PositionTab.Orders);
                    });
                });
                RootPage.Root.NextPageModal(page);
            };

            StackLayout buttonBar = new StackLayout {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children          =
                {
                    clearOrdersButton,
                    copyOrdersButton
                }
            };

            currentTab.PageLayout.Children.Add(buttonBar);

            ordersList = currentTab.AddListView(typeof(OrderViewCell), null, (sender, e) => {
                currentTab.Spinner.IsRunning = true;
                Phoenix.Application.OrderManager.Get(((Order)e.Item).Id, (order) => {
                    OrderEditPage page = new OrderEditPage(order);
                    Device.BeginInvokeOnMainThread(() => {
                        RootPage.Root.NextPage(page);
                        currentTab.Spinner.IsRunning = false;
                    });
                });
            });

            Button addOrderButton = new Button {
                Text            = "Add Order",
                TextColor       = Color.White,
                BackgroundColor = Color.Blue
            };

            addOrderButton.Clicked += (sender, e) => {
                OrderSelectorPage page = new OrderSelectorPage(CurrentPosition);
                RootPage.Root.NextPageModal(page);
            };
            currentTab.PageLayout.Children.Add(addOrderButton);

            currentTab.AddHelpLabel("Tap an order to edit. Swipe left to delete an order.");

            ordersList.IsRefreshing = true;

            Phoenix.Application.OrderManager.AllForPosition(CurrentPosition.Id, (results) => {
                if (results.Count > 0)
                {
                    UpdateOrders(results);
                    Device.BeginInvokeOnMainThread(() => {
                        ordersList.IsRefreshing = false;
                        ordersList.ItemsSource  = Orders;
                    });
                }
                else
                {
                    Phoenix.Application.OrderManager.FetchForPosition(CurrentPosition.Id, (fetchResults, ex) => {
                        if (ex == null)
                        {
                            UpdateOrders(fetchResults);
                        }
                        else
                        {
                            Orders = new ObservableCollection <Order>();
                            ShowErrorAlert(ex);
                        }
                        Device.BeginInvokeOnMainThread(() => {
                            ordersList.IsRefreshing = false;
                            ordersList.ItemsSource  = Orders;
                        });
                    });
                }
            });
        }