Exemplo n.º 1
0
        public async Task LoadDescriptionsAsync()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

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

            StorageFile file = await picker.PickSingleFileAsync();

            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            using (StreamReader sr = new StreamReader(stream.AsStreamForRead()))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();

                    if (line[0] == '0')
                    {
                        var val = line.Split('\t');

                        if (val[4] == "1")
                        {
                            int     id   = Int32.Parse(val[1]);
                            BdoItem item = BdoDataService.GetItemById(id);

                            if (item != null)
                            {
                                string description = val[5].Trim('\"');
                                item.Description = description;

                                BdoDataService.UpdateItem(item);
                                BdoDataService.Commit();
                            }
                        }
                    }
                    else if (line.StartsWith("34"))
                    {
                        var val = line.Split('\t');

                        if (val[4] == "1")
                        {
                            BdoItem item = BdoDataService.GetItemsByKnowledge($"theme--{val[1]}")?.FirstOrDefault();


                            if (item != null)
                            {
                                string knowledge = val[5].Trim('\"');
                                item.Knowledge = knowledge;

                                BdoDataService.UpdateItem(item);
                                BdoDataService.Commit();
                            }
                        }
                    }
                }
            }
            await LoadDataAsync();
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
        public async Task LoadItemsAsync()
        {
            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);

            List <BdoItem> items = await Json.ToObjectAsync <List <BdoItem> >(jsonText);

            foreach (var item in items)
            {
                BdoItem bdoItem = BdoDataService.GetItemById(item.Id);
                if (bdoItem == null)
                {
                    BdoDataService.AddItem(item);
                }
                else
                {
                    bdoItem.Name        = item.Name;
                    bdoItem.Grade       = item.Grade;
                    bdoItem.Img         = item.Img;
                    bdoItem.Description = item.Description;
                    bdoItem.Category    = item.Category;
                    bdoItem.Weight      = item.Weight;
                    bdoItem.ItemGroupId = item.ItemGroupId;
                    bdoItem.BuyPrice    = item.BuyPrice;
                    bdoItem.SellPrice   = item.SellPrice;
                    bdoItem.Knowledge   = item.Knowledge;

                    BdoDataService.UpdateItem(bdoItem);
                }
                BdoDataService.Commit();
            }

            await LoadDataAsync();
        }