Beispiel #1
0
        public void AddTerminal(CrawlerTerminal terminal)
        {
            if (Terminals.Any(i => i.ConnectionId == terminal.ConnectionId) &&
                Terminals.Any(i => i.Group == terminal.Group))
            {
                return;
            }

            Terminals.Add(terminal);
        }
Beispiel #2
0
 public bool HasTerminal(string id, IDepot depot)
 {
     if (Terminals == null || Terminals.Count < 1)
     {
         return(false);
     }
     return(Terminals.Any(t => t.Id == id &&
                          t.Body == depot.Body &&
                          t.Biome == depot.Biome));
 }
Beispiel #3
0
        public SelectCustomerPageViewModel(INavigationService navigationService,
                                           IProductService productService,
                                           ITerminalService terminalService,
                                           IUserService userService,
                                           IWareHousesService wareHousesService,
                                           IAccountingService accountingService,
                                           IDialogService dialogService,
                                           ILiteDbService <VisitStore> conn) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "选择客户";

            _conn = conn;

            //搜索
            this.WhenAnyValue(x => x.Filter.SerchKey)
            .Select(s => s)
            .Skip(1)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s =>
            {
                ((ICommand)Load)?.Execute(null);
            })
            .DisposeWith(DeactivateWith);

            //片区选择
            this.WhenAnyValue(x => x.Filter.DistrictId)
            .Where(s => s > 0)
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s =>
            {
                ((ICommand)Load)?.Execute(null);
            })
            .DisposeWith(DeactivateWith);

            //加载数据
            this.Load = ReactiveCommand.Create(async() =>
            {
                try
                {
                    //重载时排它
                    ItemTreshold = 1;

                    try
                    {
                        if (Terminals != null && Terminals.Any())
                        {
                            Terminals?.Clear();
                        }
                    }
                    catch (Exception) { }

                    DataVewEnable  = false;
                    NullViewEnable = true;
                    using (var dig = UserDialogs.Instance.Loading("加载中..."))
                    {
                        this.Longitude = GlobalSettings.Longitude ?? 0;
                        this.Latitude  = GlobalSettings.Latitude ?? 0;

                        string searchStr    = Filter?.SerchKey;
                        int?districtId      = Filter?.DistrictId;
                        int?channelId       = Filter?.ChannelId;
                        int?businessUserId  = Filter?.BusinessUserId;
                        int?rankId          = Filter?.RankId;
                        int pageNumber      = 0;
                        int pageSize        = PageSize;
                        int?lineTierId      = Filter?.LineId;
                        int distanceOrderBy = Filter.DistanceOrderBy;

                        var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                           districtId,
                                                                           channelId,
                                                                           rankId,
                                                                           lineTierId,
                                                                           businessUserId,
                                                                           true,
                                                                           distanceOrderBy,
                                                                           GlobalSettings.Latitude ?? 0,
                                                                           GlobalSettings.Longitude ?? 0,
                                                                           0.5,
                                                                           pageNumber,
                                                                           pageSize);

                        var series = tuple.Item2;
                        if (series != null && series.Any())
                        {
                            this.Terminals = new AsyncObservableCollection <TerminalModel>(series);
                        }
                        else
                        {
                            ItemTreshold = -1;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
                finally
                {
                    NullViewEnable = false;
                    DataVewEnable  = true;
                }
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                if (ItemTreshold == -1)
                {
                    return;
                }
                try
                {
                    int pageIdex = Terminals.Count / (PageSize == 0 ? 1 : PageSize);
                    if (pageIdex > 0)
                    {
                        using (var dig = UserDialogs.Instance.Loading("加载中..."))
                        {
                            string searchStr    = Filter?.SerchKey;
                            int?districtId      = Filter?.DistrictId;
                            int?channelId       = Filter?.ChannelId;
                            int?businessUserId  = Filter?.BusinessUserId;
                            int?rankId          = Filter?.RankId;
                            int pageNumber      = pageIdex;
                            int pageSize        = PageSize;
                            int?lineTierId      = Filter?.LineId;
                            int distanceOrderBy = Filter.DistanceOrderBy;

                            var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                               districtId,
                                                                               channelId,
                                                                               rankId,
                                                                               lineTierId,
                                                                               businessUserId,
                                                                               true,
                                                                               distanceOrderBy,
                                                                               GlobalSettings.Latitude ?? 0,
                                                                               GlobalSettings.Longitude ?? 0,
                                                                               0.5,
                                                                               pageNumber,
                                                                               pageSize);

                            var series = tuple.Item2;
                            if (series != null && series.Any())
                            {
                                try
                                {
                                    foreach (var s in series)
                                    {
                                        if (!(this.Terminals?.Select(s => s.Id).Contains(s.Id) ?? false))
                                        {
                                            this.Terminals?.Add(s);
                                        }
                                    }
                                }
                                catch (Exception) { }
                            }
                            else
                            {
                                ItemTreshold = -1;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                    ItemTreshold = -1;
                }
            });

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


            this.BindBusyCommand(Load);
        }
        public CurrentCustomerPageViewModel(INavigationService navigationService,
                                            IProductService productService,
                                            IUserService userService,
                                            ITerminalService terminalService,
                                            IWareHousesService wareHousesService,
                                            IAccountingService accountingService,
                                            IDialogService dialogService,
                                            ILiteDbService <VisitStore> conn) : base(navigationService, productService, terminalService, userService, wareHousesService, accountingService, dialogService)
        {
            Title = "拜访选择终端客户";
            _conn = conn;

            this.PageSize = 20;


            //搜索(默认触发Load)
            this.WhenAnyValue(x => x.Filter.SerchKey)
            .Skip(1)
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s => ((ICommand)Load)?.Execute(null))
            .DisposeWith(DeactivateWith);

            //片区选择
            this.WhenAnyValue(x => x.Filter.DistrictId)
            .Where(s => s > 0)
            .Select(s => s)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s => ((ICommand)Load)?.Execute(null))
            .DisposeWith(DeactivateWith);

            //距离排序
            this.WhenAnyValue(x => x.Filter.DistanceOrderBy)
            .Where(s => s > 0)
            .Select(s => s)
            .Skip(1)
            .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
            .Subscribe(s => ((ICommand)Load)?.Execute(null))
            .DisposeWith(DeactivateWith);

            //加载数据
            this.Load = ReactiveCommand.Create(async() =>
            {
                try
                {
                    System.Diagnostics.Debug.Print("----------------------CurrentCustomerPageViewModel----------------------------->");

                    //重载时排它
                    ItemTreshold = 1;

                    try
                    {
                        if (Terminals != null && Terminals.Any())
                        {
                            Terminals?.Clear();
                        }
                    }
                    catch (Exception) { }

                    PageCounter  = 0;
                    itemTreshold = true;

                    DataVewEnable  = false;
                    NullViewEnable = true;

                    this.Longitude = GlobalSettings.Longitude ?? 0;
                    this.Latitude  = GlobalSettings.Latitude ?? 0;

                    string searchStr    = Filter?.SerchKey;
                    int?districtId      = Filter?.DistrictId;
                    int?channelId       = Filter?.ChannelId;
                    int?businessUserId  = Filter?.BusinessUserId;
                    int?rankId          = Filter?.RankId;
                    int pageNumber      = 0;
                    int pageSize        = PageSize;
                    int?lineTierId      = Filter?.LineId;
                    int distanceOrderBy = Filter.DistanceOrderBy;

                    var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                       districtId,
                                                                       channelId,
                                                                       rankId,
                                                                       lineTierId,
                                                                       businessUserId,
                                                                       true,
                                                                       distanceOrderBy,
                                                                       GlobalSettings.Latitude ?? 0,
                                                                       GlobalSettings.Longitude ?? 0,
                                                                       1.5,
                                                                       pageNumber,
                                                                       pageSize);


                    var series = tuple.Item2;
                    if (series != null && series.Any())
                    {
                        this.Terminals = new AsyncObservableCollection <TerminalModel>(series);
                    }
                    else
                    {
                        ItemTreshold = -1;
                    }

                    itemTreshold = false;
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
                finally
                {
                    DataVewEnable  = true;
                    NullViewEnable = false;
                }
            });

            //以增量方式加载数据
            this.ItemTresholdReachedCommand = ReactiveCommand.Create(async() =>
            {
                if (ItemTreshold == -1 || itemTreshold)
                {
                    return;
                }

                try
                {
                    itemTreshold = true;
                    int pageIdex = Terminals.Count / (PageSize == 0 ? 1 : PageSize);
                    if (pageIdex > 0)
                    {
                        using (var dig = UserDialogs.Instance.Loading("加载中..."))
                        {
                            string searchStr    = Filter?.SerchKey;
                            int?districtId      = Filter?.DistrictId;
                            int?channelId       = Filter?.ChannelId;
                            int?businessUserId  = Filter?.BusinessUserId;
                            int?rankId          = Filter?.RankId;
                            int pageNumber      = pageIdex;
                            int pageSize        = PageSize;
                            int?lineTierId      = Filter?.LineId;
                            int distanceOrderBy = Filter.DistanceOrderBy;

                            var tuple = await _terminalService.SearchTerminals(searchStr,
                                                                               districtId,
                                                                               channelId,
                                                                               rankId,
                                                                               lineTierId,
                                                                               businessUserId,
                                                                               true,
                                                                               distanceOrderBy,
                                                                               GlobalSettings.Latitude ?? 0,
                                                                               GlobalSettings.Longitude ?? 0,
                                                                               1.5,
                                                                               pageNumber,
                                                                               pageSize);

                            var series = tuple.Item2;
                            if (series != null && series.Any())
                            {
                                try
                                {
                                    foreach (var s in series)
                                    {
                                        if (!(this.Terminals?.Select(s => s.Id).Contains(s.Id) ?? true))
                                        {
                                            this.Terminals?.Add(s);
                                        }
                                    }
                                }
                                catch (Exception) { }
                                itemTreshold = false;
                            }
                            else
                            {
                                ItemTreshold = -1;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                    ItemTreshold = -1;
                }
            });


            //线路选择
            this.LineSelected = ReactiveCommand.Create <object>(async e => await SelectUserLine((data) =>
            {
                if (data != null)
                {
                    Filter.LineId   = data.Id;
                    Filter.LineName = data.Name;
                    if (Filter.LineId > 0)
                    {
                        var dts = data.Terminals;
                        if (dts != null && dts.Any())
                        {
                            var series = dts.OrderByDescending(t => t.Id);

                            series?.ToList().ForEach(s =>
                            {
                                s.RankName = string.IsNullOrEmpty(s.RankName) ? "A级" : s.RankName;
                                s.Distance = MapHelper.CalculateDistance(GlobalSettings.Latitude ?? 0, GlobalSettings.Longitude ?? 0, s.Location_Lat ?? 0, s.Location_Lng ?? 0);
                            });

                            if (series.Count() > 0)
                            {
                                Terminals = new AsyncObservableCollection <TerminalModel>(series);
                                MessageBus.Current.SendMessage(Terminals, Constants.TRACKTERMINALS_KEY);
                            }
                        }
                    }
                }
            }, Filter.LineId));

            //打开导航
            this.OpenNavigationToCommand = ReactiveCommand.Create <TerminalModel>(e =>
            {
                try
                {
                    var _baiduLocationService = App.Resolve <IBaiduNavigationService>();
                    _baiduLocationService?.OpenNavigationTo(e.Location_Lat ?? 0, e.Location_Lng ?? 0, e.Address);
                }
                catch (Exception)
                {
                    _dialogService.LongAlert("没有安装导航软件");
                }
            });

            //距离排序
            this.DistanceOrderCommand = ReactiveCommand.Create <int>(e =>
            {
                if (!OrderByDistance)
                {
                    this.OrderByDistance        = true;
                    this.Filter.DistanceOrderBy = 1;
                }
                else
                {
                    this.OrderByDistance        = false;
                    this.Filter.DistanceOrderBy = 2;
                }
            });

            //片区选择
            this.DistrictSelected = ReactiveCommand.Create <object>(async e => await this.NavigateAsync("SelectAreaPage", null));

            //附近客户
            this.OtherCustomerCommand = ReactiveCommand.Create <object>(e =>
            {
                if (this.MapVewEnable == false)
                {
                    Title = "附近客户";
                    this.ListVewEnable = false;
                    this.MapVewEnable  = true;
                    Filter.LineId      = 0;
                    ((ICommand)RefreshCommand)?.Execute(null);
                }
                else
                {
                    Title = "选择客户";
                    this.ListVewEnable = true;
                    this.MapVewEnable  = false;
                }
            });

            //添加客户
            this.AddCustomerCommand = ReactiveCommand.Create <object>(async e => await this.NavigateAsync("AddCustomerPage"));

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


            //绑定页面菜单
            _popupMenu = new PopupMenu(this, new Dictionary <MenuEnum, Action <SubMenu, ViewModelBase> >
            {
                //整单备注
                { MenuEnum.NEARCUSTOMER, (m, vm) => {
                      if (this != null)
                      {
                          Title         = "附近客户";
                          Filter.LineId = 0;
                          ((ICommand)RefreshCommand)?.Execute(null);
                      }
                  } },
                //清空单据
                { MenuEnum.LINESELECT, (m, vm) => {
                      if (this != null)
                      {
                          ((ICommand)LineSelected)?.Execute(null);
                      }
                  } }
            });

            this.BindBusyCommand(Load);
        }
Beispiel #5
0
 public bool AnyEmpty() => Terminals.Any(x => x.Value == "ε");
Beispiel #6
0
 private bool IsTerminal(string production) => Terminals.Any(x => x.Value == production);
Beispiel #7
0
 public bool IsTerminalAvailable(string group)
 {
     return(Terminals.Any(i => i.Group == group));
 }