private void Collected(object sender, RoutedEventArgs e)
        {
            if (!UserManagement.GetInstance().returnMain)
            {
                return;
            }
            //查找该项目的位置
            var instance = SampleDataService.GetInstance();
            int pos      = 0;;
            int id       = MasterMenuItem.OrderId;

            for (int i = 0; i < instance.allItems.Count; i++)
            {
                if (id == instance.allItems[i].OrderId)
                {
                    pos = i;
                    break;
                }
            }
            //赞+1并添加到数据库。新建实例以防止Ordered变量被修改
            instance.allItems[pos].Collected++;
            SampleOrder newOne = instance.allItems[pos];

            newOne.Ordered = 0;
            SampleOrderSQLManagement.GetInstance().update(newOne);
            //防止重复点赞
            UserManagement.GetInstance().returnMain = false;
        }
Example #2
0
        public void UpdateTile()
        {
            TileUpdateManager.CreateTileUpdaterForApplication().Clear();
            SampleOrderSQLManagement.GetInstance().GetAll();
            ObservableCollection <SampleOrder> all_item = new ObservableCollection <SampleOrder>();

            for (int i = 0; i < SampleOrderSQLManagement.GetInstance().allItems.Count; ++i)
            {
                all_item.Add(SampleOrderSQLManagement.GetInstance().allItems[i]);
            }
            for (int i = 0; i < all_item.Count; i++)
            {
                for (int j = i + 1; j < all_item.Count; j++)
                {
                    if (all_item[i].Collected < all_item[j].Collected)
                    {
                        SampleOrder tmp = all_item[i];
                        all_item[i] = all_item[j];
                        all_item[j] = tmp;
                    }
                }
            }
            int count = all_item.Count >= 10 ? 10 : all_item.Count;

            for (int i = 0; i < count; i++)
            {
                createTile(all_item[i]);
            }
        }
Example #3
0
 //根据字符串查找相符合的菜品
 private void GetItemsAccordingToString(String str, ObservableCollection <SampleOrder> collection)
 {
     SampleOrderSQLManagement.GetInstance().queryItem(str);
     for (int i = 0; i < SampleOrderSQLManagement.GetInstance().allItems.Count; ++i)
     {
         collection.Add(SampleOrderSQLManagement.GetInstance().allItems[i]);
     }
 }
Example #4
0
 //根据访问量对ObservableCollection进行排序
 private void SortObservableCollectionByVisited()
 {
     tmpItems.Clear();
     SampleOrderSQLManagement.GetInstance().GetAll();
     for (int i = 0; i < SampleOrderSQLManagement.GetInstance().allItems.Count; ++i)
     {
         tmpItems.Add(SampleOrderSQLManagement.GetInstance().allItems[i]);
     }
     //冒泡排序
     for (int i = 0; i < tmpItems.Count; i++)
     {
         for (int j = i + 1; j < tmpItems.Count; j++)
         {
             if (tmpItems[i].Visited < tmpItems[j].Visited)
             {
                 SampleOrder tmp = tmpItems[i];
                 tmpItems[i] = tmpItems[j];
                 tmpItems[j] = tmp;
             }
         }
     }
 }
Example #5
0
 //根据点赞数量对ObservableCollection进行排序
 private void SortObservableCollectionByCollected()
 {
     mainPageViewItems.Clear();
     //从数据库中获得所有菜品数据
     SampleOrderSQLManagement.GetInstance().GetAll();
     for (int i = 0; i < SampleOrderSQLManagement.GetInstance().allItems.Count; ++i)
     {
         mainPageViewItems.Add(SampleOrderSQLManagement.GetInstance().allItems[i]);
     }
     //冒泡排序
     for (int i = 0; i < mainPageViewItems.Count; i++)
     {
         for (int j = i + 1; j < mainPageViewItems.Count; j++)
         {
             if (mainPageViewItems[i].Collected < mainPageViewItems[j].Collected)
             {
                 SampleOrder tmp = mainPageViewItems[i];
                 mainPageViewItems[i] = mainPageViewItems[j];
                 mainPageViewItems[j] = tmp;
             }
         }
     }
 }
        private async void AddToCart(object sender, RoutedEventArgs e)
        {
            //去重
            int currentID = MasterMenuItem.OrderId;

            for (int i = 0; i < UserDataService.GetInstance()._current.SampleItems.Count; ++i)
            {
                if (UserDataService.GetInstance()._current.SampleItems[i].OrderId == currentID)
                {
                    if (UserDataService.GetInstance()._current.SampleItems[i].Ordered == 99)
                    {
                        //数量到达上限
                        ContentDialog FailedAdd = new ContentDialog()
                        {
                            Title             = "添加错误",
                            Content           = "菜品\"" + MasterMenuItem.OrderName + "\"已经存在购物车中,数量大于上限99",
                            PrimaryButtonText = "好"
                        };
                        ContentDialogResult response = await FailedAdd.ShowAsync();
                    }
                    else
                    {
                        //数量加上1
                        ContentDialog NumAdd = new ContentDialog()
                        {
                            Title             = "添加到购物车",
                            Content           = "菜品\"" + MasterMenuItem.OrderName + "\"已经存在购物车中,数量加1",
                            PrimaryButtonText = "好"
                        };
                        UserDataService.GetInstance()._current.SampleItems[i].Ordered++;
                        Calculate();
                        ContentDialogResult response = await NumAdd.ShowAsync();
                    }
                    return;
                }
            }
            //增加访问量
            var instance = SampleDataService.GetInstance();
            int pos      = 0;
            int id       = MasterMenuItem.OrderId;

            for (int i = 0; i < instance.allItems.Count; i++)
            {
                if (id == instance.allItems[i].OrderId)
                {
                    pos = i;
                    break;
                }
            }
            //赞+1并添加到数据库
            instance.allItems[pos].Visited++;
            SampleOrder newOne = instance.allItems[pos];

            newOne.Ordered = 0;
            SampleOrderSQLManagement.GetInstance().update(newOne);

            //正常添加购物车
            MasterMenuItem.Ordered++;
            UserDataService.GetInstance()._current.SampleItems.Add(MasterMenuItem);
            ContentDialog SuccessAdd = new ContentDialog()
            {
                Title             = "添加到购物车",
                Content           = "已将\"" + MasterMenuItem.OrderName + "\"添加到购物车",
                PrimaryButtonText = "好"
            };

            Calculate();
            ContentDialogResult result = await SuccessAdd.ShowAsync();
        }