protected override void OnInitialize() { base.OnInitialize(); AddressSelector.Init(); AddressSelector.Description = "Все накладные"; Bus.Listen <string>("reload").Cast <object>() .Merge(DbReloadToken) .Merge(StatusFilter.FilterChanged()) .Merge(AddressSelector.FilterChanged.Cast <object>()) .Merge(OnlyRejected.Changed()) .SelectMany(_ => RxQuery(x => { var query = x.Query <Stock>().Where(y => y.Quantity != 0 || y.ReservedQuantity != 0); if (StatusFilter.IsFiltred()) { var values = StatusFilter.GetValues(); query = query.Where(y => values.Contains(y.Status)); } if (OnlyRejected.Value) { query = query.Where(r => r.RejectStatus == RejectStatus.Defective || r.RejectStatus == RejectStatus.Perhaps); } var addresses = AddressSelector.GetActiveFilter().Select(y => y.Id); query = query.Where(y => addresses.Contains(y.Address.Id)); return(query.Fetch(y => y.Address).OrderBy(y => y.Product).ToList()); })) .Subscribe(Items, CloseCancellation.Token); }
protected override void OnInitialize() { base.OnInitialize(); DbReloadToken .Merge(Begin.Select(x => (object)x)) .Merge(End.Select(x => (object)x)) .SelectMany(_ => RxQuery(s => s.Query <Check>() .Where(x => x.Clerk != null && x.Date <= End.Value.AddDays(1) && x.Date >= Begin.Value) .Select(x => x.Clerk) .Distinct().ToList() .Select(x => new Selectable <string>(x)).ToList())) .Subscribe(Users); AddressSelector.Init(); AddressSelector.FilterChanged.Cast <object>() .Merge(DbReloadToken) .Merge(Begin.Select(x => (object)x)) .Merge(End.Select(x => (object)x)) .Merge(Users.SelectMany(x => x?.Select(p => p.Changed()).Merge() ?? Observable.Empty <EventPattern <PropertyChangedEventArgs> >())) .Throttle(Consts.FilterUpdateTimeout, UiScheduler) .SelectMany(_ => RxQuery(s => { var query = s.Query <Check>() .Where(c => c.Date <= End.Value.AddDays(1) && c.Date >= Begin.Value && AddressSelector.GetActiveFilter().Contains(c.Address)); var selectedUsers = Users.Value.Where(x => x.IsSelected).Select(x => x.Item).ToArray(); if (selectedUsers.Length != Users.Value.Count && Users.Value.Count > 0) { query = query.Where(x => selectedUsers.Contains(x.Clerk)); } return(query.OrderByDescending(x => x.Date) .Fetch(x => x.Address) .ToList()); })) .Subscribe(Items); }
public override void Update() { if (Suppliers.Value == null) { return; } //уже не актуально но поучительно //скорбная песнь: при переходе на форму сводный заказ //wpf обновит состояние флага IsFilterByDocumentDate //когда эта форма уже закрыта //RadioButton имеет внутри статичный список всех кнопок на форме и обновляет их состояние //наверно в качестве родителя считается окно и для всех потомков с одинаковым GroupName //производится обновление Env.RxQuery(s => { var query = s.Query <Waybill>(); var begin = Begin.Value; var end = End.Value.AddDays(1); if (IsFilterByDocumentDate) { query = query.Where(w => w.DocumentDate >= begin && w.DocumentDate <= end); } else { query = query.Where(w => w.WriteTime >= begin && w.WriteTime <= end); } if (RejectFilter.Value == ViewModels.RejectFilter.Changed) { query = query.Where(w => w.IsRejectChanged); } var supplierIds = Suppliers.Value.Where(x => x.IsSelected).Select(x => x.Item.Id).ToArray(); if (supplierIds.Length != Suppliers.Value.Count) { query = query.Where(w => supplierIds.Contains(w.Supplier.Id)); } var addressIds = AddressSelector.GetActiveFilter().Select(a => a.Id).ToArray(); if (addressIds.Length != AddressSelector.Addresses.Count) { query = query.Where(w => addressIds.Contains(w.Address.Id)); } if (TypeFilter.Value == DocumentTypeFilter.Waybills) { query = query.Where(w => w.DocType == DocType.Waybill || w.DocType == null); } else if (TypeFilter.Value == DocumentTypeFilter.Rejects) { query = query.Where(w => w.DocType == DocType.Reject); } var result = query .OrderByDescending(w => w.WriteTime) .Fetch(w => w.Supplier) .Fetch(w => w.Address) .ToObservableCollection(); for (var i = 0; i < result.Count; i++) { result[i].CalculateStyle(Address); } return(result); }).Subscribe(Waybills, CloseCancellation.Token); }
public override void Update() { //до загрузки прайс-листов избегаем выбирать данные что бы не делать лишних запросов if (Prices.Value == null) { return; } var priceIds = Prices.Value.Where(x => x.IsSelected).Select(x => x.Item.Id).ToArray(); if (IsSentSelected) { var filterAddresses = AddressSelector.GetActiveFilter().Select(a => a.Id).ToArray(); var begin = Begin.Value; var end = End.Value.AddDays(1); Env.RxQuery(s => { var query = s.Query <SentOrder>() .Fetch(o => o.Price) .Fetch(o => o.Address) .Where(o => o.SentOn >= begin && o.SentOn < end && filterAddresses.Contains(o.Address.Id)); query = Util.Filter(query, o => o.Price.Id, Prices.Value); return(query .OrderByDescending(o => o.SentOn) .Take(1000) .ToObservableCollection()); }).CatchSubscribe(x => { for (var i = 0; i < x.Count; i++) { x[i].CalculateStyle(Address); } SentOrders = x; }); } if (IsDeletedSelected) { Env.RxQuery(s => { var result = s.Query <DeletedOrder>() .Fetch(o => o.Price) .Fetch(o => o.Address) .OrderByDescending(o => o.DeletedOn) .ToList(); if (CurrentDeletedOrder != null) { CurrentDeletedOrder = result.FirstOrDefault(x => x.Id == CurrentDeletedOrder.Id); } return(new ReactiveCollection <DeletedOrder>(result) { ChangeTrackingEnabled = true }); }).CatchSubscribe(x => { DeletedOrders = x; }); } //обновить данные нужно в нескольких ситуациях //изменился фильтр //изменились данные в базе //если изменился фильтры данные загружать не нужно //если изменились данные то нужно загрузить данные повторно if (IsCurrentSelected || UpdateOnActivate) { if (UpdateOnActivate) { RebuildSessionIfNeeded(); } //этот вызов должен быть после RebuildSessionIfNeeded //тк он перезагрузить объекты var orders = new List <Order>(); if (IsSelectedAllAddress() && AddressSelector.All) { orders = Session.Query <Order>().ToList() .Where(x => priceIds.Contains(x.Price.Id) || IsSelectedAllPrices()) .OrderBy(o => o.PriceName) .ToList(); orders.Each(o => o.CalculateStyle(Address)); } else { orders = AddressSelector.GetActiveFilter() .SelectMany(a => a.Orders) .Where(x => priceIds.Contains(x.SafePrice.Id) || IsSelectedAllPrices()) .OrderBy(o => o.PriceName) .ToList(); orders.Each(o => o.CalculateStyle(Address)); } if (CurrentOrder != null) { CurrentOrder = orders.FirstOrDefault(x => x.Id == CurrentOrder.Id); SetAddressesToMove(); } Orders = new ReactiveCollection <Order>(orders) { ChangeTrackingEnabled = true }; Price.LoadOrderStat(Env, orders.Select(o => o.Price), Address).LogResult(); } }
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(_ => {}); }
protected override void OnInitialize() { base.OnInitialize(); OnlyWarningVisible = IsCurrentSelected.Select(v => v && User.IsPreprocessOrders).ToValue(); ProductInfo = new ProductInfo(this, CurrentLine); ProductInfo2 = new ProductInfo(this, SelectedSentLine); AddressSelector.Init(); AddressSelector.FilterChanged .Merge(Prices.Select(p => p.Changed()).Merge().Throttle(Consts.FilterUpdateTimeout, UiScheduler)) .Merge(DbReloadToken) .Merge(OrdersReloadToken) .Merge(FilterItems.Select(p => p.Changed()).Merge().Throttle(Consts.FilterUpdateTimeout, UiScheduler)) .Where(_ => IsCurrentSelected && Session != null) .Select(_ => { var orders = AddressSelector.GetActiveFilter().SelectMany(o => o.Orders) .Where(x => Prices.Where(y => y.IsSelected).Select(y => y.Item.Id).Contains(x.Price.Id)).ToList(); var activeOrders = orders.Where(x => !x.Frozen).ToList(); var lines = activeOrders.SelectMany(o => o.Lines) .OrderBy(l => l.Id) .ToObservableCollection(); lines.Each(l => { l.Settings = Settings; l.Order.CalculateStyle(Address); if (l.Order.IsAddressExists()) { l.CalculateRetailCost(Settings.Value.Markups, Shell?.SpecialMarkupProducts.Value, User); } }); // #48323 Присутствует в замороженных заказах var productInFrozenOrders = orders.Where(x => x.Frozen).SelectMany(x => x.Lines) .Select(x => x.ProductId).Distinct().ToList(); lines.Where(x => productInFrozenOrders.Contains(x.ProductId)) .Each(x => x.InFrozenOrders = true); var selected = FilterItems.Where(p => p.IsSelected).Select(p => p.Item.Item1).ToArray(); if (selected.Count() != FilterItems.Count()) { var ids = new List <uint>(); if (selected.Contains("InFrozenOrders")) { ids.AddRange(lines.Where(x => x.InFrozenOrders).Select(x => x.Id)); } if (selected.Contains("IsMinCost")) { ids.AddRange(lines.Where(x => x.IsMinCost).Select(x => x.Id)); } if (selected.Contains("IsNotMinCost")) { ids.AddRange(lines.Where(x => !x.IsMinCost).Select(x => x.Id)); } if (selected.Contains("OnlyWarning")) { ids.AddRange(lines.Where(x => x.SendResult != LineResultStatus.OK).Select(x => x.Id)); } return(lines.Where(x => ids.Contains(x.Id)).ToObservableCollection()); } return(lines); }) .Subscribe(Lines, CloseCancellation.Token); IsSentSelected.Where(v => v) .Select(v => (object)v) .Merge(Begin.Select(d => (object)d)) .Merge(End.Select(d => (object)d)) .Merge(Prices.Select(p => p.Changed()).Merge().Throttle(Consts.FilterUpdateTimeout, UiScheduler)) .Merge(AddressSelector.FilterChanged) .Merge(DbReloadToken) .Do(_ => { IsLoading.Value = true; }) //защита от множества запросов .Throttle(TimeSpan.FromMilliseconds(30), Scheduler) .Where(_ => IsSentSelected) .Select(_ => RxQuery(s => { var begin = Begin.Value; var end = End.Value.AddDays(1); var addressIds = AddressSelector.GetActiveFilter().Select(a => a.Id).ToArray(); var query = s.Query <SentOrderLine>() .Fetch(l => l.Order) .ThenFetch(o => o.Address) .Fetch(o => o.Order) .ThenFetch(o => o.Price) .Where(l => l.Order.SentOn > begin && l.Order.SentOn < end) .Where(l => addressIds.Contains(l.Order.Address.Id)); query = Util.Filter(query, l => l.Order.Price.Id, Prices); var lines = query.OrderBy(l => l.ProductSynonym) .ThenBy(l => l.ProductSynonym) .Take(1000) .ToList(); if (Settings.Value.HighlightUnmatchedOrderLines) { var lookup = MatchedWaybills.GetLookUp(s, lines); lines.Each(l => l.Order.CalculateStyle(Address)); lines.Each(l => l.Configure(User, lookup)); } else { lines.Each(l => l.Order.CalculateStyle(Address)); lines.Each(l => l.Configure(User)); } return(lines); })) .Switch() .Do(_ => IsLoading.Value = false) .Subscribe(SentLines, CloseCancellation.Token); CurrentLine .Throttle(Consts.ScrollLoadTimeout, UiScheduler) .Merge(DbReloadToken) .Subscribe(_ => UpdateAsync(), CloseCancellation.Token); CurrentLine .Throttle(Consts.LoadOrderHistoryTimeout, Scheduler) .SelectMany(x => Env.RxQuery(s => LoadOrderHistory(s, Cache, Settings.Value, x, ActualAddress))) .Subscribe(HistoryOrders, CloseCancellation.Token); }