Пример #1
0
        private async void UxProcessTips_Click(object sender, RoutedEventArgs e)
        {
            bool success = false;

            foreach (Tip tip in uxTipListView.Items)
            {
                success = await DeleteTipRequest.SendDeleteTipRequest(tip._id);
            }
            if (success)
            {
                ContentDialog responseAlert = new ContentDialog
                {
                    Title           = "Processed",
                    Content         = "Employee tips have been processed",
                    CloseButtonText = "Ok"
                };
                ContentDialogResult result = await responseAlert.ShowAsync();

                var validGetTips = await GetEmployeeTips.SendGetEmployeeTips(selectedEmployee._id);

                uxTipListView.ItemsSource = RealmManager.All <Tips>().FirstOrDefault().tip;
            }
            else
            {
                ContentDialog responseAlert = new ContentDialog
                {
                    Title           = "Unsuccessful",
                    Content         = "Tip processing was unsuccessful",
                    CloseButtonText = "Ok"
                };
                ContentDialogResult result = await responseAlert.ShowAsync();
            }
        }
Пример #2
0
        private async Task RefreshIngredientList()
        {
            //send the GetIngredients service request
            var validSendGetIngredientsRequest = await GetIngredientsRequest.SendGetIngredientsRequest();

            //updates the itemsource with the newly populated data
            uxIngredientGridView.ItemsSource = RealmManager.All <IngredientList>().FirstOrDefault().doc.OrderBy(ingredient => ingredient.name);
        }
Пример #3
0
        public async Task RefreshMenuItemLists()
        {
            var validMenuItemList = await GetMenuItemsRequest.SendGetMenuItemsRequest();

            var menuItemsList = RealmManager.All <MenuItemList>().FirstOrDefault().menuItems;

            uxAppliedItemsList.ItemsSource  = menuItemsList;
            uxRequiredItemsList.ItemsSource = menuItemsList;
        }
Пример #4
0
        private async void UxTipPopupButton_Click(object sender, RoutedEventArgs e)
        {
            uxTipCompPopup.IsOpen    = true;
            uxTipListView.Visibility = Visibility.Visible;
            uxProcessTips.Visibility = Visibility.Visible;
            var validGetTips = await GetEmployeeTips.SendGetEmployeeTips(selectedEmployee._id);

            uxTipListView.ItemsSource = RealmManager.All <Tips>().FirstOrDefault().tip;
        }
Пример #5
0
        private async void UxCompPopupButton_Click(object sender, RoutedEventArgs e)
        {
            uxTipCompPopup.IsOpen     = true;
            uxClearComps.Visibility   = Visibility.Visible;
            uxCompListView.Visibility = Visibility.Visible;
            var validGetComps = await GetAllComps.SendGetAllCompsEmployee(selectedEmployee._id);

            uxCompListView.ItemsSource = await SyncCompData(RealmManager.All <CompList>().FirstOrDefault().comp);
        }
Пример #6
0
        private async void UxEmployeeListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            uxTimePopup.IsOpen = true;
            SelectedEmployee   = (Employee)e.ClickedItem;

            var validShiftRequest = await GetAllShiftsRequest.SendGetAllShiftsRequest(SelectedEmployee._id);

            uxShiftListView.ItemsSource = RealmManager.All <ShiftList>().FirstOrDefault().shifts.ToList();
        }
Пример #7
0
        public async void RefreshEmployeeList()
        {
            RealmManager.RemoveAll <EmployeeList>();
            RealmManager.RemoveAll <Employee>();
            await GetEmployeeListRequest.SendGetEmployeeListRequest();

            uxEmployeeListView.ItemsSource = RealmManager.All <EmployeeList>().FirstOrDefault().employees.ToList();
            uxStatisticsButton.Click      += uxStatisticsButton_Clicked;
        }
Пример #8
0
        public async void RefreshEmployeeList()
        {
            RealmManager.RemoveAll <EmployeeList>();
            RealmManager.RemoveAll <Employee>();
            await GetEmployeeListRequest.SendGetEmployeeListRequest();

            await GetMenuItemsRequest.SendGetMenuItemsRequest();

            uxEmployeeListView.ItemsSource = RealmManager.All <EmployeeList>().FirstOrDefault().employees.ToList();
        }
Пример #9
0
        private async void UxClearComps_Click(object sender, RoutedEventArgs e)
        {
            foreach (Comp comp in RealmManager.All <CompList>().FirstOrDefault().comp)
            {
                await DeleteComp.SendDeleteComp(comp._id);
            }

            var validGetComps = await GetAllComps.SendGetAllCompsEmployee(selectedEmployee._id);

            uxCompListView.ItemsSource = await SyncCompData(RealmManager.All <CompList>().FirstOrDefault().comp);
        }
Пример #10
0
        private async void RefreshMenuItemList()
        {
            RealmManager.RemoveAll <MenuItemList>();
            RealmManager.RemoveAll <MenuItem>();
            var validGetMenuItemsRequest = await GetMenuItemsRequest.SendGetMenuItemsRequest();

            if (validGetMenuItemsRequest)
            {
                uxMenuItemListView.ItemsSource = RealmManager.All <MenuItemList>().FirstOrDefault().menuItems.ToList();
            }
        }
Пример #11
0
        private async void getRestrauntCoupons()
        {
            await GetCouponsRequest.SendGetCouponsRequest();

            for (int i = 0; i < RealmManager.All <CouponsList>().First().Coupons.Count(); i++)
            {
                if (RealmManager.All <CouponsList>().First().Coupons[i].couponType == "Restaurant")
                {
                    coupons.Add(new Coupon(RealmManager.All <CouponsList>().First().Coupons[i]));
                }
            }
        }
Пример #12
0
        //review was written. send review service request here
        private async void uxSubmitBtn_Clicked(object sender, EventArgs e)
        {
            string empID   = RealmManager.All <Order>().FirstOrDefault().employee_id;
            string orderID = RealmManager.All <Order>().FirstOrDefault()._id;
            await PostReviewRequest.SendPostReviewRequest(orderID, empID, Q1Rating, uxQ1UserReview.Text, Q2Rating, uxQ2UserReview.Text, Q3Rating, uxQ3UserReview.Text);


            await DisplayAlert("Sucess!", "Thanks for your review", "OK");

            //special type of pop out of page due to plugin
            await PopupNavigation.Instance.PopAllAsync();
        }
Пример #13
0
        private async Task DeleteComps(string id)
        {
            var validComp = await GetAllComps.SendAllCompsNoArgs();

            List <Comp> comps = RealmManager.All <Comps>().FirstOrDefault().comps.ToList();

            foreach (Comp comp in comps)
            {
                if (comp.menuItem_id == id)
                {
                    await DeleteComp.SendDeleteComp(comp._id);
                }
            }
        }
Пример #14
0
        private async void HomeClicked(object sender, EventArgs e)
        {
            Models.KidsLoc kt = RealmManager.All <Models.KidsLoc>().First();
            result = await DisplayPromptAsync("Pin", "Enter A Pin", initialValue : "", maxLength : 4, keyboard : Keyboard.Numeric);

            if (result == kt.Id || result == kt.Master)
            {
                await Navigation.PopAsync();
            }
            else
            {
                await DisplayAlert("Incorrect Pin", "Please Try Again", "ok");
            }
        }
Пример #15
0
        public void CheckOut_MenuItemsAdd()
        {
            Task.Run(() => GetMenuItemsRequest.SendGetMenuItemsRequest()).Wait();

            testMenuList = RealmManager.All <MenuList>().FirstOrDefault();

            OrderList testOrder = new OrderList();


            TabletApp.Models.MenuItem  testItem      = testMenuList.menuItems[0];
            TabletApp.Models.OrderItem testOrderItem = new OrderItem(testItem);
            testOrder.orderItems.Add(testOrderItem);

            Assert.AreEqual(testOrder.orderItems[0].name, "Dijktra's Jalenpeno Poppers");
        }
Пример #16
0
        public MainMenu()
        {
            InitializeComponent();

            _instance = this;

            uxTableNumButton.Text = "Table " + RealmManager.All <Table>().First().table_number;

            OnReturn();

            uxOrderButton.Clicked        += uxOrderButton_Clicked;
            uxPlayButton.Clicked         += UxPlayButton_Clicked;
            uxCallServerButton.Clicked   += uxCallServerButton_Clicked;
            uxRefillButton.Clicked       += uxRefillButton_Clicked;
            uxRefreshTableButton.Clicked += uxRefreshTableButton_Clicked;
        }
Пример #17
0
        private async void cpCheckoutButton_Clicked(object sender, EventArgs e)
        {
            if (checkOutOrder.orderItems.Count() == 0)
            {
                await DisplayAlert("No Items Selected", "Please select items to checkout", "OK");

                return;
            }

            await UpdateOrderMenuItemsRequest.SendUpdateOrderMenuItemsRequest(order._id, order.menuItems);

            tip = (cpTip.Text == "") ? 0f : Double.Parse(cpTip.Text);

            updateItems();

            MainMenu.OnReturn();

            await PostTipRequest.SendPostTipRequest(order.employee_id, tip);

            for (int i = 0; i < coupons.Count(); i++)
            {
                if (coupons[i].couponType == "Customer")
                {
                    await DeactivateCouponRequest.SendDeactivateCouponRequest(coupons[i]._id);
                }
            }

            bool orderComplete = true;

            await GetTableRequest.SendGetTableRequest(RealmManager.All <Table>().First().table_number);

            for (int i = 0; i < RealmManager.All <Table>().First().order_id.menuItems.Count(); i++)
            {
                if (!RealmManager.All <Table>().First().order_id.menuItems[i].paid && !RealmManager.All <Table>().First().order_id.menuItems[i].prepared)
                {
                    orderComplete = false;
                    break;
                }
            }

            if (orderComplete)
            {
                await FinishOrderRequest.SendFinishOrderRequest(RealmManager.All <Table>().First()._id);
            }

            await Navigation.PushAsync(new PaymentPage(totalPrice, tip));
        }
Пример #18
0
        public static async void OnReturn()
        {
            bool unpaid = false;

            await GetTableRequest.SendGetTableRequest(RealmManager.All <Table>().First().table_number);

            for (int i = 0; i < RealmManager.All <Table>().First().order_id.menuItems.Count(); i++)
            {
                if (!RealmManager.All <Table>().First().order_id.menuItems[i].paid)
                {
                    unpaid = true;
                    break;
                }
            }

            if (unpaid)
            {
                if (_instance.checkOutButton == null)
                {
                    _instance.checkOutButton = new Button()
                    {
                        Margin          = new Thickness(100, 0, 100, 0),
                        Padding         = new Thickness(0, 15, 0, 15),
                        Text            = "Pay Ticket",
                        FontSize        = 35,
                        FontAttributes  = FontAttributes.Bold,
                        TextColor       = Xamarin.Forms.Color.White,
                        CornerRadius    = 15,
                        BackgroundColor = Xamarin.Forms.Color.FromHex("#24BF87")
                    };

                    _instance.checkOutButton.Clicked += uxCheckOutButton_Clicked;

                    _instance.uxTitleButtonStack.Children.Add(_instance.checkOutButton);
                }
            }
            else
            {
                if (_instance.checkOutButton != null)
                {
                    _instance.uxTitleButtonStack.Children.Remove(_instance.checkOutButton);
                }

                _instance.checkOutButton = null;
            }
        }
Пример #19
0
        private async void UxIngredientsButton_Clicked(object sender, RoutedEventArgs e)
        {
            uxInfoPopup.IsOpen = true;
            uxIngredientInfoListView.Visibility = Visibility.Visible;

            if (Creating)
            {
                var successfulGetIngredientsRequest = await GetIngredientsRequest.SendGetIngredientsRequest();

                uxIngredientInfoListView.ItemsSource   = RealmManager.All <IngredientList>().FirstOrDefault().doc.ToList();
                uxIngredientInfoListView.SelectionMode = ListViewSelectionMode.Multiple;
            }
            else
            {
                uxIngredientInfoListView.ItemsSource = SelectedMenuItem.ingredients.ToList();
            }
        }
Пример #20
0
            public UxListViewModel(Dictionary <string, int> menuItemCount)
            {
                //initalizing class variable
                Data = new List <MenuItemPerformanceData>();

                //going through each menuItem and adding the count and object to the data property.
                foreach (MenuItem m in RealmManager.All <MenuItemList>().FirstOrDefault().menuItems)
                {
                    //creating tempary MenuItemPerformanceData with information passed and stored in xaml
                    MenuItemPerformanceData temp = new MenuItemPerformanceData
                    {
                        Name  = m.name,
                        Count = menuItemCount[m._id]
                    };

                    //adding temp to the list
                    Data.Add(temp);
                }
            }
Пример #21
0
        private async void foSubmitFoodButton_Clicked(object sender, EventArgs e)
        {
            if (fullOrder.orderItems.Count() != 0)
            {
                for (int i = 0; i < RealmManager.All <Table>().First().order_id.menuItems.Count(); i++)
                {
                    fullOrder.orderItems.Add(RealmManager.All <Table>().First().order_id.menuItems[i]);
                }

                await UpdateOrderMenuItemsRequest.SendUpdateOrderMenuItemsRequest(RealmManager.All <Table>().First().order_id._id, fullOrder.orderItems);

                RealmManager.RemoveAll <OrderList>();
                RealmManager.AddOrUpdate <OrderList>(new OrderList());

                MainMenu.OnReturn();

                await Navigation.PopAsync();
            }
        }
Пример #22
0
        public menuPage()
        {
            InitializeComponent();

            SetupMenuItems();

            _instance = this;

            OnReturn();

            if (RealmManager.All <OrderList>().Count() == 0)
            {
                RealmManager.AddOrUpdate <OrderList>(new OrderList());
            }

            mpViewOrderButton.Clicked += mpViewOrderButton_Clicked;

            mpRefillButton.Clicked     += mpRefillButton_Clicked;
            mpCallServerButton.Clicked += mpCallServerButton_Clicked;
        }
Пример #23
0
        private void UpdateOrder()
        {
            OrderList order = new OrderList();

            for (int i = 0; i < RealmManager.All <OrderList>().First().orderItems.Count(); i++)
            {
                OrderItem oldItem = RealmManager.All <OrderList>().First().orderItems[i];

                order.orderItems.Add(oldItem);
            }

            OrderItem newItem = new OrderItem(menuItem);

            newItem.special_instruct = miItemSpecialInstructions.Text;

            order.orderItems.Add(newItem);

            RealmManager.RemoveAll <OrderList>();
            RealmManager.AddOrUpdate <OrderList>(order);
        }
Пример #24
0
        private async void cpAddCouponButton_Clicked(object sender, EventArgs e)
        {
            string input = "";

            input = await DisplayPromptAsync("Coupon Code", "You agknowledge by entering this coupon code that the coupon will be applied whether or not the items in question are being payed for or not.", "OK", "Cancel", null, -1, null, "");

            RealmManager.RemoveAll <Coupon>();
            await GetCouponsByIDRequest.SendGetCouponsByIDRequest(input);

            if (RealmManager.All <Coupon>().Count() == 0)
            {
                await DisplayAlert("Coupon Code Invalid", "", "OK");
            }
            else
            {
                await DisplayAlert("Your coupon has been activated", "To see it take effect toggle or re-toggle the items in question", "OK");

                Coupon coupon = RealmManager.All <Coupon>().First();

                coupons.Add(coupon);
            }
        }
Пример #25
0
        private async void UpdateHotItem()
        {
            //initalizing last week date
            DateTime td            = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek); //sets td to the beginning of the week
            DateTime lastWeekStart = new DateTime(td.Year, td.Month, td.Day, 0, 0, 0).AddDays(-7);



            //Checking if hotItem are still up to date
            if (RealmManager.All <HotItem>().FirstOrDefault() != null)
            {
                //getting last time hot items have been updated
                DateTime lastUpdated = DateTime.Parse(RealmManager.All <HotItem>().FirstOrDefault().createdAt);

                if (DateTime.Compare(lastWeekStart, lastUpdated) == 0)
                {
                    //return;
                }
            }

            RealmManager.RemoveAll <OrderList>();
            RealmManager.RemoveAll <MenuItemList>();
            List <MenuItem> somelist = new List <MenuItem>();
            //finding each distinct category and adding it
            await GetOrdersRequest.SendGetOrdersRequest();

            await GetMenuItemsRequest.SendGetMenuItemsRequest();

            //creating a list of every menu item id for each order including duplicates
            List <OrderItem> menuItemIds = new List <OrderItem>();
            //creating a dictionary to keep track of the count of each menuItem
            Dictionary <String, Dictionary <MenuItem, int> > menuItemCounter = new Dictionary <String, Dictionary <MenuItem, int> >();

            foreach (Order o in RealmManager.All <OrderList>().FirstOrDefault().orders)
            {
                //this will ignore all uncompleted orders
                if (o.time_completed == null)
                {
                    continue;
                }


                DateTime orderTime = DateTime.ParseExact(o.time_completed.Replace('T', ' ').TrimEnd('Z'), "yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture);

                //Makes it easier for keying the revenue map by WEEK
                orderTime = orderTime.AddDays(-(int)orderTime.DayOfWeek);
                orderTime = new DateTime(orderTime.Year, orderTime.Month, orderTime.Day, 0, 0, 0);

                //only added menuItems from orders for the current month
                if (DateTime.Compare(lastWeekStart, orderTime) == 0)
                {
                    foreach (OrderItem oi in o.menuItems)
                    {
                        menuItemIds.Add(oi); //add next menuitem id
                    }
                }
            }

            List <MenuItem> tempList = RealmManager.All <MenuItem>().ToList();

            //updating menuItem map to see how often each was ordered
            foreach (OrderItem o in menuItemIds)
            {
                MenuItem tempMenuItem = tempList.Find(x => x._id == o._id);
                if (tempMenuItem == null)
                {
                    continue;
                }
                if (menuItemCounter.ContainsKey(tempMenuItem.category))
                {
                    try
                    {
                        menuItemCounter[tempMenuItem.category][tempMenuItem] = menuItemCounter[tempMenuItem.category][tempMenuItem] + 1;
                    }
                    catch
                    {
                        menuItemCounter[tempMenuItem.category].Add(tempMenuItem, 1);
                    }
                }
                else
                {
                    menuItemCounter[tempMenuItem.category] = new Dictionary <MenuItem, int> {
                        { tempMenuItem, 1 }
                    };
                }
            }
            foreach (string key in menuItemCounter.Keys)
            {
                KeyValuePair <MenuItem, int> topMenuItem;
                //finding the top menuItem for each category
                topMenuItem = menuItemCounter[key].Aggregate((x, y) => x.Value > y.Value ? x : y);
                //grabbing what was the top menuItem in the category from the previous week
                HotItem tempItem = RealmManager.Find <HotItem>(topMenuItem.Key.category);

                //if hotitem is in realm yet
                if (tempItem == null)
                {
                    //creating new hotitem object
                    HotItem tempHotItem = new HotItem();
                    tempHotItem.category  = topMenuItem.Key.category;
                    tempHotItem.createdAt = lastWeekStart.ToString();
                    tempHotItem._id       = topMenuItem.Key._id;

                    //getting menuItem object from list using hotItem
                    MenuItem tempMenuItem = tempList.Find(x => x._id == topMenuItem.Key._id);
                    RealmManager.Write(() => tempMenuItem.isHot = true);

                    //updating database
                    var response = await UpdateHotItemRequest.SendUpdateMenuItemRequest(tempMenuItem);

                    //updaing realm
                    RealmManager.AddOrUpdate <HotItem>(tempHotItem);
                    if (!response)
                    {
                        ContentDialog responseAlert = new ContentDialog
                        {
                            Title           = "Unsuccessful",
                            Content         = "Hot Item has not been updated successfully",
                            CloseButtonText = "Ok"
                        };
                        ContentDialogResult result = await responseAlert.ShowAsync();
                    }
                }
                else
                {
                    //if the hot item is infact new
                    if (tempItem._id != topMenuItem.Key._id)
                    {
                        //finding old hotitem menuItem object
                        MenuItem oldMenuItem = tempList.Find(x => x._id == tempItem._id);
                        RealmManager.Write(() => oldMenuItem.isHot = false);

                        //updating old hotItem in database
                        var Firstresponse = await UpdateHotItemRequest.SendUpdateMenuItemRequest(oldMenuItem);

                        if (!Firstresponse)
                        {
                            ContentDialog responseAlert = new ContentDialog
                            {
                                Title           = "Unsuccessful",
                                Content         = "Original hot item has not been updated successfully",
                                CloseButtonText = "Ok"
                            };
                            ContentDialogResult result = await responseAlert.ShowAsync();
                        }

                        //finding new menuItem object using new hotItem
                        MenuItem newMenuItem = tempList.Find(x => x._id == topMenuItem.Key._id);
                        RealmManager.Write(() => newMenuItem.isHot = true);
                        var Secondresponse = await UpdateHotItemRequest.SendUpdateMenuItemRequest(newMenuItem);

                        //updating hot item in realm to match new hot Item
                        RealmManager.Write(() =>
                        {
                            tempItem._id       = topMenuItem.Key._id;
                            tempItem.createdAt = lastWeekStart.ToString();
                        });

                        if (!Secondresponse)
                        {
                            ContentDialog responseAlert = new ContentDialog
                            {
                                Title           = "Unsuccessful",
                                Content         = "Hot Item has not been updated successfully",
                                CloseButtonText = "Ok"
                            };
                            ContentDialogResult result = await responseAlert.ShowAsync();
                        }
                    }
                }
            }
            ContentDialog responseAlertCheck = new ContentDialog
            {
                Title           = "Successful",
                Content         = "Hot Items have been updated successfully",
                CloseButtonText = "Ok"
            };
            ContentDialogResult resultCheck = await responseAlertCheck.ShowAsync();
        }
Пример #26
0
 private async void mpViewOrderButton_Clicked(object sender, EventArgs e)
 {
     await Navigation.PushAsync(new fullOrderPage(RealmManager.All <OrderList>().First()));
 }
Пример #27
0
        private static async void uxCheckOutButton_Clicked(object sender, EventArgs e)
        {
            await GetTableRequest.SendGetTableRequest(RealmManager.All <Table>().First().table_number);

            await _instance.Navigation.PushAsync(new CheckoutPage());
        }
Пример #28
0
        async void SetupMenuItems()
        {
            await GetMenuItemsRequest.SendGetMenuItemsRequest();

            await GetIngredientsRequest.SendGetIngredientsRequest();

            IngredientList ingredientList = new IngredientList();

            for (int i = 0; i < RealmManager.All <IngredientList>().First().doc.Count(); i++)
            {
                ingredientList.doc.Add(RealmManager.All <IngredientList>().First().doc[i]);
            }

            for (int i = 0; i < RealmManager.All <MenuList>().First().menuItems.Count(); i++)
            {
                Models.MenuItem currItem = RealmManager.All <MenuList>().First().menuItems[i];

                bool available = true;

                for (int j = 0; j < currItem.ingredients.Count(); j++)
                {
                    IList <Ingredient> ingredients = ingredientList.doc.Where((Ingredient ing) => (ing._id == currItem.ingredients[j]._id)).ToList <Ingredient>();

                    for (int k = 0; k < ingredients.Count(); k++)
                    {
                        if (ingredients[k].quantity == 0)
                        {
                            available = false;
                            break;
                        }
                    }

                    if (!available)
                    {
                        break;
                    }
                }

                if (!available)
                {
                    continue;
                }

                Button newButton = new Button()
                {
                    Text            = currItem.name,
                    Margin          = new Thickness(30, 0, 30, 15),
                    FontSize        = 20,
                    WidthRequest    = 100,
                    FontAttributes  = FontAttributes.Bold,
                    TextColor       = Xamarin.Forms.Color.White,
                    CornerRadius    = 15,
                    BackgroundColor = Xamarin.Forms.Color.FromHex("#24BF87"),
                };

                newButton.Clicked += async(sender, args) => await Navigation.PushAsync(new menuItemPage(currItem));

                if (currItem.category == "Entrees")
                {
                    entreeScroll.Children.Add(newButton);
                }
                else if (currItem.category == "Appetizers")
                {
                    appScroll.Children.Add(newButton);
                }
                else if (currItem.category == "Kids Meals")
                {
                    kidsScroll.Children.Add(newButton);
                }
                else if (currItem.category == "Drinks")
                {
                    drinkScroll.Children.Add(newButton);
                }
                else if (currItem.category == "Sides")
                {
                    sideScroll.Children.Add(newButton);
                }
                else if (currItem.category == "Desserts")
                {
                    dessertScroll.Children.Add(newButton);
                }
                else if (currItem.category == "$5 Meal Deals")
                {
                    fiveMealScroll.Children.Add(newButton);
                }
                else
                {
                    otherScroll.Children.Add(newButton);
                }
            }
        }
Пример #29
0
        private async void KPIComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // this is the selections on the combo box
            string viewSelection = e.AddedItems[0].ToString();

            //excutes if the GET order request returns back okay
            if (await GetOrdersRequest.SendGetOrdersRequest() && await GetMenuItemsRequest.SendGetMenuItemsRequest())
            {
                //creating a dictionary to keep track of the count of each menuItem
                Dictionary <String, int> menuItemCounter = new Dictionary <String, int>();
                foreach (MenuItem m in RealmManager.All <MenuItemList>().FirstOrDefault().menuItems)
                {
                    menuItemCounter.Add(m._id, 0);
                }

                //will keep track of revenue made yearly, monthly and weekly
                Dictionary <DateTime, int> revenueCalendar = new Dictionary <DateTime, int>();

                //creating a list of every menu item id for each order including duplicates
                List <string> menuItemIds = new List <string>();

                //Will store a date and the number of orders
                Dictionary <DateTime, int> orderCount = new Dictionary <DateTime, int>();

                //figuring out which view needs to be populated
                switch (viewSelection)
                {
                //MONTHLY VIEW
                case "Current Weekly View":
                    if (await DisplayWeeklyViewAsync(menuItemCounter, revenueCalendar, menuItemIds, orderCount))
                    {
                        break;
                    }
                    else
                    {
                        //Error handling
                        ContentDialog responseAlert = new ContentDialog
                        {
                            Title           = "Weekly View Error",
                            Content         = "Something went wrong with the selection.",
                            CloseButtonText = "Ok"
                        };
                        ContentDialogResult result = await responseAlert.ShowAsync();

                        break;
                    }


                //WEEKLY VIEW
                case "Current Monthly View":
                    if (await DisplayMonthlyViewAsync(menuItemCounter, revenueCalendar, menuItemIds, orderCount))
                    {
                        break;
                    }
                    else
                    {
                        //Error handling
                        ContentDialog responseAlert = new ContentDialog
                        {
                            Title           = "Monthly View Error",
                            Content         = "Something went wrong with the selection.",
                            CloseButtonText = "Ok"
                        };
                        ContentDialogResult result = await responseAlert.ShowAsync();

                        break;
                    }

                //YEARLY VIEW
                case "Current Yearly View":
                    if (await DisplayYearlyViewAsync(menuItemCounter, revenueCalendar, menuItemIds, orderCount))
                    {
                        break;
                    }
                    else
                    {
                        //Error handling
                        ContentDialog responseAlert = new ContentDialog
                        {
                            Title           = "Yearly View Error",
                            Content         = "Something went wrong with the selection.",
                            CloseButtonText = "Ok"
                        };
                        ContentDialogResult result = await responseAlert.ShowAsync();

                        break;
                    }
                }
            }
            else
            {
                //Error handling
                ContentDialog responseAlert = new ContentDialog
                {
                    Title           = "Combobox Error",
                    Content         = "Something went wrong with the selection.",
                    CloseButtonText = "Ok"
                };
                ContentDialogResult result = await responseAlert.ShowAsync();
            }
        }
Пример #30
0
        //YEARLY VIEW
        public async System.Threading.Tasks.Task <bool> DisplayYearlyViewAsync(Dictionary <String, int> menuItemCounter, Dictionary <DateTime, int> revenueCalendar, List <string> menuItemIds, Dictionary <DateTime, int> orderCount)
        {
            //String that will store the most popular item id
            string mostPopularMenuItemId;

            foreach (Order o in RealmManager.All <OrderList>().FirstOrDefault().orders)
            {
                //this will ignore all uncompleted orders
                if (o.time_completed == null)
                {
                    continue;
                }

                //initalize this month and last month
                DateTime td        = DateTime.Today;
                DateTime weekStart = new DateTime(td.Year, 1, 1, 0, 0, 0);
                DateTime orderTime = DateTime.ParseExact(o.time_completed.Replace('T', ' ').TrimEnd('Z'), "yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture);;

                //makeing it easier to key the revenue map by MONTH
                orderTime = new DateTime(orderTime.Year, orderTime.Month, 1, 0, 0, 0);



                //only added menuItems from orders for the current week
                if (DateTime.Compare(weekStart, orderTime) < 0)
                {
                    //adding a key and setting it to 0 if it doesn't exist
                    try
                    {
                        if (revenueCalendar[orderTime] == 0)
                        {
                        }
                    }
                    catch
                    {
                        orderCount[orderTime]      = 0;
                        revenueCalendar[orderTime] = 0;
                    }
                    //incrementing order count every order
                    orderCount[orderTime] = orderCount[orderTime] + 1;
                    foreach (OrderItem oi in o.menuItems)
                    {
                        menuItemIds.Add(oi._id);                                                             //add next menuitem id
                        revenueCalendar[orderTime] = revenueCalendar[orderTime] + Convert.ToInt32(oi.price); //adding price of new menuitem
                    }
                }
            }
            //updating menuItem map to see how often each was ordered
            foreach (string id in menuItemIds)
            {
                try
                {
                    menuItemCounter[id] = menuItemCounter[id] + 1;
                }
                catch
                {
                    continue;
                }
            }

            //finding the largest value and storing the key
            mostPopularMenuItemId = menuItemCounter.Aggregate((x, y) => x.Value > y.Value ? x : y).Key; //Getting the most popular menuItem of the YEAR

            //this will only generate the charts once. After that the values you have been bound.
            if (yearlyDisplayed == false)
            {
                UxYearlyCharts(menuItemCounter, revenueCalendar, orderCount);
                yearlyDisplayed = true;
            }

            //finding in Realm, the most popular id
            MenuItem tempMenuItem = RealmManager.All <MenuItemList>().FirstOrDefault().menuItems.Where(x => x._id == mostPopularMenuItemId).FirstOrDefault();

            YearlyPicture.Source = await ImageConverter.ConvertBase64ToImageSource(tempMenuItem.picture);

            YearlyTopItem.Text = tempMenuItem.name;

            //makeing the other grids hidden
            uxMonthlyViewGrid.Visibility = Visibility.Collapsed;
            uxWeeklyViewGrid.Visibility  = Visibility.Collapsed;
            uxYearlyViewGrid.Visibility  = Visibility.Visible;

            return(true);
        }