public CurrentCatalog DifficultyModel(int type) { CurrentCatalog model = new CurrentCatalog(); model._type = type; model._name = "Difficulty"; model._listCatalog = new List <CatalogModel>(); foreach (View_Difficulty difficulty in db.View_Difficulty.ToList()) { model._listCatalog.Add(new CatalogModel(difficulty.Id, difficulty.Name, difficulty.Inactive)); } return(model); }
public CurrentCatalog HikeTypeModel(int type) { CurrentCatalog model = new CurrentCatalog(); model._type = type; model._name = "Hike Types"; model._listCatalog = new List <CatalogModel>(); foreach (View_HikeType hikeType in db.View_HikeType.ToList()) { model._listCatalog.Add(new CatalogModel(hikeType.Id, hikeType.Name, hikeType.Inactive)); } return(model); }
public CurrentCatalog QualityModel(int type) { CurrentCatalog model = new CurrentCatalog(); model._type = type; model._name = "Quality"; model._listCatalog = new List <CatalogModel>(); foreach (View_Quality quality in db.View_Quality.ToList()) { model._listCatalog.Add(new CatalogModel(quality.Id, quality.Name, quality.Inactive)); } return(model); }
public CurrentCatalog PriceModel(int type) { CurrentCatalog model = new CurrentCatalog(); model._type = type; model._name = "Price"; model._listCatalog = new List <CatalogModel>(); foreach (View_Price price in db.View_Price.ToList()) { model._listCatalog.Add(new CatalogModel(price.Id, price.Name, price.Inactive)); } return(model); }
public Frontend2() { DisplayName = "Регистрация продаж"; InitFields(); Status.Value = "Готов к работе(F1 для справки)"; Lines = new ReactiveCollection <CheckLine>(); CheckLinesForReturn = new List <CheckLine>(); Warning = new InlineEditWarning(Scheduler, Manager); OnCloseDisposable.Add(SearchBehavior = new SearchBehavior(Env)); SearchBehavior.ActiveSearchTerm.Where(x => !String.IsNullOrEmpty(x)) .Subscribe(x => Coroutine.BeginExecute(Enter().GetEnumerator())); CurrentCatalog.Select(x => x?.Name?.Description != null) .Subscribe(CanShowDescription); }
public BaseOfferViewModel(OfferComposedId initOfferId = null) { Readonly = true; UpdateOnActivate = false; this.initOfferId = initOfferId; LastEditOffer = new NotifyValue <Offer>(); Offers = new NotifyValue <IList <Offer> >(new List <Offer>()); CurrentProducer = new NotifyValue <Producer>(EmptyProducer); Producers = new NotifyValue <List <Producer> >(new List <Producer> { EmptyProducer }); InitFields(); CurrentCatalog.Select(x => x?.Name?.Description != null) .Subscribe(CanShowDescription); CurrentCatalog.Select(x => x?.Name?.Mnn != null) .Subscribe(CanShowCatalogWithMnnFilter); CurrentOffer.Select(x => x?.OrderLine?.Order) .Subscribe(CurrentOrder); CurrentOffer.Subscribe(_ => { if (ResetAutoComment) { AutoCommentText = CurrentOffer.Value?.OrderLine?.Comment; } }); CurrentOffer .Select(_ => (List <SentOrderLine>)Cache[HistoryOrdersCacheKey(Settings.Value, CurrentOffer.Value)]) .Subscribe(HistoryOrders); Settings.Subscribe(_ => Calculate()); SessionValue(CanSaveFilterProducer, "CanSaveFilterProducer"); SessionValue(CurrentFilterProducer, "CurrentFilterProducer"); }
protected override void OnInitialize() { base.OnInitialize(); CatalogTerm .Throttle(Consts.TextInputLoadTimeout, Scheduler) .SelectMany(t => RxQuery(s => { var threshold = 2; if (String.IsNullOrEmpty(t) || t.Length < threshold) { return(new List <Product>()); } if (CurrentCatalog.Value != null && CurrentCatalog.Value.Name == t) { return(Catalogs.Value); } return(s.CreateSQLQuery(@" (select {p.*}, 0 as Score from Products p where p.Name like :term) union (select {p.*}, 1 as Score from Products p where p.Name like :fullterm and p.Name not like :term) order by Score, {p.Name}") .AddEntity("p", typeof(Product)) .SetParameter("term", t + "%") .SetParameter("fullterm", "%" + t + "%") .List <Product>() .ToList()); })) .Subscribe(Catalogs, CloseCancellation.Token); Catalogs.Subscribe(x => IsCatalogOpen.Value = x != null && x.Count > 0); CurrentCatalog.Subscribe(v => { Item.ProductId = (v != null && v.Id > 0) ? v.Id : 0; Item.CatalogId = (v != null && v.CatalogId > 0) ? v.CatalogId : 0; Item.Product = (v != null && v.Id > 0) ? v.Name : string.Empty; }); ProducerTerm .Throttle(Consts.TextInputLoadTimeout, Scheduler) .Do(t => { if (String.IsNullOrEmpty(t)) { CurrentProducer.Value = null; } }) .SelectMany(t => RxQuery(s => { if (String.IsNullOrEmpty(t)) { return(s.Query <Producer>().OrderBy(x => x.Name).ToList()); } if (CurrentProducer.Value != null && CurrentProducer.Value.Name == t) { return(Producers.Value); } return(s.CreateSQLQuery(@" (select {p.*}, 0 as Score from Producers p where p.Name like :term) union (select {p.*}, 1 as Score from Producers p where p.Name like :fullterm and p.Name not like :term) order by Score, {p.Name}") .AddEntity("p", typeof(Producer)) .SetParameter("term", t + "%") .SetParameter("fullterm", "%" + t + "%") .List <Producer>() .ToList()); })) .Subscribe(Producers, CloseCancellation.Token); Producers.Subscribe(x => IsProducerOpen.Value = x != null && x.Count > 0); CurrentProducer.Subscribe(v => { Item.Producer = (v != null && v.Id > 0) ? v.Name : string.Empty; Item.ProducerId = (v != null && v.Id > 0) ? v.Id : (uint?)null; }); }
public CatalogChooser(string term, Address address) { BaseScreen.InitFields(this); DisplayName = "Выберите товар"; WasCancelled = true; var env = Config.Env.Current; SearchBehavior = new SearchBehavior(env); SearchBehavior.ActiveSearchTerm.Value = term; SearchBehavior.ActiveSearchTerm .Do(_ => IsLoading.Value = true) .Select(_ => env.RxQuery(s => { var sql = @" drop temporary table if exists StockCatalogs; create temporary table StockCatalogs( CatalogId int unsigned, MinRetailCost decimal(12, 2), primary key(CatalogId) ); insert into StockCatalogs select CatalogId, min(RetailCost) as MinRetailCost from Stocks where AddressId = @addressId and Quantity > 0 and Status = @stockStatus and RetailCost > 0 group by CatalogId; drop temporary table if exists GroupByType; create temporary table GroupByType ( MnnId int unsigned, Type int unsigned, MinRetailCost decimal(12, 2), primary key(MnnId, Type) ) select cn.MnnId, c.Type, min(MinRetailCost) as MinRetailCost from StockCatalogs s join Catalogs c on c.Id = s.CatalogId join CatalogNames cn on cn.Id = c.NameId where cn.MnnId is not null and c.Type is not null group by cn.MnnId, c.Type; select c.Id as CatalogId, cn.Name, c.Form, c.HaveOffers, c.VitallyImportant, s.MinRetailCost as MinRetailCost, t.MinRetailCost as MinEquivalentCost from Catalogs c join CatalogNames cn on cn.Id = c.NameId left join StockCatalogs s on s.CatalogId = c.Id left join GroupByType t on t.MnnId = cn.MnnId and t.Type = c.TYpe where (cn.Name like @term or c.Form like @term) and (s.CatalogId is not null or t.MnnId is not null) order by cn.Name, c.Form; drop temporary table GroupByType; drop temporary table StockCatalogs; "; return(s.Connection.Query <CatalogLine>(sql, new { term = "%" + SearchBehavior.ActiveSearchTerm.Value + "%", addressId = address.Id, stockStatus = StockStatus.Available }).ToList()); })) .Switch() .Do(_ => IsLoading.Value = false) .Subscribe(Items); Items.Subscribe(_ => { CurrentItem.Value = (Items.Value ?? Enumerable.Empty <CatalogDisplayItem>()).FirstOrDefault(); }); CurrentItem .SelectMany(x => Env.RxQuery(s => { if (x == null) { return(null); } var catalogId = x.CatalogId; return(s.Query <Catalog>() .Fetch(c => c.Name) .ThenFetch(n => n.Mnn) .FirstOrDefault(c => c.Id == catalogId)); })) .Subscribe(CurrentCatalog, CloseCancellation.Token); CurrentCatalog.Select(x => x?.Name?.Description != null).Subscribe(CanShowDescription); }
protected override void OnInitialize() { base.OnInitialize(); RxQuery(s => { return(s.Query <Catalog>() .Join(s.Query <Stock>(), catalog => catalog.Id, stock => stock.ProductId, (catalog, stock) => new { catalog, stock }) .Where(p => p.stock.Status == StockStatus.Available) .Select(c => c.catalog) .OrderBy(c => c.Name) .Distinct() .ToArray() .ToList()); }).Subscribe(Catalogs); Catalogs .Changed() .Throttle(TimeSpan.FromMilliseconds(30), Scheduler) .Subscribe(_ => { CurrentCatalog.Value = (Catalogs.Value ?? Enumerable.Empty <Catalog>()).FirstOrDefault(); }); CurrentCatalog .Changed() .Select(_ => RxQuery(LoadAddressStock)) .Switch() .Subscribe(AddressStock, CloseCancellation.Token); AddressStock .Changed() .Throttle(TimeSpan.FromMilliseconds(30), Scheduler) .Subscribe(_ => { CurrentAddressStock.Value = (AddressStock.Value ?? Enumerable.Empty <AddressStock>()).FirstOrDefault(); }); CurrentAddressStock .Changed() .Select(_ => RxQuery(LoadStoks)) .Switch() .Subscribe(Stocks, CloseCancellation.Token); Stocks .Changed() .Throttle(TimeSpan.FromMilliseconds(30), Scheduler) .Subscribe(_ => { CurrentStock.Value = (Stocks.Value ?? Enumerable.Empty <Stock>()).FirstOrDefault(); }); CurrentStock .Changed() .Select(_ => RxQuery(LoadStockActions)) .Switch() .Subscribe(StockActions, CloseCancellation.Token); StockActions .Changed() .Throttle(TimeSpan.FromMilliseconds(30), Scheduler) .Subscribe(_ => { CurrentStockAction.Value = (StockActions.Value ?? Enumerable.Empty <StockAction>()).FirstOrDefault(); }); }
protected override void OnInitialize() { base.OnInitialize(); Catalogs = CatalogTerm .Throttle(Consts.TextInputLoadTimeout, Scheduler) .Select(t => RxQuery(s => { if (String.IsNullOrEmpty(t)) { return(new List <Catalog>()); } if (CurrentCatalog.Value != null && CurrentCatalog.Value.FullName == t) { return(Catalogs.Value); } return(s.CreateSQLQuery(@" (select {c.*}, 0 as Score from Catalogs c where c.Fullname like :term) union distinct (select {c.*}, 1 as Score from Catalogs c where c.Fullname like :fullterm) order by Score, {c.FullName}") .AddEntity("c", typeof(Catalog)) .SetParameter("term", t + "%") .SetParameter("fullterm", "%" + t + "%") .List <Catalog>() .ToList()); })) .Switch() .ToValue(CloseCancellation); IsCatalogOpen = Catalogs.Select(v => v != null && v.Count > 0).Where(v => v).ToValue(); CurrentCatalog.Subscribe(v => Item.Catalog = v); Producers = ProducerTerm .Throttle(Consts.TextInputLoadTimeout, Scheduler) .Select(t => RxQuery(s => { if (String.IsNullOrEmpty(t)) { return new List <Producer> { emptyProducer } } ; if (CurrentProducer.Value != null && CurrentProducer.Value.Name == t) { return(Producers.Value); } CurrentProducer.Value = null; var items = s.CreateSQLQuery(@" (select {p.*}, 0 as Score from Producers p where p.Name like :term) union distinct (select {p.*}, 1 as Score from Producers p where p.Name like :fullterm) order by Score, {p.Name}") .AddEntity("p", typeof(Producer)) .SetParameter("term", t + "%") .SetParameter("fullterm", "%" + t + "%") .List <Producer>(); return(new[] { emptyProducer }.Concat(items).ToList()); })) .Switch() .ToValue(CloseCancellation); IsProducerOpen = Producers.Select(v => v != null && v.Count > 1).Where(v => v).ToValue(); CurrentProducer.Subscribe(v => Item.Producer = (v != null && v.Id > 0) ? v : null); }
protected override void OnInitialize() { base.OnInitialize(); Promotions = new PromotionPopup(Shell.Config, CurrentCatalog.Select(x => x?.Name), Env); ProducerPromotions = new ProducerPromotionPopup(Shell.Config, CurrentCatalog.Select(x => x?.Name), Env); OrderWarning = new InlineEditWarning(UiScheduler, Manager); CurrentOffer .Throttle(Consts.LoadOrderHistoryTimeout, Scheduler) .Select(_ => RxQuery(LoadHistoryOrders)) .Switch() .Subscribe(HistoryOrders, CloseCancellation.Token); CurrentOffer .Where(x => !(x?.StatLoaded).GetValueOrDefault()) .Throttle(Consts.LoadOrderHistoryTimeout, Scheduler) .Select(_ => RxQuery(LoadStat)) .Switch() .Subscribe(x => { if (x == null || CurrentOffer.Value == null) { return; } ApplyStat(x); }, CloseCancellation.Token); CurrentOffer #if !DEBUG .Throttle(Consts.ScrollLoadTimeout) #endif .Select(x => RxQuery(s => { if (x == null) { return(null); } if (CurrentCatalog.Value?.Id == x.CatalogId) { return(CurrentCatalog.Value); } var sql = @"select c.*, cn.*, m.*, cn.DescriptionId as Id from Catalogs c join CatalogNames cn on cn.Id = c.NameId left join Mnns m on m.Id = cn.MnnId where c.Id = ?"; return(s .Connection.Query <Catalog, CatalogName, Mnn, ProductDescription, Catalog>(sql, (c, cn, m, d) => { c.Name = cn; if (cn != null) { cn.Mnn = m; cn.Description = d; } return c; }, new { x.CatalogId }).FirstOrDefault()); })) .Switch() .Subscribe(CurrentCatalog, CloseCancellation.Token); //изменения в LastEditOffer могут произойти уже после перехода на другое предложение //по этому нужно отслеживать изменения в CurrentOffer и LastEditOffer var observable = this.ObservableForProperty(m => m.CurrentOffer.Value.OrderCount) .Merge(this.ObservableForProperty(m => m.LastEditOffer.Value.OrderCount)) .Throttle(Consts.RefreshOrderStatTimeout, UiScheduler) .Select(e => new Stat(Address)); OnCloseDisposable.Add(Bus.RegisterMessageSource(observable)); }