예제 #1
0
        public GameStoreViewModel(IDispatcherService dispatcherService, string functionTag,
                                  IDialogService dialogService, ScoreInfoService scoreInfoService, GoodsService goodsService) : base(dispatcherService, functionTag)
        {
            _dialogService    = dialogService;
            _scoreInfoService = scoreInfoService;
            _goodsService     = goodsService;

            DataGridItemChanged = new RelayCommand <DataGridItemChangedEventArgs>(OnDataGridItemChanged);

            RefreshList = new RelayCommand(PrivateRefreshList);

            RemoveItem = new RelayCommand(() =>
            {
                if (_dialogService.ShowOKCancel("确定删除选中数据吗?"))
                {
                    _ = _goodsService.RemoveAsync(SelectedItem);
                    GoodsItems.Remove(SelectedItem);
                }
            }, () => { return(SelectedItem != null); });

            RemoveAll = new RelayCommand(() =>
            {
                if (_dialogService.ShowOKCancel("确定删除所有数据吗?"))
                {
                    _          = _goodsService.RemoveAllAsync();
                    GoodsItems = null;
                }
            }, () => { return(GoodsItems != null); });

            AddData = new RelayCommand(() =>
            {
                if (string.IsNullOrEmpty(BuyCmd))
                {
                    _dialogService.ShowInformation("购买命令不能为空");
                    return;
                }
                if (GoodsItems.FirstOrDefault(p => p.BuyCmd == BuyCmd) != null)
                {
                    _dialogService.ShowInformation("购买命令重复");
                    return;
                }

                var dto = new GoodsDto()
                {
                    GoodsName = GoodsName,
                    BuyCmd    = BuyCmd,
                    Content   = Content,
                    Amount    = Amount,
                    Quality   = Quality,
                    Price     = Price,
                    GoodsType = GoodsType
                };
                _ = _goodsService.AddAsync(dto);
                GoodsItems.Add(dto);
            });

            AddAvailableVariables();

            PrivateRefreshList();
        }
예제 #2
0
        private void OnDataGridItemChanged(DataGridItemChangedEventArgs eventArgs)
        {
            if (eventArgs.IsChanged == false)
            {
                return;
            }

            if (eventArgs.NewItem is GoodsDto newItem && eventArgs.OldItem is GoodsDto oldItem)
            {
                if (GoodsItems.FirstOrDefault(p => p.BuyCmd == newItem.BuyCmd && object.Equals(p, newItem) == false) != null)
                {
                    _dialogService.ShowInformation("购买命令重复");
                    newItem.BuyCmd = oldItem.BuyCmd;// 此时新值还未更新至ui
                }
                else
                {
                    _ = _goodsService.UpdateAsync(newItem);
                }
            }
        }