예제 #1
0
        public override void Open()
        {
            CloseActiveMenus(); //main menus never overlap

            if (!init)
            {   //create items on first opening, otherwise pointers to 'Open()-Methods' of other menus, which are yet not constructed, will be used => crash
                //could also be solved with static Open()-Methods
                OnCreate();
                init = true;
            }

            base.Open();
            Back.Show();
            helpVis.Show();
            for (int i = 0; i < items.Count; i++)
            {
                items[i].Show();
            }

            cursor      = preferredCursorItem;
            CurrentItem = items[cursor];

            if (!CurrentItem.Enabled)
            {
                sndEnabled = false; //sound would be played on opening
                MoveCursor();
                sndEnabled = true;
            }
            CurrentItem.Select();
            UpdateHelpText();

            isOpen = true;
        }
예제 #2
0
 internal void HandleToolStripMouseLeave(ToolStrip toolStrip)
 {
     if (InTransition && toolStrip == fromItem.ParentInternal)
     {
         // restore the selection back to CurrentItem.
         // we're about to fall off the edge of the toolstrip, something should be selected
         // at all times while we're InTransition mode - otherwise it looks really funny
         // to have an auto expanded item
         if (CurrentItem is not null)
         {
             CurrentItem.Select();
         }
     }
     else
     {
         // because we've split up selected/pressed, we need to make sure
         // that onmouseleave we make sure there's a selected menu item.
         if (toolStrip.IsDropDown && toolStrip.ActiveDropDowns.Count > 0)
         {
             ToolStripMenuItem menuItem = (!(toolStrip.ActiveDropDowns[0] is ToolStripDropDown dropDown)) ? null : dropDown.OwnerItem as ToolStripMenuItem;
             if (menuItem is not null && menuItem.Pressed)
             {
                 menuItem.Select();
             }
         }
     }
 }
예제 #3
0
        protected void MoveCursor(bool up)
        {
            CurrentItem.Deselect();
            for (int i = 0; i < items.Count; i++)
            {
                if (up)
                {
                    cursor--;
                    if (cursor < 0)
                    {
                        cursor = items.Count - 1;
                    }
                }
                else
                {
                    cursor++;
                    if (cursor >= items.Count)
                    {
                        cursor = 0;
                    }
                }

                CurrentItem = items[cursor];
                if (CurrentItem.Enabled)
                {
                    CurrentItem.Select();
                    UpdateHelpText();
                    break;
                }
            }
            PlaySound(sndBrowse);
        }
예제 #4
0
 protected void SetCursor(int i)
 {
     if (i >= 0 && i < items.Count)
     {
         MainMenuItem newItem = items[i];
         if (newItem.Enabled)
         {
             CurrentItem.Deselect();
             cursor      = i;
             CurrentItem = newItem;
             CurrentItem.Select();
             UpdateHelpText();
         }
     }
 }
예제 #5
0
        protected void SetCursor(int i)
        {
            if (i >= 0 && i < Items.Count)
            {
                MainMenuItem newItem = Items[i];
                if (newItem.Enabled)
                {
                    CurrentItem?.Deselect();
                    cursor      = i;
                    CurrentItem = newItem;
                    CurrentItem.Select();
                    UpdateHelpText();
                }

                CursorChanged?.Invoke(this);
            }
        }
예제 #6
0
        protected void MoveCursor(bool up)
        {
            //We do not have any items so we can not change the selected item.
            if ((Items?.Count ?? 0) <= 0)
            {
                return;
            }

            CurrentItem?.Deselect();


            for (int i = 0; i < Items.Count; i++)
            {
                if (up)
                {
                    cursor--;
                    if (cursor < 0)
                    {
                        cursor = Items.Count - 1;
                    }
                }
                else
                {
                    cursor++;
                    if (cursor >= Items.Count)
                    {
                        cursor = 0;
                    }
                }

                CurrentItem = Items[cursor];
                if (CurrentItem.Enabled)
                {
                    CurrentItem.Select();
                    UpdateHelpText();
                    break;
                }
            }
            PlaySound(sndBrowse);
            CursorChanged?.Invoke(this);
        }
예제 #7
0
        public Stocks()
        {
            DisplayName            = "Товарные запасы";
            AddressSelector        = new AddressSelector(this);
            Items.PropertyChanged += Items_PropertyChanged;
            ItemsTotal             = new ObservableCollection <StockTotal>();
            ItemsTotal.Add(new StockTotal {
                Total = "Итого",
            });

            Name = User?.FullName ?? "";
            StatusFilter.Value = DescriptionHelper.GetDescriptions(typeof(StockStatus))
                                 .Select(x => new Selectable <StockStatus>((StockStatus)x.Value, x.Name))
                                 .ToList();
            QuickSearch = new QuickSearch <Stock>(UiScheduler,
                                                  t => Items?.Value.FirstOrDefault(p => p.Product.IndexOf(t, StringComparison.CurrentCultureIgnoreCase) >= 0),
                                                  CurrentItem);
            TrackDb(typeof(Stock));

            PrintMenuItems = new ObservableCollection <MenuItem>();
            IsView         = true;
            CurrentItem.Select(x => x?.WaybillId != null).Subscribe(CanOpenWaybill);
        }
예제 #8
0
        public Index()
        {
            InitFields();

            DisplayName = "Сбис";
            CurrentItem
            .Select(x => {
                if (x == null)
                {
                    return(Observable.Return <string>(null));
                }
                return(Observable.StartAsync(async() => {
                    var dir = FileHelper.MakeRooted("sbis");
                    Directory.CreateDirectory(dir);
                    var filename = Directory.GetFiles(dir, $"{x.Attachment.Идентификатор}.*").FirstOrDefault();
                    if (!String.IsNullOrEmpty(filename))
                    {
                        return filename;
                    }

                    var result = await client.JsonRpc("СБИС.ПрочитатьДокумент", new {
                        Документ = new {
                            Идентификатор = x.Message.Идентификатор,
                        }
                    });
                    var attachments = result["result"]["Вложение"].ToObject <Attach[]>();
                    var attachment = attachments.FirstOrDefault(y => y.Идентификатор == x.Attachment.Идентификатор);
                    if (attachment == null)
                    {
                        throw new Exception($"Не удалось найти вложение с идентификатором {x.Attachment.Идентификатор}");
                    }

                    x.Attachment = attachment;
                    filename = Path.Combine(dir, x.Attachment.Идентификатор + Path.GetExtension(x.FileName));
                    await LoadToFile(filename, attachment.Файл.Ссылка);
                    return filename;
                }).Catch <string, Exception>(y => {
                    Log.Error("Не удалось загрузить документ", y);
                    return Observable.Return <string>(null);
                }));
            })
            .Switch()
            .ObserveOn(UiScheduler)
            .CatchSubscribe(x => {
                if (CurrentItem.Value != null)
                {
                    CurrentItem.Value.LocalFilename = x;
                }
                Filename.Value = x;
            });
            Filename.Select(x => {
                if (x == null)
                {
                    return(Observable.Return <string>(null));
                }

                var attachment = CurrentItem.Value;
                if (fileformats.Contains(Path.GetExtension(x) ?? "", StringComparer.CurrentCultureIgnoreCase))
                {
                    return(Observable.Return(x));
                }

                return(Observable
                       .StartAsync(async() => await LoadPrintPdf(attachment))
                       .Catch <string, Exception>(y => {
                    Log.Error("Не удалось загрузить pdf");
                    return Observable.Return <string>(null);
                }));
            })
            .Switch()
            .ObserveOn(UiScheduler)
            .Subscribe(PreviewFilename);

            CurrentItem.Select(x => (x?.CanSign()).GetValueOrDefault())
            .Subscribe(CanSign);
            CurrentItem.Select(x => (x?.CanSign()).GetValueOrDefault())
            .Subscribe(CanReject);

            Filename.Select(x => x != null)
            .Subscribe(CanOpen);
            Filename.Select(x => x != null)
            .Subscribe(CanSave);
            CurrentItem.Select(x => x != null)
            .Subscribe(CanDelete);
            CurrentItem.Select(x => x != null)
            .Subscribe(CanDeleteItem);
            CurrentItem.Select(x => x != null)
            .Subscribe(CanPrintItem);

            SearchTerm
            .Throttle(Consts.TextInputLoadTimeout, Scheduler)
            .Select(x => String.IsNullOrEmpty(x)
                                        ? items.ToObservableCollection()
                                        : items.Where(y => y.FileName.IndexOf(x, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    .ToObservableCollection())
            .Subscribe(Items);
            //CurrentItem.Select(x => AttachmentHistory.Collect(x))
            //	.Subscribe(History);
            IsLoading.Select(x => !x).Subscribe(IsLoaded);
            IsLoading.Select(x => !x).Subscribe(CanPrev);
            IsLoading.Select(x => !x).Subscribe(CanNext);
            IsLoading.Select(x => !x).Subscribe(CanReload);
        }
예제 #9
0
        public Index()
        {
            DisplayName = "Диадок";
            InitFields();

            CurrentItem.Subscribe(LoadFiles);
            CurrentItem
            .Select(x => {
                if (x == null)
                {
                    return(Observable.Return <string>(null));
                }
                return(Observable.Start(() => {
                    var dir = FileHelper.MakeRooted("diadok");
                    Directory.CreateDirectory(dir);
                    var filename = Directory.GetFiles(dir, $"{x.Entity.EntityId}.*").FirstOrDefault();
                    if (!String.IsNullOrEmpty(filename))
                    {
                        return filename;
                    }

                    var bytes = x.Entity.Content.Data
                                ?? api.GetEntityContent(token, box.BoxId, x.Entity.DocumentInfo.MessageId, x.Entity.EntityId);
                    filename = Path.Combine(dir, x.Entity.EntityId + Path.GetExtension(x.Entity.FileName));
                    File.WriteAllBytes(filename, bytes);
                    return filename;
                }, Scheduler).DefaultIfFail());
            })
            .Switch()
            .ObserveOn(UiScheduler)
            .CatchSubscribe(x => {
                if (CurrentItem.Value != null)
                {
                    CurrentItem.Value.LocalFilename = x;
                }
                Filename.Value = x;
            });
            Filename.Select(x => {
                if (x == null)
                {
                    return(Observable.Return <string>(null));
                }

                var attachment = CurrentItem.Value;
                if (fileformats.Contains(Path.GetExtension(x) ?? "", StringComparer.CurrentCultureIgnoreCase))
                {
                    return(Observable.Return(x));
                }

                return(Observable.Start(() => LoadPrintPdf(attachment), Scheduler).DefaultIfFail());
            })
            .Switch()
            .ObserveOn(UiScheduler)
            .Subscribe(PreviewFilename);

            CurrentItem.Select(x => (x?.CanSign()).GetValueOrDefault())
            .Subscribe(CanSign);
            CurrentItem.Select(x => (x?.CanSign()).GetValueOrDefault())
            .Subscribe(CanReject);
            CurrentItem.Select(x => (x?.CanSign()).GetValueOrDefault())
            .Subscribe(CanRequestSign);
            CurrentItem.Select(x => x != null &&
                               !(x.Entity.DocumentInfo.NonformalizedDocumentMetadata?.DocumentStatus == NonformalizedDocumentStatus.InboundRecipientSignatureRequestRejected ||
                                 x.Entity.DocumentInfo.RevocationStatus != RevocationStatus.RevocationStatusNone))
            .Subscribe(CanRevoke);

            Filename.Select(x => x != null)
            .Subscribe(CanOpen);
            Filename.Select(x => x != null)
            .Subscribe(CanSave);
            CurrentItem.Select(x => x != null)
            .Subscribe(CanDelete);
            CurrentItem.Select(x => x != null)
            .Subscribe(CanDeleteItem);
            CurrentItem.Select(x => x != null)
            .Subscribe(CanRequestResolution);
            CurrentItem.Select(x => x != null)
            .Subscribe(CanApprove);
            CurrentItem.Select(x => x != null)
            .Subscribe(CanDisapprove);
            CurrentItem.Select(x => x != null)
            .Subscribe(CanPrintItem);

            SearchTerm
            .Throttle(Consts.TextInputLoadTimeout, Scheduler)
            .Select(x => String.IsNullOrEmpty(x)
                                        ? items.ToObservableCollection()
                                        : items.Where(y => y.FileName.IndexOf(x, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    .ToObservableCollection())
            .Subscribe(Items);
            CurrentItem.Select(x => AttachmentHistory.Collect(x))
            .Subscribe(History);
            IsLoading.Select(x => !x).Subscribe(IsLoaded);
            IsLoading.Select(x => !x).Subscribe(CanPrev);
            IsLoading.Select(x => !x).Subscribe(CanNext);
            IsLoading.Select(x => !x).Subscribe(CanReload);
        }