示例#1
0
        private void LoadMaterials()
        {
            Materials.Clear();
            Results.Clear();
            var materials = BdoDataService.GetRecipeMatsByRecipeID(SelectedRecipe.Id);

            foreach (var material in materials)
            {
                if (material.IsItem)
                {
                    material.Item = BdoDataService.GetItemById(material.ItemId.Value);
                    Materials.Add(new RecipeMaterialModel
                    {
                        Name   = material.Item.Name,
                        Img    = material.Item.Img,
                        Grade  = material.Item.Grade,
                        IsItem = true,
                        Id     = material.Item.Id,
                        Amount = material.Amount
                    });
                }
                else
                {
                    //Item Group
                    material.ItemGroup = BdoDataService.GetItemGroupById(material.ItemGroupId.Value);
                    BdoItem item = BdoDataService.FirstItemFromItemGroup(material.ItemGroupId.Value);
                    Materials.Add(new RecipeMaterialModel
                    {
                        Name   = material.ItemGroup.Name,
                        Img    = material.ItemGroup.Items[0].Img,
                        Grade  = ItemGrade.White,
                        IsItem = false,
                        Id     = material.ItemGroup.Id,
                        Amount = material.Amount
                    });
                }
            }

            BdoItem result0 = BdoDataService.GetItemById(SelectedRecipe.Item1Id.Value);

            Results.Add(result0);

            if (SelectedRecipe.Item2Id.HasValue)
            {
                BdoItem result1 = BdoDataService.GetItemById(SelectedRecipe.Item2Id.Value);
                Results.Add(result1);
            }

            NotifyOfPropertyChange(() => Materials);
            NotifyOfPropertyChange(() => Results);
        }
示例#2
0
        public async Task LoadItemGroups()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            picker.FileTypeFilter.Add(".json");

            StorageFile file = await picker.PickSingleFileAsync();

            string jsonText = await FileIO.ReadTextAsync(file);

            var itemGroups = await Json.ToObjectAsync <List <ItemGroup> >(jsonText);

            foreach (var itemGroup in itemGroups)
            {
                ItemGroup dbitemgroup = BdoDataService.GetItemGroupById(itemGroup.Id);
                if (dbitemgroup != null)
                {
                    continue;
                }

                BdoDataService.AddItemGroup(new ItemGroup
                {
                    Id   = itemGroup.Id,
                    Name = itemGroup.Name
                });

                BdoDataService.Commit();

                foreach (var item in itemGroup.Items)
                {
                    var dbItem = BdoDataService.GetItemById(item.Id);

                    if (dbItem == null)
                    {
                        item.ItemGroupId = itemGroup.Id;
                        BdoDataService.AddItem(item);
                    }
                    else
                    {
                        dbItem.ItemGroupId = itemGroup.Id;
                        BdoDataService.UpdateItem(dbItem);
                    }

                    BdoDataService.Commit();
                }
            }
            await LoadDataAsync();
        }