Exemple #1
0
 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);
 }
Exemple #2
0
        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");
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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));
        }