示例#1
0
        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;
            });
        }
示例#2
0
        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();

            Producers = ProducerTerm
                        .Throttle(Consts.TextInputLoadTimeout, Scheduler)
                        .Select(t => RxQuery(s => {
                if (String.IsNullOrEmpty(t))
                {
                    return(new List <Producer>());
                }
                if (CurrentProducer.Value != null && CurrentProducer.Value.Name == t)
                {
                    return(Producers.Value);
                }

                CurrentProducer.Value = null;
                return(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>()
                       .ToList());
            }))
                        .Switch()
                        .ToValue(CloseCancellation);
            IsProducerOpen = Producers.Select(v => v != null && v.Count > 1).Where(v => v).ToValue();
        }