private static GridRowContent BuildGridRowContent(ITransferBundle bundle, ITransferBundleSettings bundleSettings)
        {
            var gridRowContent = new GridRowContent(bundle.Id.ToString(), bundle);

            switch (bundle.State)
            {
            case TransferBundleState.Registered:
                gridRowContent.BackColor          = Color.White;
                gridRowContent.SelectionBackColor = bundleSettings.SelectionColor;
                break;

            case TransferBundleState.Pended:
                gridRowContent.BackColor          = bundleSettings.PendedColor;
                gridRowContent.SelectionBackColor = ColorUtility.CalculateSelectionColor(bundleSettings.PendedColor);
                break;

            case TransferBundleState.Processed:
                gridRowContent.BackColor          = bundleSettings.ProcessedColor;
                gridRowContent.SelectionBackColor = ColorUtility.CalculateSelectionColor(bundleSettings.ProcessedColor);
                break;

            case TransferBundleState.Completed:
                gridRowContent.BackColor          = bundleSettings.CompletedColor;
                gridRowContent.SelectionBackColor = ColorUtility.CalculateSelectionColor(bundleSettings.CompletedColor);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(gridRowContent);
        }
Ejemplo n.º 2
0
        private static GridRowContent BuildGridRowContent(IPreparedTransfer transfer, IPreparedTransferSettings transferSettings)
        {
            var gridRowContent = new GridRowContent(transfer.Id.ToString(), transfer);

            switch (transfer.State)
            {
            case PreparedTransferState.Failed:
                gridRowContent.BackColor          = transferSettings.FailedColor;
                gridRowContent.SelectionBackColor =
                    ColorUtility.CalculateSelectionColor(transferSettings.FailedColor);
                break;

            case PreparedTransferState.Registered:
                gridRowContent.BackColor          = Color.White;
                gridRowContent.SelectionBackColor = transferSettings.SelectionColor;
                break;

            case PreparedTransferState.Pended:
                gridRowContent.BackColor          = transferSettings.PendedColor;
                gridRowContent.SelectionBackColor =
                    ColorUtility.CalculateSelectionColor(transferSettings.PendedColor);
                break;

            case PreparedTransferState.Processed:
                gridRowContent.BackColor          = transferSettings.ProcessedColor;
                gridRowContent.SelectionBackColor =
                    ColorUtility.CalculateSelectionColor(transferSettings.ProcessedColor);
                break;

            case PreparedTransferState.Interrupted:
                gridRowContent.BackColor          = transferSettings.InterruptedColor;
                gridRowContent.SelectionBackColor =
                    ColorUtility.CalculateSelectionColor(transferSettings.InterruptedColor);
                break;

            case PreparedTransferState.Completed:
                gridRowContent.BackColor          = transferSettings.CompletedColor;
                gridRowContent.SelectionBackColor =
                    ColorUtility.CalculateSelectionColor(transferSettings.CompletedColor);
                break;
            }

            return(gridRowContent);
        }
Ejemplo n.º 3
0
        public Control GetScreen(ScreenContainerContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var origin = new FilterOrigin(context.ExtensionManager,
                                          ExtensionCatalog.IncomingInvoiceFilterScreen)
            {
                MenuItemsTagName  = ExtensionCatalog.Tags.IncomingInvoiceExtension,
                CommandBarTagName = ExtensionCatalog.Tags.IncomingInvoiceFilterExtension,
                ColumnsSettings   = context.Session.SettingsService.GetSettings().IncomingInvoiceSettings
            };

            var template = FilterDisplayHelper.LoadFilterScreenTemplate(origin);

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

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

            var screen = new FilterScreen();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, screen);

            var now = DateTime.Now;

            var incomeValuesWrapper = new IncomingInvoiceFilterFormValuesWrapper
            {
                Control1FromTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, DateTimeKind.Local),
                Control2ToTime   = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, DateTimeKind.Local)
            };

            screen.ApplyTemplate(template);
            screen.ApplyShapeValues(incomeValuesWrapper.CollectIncomeValues());

            // Меню
            screen.MenuItemResolver = (entity, command) =>
            {
                var invoice = screen.CurrentEntity as IIncomingInvoice;

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

                var invoiceContext = new IncomingInvoiceContext(context, invoice);

                var formProvider = context.ExtensionManager.TryGetIncomingInvoiceFormProvider(command);
                return(formProvider?.CheckCompatibility(invoiceContext) ?? false);
            };

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

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

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

                if (FilterScreen.BeginUpdateServiceCommand.Equals(args.Command))
                {
                    context.ScreenContainer.OnStartProgress();
                    return;
                }

                if (FilterScreen.EndUpdateServiceCommand.Equals(args.Command))
                {
                    context.ScreenContainer.OnStopProgress();
                    return;
                }

                if (FilterScreen.DisplayContentServiceCommand.Equals(args.Command))
                {
                    return;
                }

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

                var form = screen.FindForm();

                var invoice = args.Argument as IIncomingInvoice;

                // Кнопки
                if (null == invoice)
                {
                    var formProvider = context.ExtensionManager.TryGetTopFormProvider(command);
                    formProvider?.GetForm(context).Show(form);
                }
                else
                {
                    // Системная
                    var formProvider = context.ExtensionManager.TryGetIncomingInvoiceFormProvider(command);
                    formProvider?.GetForm(new IncomingInvoiceContext(context, invoice))
                    .Show(form);
                }
            };

            // Команда Refresh
            screen.WorkCallback = list =>
            {
                var valuesWrapper = new IncomingInvoiceFilterFormValuesWrapper(list);

                var invoiceService = context.UnityContainer.Resolve <IInvoiceService>();

                var invoices = invoiceService.SelectIncomingInvoices(valuesWrapper.Control1FromTime.ToUniversalTime(),
                                                                     valuesWrapper.Control2ToTime.ToUniversalTime(), true);

                var gridRowContentList = new List <GridRowContent>();

                var operationSettings = context.Session.SettingsService.GetSettings().OperationSettings;

                decimal paid    = 0;
                decimal notPaid = 0;
                decimal refused = 0;

                foreach (var invoice in invoices)
                {
                    var gridRowContent = new GridRowContent(invoice.PrimaryId.ToString(), invoice);

                    switch (invoice.State)
                    {
                    case InvoiceState.Paid:
Paid:
                        gridRowContent.ForeColor          = operationSettings.OutcomeForeColor;
                        gridRowContent.SelectionForeColor = operationSettings.OutcomeForeColor;
                        break;

                    case InvoiceState.PaidWithProtection:
                        gridRowContent.BackColor          = operationSettings.ProtectedColor;
                        gridRowContent.SelectionBackColor = ColorUtility.CalculateSelectionColor(operationSettings.ProtectedColor);
                        goto Paid;

                    case InvoiceState.Refusal:
                        gridRowContent.Strikeout = true;
                        break;
                    }

                    switch (invoice.State)
                    {
                    case InvoiceState.NotPaid:
                        notPaid += invoice.Amount;
                        break;

                    case InvoiceState.PaidWithProtection:
                    case InvoiceState.Paid:
                        paid += invoice.Amount;
                        break;

                    case InvoiceState.Refusal:
                        refused += invoice.Amount;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    gridRowContentList.Add(gridRowContent);
                }

                var chartPoint1 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.IncomingInvoiceFilterScreen, "Paid"), (double)paid);
                var chartPoint2 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.IncomingInvoiceFilterScreen, "Not paid"),
                    (double)notPaid);
                var chartPoint3 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.IncomingInvoiceFilterScreen, "Refused"), (double)refused);

                var filterScreenContent = new FilterScreenContent();

                filterScreenContent.RowContentList.AddRange(gridRowContentList);

                if (paid > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint1);
                }

                if (notPaid > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint2);
                }

                if (refused > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint3);
                }

                return(filterScreenContent);
            };

            return(screen);
        }
Ejemplo n.º 4
0
        public Form GetForm(PurseContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var origin = new FilterOrigin(context.ExtensionManager,
                                          ExtensionCatalog.TransferFilter)
            {
                MenuItemsTagName  = ExtensionCatalog.Tags.TransferExtension,
                CommandBarTagName = ExtensionCatalog.Tags.TransferFilterExtension,
                ColumnsSettings   = context.Session.SettingsService.GetSettings().TransferSettings
            };

            var template = FilterDisplayHelper.LoadFilterFormTemplate(origin);

            template.Title = string.Format(CultureInfo.InvariantCulture, "{0} {1}",
                                           Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "History by purse"),
                                           context.Account.Number);

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

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

            var form = new FilterForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.ApplyTemplate(template);

            var now = DateTime.Now;

            var incomeValuesWrapper = new TransferFilterFormValuesWrapper
            {
                Control1FromTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, DateTimeKind.Local),
                Control2ToTime   = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, DateTimeKind.Local)
            };

            form.ApplyShapeValues(incomeValuesWrapper.CollectIncomeValues());

            // Сохранение документа
            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.TransferSettings;

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

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

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

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

                var transferContext = new TransferContext(context, transfer);

                var formProvider = context.ExtensionManager.TryGetTransferFormProvider(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 ITransfer;

                // Кнопки
                if (null == transfer)
                {
                    var formProvider = context.ExtensionManager.TryGetPurseFormProvider(command);
                    formProvider?.GetForm(context).Show(form);
                }
                else
                {
                    // Системная
                    var formProvider = context.ExtensionManager.TryGetTransferFormProvider(command);
                    formProvider?.GetForm(new TransferContext(context, transfer))
                    .Show(form);
                }
            };

            // Команда Refresh
            form.WorkCallback = values =>
            {
                var valuesWrapper = new TransferFilterFormValuesWrapper(values);


                var tansferService = context.UnityContainer.Resolve <ITransferService>();

                var transfers = tansferService.SelectTransfers(context.Account.Number,
                                                               valuesWrapper.Control1FromTime.ToUniversalTime(), valuesWrapper.Control2ToTime.ToUniversalTime(),
                                                               !valuesWrapper.Control3OfflineSearch);

                var gridRowContentList = new List <GridRowContent>();

                decimal income  = 0;
                decimal outcome = 0;

                var operationSettings = context.Session.SettingsService.GetSettings().OperationSettings;

                foreach (var transfer in transfers)
                {
                    var gridRowContent = new GridRowContent(transfer.PrimaryId.ToString(), transfer);

                    switch (transfer.Type)
                    {
                    case TransferType.Regular:
                        gridRowContent.SelectionBackColor = operationSettings.SelectionColor;
                        break;

                    case TransferType.Protected:
Protected:
                        gridRowContent.BackColor          = operationSettings.ProtectedColor;
                        gridRowContent.SelectionBackColor = ColorUtility.CalculateSelectionColor(operationSettings.ProtectedColor);
                        break;

                    case TransferType.Canceled:
                        gridRowContent.Strikeout = true;
                        goto Protected;
                    }

                    var foreColor = transfer.SourcePurse.Equals(context.Account.Number)
                        ? operationSettings.OutcomeForeColor
                        : operationSettings.IncomeForeColor;

                    gridRowContent.ForeColor          = foreColor;
                    gridRowContent.SelectionForeColor = foreColor;

                    if (TransferType.Canceled != transfer.Type &&
                        TransferType.Protected != transfer.Type)
                    {
                        if (transfer.SourcePurse.Equals(context.Account.Number))
                        {
                            outcome += transfer.Amount;
                        }
                        else
                        {
                            income += transfer.Amount;
                        }
                    }

                    gridRowContentList.Add(gridRowContent);
                }

                var chartPoint1 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "Income"), (double)income)
                {
                    Color     = operationSettings.IncomeChartColor,
                    FontColor = ChartFontColor
                };
                var chartPoint2 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "Outcome"), (double)outcome)
                {
                    Color     = operationSettings.OutcomeChartColor,
                    FontColor = ChartFontColor
                };

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

                if (income > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint1);
                }

                if (outcome > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint2);
                }

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

                var filterFormContent = new FilterFormContent(filterScreenContent);
                filterFormContent.LabelValues.Add(
                    $"{Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "IN")}: {formattingService.FormatAmount(income)}");
                filterFormContent.LabelValues.Add(
                    $"{Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "OUT")}: {formattingService.FormatAmount(outcome)}");

                return(filterFormContent);
            };

            return(form);
        }
Ejemplo n.º 5
0
        public Form GetForm(PurseContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var origin = new FilterOrigin(context.ExtensionManager,
                                          ExtensionCatalog.OutgoingInvoiceFilter)
            {
                MenuItemsTagName  = ExtensionCatalog.Tags.OutgoingInvoiceExtension,
                CommandBarTagName = ExtensionCatalog.Tags.OutgoingInvoiceFilterExtension,
                ColumnsSettings   = context.Session.SettingsService.GetSettings().OutgoingInvoiceSettings
            };

            var template = FilterDisplayHelper.LoadFilterFormTemplate(origin);

            template.Title = string.Format(CultureInfo.InvariantCulture, "{0} {1}",
                                           Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "Outgoing invoices by purse"),
                                           context.Account.Number);

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

                if (!(purseFormProvider?.CheckCompatibility(context) ?? false))
                {
                    templateCommandButton.Enabled = false;
                }
            }

            var form = new FilterForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            var now = DateTime.Now;

            var incomeValuesWrapper = new OutgoingInvoiceFilterFormValuesWrapper
            {
                Control1FromTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, DateTimeKind.Local),
                Control2ToTime   = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, DateTimeKind.Local)
            };

            form.ApplyTemplate(template);
            form.ApplyShapeValues(incomeValuesWrapper.CollectIncomeValues());

            // Сохранение документа
            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 outgoingInvoiceSettings = settings.OutgoingInvoiceSettings;

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

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

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

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

                var invoiceContext = new OutgoingInvoiceContext(context, invoice);

                var formProvider = context.ExtensionManager.TryGetOutgoingInvoiceFormProvider(command);
                return(formProvider?.CheckCompatibility(invoiceContext) ?? 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 invoice = args.Argument as IOutgoingInvoice;

                // Кнопки
                if (null == invoice)
                {
                    var formProvider = context.ExtensionManager.TryGetPurseFormProvider(command);
                    formProvider?.GetForm(context).Show(form);
                }
                else
                {
                    // Системная
                    var formProvider = context.ExtensionManager.TryGetOutgoingInvoiceFormProvider(command);
                    formProvider?.GetForm(new OutgoingInvoiceContext(context, invoice))
                    .Show(form);
                }
            };

            // Команда Refresh
            form.WorkCallback = list =>
            {
                var valuesWrapper = new OutgoingInvoiceFilterFormValuesWrapper(list);

                var invoiceService = context.UnityContainer.Resolve <IInvoiceService>();

                var invoices = invoiceService.SelectOutgoingInvoices(context.Account.Number,
                                                                     valuesWrapper.Control1FromTime.ToUniversalTime(), valuesWrapper.Control2ToTime.ToUniversalTime(), true);

                var gridRowContentList = new List <GridRowContent>();
                var operationSettings  = context.Session.SettingsService.GetSettings().OperationSettings;

                decimal paid    = 0;
                decimal notPaid = 0;
                decimal refused = 0;

                foreach (var invoice in invoices)
                {
                    var gridRowContent = new GridRowContent(invoice.PrimaryId.ToString(), invoice);

                    switch (invoice.State)
                    {
                    case InvoiceState.Paid:
Paid:
                        gridRowContent.ForeColor          = operationSettings.OutcomeForeColor;
                        gridRowContent.SelectionForeColor = operationSettings.OutcomeForeColor;
                        break;

                    case InvoiceState.PaidWithProtection:
                        gridRowContent.BackColor          = operationSettings.ProtectedColor;
                        gridRowContent.SelectionBackColor =
                            ColorUtility.CalculateSelectionColor(operationSettings.ProtectedColor);
                        goto Paid;

                    case InvoiceState.Refusal:
                        gridRowContent.Strikeout = true;
                        break;
                    }

                    switch (invoice.State)
                    {
                    case InvoiceState.NotPaid:
                        notPaid += invoice.Amount;
                        break;

                    case InvoiceState.PaidWithProtection:
                    case InvoiceState.Paid:
                        paid += invoice.Amount;
                        break;

                    case InvoiceState.Refusal:
                        refused += invoice.Amount;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    gridRowContentList.Add(gridRowContent);
                }

                var chartPoint1 = new ChartPoint(Translator.Instance.Translate(ExtensionCatalog.OutgoingInvoiceFilter, "Paid"),
                                                 (double)paid);
                var chartPoint2 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.OutgoingInvoiceFilter, "Not paid"), (double)notPaid);
                var chartPoint3 = new ChartPoint(
                    Translator.Instance.Translate(ExtensionCatalog.OutgoingInvoiceFilter, "Refused"), (double)refused);

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

                if (paid > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint1);
                }

                if (notPaid > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint2);
                }

                if (refused > 0)
                {
                    filterScreenContent.ChartPoints.Add(chartPoint3);
                }

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

                var filterFormContent = new FilterFormContent(filterScreenContent);
                filterFormContent.LabelValues.Add(
                    $"{Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "PAID")}: {formattingService.FormatAmount(paid)}");
                filterFormContent.LabelValues.Add(
                    $"{Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "UNP")}: {formattingService.FormatAmount(notPaid)}");
                filterFormContent.LabelValues.Add(
                    $"{Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "REF")}: {formattingService.FormatAmount(refused)}");

                return(filterFormContent);
            };

            return(form);
        }
        public Form GetForm(SessionContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var origin = new FilterOrigin(context.ExtensionManager,
                                          ExtensionCatalog.ContractFilter)
            {
                MenuItemsTagName  = ExtensionCatalog.Tags.ContractExtension,
                CommandBarTagName = ExtensionCatalog.Tags.ContractFilterExtension,
                ColumnsSettings   = context.Session.SettingsService.GetSettings().ContractSettings
            };

            var template = FilterDisplayHelper.LoadFilterFormTemplate(origin);

            template.Title = Translator.Instance.Translate(ExtensionCatalog.TransferFilter, "Contracts");

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

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

            _form = new FilterForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, _form);

            var now = DateTime.Now;

            var incomeValuesWrapper = new TransferFilterFormValuesWrapper
            {
                Control1FromTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, DateTimeKind.Local),
                Control2ToTime   = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, DateTimeKind.Local)
            };

            _form.ApplyTemplate(template);
            _form.ApplyShapeValues(incomeValuesWrapper.CollectIncomeValues());

            // Подписка на создание/изменение контракта
            EventBroker.ContractChanged += EventBrokerOnContractChanged;

            // Сохранение документа
            _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 contractSettings = settings.ContractSettings;

                FilterDisplayHelper.UpdateColumnsSettings(contractSettings, _form.SelectGridSettings());

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

            // Меню
            _form.MenuItemResolver = (entity, command) =>
            {
                var contract = _form.CurrentEntity as IContract;

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

                var contractContext = new ContractContext(context, contract);

                if (command.Equals(ExtensionCatalog.RefreshContract))
                {
                    var actionProvider = context.ExtensionManager.TryGetContractActionProvider(command);
                    return(actionProvider?.CheckCompatibility(contractContext) ?? false);
                }

                var formProvider = context.ExtensionManager.TryGetContractFormProvider(command);
                return(formProvider?.CheckCompatibility(contractContext) ?? 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.ContractDetails;
                }

                var contract = args.Argument as IContract;

                // Кнопки
                if (null == contract)
                {
                    var formProvider = context.ExtensionManager.TryGetTopFormProvider(command);

                    formProvider?.GetForm(context).Show(_form);
                }
                else
                {
                    var contractContext = new ContractContext(context, contract);

                    if (command.Equals(ExtensionCatalog.RefreshContract))
                    {
                        var actionProvider = context.ExtensionManager.TryGetContractActionProvider(command);
                        actionProvider?.RunAction(contractContext);
                    }
                    else
                    {
                        var formProvider = context.ExtensionManager.TryGetContractFormProvider(command);
                        formProvider?.GetForm(contractContext).Show(_form);
                    }
                }
            };

            // Команда Refresh
            _form.WorkCallback = values =>
            {
                var valuesWrapper = new ContractFilterFormValuesWrapper(values);

                var contractService = context.UnityContainer.Resolve <IContractService>();

                var contracts =
                    contractService.SelectContracts(valuesWrapper.Control1FromTime, valuesWrapper.Control2ToTime);

                var gridRowContentList = new List <GridRowContent>();

                int signed   = 0;
                int unsigned = 0;

                var contractSettings = context.Session.SettingsService.GetSettings().ContractSettings;

                foreach (var contract in contracts)
                {
                    var gridRowContent = new GridRowContent(contract.Id.ToString(), contract);

                    switch (contract.State)
                    {
                    case ContractState.Created:
                        gridRowContent.BackColor          = Color.White;
                        gridRowContent.SelectionBackColor = contractSettings.SelectionColor;
                        unsigned++;
                        break;

                    case ContractState.Signed:
                    case ContractState.Completed:
                        gridRowContent.BackColor          = contractSettings.SignedColor;
                        gridRowContent.SelectionBackColor =
                            ColorUtility.CalculateSelectionColor(contractSettings.SignedColor);
                        signed++;
                        break;

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

                    if (0 == contract.AccessCount)
                    {
                        gridRowContent.ForeColor          = contractSettings.PublicForeColor;
                        gridRowContent.SelectionForeColor = contractSettings.PublicForeColor;
                    }

                    gridRowContentList.Add(gridRowContent);
                }

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

                var filterFormContent = new FilterFormContent(filterScreenContent);

                filterFormContent.LabelValues.Add(string.Format(CultureInfo.InvariantCulture, "SIG: {0}", signed));
                filterFormContent.LabelValues.Add(string.Format(CultureInfo.InvariantCulture, "UNSIG: {0}", unsigned));

                return(filterFormContent);
            };

            _form.Disposed += (sender, args) =>
            {
                EventBroker.ContractChanged -= EventBrokerOnContractChanged;
            };

            return(_form);
        }