public void MonthProductChange(string item)
        {
            int index = MonthRevenueLabels.IndexOf(item);
            ObservableCollection <string[]> result = AdvancedQuery.GetProductRevenue(revenue_month[index], revenue_year[index]);

            ProductSeries.Clear();
            // Debug log
            for (int i = 0; i < result.Count; i++)
            {
                ProductSeries.Add
                (
                    new PieSeries
                {
                    Title  = result[i][1] + " (" + result[i][2] + ")",
                    Values = new ChartValues <ObservableValue> {
                        new ObservableValue(Double.Parse(result[i][3]))
                    },
                    DataLabels = true
                }
                );
            }
        }
示例#2
0
        public SelectProductPageViewModel(INavigationService navigationService,
                                          IProductService productService,
                                          IDialogService dialogService) : base(navigationService, dialogService)
        {
            Title = "选择商品";

            _navigationService = navigationService;
            _dialogService     = dialogService;
            _productService    = productService;

            //只显库存商品
            this.WhenAnyValue(x => x.UsableQuantity)
            .Skip(1)
            .Subscribe(s =>
            {
                ((ICommand)Load)?.Execute(null);
                this.ForceRefresh = true;
            }).DisposeWith(DeactivateWith);

            //我的收藏
            this.WhenAnyValue(x => x.UsableFavorite)
            .Skip(1)
            .Subscribe(s =>
            {
                ((ICommand)Load)?.Execute(null);
                this.ForceRefresh = true;
            }).DisposeWith(DeactivateWith);

            //搜索
            this.WhenAnyValue(x => x.Filter.SerchKey)
            .Where(s => !string.IsNullOrEmpty(s))
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(2), RxApp.MainThreadScheduler)
            .Subscribe(s =>
            {
                ((ICommand)SerchCommand)?.Execute(s);
            }).DisposeWith(DeactivateWith);

            this.SerchCommand = ReactiveCommand.Create <string>(e =>
            {
                if (string.IsNullOrEmpty(Filter.SerchKey))
                {
                    this.Alert("请输入关键字!");
                    return;
                }
                ((ICommand)Load)?.Execute(null);
            });

            //Load
            this.Load = ReactiveCommand.Create(async() =>
            {
                try
                {
                    ItemTreshold   = 1;
                    DataVewEnable  = false;
                    NullViewEnable = true;

                    var items = await GetProductsPage(0, 50);
                    if (items != null && items.Any())
                    {
                        //清除列表
                        ProductSeries?.Clear();
                        foreach (var item in items)
                        {
                            if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0)
                            {
                                ProductSeries.Add(item);
                            }
                        }
                    }
                }
                catch (Exception ex) { Crashes.TrackError(ex); }
                finally
                {
                    DataVewEnable  = true;
                    NullViewEnable = false;
                }
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                using (var dig = UserDialogs.Instance.Loading("加载中..."))
                {
                    try
                    {
                        int pageIdex         = ProductSeries.Count / 50;
                        var items            = await GetProductsPage(pageIdex, PageSize);
                        var previousLastItem = ProductSeries.Last();
                        if (items != null)
                        {
                            foreach (var item in items)
                            {
                                if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0)
                                {
                                    ProductSeries.Add(item);
                                }
                            }

                            if (items.Count() == 0 || items.Count() == ProductSeries.Count)
                            {
                                ItemTreshold = -1;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                        ItemTreshold = -1;
                    }
                }
            }, this.WhenAny(x => x.ProductSeries, x => x.GetValue().Count > 0));


            //初始类别
            this.InitCatagory = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    var result = await _productService.GetAllCategoriesAsync(true, new System.Threading.CancellationToken());
                    if (result != null && result.Any())
                    {
                        var categories = result.ToList();
                        if (categories != null && categories.Any())
                        {
                            foreach (var op in categories)
                            {
                                op.SelectedCommand = ReactiveCommand.Create <int>(r =>
                                {
                                    op.Selected = !op.Selected;
                                });
                            }
                            this.BindCategories = new ObservableCollection <CategoryModel>(categories);
                        }
                    }
                }
                catch (Exception ex) { Crashes.TrackError(ex); }
            });
            //选择类别
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(x =>
            {
                if (x != null)
                {
                    Filter.CatagoryIds = new int[] { x.Id };
                    this.ForceRefresh  = true;

                    foreach (var op in this.BindCategories)
                    {
                        op.Selected = false;
                    }

                    x.Selected = !x.Selected;

                    ((ICommand)Load)?.Execute(null);
                }
                Selecter = null;
            })
            .DisposeWith(DeactivateWith);


            this.WhenAnyValue(x => x.ReferencePage)
            .Where(x => !string.IsNullOrEmpty(x))
            .Subscribe(x =>
            {
                this.ShowStockQty = !(x.Equals("InventoryOPBillPage") || x.Equals("InventoryBillPage"));
            }).DisposeWith(DeactivateWith);

            //选择礼品
            this.SelectGiftsCommand = ReactiveCommand.Create(async() =>
            {
                await this.NavigateAsync("SelectGiftsPage", ("WareHouse", WareHouse), ("Terminaler", this.Terminal));
            });
            //保存选择商品
            this.SubmitDataCommand = ReactiveCommand.CreateFromTask <object>(async e =>
            {
                if (string.IsNullOrEmpty(ReferencePage))
                {
                    await _navigationService.GoBackAsync();
                    return;
                }

                var products = ProductSeries.Select(p => p).Where(p => p.Selected == true).ToList();
                if (products.Count == 0)
                {
                    this.Alert("请选择商品项目");
                    return;
                }

                if (ReferencePage == nameof(InventoryReportPage))
                {
                    //添加上报商品
                    await this.NavigateAsync(nameof(AddReportProductPage),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(AllocationBillPage))
                {
                    if (this.Bill == null)
                    {
                        this.Alert("单据不能关联,请确保参数");
                        return;
                    }

                    //添加调拨商品
                    await this.NavigateAsync(nameof(AddAllocationProductPage),
                                             ("Bill", Bill),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(BackStockBillPage))
                {
                    //添加回库调拨单商品
                    await this.NavigateAsync(nameof(AddBackStockBillPage),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(TrackAllocationBillPage))
                {
                    //添加回库调拨单商品
                    await this.NavigateAsync(nameof(AddAllocationProductPage),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(CostContractBillPage))
                {
                    //添加合同商品
                    await this.NavigateAsync(nameof(AddCostContractProductPage),
                                             ("Reference", ReferencePage),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(InventoryOPBillPage) || ReferencePage == nameof(InventoryBillPage))
                {
                    //追加商品
                    if (TempProductSeries.Any())
                    {
                        var temps = TempProductSeries.ToList();
                        foreach (var tp in temps)
                        {
                            if (products.Where(s => s.ProductId == tp.ProductId).Count() == 0)
                            {
                                products.Add(tp);
                            }
                        }
                    }

                    //添加盘点商品
                    await this.NavigateAsync(nameof(AddInventoryProductPage),
                                             ("Reference", ReferencePage),
                                             ("WareHouse", WareHouse),
                                             ("Products", products));
                }
                else if (ReferencePage == nameof(FilterPage))
                {
                    //过滤
                    await _navigationService.GoBackAsync(
                        ("Filter", Filter),
                        ("Reference", ReferencePage),
                        ("Products", products));
                }
                else if (ReferencePage == nameof(PurchaseOrderBillPage))
                {
                    //添加采购商品
                    await this.NavigateAsync(nameof(AddPurchaseProductPage),
                                             ("WareHouse", WareHouse),
                                             ("Reference", ReferencePage),
                                             ("Products", products)
                                             );
                }
                else if (ReferencePage == nameof(ExchangeBillPage))
                {
                    //添加换货商品
                    await this.NavigateAsync(nameof(AddExchangeProductPage),
                                             ("WareHouse", WareHouse),
                                             ("Reference", ReferencePage),
                                             ("Products", products)
                                             );
                }
                else
                {
                    //添加单据商品
                    await this.NavigateAsync($"{nameof(AddProductPage)}",
                                             ("WareHouse", WareHouse),
                                             ("Reference", ReferencePage),
                                             ("Products", products)
                                             );
                }
            });
            //收藏
            this.FavoriteCommand = ReactiveCommand.Create <ProductModel>(p =>
            {
                try
                {
                    var ps = Settings.FavoriteProducts;
                    this.Filter.SerchKey = "";
                    if (!p.Favorited)
                    {
                        if (!ps.Select(s => s.ProductId).Contains(p.ProductId))
                        {
                            p.Favorited = true;
                            ps.Add(p);
                            Settings.FavoriteProducts = ps;
                            _dialogService.ShortAlert("收藏成功!");
                        }
                    }
                    else
                    {
                        var cur = ps.Where(s => s.ProductId == p.ProductId).FirstOrDefault();
                        if (cur != null)
                        {
                            cur.Favorited = false;
                            p.Favorited   = false;
                            ps.Remove(cur);
                            Settings.FavoriteProducts = ps;
                            _dialogService.ShortAlert("收藏已移除!");
                        }
                    }

                    if (UsableFavorite)
                    {
                        if (ProductSeries != null && ProductSeries.Any())
                        {
                            var reload = ProductSeries.Where(s => s.Favorited == true).ToList();
                            if (reload != null && reload.Any())
                            {
                                this.ProductSeries = new ObservableCollection <ProductModel>(reload);
                            }
                            else
                            {
                                this.UsableFavorite = false;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            });

            this.BindBusyCommand(Load);

            this.Load.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.ItemTresholdReachedCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.InitCatagory.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.SelectGiftsCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.SubmitDataCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.FavoriteCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
        }
示例#3
0
        public ProductArchivesPageViewModel(INavigationService navigationService,
                                            IProductService productService,
                                            IUserService userService,
                                            ITerminalService terminalService,
                                            IWareHousesService wareHousesService,
                                            IAccountingService accountingService,
                                            IDialogService dialogService
                                            ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "商品档案";

            _navigationService = navigationService;
            _dialogService     = dialogService;
            _terminalService   = terminalService;
            _productService    = productService;
            _userService       = userService;
            _wareHousesService = wareHousesService;
            _accountingService = accountingService;


            //搜索
            this.WhenAnyValue(x => x.Filter.SerchKey)
            .Where(s => !string.IsNullOrEmpty(s))
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(2), RxApp.MainThreadScheduler)
            .Subscribe(s =>
            {
                ((ICommand)SerchCommand)?.Execute(s);
            }).DisposeWith(DeactivateWith);

            this.SerchCommand = ReactiveCommand.Create <string>(e =>
            {
                if (string.IsNullOrEmpty(Filter.SerchKey))
                {
                    this.Alert("请输入关键字!");
                    return;
                }
                ((ICommand)Load)?.Execute(null);
            });
            this.Load = ProductSeriesLoader.Load(async() =>
            {
                //重载时排它
                ItemTreshold = 1;

                var items = await GetProductsPage(0, PageSize);

                //清除列表
                ProductSeries?.Clear();

                if (items != null && items.Any())
                {
                    foreach (var item in items)
                    {
                        if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0)
                        {
                            ProductSeries.Add(item);
                        }
                    }
                }

                if (ProductSeries.Count > 0)
                {
                    this.ProductSeries = new System.Collections.ObjectModel.ObservableCollection <ProductModel>(ProductSeries);
                }

                return(ProductSeries);
            });
            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                int pageIdex = ProductSeries.Count / PageSize;
                using (var dig = UserDialogs.Instance.Loading("加载中..."))
                {
                    try
                    {
                        var items            = await GetProductsPage(pageIdex, PageSize);
                        var previousLastItem = ProductSeries.Last();

                        if (items != null)
                        {
                            foreach (var item in items)
                            {
                                if (ProductSeries.Count(s => s.ProductId == item.ProductId) == 0)
                                {
                                    ProductSeries.Add(item);
                                }
                            }

                            if (items.Count() == 0 || items.Count() == ProductSeries.Count)
                            {
                                ItemTreshold = -1;
                                //return this.ProductSeries;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                        ItemTreshold = -1;
                    }
                }
            }, this.WhenAny(x => x.ProductSeries, x => x.GetValue().Count > 0));


            //选择商品
            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                await this.NavigateAsync("AddProductArchivePage", ("Product", item));
                Selecter = null;
            }).DisposeWith(DeactivateWith);

            this.AddCommand = ReactiveCommand.Create <object>(async e => await this.NavigateAsync("AddProductArchivePage"));

            this.CatagorySelected = ReactiveCommand.Create <object>(async e =>
            {
                await SelectCatagory((data) =>
                {
                    Filter.CatagoryId   = data.Id;
                    Filter.CatagoryName = data.Name;
                    Filter.CatagoryIds  = new int[] { data.Id };
                });
            });

            this.BindBusyCommand(Load);


            this.Load.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.SerchCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.ItemTresholdReachedCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.AddCommand.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
            this.CatagorySelected.ThrownExceptions.Subscribe(ex => { Debug.Print(ex.StackTrace); }).DisposeWith(this.DeactivateWith);
        }