private void CreateReport()
        {
            Date = string.Format("Парковый отчет за период: с {0} по {1}", DateTime.Now.AddDays(-7).ToShortDateString(),
                                 DateTime.Now.ToShortDateString());
            foreach (var car in CarsHandler.Instance.Cars)
            {
                var value = new Random();
                var dt    = value.NextDouble();
                var dd    = value.NextDouble();

                ReportLines.Add(new ParkReportLine
                {
                    DID           = car.Name, Start = DateTime.Now.AddDays(-7), End = DateTime.Now, Distance = (int)(795 * dt), Odometr = (int)(546846 * dd),
                    DriverSupport = new ChangedValue {
                        OldValue = 60 * value.NextDouble(), Value = 60 * value.NextDouble(), UsePercent = true
                    },
                    NakatValue = new ChangedValue {
                        OldValue = 18 * value.NextDouble(), Value = 18 * value.NextDouble(), UsePercent = true
                    },
                    Idling = new ChangedValue {
                        OldValue = 7 * value.NextDouble(), Value = 7 * value.NextDouble(), UsePercent = true
                    },
                    Speeding = new ChangedValue {
                        OldValue = 29 * value.NextDouble(), Value = 29 * value.NextDouble(), UsePercent = true
                    },
                    HardBrakes = new ChangedValue {
                        OldValue = dt, Value = dt, UsePercent = false
                    },
                    FuelRate = new ChangedValue {
                        OldValue = 25 * dd, Value = 25 * dd, UsePercent = false
                    }
                });
                Thread.Sleep(10);
            }
            var midNakatValue = ReportLines.Average(o => o.NakatValue.Value);
            var midIdling     = ReportLines.Average(o => o.Idling.Value);
            var midSpeeding   = ReportLines.Average(o => o.Speeding.Value);
            var midHardBrakes = ReportLines.Average(o => o.HardBrakes.Value);
            var midFuelRate   = ReportLines.Average(o => o.FuelRate.Value);

            MidNakatValue = new ChangedValue {
                OldValue = midNakatValue, Value = midNakatValue, UsePercent = true
            };
            MidIdling = new ChangedValue {
                OldValue = midIdling, Value = midIdling, UsePercent = true
            };
            MidSpeeding = new ChangedValue {
                OldValue = midSpeeding, Value = midSpeeding, UsePercent = true
            };
            MidHardBrakes = new ChangedValue {
                OldValue = midHardBrakes, Value = midHardBrakes, UsePercent = false
            };
            MidFuelRate = new ChangedValue {
                OldValue = midFuelRate, Value = midFuelRate, UsePercent = false
            };
        }
Example #2
0
        public void BuildLineViews(List <BatchLine> batchLines)
        {
            var orderLines = Addresses.SelectMany(a => a.ActiveOrders()).SelectMany(o => o.Lines);
            var lookup     = orderLines.ToLookup(l => l.ExportBatchLineId);
            var items      = batchLines.Select(l => new BatchLineView(l, lookup[l.ExportId].FirstOrDefault())).ToArray();

            Lines.Value = orderLines.Except(items.Where(x => x.OrderLine != null).Select(x => x.OrderLine))
                          .Select(x => new BatchLineView(x)).Concat(items).ToObservableCollection();
            BatchLine.CalculateStyle(Address, Addresses, Lines.Value);
            Lines.Value.Where(l => l.OrderLine != null).Each(l => l.OrderLine.Configure(User));
            ReportLines.Recalculate();
        }
Example #3
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            lastUsedDir = (string)Shell.PersistentContext.GetValueOrDefault("BatchDir", Settings.Value.GetVarRoot());
            CurrentReportLine
            .Subscribe(_ => {
                CurrentElementAddress = Addresses.FirstOrDefault(a => a.Id == CurrentReportLine.Value?.Address.Id);
            });

            CurrentReportLine
            .Throttle(Consts.ScrollLoadTimeout, UiScheduler)
            .Merge(DbReloadToken)
            .SelectMany(x => Env.RxQuery(s => {
                if (CurrentReportLine.Value?.ProductId == null)
                {
                    return(new List <Offer>());
                }

                var productId = CurrentReportLine.Value.ProductId;
                return(s.Query <Offer>()
                       .Fetch(o => o.Price)
                       .Where(o => o.ProductId == productId)
                       .OrderBy(o => o.Cost)
                       .ToList()
                       .OrderBy(o => o.ResultCost)
                       .ToList());
            })).Subscribe(UpdateOffers, CloseCancellation.Token);

            AddressSelector.Init();
            AddressSelector.FilterChanged
            .Merge(DbReloadToken)
            .SelectMany(_ => Env.RxQuery(s => {
                var ids = AddressSelector.GetActiveFilter().Select(a => a.Id).ToArray();
                return(s.Query <BatchLine>()
                       .Fetch(l => l.Address)
                       .Where(l => ids.Contains(l.Address.Id))
                       .ToList());
            })).CatchSubscribe(BuildLineViews, CloseCancellation);

            if (LastSelectedLine > 0)
            {
                CurrentReportLine.Value = CurrentReportLine.Value
                                          ?? ReportLines.Value.FirstOrDefault(v => v.BatchLine?.Id == LastSelectedLine);
            }

            if (Address != null)
            {
                Bus.RegisterMessageSource(Address.StatSubject);
            }

            CurrentReportLine
            .Throttle(Consts.ScrollLoadTimeout, Env.Scheduler)
            .SelectMany(x => Env.RxQuery(s => {
                if (x?.CatalogId == null)
                {
                    return(null);
                }
                var catalogId = x.CatalogId;
                return(s.Query <Catalog>()
                       .Fetch(c => c.Name)
                       .ThenFetch(n => n.Mnn)
                       .First(c => c.Id == catalogId));
            }))
            .Subscribe(CurrentCatalog, CloseCancellation.Token);

            ReportLines
            .Select(v => v.Changed())
            .Switch()
            .Where(e => e.EventArgs.Action == NotifyCollectionChangedAction.Remove)
            .Select(x => x.EventArgs.OldItems.Cast <BatchLineView>().Select(b => b.BatchLine).Where(y => y != null).ToArray())
            .Where(x => x.Length > 0)
            .SelectMany(x => Observable.FromAsync(() => Env.Query(s => s.DeleteEach(x))))
            .CatchSubscribe(_ => {});
        }