Ejemplo n.º 1
0
        //Refresh the page every 10 seconds
        public async Task AutoRefreshEnabled()
        {
            while (true)
            {
                uxReceivedOrdersControl0.IsEnabled = false;
                uxReceivedOrdersControl1.IsEnabled = false;
                uxReceivedOrdersControl2.IsEnabled = false;
                uxReceivedOrdersControl4.IsEnabled = false;
                var validSendGetOrdersRequest = await GetOrdersRequest.SendGetOrdersRequest();

                RefreshItemSource();
                uxReceivedOrdersControl0.IsEnabled = true;
                uxReceivedOrdersControl1.IsEnabled = true;
                uxReceivedOrdersControl2.IsEnabled = true;
                uxReceivedOrdersControl4.IsEnabled = true;
                await Task.Delay(TimeSpan.FromSeconds(10));
            }
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
        private async void GetReviewContext()
        {
            var validGetReviews = await GetReviews.SendGetReviews();

            await GetOrdersRequest.SendGetOrdersRequest();

            if (validGetReviews)
            {
                var reviewList = RealmManager.All <ReviewList>().FirstOrDefault().reviews;
                ReviewStatList = new ReviewStatList(reviewList);

                uxOverallReviewList.ItemsSource   = ReviewStatList.OverallReviewStats;
                uxWaitstaffReviewList.ItemsSource = ReviewStatList.WaitstaffReviewStats;
                uxFoodReviewList.ItemsSource      = ReviewStatList.FoodReviewStats;

                uxScore1ReviewNumber.Text = "Dijkstra's Average Rating: " + ReviewStatList.Average1.ToString() + " Stars";

                if (ReviewStatList.Average1 <= 1)
                {
                    uxScore1Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore1Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore1Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore1Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average1 > 1 && ReviewStatList.Average1 <= 2)
                {
                    uxScore1Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore1Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore1Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average1 > 2 && ReviewStatList.Average1 <= 3)
                {
                    uxScore1Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore1Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average1 > 3 && ReviewStatList.Average1 <= 4)
                {
                    uxScore1Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average1 > 4 && ReviewStatList.Average1 <= 5)
                {
                    uxScore1Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore1Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                }

                uxScore2ReviewNumber.Text = "Dijkstra's Average Rating: " + ReviewStatList.Average2.ToString() + " Stars";

                if (ReviewStatList.Average2 <= 1)
                {
                    uxScore2Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore2Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore2Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore2Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average2 > 1 && ReviewStatList.Average2 <= 2)
                {
                    uxScore2Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore2Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore2Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average2 > 2 && ReviewStatList.Average2 <= 3)
                {
                    uxScore2Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore2Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average2 > 3 && ReviewStatList.Average2 <= 4)
                {
                    uxScore2Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average2 > 4 && ReviewStatList.Average2 <= 5)
                {
                    uxScore2Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore2Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                }

                uxScore3ReviewNumber.Text = "Dijkstra's Average Rating: " + ReviewStatList.Average3.ToString() + " Stars";

                if (ReviewStatList.Average3 <= 1)
                {
                    uxScore3Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore3Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore3Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore3Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average3 > 1 && ReviewStatList.Average3 <= 2)
                {
                    uxScore3Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore3Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore3Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average3 > 2 && ReviewStatList.Average3 <= 3)
                {
                    uxScore3Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                    uxScore3Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average3 > 3 && ReviewStatList.Average3 <= 4)
                {
                    uxScore3Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/greyStar.png"));
                }
                if (ReviewStatList.Average3 > 4 && ReviewStatList.Average3 <= 5)
                {
                    uxScore3Star1.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star2.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star3.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star4.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                    uxScore3Star5.Source = new BitmapImage(new Uri("ms-appx:///Assets/goldStar.png"));
                }
            }
        }