Beispiel #1
0
        public SearchOfferViewModel()
        {
            DisplayName           = "Поиск в прайс-листах";
            NeedToCalculateDiff   = true;
            NavigateOnShowCatalog = true;

            HideJunk = new NotifyValue <bool>();
            OnlyBase = new NotifyValue <bool>();

            if (Session != null)
            {
                Prices = Session.Query <Price>()
                         .OrderBy(p => p.Name)
                         .Select(p => new Selectable <Price>(p))
                         .ToList();
            }
            else
            {
                Prices = new List <Selectable <Price> >();
            }
            Settings.Subscribe(_ => {
                Offers.Value = SortOffers(Offers.Value);
            });
            SearchBehavior = new SearchBehavior(this);
            IsLoading      = new NotifyValue <bool>();
            Persist(HideJunk, "HideJunk");
        }
        public PriceOfferViewModel(PriceComposedId priceId, bool showLeaders, OfferComposedId initOfferId = null)
            : base(initOfferId)
        {
            //мы не можем принимать объект который принадлежит другой форме
            //это может вызвать исключение если сессия в которой был загружен объект будет закрыта
            //утечки памяти если текущая форма подпишется на события изменения в переданном объекте
            //между формами можно передавать только примитивные объекты
            this.priceId = priceId;

            DisplayName = "Заявка поставщику";
            Price       = new NotifyValue <Price>();
            IsLoading   = new NotifyValue <bool>();

            Filters       = filters;
            CurrentFilter = new NotifyValue <string>(filters[0]);
            if (showLeaders)
            {
                FilterLeader();
            }

            //по идее это не нужно тк обо всем должен позаботится сборщик мусора
            //но если не удалить подписку будет утечка памяти
            OnCloseDisposable.Add(this.ObservableForProperty(m => m.Price.Value.Order)
                                  .Subscribe(_ => NotifyOfPropertyChange(nameof(CanDeleteOrder))));
            SearchBehavior = new SearchBehavior(this);

            CurrentProducer.Cast <object>()
            .Merge(CurrentFilter.Cast <object>())
            .Merge(SearchBehavior.ActiveSearchTerm.Cast <object>())
            .Subscribe(_ => Filter());

            PrintMenuItems = new ObservableCollection <MenuItem>();
            IsView         = true;
        }
        public CatalogSearchViewModel(CatalogViewModel catalog)
        {
            Shell = catalog.Shell;
            InitFields();
            Items.Value = new List <CatalogDisplayItem>();
            CurrentItem
#if !DEBUG
            .Throttle(Consts.ScrollLoadTimeout, UiScheduler)
#endif
            .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);
            ParentModel = catalog;
            QuickSearch = new QuickSearch <CatalogDisplayItem>(UiScheduler,
                                                               v => Items.Value.FirstOrDefault(c => c.Name.StartsWith(v, StringComparison.CurrentCultureIgnoreCase)),
                                                               CurrentItem);
            QuickSearch.IsEnabled = false;

            SearchBehavior  = new SearchBehavior(this);
            IsLoading.Value = true;
            IsQuickSearchEnabled.Subscribe(v => {
                QuickSearch.IsEnabled = v;
                SearchBehavior.HandleGridKeyboardInput = !v;
            });
        }
 public MinCosts()
 {
     DisplayName    = "Минимальные цены";
     CurrentCost    = new NotifyValue <MinCost>();
     Diff           = new NotifyValue <int>(7);
     SearchBehavior = new SearchBehavior(this);
     IsLoading      = new NotifyValue <bool>(true);
     Persist(Diff, "Diff");
 }
Beispiel #5
0
 public StockSearch(decimal cost)
 {
     DisplayName    = "Поиск товара по цене";
     SearchBehavior = new SearchBehavior(this);
     SearchBehavior.ActiveSearchTerm.Value = cost.ToString();
     SearchBehavior.SearchText.Value       = cost.ToString();
     WasCancelled = true;
     Type         = SearchType.ByCost;
 }
Beispiel #6
0
 public StockSearch(uint id)
 {
     DisplayName    = "Поиск товара по поставщику";
     SearchBehavior = new SearchBehavior(this);
     SearchBehavior.ActiveSearchTerm.Value = id.ToString();
     SearchBehavior.SearchText.Value       = id.ToString();
     WasCancelled = true;
     Type         = SearchType.BySupplier;
 }
Beispiel #7
0
        public void Do_not_update()
        {
            var screen   = new TestScreen();
            var behavior = new SearchBehavior(screen);

            behavior.SearchText.Value = "test";
            behavior.Search();
            Assert.AreEqual("", behavior.SearchText.Value);
            Assert.AreEqual("test", behavior.ActiveSearchTerm.Value);
        }
Beispiel #8
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);
 }
Beispiel #9
0
        public StockSearch(string term = "")
        {
            DisplayName    = "Поиск товара по названию";
            SearchBehavior = new SearchBehavior(this);
            SearchBehavior.ActiveSearchTerm.Value = term;
            SearchBehavior.SearchText.Value       = term;
            WasCancelled       = true;
            Type               = SearchType.ByName;
            IsTheOnlyProductId = false;

            Items.Subscribe(s => {
                if (Items.HasValue && (Items.Value.Count == 1) &&
                    !IsTheOnlyProductId)
                {
                    IsTheOnlyProductId = true;
                    SearchBehavior.ActiveSearchTerm.Mute("");
                    SearchBehavior.SearchText.Mute("");
                    if (SelectItemsByStockProducerId(Items.Value.First()))
                    {
                        var sortedValues  = Items.Value.OrderBy(x => x.Exp).ThenBy(x => x.Product).ToList();
                        Items.Value       = null;
                        Items.Value       = sortedValues;
                        CurrentItem.Value = Items.Value.First();
                    }
                }

                if (Items.HasValue &&
                    Items.Value.Count > 1 &&
                    Items.Value.Where(i => i.ProductId.HasValue).Select(d => d.ProductId).GroupBy(f => f.Value).ToList().Count == 1 &&
                    !IsTheOnlyProductId)
                {
                    IsTheOnlyProductId = true;
                    SearchBehavior.ActiveSearchTerm.Mute("");
                    SearchBehavior.SearchText.Mute("");
                    var sortedValues  = Items.Value.OrderBy(x => x.Exp).ThenBy(x => x.Product).ToList();
                    Items.Value       = null;
                    Items.Value       = sortedValues;
                    CurrentItem.Value = Items.Value.First();
                }
                if (IsTheOnlyProductId && Items.HasValue &&
                    Items.Value.Count > 1 &&
                    Items.Value.Where(i => i.ProductId.HasValue).Select(d => d.ProductId).GroupBy(f => f.Value).ToList().Count != 1)
                {
                    IsTheOnlyProductId = false;
                    SearchBehavior.ActiveSearchTerm.Mute("");
                    SearchBehavior.SearchText.Mute("");
                    CurrentItem.Value = Items.Value.First();
                }
            });
        }
        public WaybillLineSearch(DateTime begin, DateTime end)
        {
            DisplayName = "Поиск товара в накладных";
            this.begin  = begin;
            this.end    = end;

            Lines          = new NotifyValue <List <WaybillLine> >(new List <WaybillLine>());
            SearchBehavior = new SearchBehavior(this);
            CurrentLine    = new NotifyValue <WaybillLine>();
            CanEnterLine   = new NotifyValue <bool>();

            CurrentLine.Select(x => x != null)
            .Subscribe(CanEnterLine);
        }
Beispiel #11
0
        public Checks()
        {
            Dialog           = false;
            DialogCancelled  = true;
            Begin.Value      = DateTime.Today.AddDays(-7);
            End.Value        = DateTime.Today;
            ChangeDate.Value = DateTime.Today;
            SearchBehavior   = new SearchBehavior(this);
            AddressSelector  = new AddressSelector(this);
            DisplayName      = "Чеки";
            TrackDb(typeof(Check));

            PrintMenuItems = new ObservableCollection <MenuItem>();
            IsView         = true;
            var stat = new ChecksStat();

            Stat = new List <ChecksStat> {
                stat
            };
            Items.Subscribe(x => {
                stat.Sum       = x?.Sum(y => y.CheckType == CheckType.CheckReturn ? -y.Sum : y.Sum) ?? 0;
                stat.RetailSum = x?.Sum(y => y.CheckType == CheckType.CheckReturn ? -y.RetailSum : y.RetailSum) ?? 0;
            });
        }
Beispiel #12
0
 public MnnViewModel()
 {
     DisplayName = "Поиск по МНН";
     InitFields();
     SearchBehavior = new SearchBehavior(this);
 }
Beispiel #13
0
        public Batch()
        {
            NavigateOnShowCatalog = true;
            DisplayName           = "АвтоЗаказ";
            AddressSelector       = new AddressSelector(this);
            Filter = new[] {
                "Все",
                "Заказано",
                "   Минимальные",
                "   Не минимальные",
                "   Присутствующие в замороженных заказах",
                "   Ограничен лимитом",
                "Не заказано",
                "   Нет предложений",
                "   Нулевое количество",
                "   Прочее",
                "   Не сопоставлено",
                "   Лимит исчерпан"
            };
            CurrentFilter  = new NotifyValue <string>("Все");
            SearchBehavior = new SearchBehavior(this);
            Lines          = new NotifyValue <ObservableCollection <BatchLineView> >(new ObservableCollection <BatchLineView>());
            ReportLines    = new NotifyValue <ObservableCollection <BatchLineView> >(() => {
                var query = Lines.Value.Where(l => l.Product.CultureContains(SearchBehavior.ActiveSearchTerm.Value) &&
                                              (l.OrderLine != null || !l.BatchLine.Status.HasFlag(ItemToOrderStatus.Ordered)));
                if (CurrentFilter.Value == Filter[1])
                {
                    query = query.Where(l => !l.IsNotOrdered);
                }
                else if (CurrentFilter.Value == Filter[2])
                {
                    query = query.Where(l => !l.IsNotOrdered && l.IsMinCost);
                }
                else if (CurrentFilter.Value == Filter[3])
                {
                    query = query.Where(l => !l.IsNotOrdered && !l.IsMinCost);
                }
                else if (CurrentFilter.Value == Filter[4])
                {
                    query = query.Where(l => !l.IsNotOrdered && l.ExistsInFreezed);
                }
                else if (CurrentFilter.Value == Filter[5])
                {
                    query = query.Where(l => l.IsSplitByLimit);
                }
                else if (CurrentFilter.Value == Filter[6])
                {
                    query = query.Where(l => l.IsNotOrdered);
                }
                else if (CurrentFilter.Value == Filter[7])
                {
                    query = query.Where(l => l.IsNotOrdered && !l.BatchLine.Status.HasFlag(ItemToOrderStatus.OffersExists));
                }
                else if (CurrentFilter.Value == Filter[8])
                {
                    query = query.Where(l => l.IsNotOrdered && l.BatchLine.Quantity == 0);
                }
                else if (CurrentFilter.Value == Filter[9])
                {
                    query = query.Where(l => l.IsNotOrdered && l.BatchLine.Quantity > 0 &&
                                        l.BatchLine.ProductId != null &&
                                        l.BatchLine.Status.HasFlag(ItemToOrderStatus.OffersExists));
                }
                else if (CurrentFilter.Value == Filter[10])
                {
                    query = query.Where(l => l.IsNotOrdered && l.BatchLine.ProductId == null);
                }
                else if (CurrentFilter.Value == Filter[11])
                {
                    query = query.Where(l => l.IsLimited);
                }
                return(query.OrderBy(l => l.Product).ToObservableCollection());
            }, CurrentFilter, SearchBehavior.ActiveSearchTerm);
            CurrentReportLine   = new NotifyValue <BatchLineView>();
            CanDelete           = CurrentReportLine.Select(l => l != null).ToValue();
            SelectedReportLines = new List <BatchLineView>();
            CanClear            = Lines.CollectionChanged()
                                  .Select(e => e.Sender as ObservableCollection <BatchLineView>)
                                  .Select(v => v != null && v.Count > 0).ToValue();
            CanReload = Lines.CollectionChanged()
                        .Select(e => e.Sender as ObservableCollection <BatchLineView>)
                        .Select(v => CanUpload && v != null && v.Count > 0).ToValue();
            WatchForUpdate(CurrentReportLine.Select(l => l?.BatchLine));
            ActivePrint = new NotifyValue <string>();
            ActivePrint.Subscribe(ExcelExporter.ActiveProperty);
            CurrentFilter.Subscribe(_ => SearchBehavior.ActiveSearchTerm.Value = "");
            ReportEditor = new ReportEditor(this);

            PrintMenuItems = new ObservableCollection <MenuItem>();
            IsView         = true;
        }
Beispiel #14
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);
        }
Beispiel #15
0
 public SearchBehaviorAttribute(SearchBehavior behavior)
 {
     Behavior = behavior;
 }
        public SettingsViewModel()
        {
            InitFields();

            DisplayName       = "Настройка";
            SelectedTab.Value = lastTab ?? "OverMarkupsTab";

            if (String.IsNullOrEmpty(Settings.Value.WaybillDir))
            {
                Settings.Value.WaybillDir = Settings.Value.MapPath("Waybills");
            }
            if (String.IsNullOrEmpty(Settings.Value.RejectDir))
            {
                Settings.Value.RejectDir = Settings.Value.MapPath("Rejects");
            }
            if (String.IsNullOrEmpty(Settings.Value.ReportDir))
            {
                Settings.Value.ReportDir = Settings.Value.MapPath("Reports");
            }

            password       = Mask(Settings.Value.Password);
            diadokPassword = Mask(Settings.Value.DiadokPassword);
            sbisPassword   = Mask(Settings.Value.SbisPassword);

            waybillConfig = Settings.Value.Waybills;
            if (Session != null)
            {
                Session.FlushMode   = FlushMode.Never;
                DirMaps             = Session.Query <DirMap>().Where(m => m.Supplier.Name != null).OrderBy(d => d.Supplier.FullName).ToList();
                CurrentDirMap.Value = DirMaps.FirstOrDefault();

                var styles    = Session.Query <CustomStyle>().OrderBy(s => s.Description).ToList();
                var newStyles = StyleHelper.GetDefaultStyles().Except(styles);
                Session.SaveEach(newStyles);
                Styles = Session.Query <CustomStyle>().OrderBy(s => s.Description).ToList();
            }

            HaveAddresses = Addresses.Length > 0;
            MarkupAddress.Select(x => MarkupByType(MarkupType.Over, x))
            .Subscribe(Markups);
            MarkupAddress.Select(x => MarkupByType(MarkupType.VitallyImportant, x))
            .Subscribe(VitallyImportantMarkups);
            MarkupAddress.Select(x => MarkupByType(MarkupType.Nds18, x))
            .Subscribe(Nds18Markups);
            MarkupAddress.Select(x => MarkupByType(MarkupType.Special, x))
            .Subscribe(SpecialMarkups);
            MarkupAddress.Select(x => Settings.Value.PriceTags.FirstOrDefault(r => r.Address == x))
            .Subscribe(PriceTagSettings);
            MarkupAddress.Select(x => Settings.Value.PriceTags.FirstOrDefault(r => r.Address == x))
            .Subscribe(_ => LoadPriceTagPreview());

            SearchBehavior = new SearchBehavior(this);
            IsLoading      = new NotifyValue <bool>(true);

            SpecialMarkupSearchText
            .Merge(SpecialMarkupSearchText.Select(v => (object)v))
            .Merge(SpecialMarkupSearchEverywhere.Select(v => (object)v))
            .Merge(SpecialMarkupSearchInStartOfString.Select(v => (object)v))
            .Throttle(TimeSpan.FromMilliseconds(30), Scheduler)
            .Do(_ => IsLoading.Value = true)
            .Select(_ => RxQuery(SearchProduct))
            .Switch()
            .Do(_ => IsLoading.Value = false)
            .Subscribe(Products, CloseCancellation.Token);

            RxQuery(s => s.Query <SpecialMarkupCatalog>().OrderBy(n => n.Name).ToObservableCollection())
            .Subscribe(SpecialMarkupProducts);

            if (string.IsNullOrEmpty(Settings.Value.UserName))
            {
                SelectedTab.Value = "LoginTab";
            }

            SelectedTab.Subscribe(_ => lastTab = SelectedTab.Value);
            Settings.Value.ObservableForProperty(x => x.GroupWaybillsBySupplier, skipInitial: false)
            .Select(x => !x.Value)
            .Subscribe(IsWaybillDirEnabled);

            LastDayForWarnOrdered = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7
            };
            Printers = PrintHelper.GetPrinters().Select(x => x.Name).ToArray();
            if (Session != null)
            {
                WriteoffReasons = new PersistentList <WriteoffReason>(Session.Query <WriteoffReason>().OrderBy(x => x.Name).ToList(), Session);
            }

            MarkupsReadonly.Value        = Settings.Value.HasMarkupGlobalConfig;
            MarkupsReadonlyInverce.Value = !Settings.Value.HasMarkupGlobalConfig;

            MarkupsReadonlyHref.Value = ConfigurationManager.AppSettings.Get("UriOfClientMarkupConfigurator");
        }
 public ProductSearch()
 {
     DisplayName    = "Поиск товара";
     SearchBehavior = new SearchBehavior(this);
     WasCancelled   = true;
 }