private void EventBrokerOnTransferBundleCreated(object o, EventArgs eventArgs)
        {
            if (null == _form)
            {
                return;
            }

            if (_form.IsDisposed)
            {
                return;
            }

            _form.ShowData();
        }
        private void EventBrokerOnContractChanged(object o, EventArgs eventArgs)
        {
            if (null == _form)
            {
                return;
            }

            if (_form.IsDisposed)
            {
                return;
            }

            _form.ShowData();
        }
コード例 #3
0
        public Form GetForm(TransferBundleContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var origin = new FilterOrigin(context.ExtensionManager,
                                          ExtensionCatalog.PreparedTransferFilter)
            {
                MenuItemsTagName  = ExtensionCatalog.Tags.PreparedTransferExtension,
                CommandBarTagName = ExtensionCatalog.Tags.PreparedTransferFilterExtension,
                ColumnsSettings   = context.Session.SettingsService.GetSettings().PreparedTransferSettings
            };

            var template = FilterDisplayHelper.LoadFilterFormTemplate(origin);

            template.Title = string.Format(CultureInfo.InvariantCulture, "{0} <{1}>",
                                           Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "History by bundle"),
                                           context.TransferBundle.Name);

            // Отключаем кнопки.
            foreach (var buttonTemplate in template.FilterScreen.CommandButtons)
            {
                var formProvider =
                    context.ExtensionManager.TryGetTopFormProvider(buttonTemplate.Command);

                if (!(formProvider?.CheckCompatibility(context) ?? false))
                {
                    buttonTemplate.Enabled = false;
                }
            }

            var form = new FilterForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.Load += (sender, args) =>
            {
                form.ShowData();
            };

            form.ApplyTemplate(template);

            var eventBroker = context.UnityContainer.Resolve <IEventBroker>();

            var subscriber = new Subscriber(context, form);

            eventBroker.Subscribe(subscriber, nameof(IPreparedTransferNotification));

            // Сохранение документа
            form.SaveItemsCallback = (s, list) =>
            {
                var importExportService = context.UnityContainer.Resolve <IImportExportService>();
                importExportService.Save(list, s);
            };

            // Сохранение настроек
            form.FormClosing += (sender, args) =>
            {
                var settings         = context.Session.SettingsService.GetSettings();
                var transferSettings = settings.PreparedTransferSettings;

                FilterDisplayHelper.UpdateColumnsSettings(transferSettings, form.SelectGridSettings());

                context.Session.SettingsService.SetSettings(settings);
                context.Session.SettingsService.Save();
            };

            // Меню
            form.MenuItemResolver = (entity, command) =>
            {
                var transfer = form.CurrentEntity as IPreparedTransfer;

                if (null == transfer)
                {
                    return(false);
                }

                var transferContext = new PreparedTransferContext(context, transfer);

                var formProvider = context.ExtensionManager.TryGetPreparedTransferFormProvider(command);
                return(formProvider?.CheckCompatibility(transferContext) ?? false);
            };

            // Обработка событий.
            form.ServiceCommand += (sender, args) =>
            {
                string command = args.Command;

                if (null == command)
                {
                    throw new InvalidOperationException("null == command");
                }

                if (command.StartsWith("CellContentClick:", StringComparison.Ordinal))
                {
                    return;
                }

                if (command.StartsWith("CellMouseDoubleClick:", StringComparison.Ordinal))
                {
                    command = ExtensionCatalog.Details;
                }

                var transfer = args.Argument as IPreparedTransfer;

                // Кнопки
                if (null == transfer)
                {
                    var formProvider = context.ExtensionManager.TryGetTransferBundleFormProvider(command);
                    formProvider?.GetForm(context).Show(form);
                }
                else
                {
                    var transferContext = new PreparedTransferContext(context, transfer);

                    var formProvider = context.ExtensionManager.TryGetPreparedTransferFormProvider(command);
                    formProvider?.GetForm(transferContext).Show(form);
                }
            };

            // Команда Refresh
            form.WorkCallback = values =>
            {
                var bundleService = context.UnityContainer.Resolve <ITransferBundleService>();

                var transfers = bundleService.ObtainBundle(context.TransferBundle.Id, true).Transfers;

                var gridRowContentList = new List <GridRowContent>();

                decimal completedAmount   = 0;
                decimal uncompletedAmount = 0;

                var transferSettings = context.Session.SettingsService.GetSettings().PreparedTransferSettings;

                foreach (var transfer in transfers)
                {
                    var gridRowContent = BuildGridRowContent(transfer, transferSettings);
                    gridRowContentList.Add(gridRowContent);

                    switch (transfer.State)
                    {
                    case PreparedTransferState.Failed:
                    case PreparedTransferState.Registered:
                    case PreparedTransferState.Pended:
                    case PreparedTransferState.Processed:
                    case PreparedTransferState.Interrupted:
                        uncompletedAmount += transfer.Amount;
                        break;

                    case PreparedTransferState.Completed:
                        completedAmount += transfer.Amount;
                        break;

                    default:
                        throw new InvalidOperationException("transfer.State == " + transfer.State);
                    }
                }

                var filterScreenContent = new FilterScreenContent();
                filterScreenContent.RowContentList.AddRange(gridRowContentList);

                var formattingService = context.UnityContainer.Resolve <IFormattingService>();

                var filterFormContent = new FilterFormContent(filterScreenContent);
                filterFormContent.LabelValues.Add(formattingService.FormatAmount(completedAmount));
                filterFormContent.LabelValues.Add(formattingService.FormatAmount(uncompletedAmount));

                return(filterFormContent);
            };

            form.Disposed += (sender, args) =>
            {
                subscriber.Dispose();
            };

            return(form);
        }