Example #1
0
        public SelectContractPageViewModel(INavigationService navigationService,
                                           IProductService productService,
                                           ITerminalService terminalService,
                                           IUserService userService,
                                           IWareHousesService wareHousesService,
                                           IAccountingService accountingService,
                                           ICostContractService costContractService,
                                           IDialogService dialogService
                                           ) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "选择费用合同";

            _costContractService = costContractService;

            this.Load = CostContractLoader.Load(async() =>
            {
                //重载时排它
                ItemTreshold = 1;
                try
                {
                    //清除列表
                    CostContracts.Clear();

                    var items = await GetDataPages(0, PageSize);
                    if (items != null)
                    {
                        foreach (var item in items)
                        {
                            if (CostContracts.Count(s => (s.BillNumber == item.BillNumber) && (s.Month == item.Month)) == 0)
                            {
                                CostContracts.Add(item);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }

                this.CostContracts = new ObservableRangeCollection <CostContractBindingModel>(CostContracts);
                return(CostContracts);
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                using (var dig = UserDialogs.Instance.Loading("加载中..."))
                {
                    try
                    {
                        int pageIdex         = CostContracts.Count / (PageSize == 0 ? 1 : PageSize);
                        var items            = await GetDataPages(pageIdex, PageSize);
                        var previousLastItem = Terminals.Last();
                        if (items != null)
                        {
                            foreach (var item in items)
                            {
                                if (CostContracts.Count(s => (s.BillNumber == item.BillNumber) && (s.Month == item.Month)) == 0)
                                {
                                    CostContracts.Add(item);
                                }
                            }

                            if (items.Count() == 0 || items.Count() == CostContracts.Count)
                            {
                                ItemTreshold = -1;
                                return(this.CostContracts);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                        ItemTreshold = -1;
                    }


                    this.CostContracts = new ObservableRangeCollection <CostContractBindingModel>(CostContracts);
                    return(this.CostContracts);
                }
            });

            //选择
            this.ItemSelectedCommand = ReactiveCommand.Create <CollectionView>(async e =>
            {
                if (e.SelectedItem != null)
                {
                    Selecter.AccountingOptionId   = this.Accounting.AccountingOptionId;
                    Selecter.AccountingOptionName = this.Accounting.AccountingOptionName;
                    await _navigationService.GoBackAsync(("CostContract", Selecter));
                }
            });

            this.BindBusyCommand(Load);
        }
Example #2
0
        public SelectManufacturerPageViewModel(INavigationService navigationService,
                                               IManufacturerService manufacturerService,
                                               IDialogService dialogService
                                               ) : base(navigationService, dialogService)
        {
            Title = "选择供应商";

            _navigationService   = navigationService;
            _dialogService       = dialogService;
            _manufacturerService = manufacturerService;

            //Load
            this.Load = ManufacturersLoader.Load(async() =>
            {
                //重载时排它
                ItemTreshold = 1;
                try
                {
                    //清除列表
                    Manufacturers.Clear();

                    var items = await GetManufacturersPage(0, PageSize);
                    if (items != null)
                    {
                        foreach (var item in items)
                        {
                            if (Manufacturers.Count(s => s.Id == item.Id) == 0)
                            {
                                Manufacturers.Add(item);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }

                this.Manufacturers = new ObservableRangeCollection <ManufacturerModel>(Manufacturers);


                return(Manufacturers.ToList());
            });

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

                            if (items.Count() == 0 || items.Count() == Terminals.Count)
                            {
                                ItemTreshold = -1;
                                return(Manufacturers.ToList());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                        ItemTreshold = -1;
                    }


                    this.Manufacturers = new ObservableRangeCollection <ManufacturerModel>(Manufacturers);
                    return(Manufacturers.ToList());
                }
            }, this.WhenAny(x => x.Terminals, x => x.GetValue().Count > 0));


            this.WhenAnyValue(x => x.Selecter).Throttle(TimeSpan.FromMilliseconds(500))
            .Skip(1)
            .Where(x => x != null)
            .SubOnMainThread(async item =>
            {
                await _navigationService.GoBackAsync(("Manufacturer", item));
                this.Selecter = null;
            }).DisposeWith(DeactivateWith);

            this.BindBusyCommand(Load);
        }