Esempio n. 1
0
        public Form GetForm(SessionContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.PasswordSettings);

            if (!context.Session.AuthenticationService.HasPassword)
            {
                template.Steps[0].TunableShape.Columns[0].Controls[0].Enabled = false; // Не спрашивать текущий пароль.
            }
            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.WorkCallback += (step, list) =>
            {
                if (0 != step)
                {
                    throw new InvalidOperationException("0 != step");
                }

                var valuesWrapper = new PasswordSettingsFormValuesWrapper(list);
                context.Session.AuthenticationService.SetPassword(valuesWrapper.Control1OldPassowrd, valuesWrapper.Control2Password);

                return(new Dictionary <string, object>());
            };

            form.ApplyTemplate(template);

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

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.FinishProtection);

            var templateWrapper = new FinishProtectionFormTemplateWrapper(template);

            var currencyService = context.UnityContainer.Resolve <ICurrencyService>();
            var currency        = currencyService.ObtainCurrencyByAccountNumber(context.Transfer.TargetPurse);

            templateWrapper.Control4Amount.CurrencyName = currencyService.AddPrefix(currency);

            var transfer = context.Transfer;

            var incomeValuesWrapper = new FinishProtectionFormValuesWrapper
            {
                Control1SourcePurse = transfer.SourcePurse,
                Control2TargetPurse = transfer.TargetPurse,
                Control3Amount      = transfer.Amount,
                Control4Description = transfer.Description
            };

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

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

            form.ServiceCommand += (sender, args) =>
            {
                if (!FinishProtectionFormValuesWrapper.Control1SourcePurseCommandFindIdentifier.Equals(args.Command))
                {
                    return;
                }

                var purseNumber = (string)args.Argument;
                IdentifierDisplayHelper.ShowFindIdentifierForm(form, context, purseNumber);
            };

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper = new FinishProtectionFormValuesWrapper(list);

                var transferService = context.UnityContainer.Resolve <ITransferService>();
                transferService.FinishProtection(transfer.PrimaryId,
                                                 valuesWrapper.Control6HoldingFeatureIsUsed ? string.Empty : valuesWrapper.Control5Code);

                return(new Dictionary <string, object>());
            };

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

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.CreatePurse);

            // Добавляем список валют
            var itemTemplates =
                AccountDisplayHelper.BuildCurrencyDropDownListItemTemplates(context.UnityContainer,
                                                                            CurrencyCapabilities.Actual | CurrencyCapabilities.CreatePurse);

            var templateWrapper = new CreatePurseFormTemplateWrapper(template);

            templateWrapper.Control1PurseType.Items.Clear();
            templateWrapper.Control1PurseType.Items.AddRange(itemTemplates);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.ApplyTemplate(template);

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper = new CreatePurseFormValuesWrapper(list);

                var currencyService = context.UnityContainer.Resolve <ICurrencyService>();
                var purseService    = context.UnityContainer.Resolve <IPurseService>();

                purseService.CreatePurse(currencyService.RemovePrefix(valuesWrapper.Control1PurseType),
                                         valuesWrapper.Control2PurseName);

                return(new Dictionary <string, object>());
            };

            form.FinalAction = objects =>
            {
                EventBroker.OnPurseChanged(new DataChangedEventArgs {
                    FreshDataRequired = true
                });
                return(true);
            };

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

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.RedeemPaymer);

            var origin =
                new AccountDropDownListOrigin(context.UnityContainer)
            {
                SelectedAccountNumber = context.Account.Number
            };

            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Transfer;

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            var redeemPaymerFormTemplateWrapper = new RedeemPaymerFormTemplateWrapper(template);

            redeemPaymerFormTemplateWrapper.Control1RedeemTo.Items.Clear();
            redeemPaymerFormTemplateWrapper.Control1RedeemTo.Items.AddRange(itemTemplates);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.ApplyTemplate(template);

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper = new RedeemPaymerFormValuesWrapper(list);

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

                transferService.RedeemPaymer(valuesWrapper.Control1RedeemTo, valuesWrapper.Control2Number,
                                             valuesWrapper.Control3Code);

                return(new Dictionary <string, object>());
            };

            return(form);
        }
        private Form GetForm(SessionContext context, long invoiceId, string targetPurse,
                             RejectInvoiceFormValuesWrapper valuesWrapper)
        {
            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.RejectInvoice);

            var templateWrapper = new RejectInvoiceFormTemplateWrapper(template);

            var currencyService = context.UnityContainer.Resolve <ICurrencyService>();
            var currency        = currencyService.ObtainCurrencyByAccountNumber(targetPurse);

            templateWrapper.Control4Amount.CurrencyName = currencyService.AddPrefix(currency);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.ApplyTemplate(template, valuesWrapper.CollectIncomeValues());

            form.ServiceCommand += (sender, args) =>
            {
                if (!RejectInvoiceFormValuesWrapper.Control1TargetIdentifierCommandFindPassport.Equals(args.Command))
                {
                    return;
                }

                IdentifierDisplayHelper.ShowFindCertificateForm(form, context, (string)args.Argument);
            };

            form.WorkCallback = (step, list) =>
            {
                var invoiceService = context.UnityContainer.Resolve <IInvoiceService>();
                invoiceService.RejectInvoice(invoiceId);
                return(new Dictionary <string, object>());
            };

            return(form);
        }
Esempio n. 6
0
        public Control GetScreen(ScreenContainerContext context)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));

            _screen = new ListScreen
            {
                Dock = DockStyle.Fill
            };

            _screen.RefreshCallback += () =>
            {
                SoundPlayer soundPlayer = new SoundPlayer(Resources.payment);
                soundPlayer.Play();

                return(new List <ListItemContent>());
            };

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, _screen);

            //_screen.ApplyTemplate(template);

            return(_screen);
        }
Esempio n. 7
0
        private Form GetForm(SessionContext context, string phone)
        {
            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.SendSms);

            var templateWrapper = new SendSmsFormTemplateWrapper(template);

            if (null != phone)
            {
                templateWrapper.Control1PhoneNumber.DefaultValue = phone;
            }

            var origin = new AccountDropDownListOrigin(context.UnityContainer);

            origin.FilterCriteria.HasMoney             = true;
            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Transfer;

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.ApplyTemplate(template);

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper = new SendSmsFormValuesWrapper(list);

                var smsService = context.UnityContainer.Resolve <ISmsService>();

                smsService.SendSms(null, valuesWrapper.Control1PhoneNumber,
                                   valuesWrapper.Control2Message, valuesWrapper.Control3UseTransliteration);

                return(new Dictionary <string, object>());
            };

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

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.CreatePaymentLink);

            var step1TemplateWrapper = new CreatePaymentLinkFormTemplateWrapper.Step1(template);

            var origin =
                new AccountDropDownListOrigin(context.UnityContainer)
            {
                SelectedAccountNumber = context.Account.Number
            };

            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Transfer;

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            step1TemplateWrapper.Control1StorePurse.Items.Clear();
            step1TemplateWrapper.Control1StorePurse.Items.AddRange(itemTemplates);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            var inputStep1ValuesWrapper =
                new CreatePaymentLinkFormValuesWrapper.Step1
            {
                Control2OrderId = context.Session.SettingsService.AllocateOrderId()
            };

            form.ApplyTemplate(template, inputStep1ValuesWrapper.CollectIncomeValues());

            form.WorkCallback = (step, list) =>
            {
                switch (step)
                {
                case 0:
                    var step1ValuesWrapper = new CreatePaymentLinkFormValuesWrapper.Step1(list);

                    var paymentLinkRequest = new PaymentLinkRequest(step1ValuesWrapper.Control2OrderId,
                                                                    step1ValuesWrapper.Control1StorePurse, step1ValuesWrapper.Control3PaymentAmount,
                                                                    step1ValuesWrapper.Control5Description)
                    {
                        Lifetime = step1ValuesWrapper.Control4ValidityPeriod
                    };


                    var paymentService = context.UnityContainer.Resolve <IPaymentService>();
                    var link           = paymentService.CreatePaymentLink(paymentLinkRequest);

                    var step2ValuesWrapper = new CreatePaymentLinkFormValuesWrapper.Step2
                    {
                        Control1PaymentLink = link
                    };

                    return(step2ValuesWrapper.CollectIncomeValues());

                case 1:
                    return(new Dictionary <string, object>());

                default:
                    throw new InvalidOperationException("step == " + step);
                }
            };

            return(form);
        }
        private Form GetForm(SessionContext context, string accountNumber)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.TakeTrust);

            var origin = new AccountDropDownListOrigin(context.UnityContainer)
            {
                Source = AccountSource.MasterIdentifier
            };

            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Transfer;

            if (null != accountNumber)
            {
                origin.SelectedAccountNumber = accountNumber;
            }

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            var step1TemplateWrapper = new TakeTrustFormTemplateWrapper.Step1(template);

            step1TemplateWrapper.Control1StorePurse.Items.Clear();
            step1TemplateWrapper.Control1StorePurse.Items.AddRange(itemTemplates);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.ApplyTemplate(template);

            form.ServiceCommand += (sender, args) =>
            {
                if (TakeTrustFormValuesWrapper.Step1.Control7WMIDCommandFindPassport.Equals(args.Command))
                {
                    var identifierValue = (string)args.Argument;
                    IdentifierDisplayHelper.ShowFindCertificateForm(form, context, identifierValue);

                    return;
                }

                if (TakeTrustFormValuesWrapper.Step2.Control4SmsReferenceCommandGoTo.Equals(args.Command))
                {
                    Process.Start((string)args.Argument);
                }
            };

            form.WorkCallback = (step, list) =>
            {
                var trustService = context.UnityContainer.Resolve <ITrustService>();

                switch (step)
                {
                case 0:
                    var step1ValuesWrapper = new TakeTrustFormValuesWrapper.Step1(list);

                    ExtendedIdentifier extendedIdentifier;

                    switch (step1ValuesWrapper.Control5IdentifierType)
                    {
                    case TakePaymentFormValuesWrapper.Step1.Control3IdentifierTypeValueWmid:
                        extendedIdentifier = new ExtendedIdentifier(ExtendedIdentifierType.WmId,
                                                                    step1ValuesWrapper.Control7WMID);
                        break;

                    case TakePaymentFormValuesWrapper.Step1.Control3IdentifierTypeValuePhone:
                        extendedIdentifier = new ExtendedIdentifier(ExtendedIdentifierType.Phone,
                                                                    step1ValuesWrapper.Control6Phone);
                        break;

                    case TakePaymentFormValuesWrapper.Step1.Control3IdentifierTypeValueEmail:
                        extendedIdentifier = new ExtendedIdentifier(ExtendedIdentifierType.Email,
                                                                    step1ValuesWrapper.Control8Email);
                        break;

                    default:
                        throw new InvalidOperationException(
                                  "step1ValuesWrapper.Control5IdentifierType == " +
                                  step1ValuesWrapper.Control5IdentifierType);
                    }

                    var originalExpressTrust =
                        new OriginalExpressTrust(step1ValuesWrapper.Control1StorePurse, extendedIdentifier);

                    originalExpressTrust.DayLimit   = step1ValuesWrapper.Control2DailyAmountLimit;
                    originalExpressTrust.WeekLimit  = step1ValuesWrapper.Control3WeeklyAmountLimit;
                    originalExpressTrust.MonthLimit = step1ValuesWrapper.Control4MonthlyAmountLimit;

                    var trustConfirmationInstruction = trustService.RequestTrust(originalExpressTrust);

                    var step2IncomeValuesWrapper = new TakeTrustFormValuesWrapper.Step2
                    {
                        Control1RequestNumber =
                            trustConfirmationInstruction.Reference.ToString(),
                        Control2Message =
                            trustConfirmationInstruction.PublicMessage ?? string.Empty,

                        Control4SmsReference =
                            !string.IsNullOrEmpty(trustConfirmationInstruction.SmsReference)
                                ? string.Format(CultureInfo.InvariantCulture, CheckSmsStateUrlTemplate, trustConfirmationInstruction.SmsReference)
                                : string.Empty
                    };

                    return(step2IncomeValuesWrapper.CollectIncomeValues());

                case 1:
                    var step2ValuesWrapper = new TakeTrustFormValuesWrapper.Step2(list);

                    var trustConfirmation =
                        new TrustConfirmation(int.Parse(step2ValuesWrapper.Control1RequestNumber),
                                              step2ValuesWrapper.Control5Code);

                    trustService.ConfirmTrust(trustConfirmation);

                    break;
                }

                return(new Dictionary <string, object>());
            };

            return(form);
        }
Esempio n. 10
0
        public Form GetForm(IncomingInvoiceContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var invoice = context.Invoice;

            var currencyService = context.UnityContainer.Resolve <ICurrencyService>();
            var currency        = currencyService.ObtainCurrencyByAccountNumber(invoice.TargetPurse);

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.PayInvoice);

            var templateWrapper = new PayInvoiceFormTemplateWrapper(template);

            templateWrapper.Control4Amount.CurrencyName = currencyService.AddPrefix(currency);

            // Устанавливаем кошельки
            var origin = new AccountDropDownListOrigin(context.UnityContainer);

            // Оплата в долг не требует денег на кошельке, осуществляется с кредитного кошелька (WMC).
            if (currencyService.CheckCapabilities(currency, CurrencyCapabilities.Debit))
            {
                currency = currencyService.SelectCurrencies(CurrencyCapabilities.Credit).First();
            }
            else
            {
                origin.FilterCriteria.HasMoney = true;
            }

            origin.FilterCriteria.Currency = currency;

            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Actual | CurrencyCapabilities.TransferByInvoice;

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            templateWrapper.Control11PayFrom.Items.Clear();
            templateWrapper.Control11PayFrom.Items.AddRange(itemTemplates);

            // Запрещена оплата с протекцией
            if (null == invoice.ProtectionPeriod)
            {
                templateWrapper.Control12UsePaymentProtection.Enabled = false;
            }
            else
            {
                templateWrapper.Control14ProtectionPeriod.MaxValue = invoice.ProtectionPeriod.Value;
            }

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

            var incomeValuesWrapper = new PayInvoiceFormValuesWrapper
            {
                Control1TargetIdentifier = formattingService.FormatIdentifier(invoice.TargetIdentifier),
                Control2TargetPurse      = invoice.TargetPurse,
                Control3Amount           = invoice.Amount,
                Control4Description      = invoice.Description ?? string.Empty,
                Control5OrderId          = invoice.OrderId.ToString(),
                Control6Address          = invoice.Address ?? string.Empty,
                Control7PaymentPeriod    = invoice.ExpirationPeriod.ToString(),
                Control9TransferId       = context.Session.SettingsService.AllocateTransferId()
            };

            if (null != invoice.ProtectionPeriod)
            {
                incomeValuesWrapper.Control8MaxProtectionPeriod = invoice.ProtectionPeriod.Value.ToString();
            }

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

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

            form.ServiceCommand += (sender, args) =>
            {
                if (!PayInvoiceFormValuesWrapper.Control1TargetIdentifierCommandFindPassport.Equals(args.Command))
                {
                    return;
                }

                IdentifierDisplayHelper.ShowFindCertificateForm(form, context, (string)args.Argument);
            };

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper   = new PayInvoiceFormValuesWrapper(list);
                var transferService = context.UnityContainer.Resolve <ITransferService>();

                var originalTransfer = new OriginalTransfer(valuesWrapper.Control9TransferId,
                                                            valuesWrapper.Control10PayFrom, invoice.TargetPurse, invoice.Amount,
                                                            invoice.Description)
                {
                    InvoiceId = invoice.PrimaryId
                };

                if (valuesWrapper.Control11UsePaymentProtection)
                {
                    originalTransfer.ProtectionPeriod = valuesWrapper.Control12ProtectionPeriod;

                    if (valuesWrapper.Control14ProtectionByTime)
                    {
                        originalTransfer.ProtectionCode = valuesWrapper.Control13ProtectionCode;
                    }
                }

                transferService.CreateTransfer(originalTransfer);

                return(new Dictionary <string, object>());
            };

            return(form);
        }
        private Form GetForm(SessionContext context, string purseNumber, long?id, PaymentNumberKind numberKind)
        {
            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.FindMerchantTransfer);

            var origin =
                new AccountDropDownListOrigin(context.UnityContainer)
            {
                SelectedAccountNumber = purseNumber
            };

            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Invoice;

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            var step1TemplateWrapper = new FindMerchantTransferFormTemplateWrapper.Step1(template);

            step1TemplateWrapper.Control1FromPurse.Items.Clear();
            step1TemplateWrapper.Control1FromPurse.Items.AddRange(itemTemplates);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            var incomeValuesWrapperStep1 = new FindMerchantTransferFormValuesWrapper.Step1();

            if (id.HasValue)
            {
                incomeValuesWrapperStep1.Control2Number = id.Value;
            }

            incomeValuesWrapperStep1.Control3NumberType = numberKind.ToString();

            form.ApplyTemplate(template, incomeValuesWrapperStep1.CollectIncomeValues());

            form.WorkCallback = (step, list) =>
            {
                switch (step)
                {
                case 0:
                    var valuesWrapperStep1 = new FindMerchantTransferFormValuesWrapper.Step1(list);

                    var paymentService = context.UnityContainer.Resolve <IPaymentService>();

                    var merchantPayment = paymentService.FindPayment(valuesWrapperStep1.Control1FromPurse,
                                                                     valuesWrapperStep1.Control2Number,
                                                                     (PaymentNumberKind)Enum.Parse(typeof(PaymentNumberKind),
                                                                                                   valuesWrapperStep1.Control3NumberType));

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

                    var records = new List <ResultRecord>();
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "System transfer ID"),
                                    merchantPayment.TransferId.ToString()));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "System invoice ID"),
                                    merchantPayment.InvoiceId.ToString()));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Amount"),
                                    formattingService.FormatAmount(merchantPayment.Amount)));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Creation time"),
                                    formattingService.FormatDateTime(merchantPayment.CreationTime)));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Description"),
                                    merchantPayment.Description ?? string.Empty));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Source purse"),
                                    merchantPayment.SourcePurse ?? string.Empty));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Source WMID"),
                                    formattingService.FormatIdentifier(merchantPayment.SourceIdentifier)));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Is Capitaller"),
                                    merchantPayment.IsCapitaller.ToString()));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Is enum"),
                                    merchantPayment.IsEnum.ToString()));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "IP Address"),
                                    merchantPayment.IPAddress?.ToString()));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Telepat phone"),
                                    merchantPayment.TelepatPhone ?? string.Empty));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Telepat method"),
                                    merchantPayment.TelepatMethod?.ToString() ?? string.Empty));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Paymer number"),
                                    merchantPayment.PaymerNumber ?? string.Empty));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Paymer email"),
                                    merchantPayment.PaymerEmail ?? string.Empty));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Paymer type"),
                                    merchantPayment.PaymerType.ToString()));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Cashier number"),
                                    merchantPayment.CashierNumber ?? string.Empty));
                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Cashier date"),
                                    merchantPayment.CashierDate?.ToString() ?? string.Empty));

                    var cashierAmountValue = string.Empty;

                    if (null != merchantPayment.CashierAmount)
                    {
                        cashierAmountValue = formattingService.FormatAmount(merchantPayment.CashierAmount.Value);
                    }

                    records.Add(new ResultRecord(
                                    Translator.Instance.Translate(ExtensionCatalog.FindMerchantTransfer, "Cashier amount"),
                                    cashierAmountValue));
                    // TODO [M] добавить SDP
                    // records.Add(new ResultRecord("sdp_type", merchantPayment.));

                    var valuesWrapperStep2 = new FindMerchantTransferFormValuesWrapper.Step2();
                    valuesWrapperStep2.Control1Payment = records.Select(r => new ListItemContent(r)).ToList();

                    return(valuesWrapperStep2.CollectIncomeValues());

                case 1:
                    return(new Dictionary <string, object>());

                default:
                    throw new InvalidOperationException("step == " + step);
                }
            };

            if (null != id)
            {
                form.Load += (sender, args) =>
                {
                    form.Submit();
                };
            }

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

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.TakePayment);

            var origin =
                new AccountDropDownListOrigin(context.UnityContainer)
            {
                SelectedAccountNumber = context.Account.Number
            };

            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Transfer;

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            var step1TemplateWrapper = new TakePaymentFormTemplateWrapper.Step1(template);

            step1TemplateWrapper.Control2StorePurse.Items.Clear();
            step1TemplateWrapper.Control2StorePurse.Items.AddRange(itemTemplates);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            var incomeValuesWrapper =
                new TakePaymentFormValuesWrapper.Step1
            {
                Control2OrderId = context.Session.SettingsService.AllocateOrderId()
            };

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

            form.ServiceCommand += (sender, args) =>
            {
                if (!TakePaymentFormValuesWrapper.Step1.Control5WMIDCommandFindPassport.Equals(args.Command))
                {
                    return;
                }

                var identifierValue = (string)args.Argument;
                IdentifierDisplayHelper.ShowFindCertificateForm(form, context, identifierValue);
            };

            long   invoiceId = 0;
            string purse     = "";

            form.WorkCallback = (step, list) =>
            {
                var paymentService = context.UnityContainer.Resolve <IPaymentService>();

                switch (step)
                {
                case 0:
                    var step1ValuesWrapper = new TakePaymentFormValuesWrapper.Step1(list);

                    ExtendedIdentifier extendedIdentifier;

                    switch (step1ValuesWrapper.Control3IdentifierType)
                    {
                    case TakePaymentFormValuesWrapper.Step1.Control3IdentifierTypeValueWmid:
                        extendedIdentifier = new ExtendedIdentifier(ExtendedIdentifierType.WmId,
                                                                    step1ValuesWrapper.Control5WMID);
                        break;

                    case TakePaymentFormValuesWrapper.Step1.Control3IdentifierTypeValuePhone:
                        extendedIdentifier = new ExtendedIdentifier(ExtendedIdentifierType.Phone,
                                                                    step1ValuesWrapper.Control4Phone);
                        break;

                    case TakePaymentFormValuesWrapper.Step1.Control3IdentifierTypeValueEmail:
                        extendedIdentifier = new ExtendedIdentifier(ExtendedIdentifierType.Email,
                                                                    step1ValuesWrapper.Control6Email);
                        break;

                    default:
                        throw new InvalidOperationException(
                                  "step1ValuesWrapper.Control3IdentifierType == " +
                                  step1ValuesWrapper.Control3IdentifierType);
                    }

                    var originalExpressPayment = new OriginalExpressPayment(step1ValuesWrapper.Control2OrderId,
                                                                            step1ValuesWrapper.Control1StorePurse, step1ValuesWrapper.Control7PaymentAmount,
                                                                            step1ValuesWrapper.Control9Description, extendedIdentifier);

                    originalExpressPayment.ConfirmationType =
                        (ConfirmationType)Enum.Parse(typeof(ConfirmationType),
                                                     step1ValuesWrapper.Control8ConfirmationType);

                    purse = originalExpressPayment.TargetPurse;

                    var confirmationInstruction = paymentService.RequestPayment(originalExpressPayment);

                    invoiceId = confirmationInstruction.InvoiceId;

                    var step2IncomeValuesWrapper = new TakePaymentFormValuesWrapper.Step2();
                    step2IncomeValuesWrapper.Control1InvoiceId = confirmationInstruction.InvoiceId.ToString();
                    step2IncomeValuesWrapper.Control2Message   = confirmationInstruction.PublicMessage ?? string.Empty;

                    return(step2IncomeValuesWrapper.CollectIncomeValues());

                case 1:

                    var step2ValuesWrapper = new TakePaymentFormValuesWrapper.Step2(list);

                    var paymentConfirmation = new PaymentConfirmation(purse, invoiceId)
                    {
                        ConfirmationCode = step2ValuesWrapper.Control4CancelInvoice
                                ? "-1"
                                : step2ValuesWrapper.Control3Code
                    };

                    paymentService.ConfirmPayment(paymentConfirmation);

                    break;

                default:
                    throw new InvalidOperationException("step == " + step);
                }

                return(new Dictionary <string, object>());
            };

            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);
        }
Esempio n. 14
0
        public Form GetForm(SessionContext context, string sourceIdentifierValue, string targetAccountNumber)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.CreateOutgoingInvoice);

            var templateWrapper = new CreateOutgoingInvoiceFormTemplateWrapper(template);

            if (null != sourceIdentifierValue)
            {
                templateWrapper.Control2ReceiversWmid.DefaultValue = sourceIdentifierValue;
            }

            // Кошельки
            var origin = new AccountDropDownListOrigin(context.UnityContainer);

            if (null != targetAccountNumber)
            {
                origin.SelectedAccountNumber = targetAccountNumber;
            }

            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Invoice;

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            templateWrapper.Control3PayTo.Items.Clear();
            templateWrapper.Control3PayTo.Items.AddRange(itemTemplates);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            var incomeValuesWrapper =
                new CreateOutgoingInvoiceFormValuesWrapper
            {
                Control1OrderId = context.Session.SettingsService.AllocateOrderId()
            };

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

            form.ServiceCommand += (sender, args) =>
            {
                if (!CreateOutgoingInvoiceFormValuesWrapper.Control2ReceiversWmidCommandFindPassport
                    .Equals(args.Command))
                {
                    return;
                }

                IdentifierDisplayHelper.ShowFindCertificateForm(form, context, (string)args.Argument);
            };

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper = new CreateOutgoingInvoiceFormValuesWrapper(list);


                var originalInvoice = new OriginalOutgoingInvoice(valuesWrapper.Control1OrderId,
                                                                  valuesWrapper.Control2ReceiversWmid, valuesWrapper.Control3PayTo, valuesWrapper.Control4Amount,
                                                                  valuesWrapper.Control5Description);

                if (valuesWrapper.Control6SpecifyAdditionalParameters)
                {
                    originalInvoice.Address = valuesWrapper.Control7Address;

                    if (valuesWrapper.Control8SpecifyPaymentPeriod)
                    {
                        originalInvoice.ExpirationPeriod = valuesWrapper.Control9PaymentPeriod;
                    }

                    if (valuesWrapper.Control10AllowPaymentWithProtection)
                    {
                        originalInvoice.ProtectionPeriod = valuesWrapper.Control11ProtectionPeriod;
                    }
                }

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

                invoiceService.CreateOutgoingInvoice(originalInvoice);

                return(new Dictionary <string, object>());
            };

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

            var template =
                TemplateLoader.LoadTemplate <SubmitFormTemplate <WMColumnTemplate> >(context.ExtensionManager,
                                                                                     ExtensionCatalog.VerifyClient);

            var step1TemplateWrapper = new VerifyClientFormTemplateWrapper.Step1(template);

            // Добавляем список валют
            var itemTemplates =
                AccountDisplayHelper.BuildCurrencyDropDownListItemTemplates(context.UnityContainer,
                                                                            CurrencyCapabilities.Invoice);

            step1TemplateWrapper.Control3PurseType.Items.Clear();
            step1TemplateWrapper.Control3PurseType.Items.AddRange(itemTemplates);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            form.ApplyTemplate(template);

            form.ServiceCommand += (sender, args) =>
            {
                switch (args.Command)
                {
                case VerifyClientFormValuesWrapper.Step1.Control6WmidCommandFindPassport:
                    var identifierValue = (string)args.Argument;
                    IdentifierDisplayHelper.ShowFindCertificateForm(form, context, identifierValue);
                    break;

                case "Copy":
                    Clipboard.SetText(((ResultRecord)args.Argument).Value, TextDataFormat.UnicodeText);
                    break;
                }
            };

            form.WorkCallback = (step, list) =>
            {
                switch (step)
                {
                case 0:
                {
                    SuspectedClientInfo suspectedClientInfo;

                    var step1Wrapper = new VerifyClientFormValuesWrapper.Step1(list);

                    var exchangeType = (ExchangeType)Enum.Parse(typeof(ExchangeType), step1Wrapper.Control1Instrument);
                    var currency     = context.UnityContainer.Resolve <ICurrencyService>()
                                       .RemovePrefix(step1Wrapper.Control3PurseType);
                    long identifier = long.Parse(step1Wrapper.Control6Wmid);

                    switch (exchangeType)
                    {
                    case ExchangeType.Cash:
                        suspectedClientInfo = SuspectedClientInfo.CreateCashPaymentVerification(
                            currency, step1Wrapper.Control4Amount,
                            identifier, step1Wrapper.Control9PassportNumber,
                            step1Wrapper.Control7FirstName, step1Wrapper.Control8SecondName);
                        break;

                    case ExchangeType.OfflineSystem:
                        suspectedClientInfo = SuspectedClientInfo.CreateOfflineSystemPaymentVerification(
                            currency, step1Wrapper.Control4Amount,
                            identifier, step1Wrapper.Control7FirstName,
                            step1Wrapper.Control8SecondName);
                        break;

                    case ExchangeType.BankAccount:
                        suspectedClientInfo = SuspectedClientInfo.CreateBankAccountPaymentVerification(
                            currency, step1Wrapper.Control4Amount,
                            identifier, step1Wrapper.Control7FirstName,
                            step1Wrapper.Control8SecondName, step1Wrapper.Control10BankName,
                            step1Wrapper.Control11BankAccount);
                        break;

                    case ExchangeType.Bankcard:
                        suspectedClientInfo = SuspectedClientInfo.CreateBankCardPaymentVerification(
                            currency, step1Wrapper.Control4Amount,
                            identifier, step1Wrapper.Control7FirstName,
                            step1Wrapper.Control8SecondName, step1Wrapper.Control10BankName,
                            step1Wrapper.Control12CardNumber);
                        break;

                    case ExchangeType.InternetSystem:
                        var paymentSystem = (PaymentSystem)Enum.Parse(typeof(PaymentSystem),
                                                                      step1Wrapper.Control13PaymentSystem);

                        suspectedClientInfo = SuspectedClientInfo.CreateInternetSystemPaymentVerification(
                            currency, step1Wrapper.Control4Amount,
                            identifier, paymentSystem,
                            step1Wrapper.Control14PaymentSystemClientId);
                        break;

                    case ExchangeType.Sms:
                        suspectedClientInfo =
                            SuspectedClientInfo.CreateSmsPaymentVerification(
                                currency, step1Wrapper.Control4Amount,
                                identifier, step1Wrapper.Control15Phone);
                        break;

                    case ExchangeType.Mobile:
                        suspectedClientInfo =
                            SuspectedClientInfo.CreateMobilePaymentVerification(
                                currency, step1Wrapper.Control4Amount,
                                identifier, step1Wrapper.Control15Phone);
                        break;

                    case ExchangeType.Blockchain:
                        var cryptoCurrency = (CryptoCurrency)Enum.Parse(typeof(CryptoCurrency),
                                                                        step1Wrapper.Control16CryptoCurrency);

                        suspectedClientInfo =
                            SuspectedClientInfo.CreateBlockchainPaymentVerification(
                                currency, step1Wrapper.Control4Amount,
                                identifier, cryptoCurrency,
                                step1Wrapper.Control17CryptoCurrencyAddress);
                        break;

                    default:
                        throw new InvalidOperationException(
                                  "valuesWrapper.Control1Instrument == " + step1Wrapper.Control1Instrument);
                    }

                    suspectedClientInfo.Output = step1Wrapper.Control2Direction.Equals(VerifyClientFormValuesWrapper
                                                                                       .Step1.Control2DirectionValueOutput);

                    var verificationService = context.UnityContainer.Resolve <IVerificationService>();
                    var verificationReport  = verificationService.VerifyClient(suspectedClientInfo);

                    var listItems = new List <ListItemContent>
                    {
                        new ListItemContent(new ResultRecord("Client name", verificationReport.ClientName)),
                        new ListItemContent(new ResultRecord("Client middle name", verificationReport.ClientMiddleName)),
                        new ListItemContent(new ResultRecord("Reference", verificationReport.Reference))
                    };

                    var step2Wrapper = new VerifyClientFormValuesWrapper.Step2 {
                        Control1Result = listItems
                    };

                    return(step2Wrapper.CollectIncomeValues());
                }

                case 1:
                    return(new Dictionary <string, object>());

                default:
                    throw new InvalidOperationException("step == " + step);
                }
            };

            return(form);
        }
        public Control GetScreen(ScreenContainerContext context)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));

            var origin =
                new AccountListScreenOrigin(context, ExtensionCatalog.TrustsScreen)
            {
                MenuItemsTagName  = ExtensionCatalog.Tags.TrustExtension,
                CommandBarTagName = ExtensionCatalog.Tags.TrustsScreenExtension
            };

            var template = AccountDisplayHelper.LoadListScreenTemplate(origin);

            _screen = new ListScreen
            {
                Dock = DockStyle.Fill
            };

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, _screen);

            EventBroker.TrustChanged += EventBrokerOnTrustChanged;

            _screen.Disposed += (sender, args) =>
            {
                EventBroker.TrustChanged -= EventBrokerOnTrustChanged;
            };

            _screen.ApplyTemplate(template);

            // Команда Refresh
            _screen.RefreshCallback += () => SelectTrusts(true);

            _screen.MenuItemResolver = (entity, command) =>
            {
                var trust = _screen.CurrentEntity as ITrust;

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

                var trustContext = new TrustContext(context, trust);

                if (command.Equals(ExtensionCatalog.CopyPurseNumber))
                {
                    return(true);
                }

                var formProvider = context.ExtensionManager.TryGetTrustFormProvider(command);
                return(formProvider?.CheckCompatibility(trustContext) ?? false);
            };

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

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

                switch (command)
                {
                case "BeginRefresh":
                    context.ScreenContainer.OnStartProgress();
                    break;

                case "EndRefresh":
                    context.ScreenContainer.OnStopProgress();
                    break;

                default:
                {
                    var trust = args.Argument as ITrust;

                    // Кнопки
                    if (null == trust)
                    {
                        var formProvider =
                            context.ExtensionManager.TryGetTopFormProvider(command);
                        formProvider?.GetForm(context).Show(context.ScreenContainer);
                    }
                    else
                    {
                        if (command.Equals(TunableList.CellMouseDoubleClickCommandName))
                        {
                            command = ExtensionCatalog.UpdateTrust;
                        }

                        var trustContext = new TrustContext(context, trust);

                        // Системная
                        if (command.Equals(ExtensionCatalog.CopyPurseNumber))
                        {
                            var actionProvider = context.ExtensionManager.TryGetTrustActionProvider(command);
                            actionProvider?.RunAction(trustContext);
                        }
                        else
                        {
                            var formProvider = context.ExtensionManager.TryGetTrustFormProvider(command);
                            formProvider?.GetForm(trustContext).Show(context.ScreenContainer);
                        }
                    }
                }
                break;
                }
            };

            _screen.DisplayContent(SelectTrusts(false));

            return(_screen);
        }
Esempio n. 17
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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
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);
        }
Esempio n. 20
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));
            }

            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var origin = new FilterOrigin(context.ExtensionManager,
                                          ExtensionCatalog.TransferBundleFilter)
            {
                MenuItemsTagName  = ExtensionCatalog.Tags.TransferBundleExtension,
                CommandBarTagName = ExtensionCatalog.Tags.TransferBundleFilterExtension,
                ColumnsSettings   = context.Session.SettingsService.GetSettings().TransferBundleSettings
            };

            var template = FilterDisplayHelper.LoadFilterFormTemplate(origin);

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

            // Отключаем кнопки.
            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);
            _form.ApplyTemplate(template);

            var now = DateTime.Now;

            var incomeValuesWrapper = new TransferBundleFilterFormValuesWrapper
            {
                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());

            EventBroker.TransferBundleCreated += EventBrokerOnTransferBundleCreated;

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

            var subscriber = new Subscriber(context, _form);

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

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

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

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

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

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

                var transferContext = new TransferBundleContext(context, transferBundle);

                if (command.Equals(ExtensionCatalog.StartTransferBundle) ||
                    command.Equals(ExtensionCatalog.StopTransferBundle))
                {
                    var actionProvider = context.ExtensionManager.TryGetTransferBundleActionProvider(command);
                    return(actionProvider?.CheckCompatibility(transferContext) ?? false);
                }

                var formProvider = context.ExtensionManager.TryGetTransferBundleFormProvider(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.PreparedTransferFilter;
                }

                var transferBundle = args.Argument as ITransferBundle;

                // Кнопки
                if (null == transferBundle)
                {
                    var formProvider = context.ExtensionManager.TryGetTopFormProvider(command);
                    formProvider?.GetForm(context).Show(_form);
                }
                else
                {
                    var transferBundleContext = new TransferBundleContext(context, transferBundle);

                    if (command.Equals(ExtensionCatalog.StartTransferBundle) ||
                        command.Equals(ExtensionCatalog.StopTransferBundle))
                    {
                        var actionProvider = context.ExtensionManager.TryGetTransferBundleActionProvider(command);
                        actionProvider?.RunAction(transferBundleContext);

                        return;
                    }

                    var formProvider = context.ExtensionManager.TryGetTransferBundleFormProvider(command);
                    formProvider?.GetForm(transferBundleContext).Show(_form);
                }
            };

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

                var transferBundleService = context.UnityContainer.Resolve <ITransferBundleService>();
                var bundles = transferBundleService.SelectBundles(valuesWrapper.Control1FromTime.ToUniversalTime(),
                                                                  valuesWrapper.Control2ToTime.ToUniversalTime());

                var gridRowContentList = new List <GridRowContent>();

                var bundleSettings = context.Session.SettingsService.GetSettings().TransferBundleSettings;

                foreach (var bundle in bundles)
                {
                    var gridRowContent = BuildGridRowContent(bundle, bundleSettings);
                    gridRowContentList.Add(gridRowContent);
                }

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

                return(filterFormContent);
            };

            _form.Disposed += (sender, args) =>
            {
                EventBroker.TransferBundleCreated -= EventBrokerOnTransferBundleCreated;
                subscriber.Dispose();
            };

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

            var transfer = context.Transfer;

            var template = TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager,
                                                                 TransferType.Protected == context.Transfer.Type
                    ? ExtensionCatalog.RejectProtection
                    : ExtensionCatalog.Moneyback);

            var templateWrapper = new MoneybackFormTemplateWrapper(template);

            var currencyService = context.UnityContainer.Resolve <ICurrencyService>();

            templateWrapper.Control6ReturnAmount.CurrencyName =
                currencyService.AddPrefix(currencyService.ObtainCurrencyByAccountNumber(transfer.SourcePurse));
            templateWrapper.Control6ReturnAmount.AvailableAmount = transfer.Amount;
            templateWrapper.Control6ReturnAmount.DefaultValue    = transfer.Amount;

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

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

            var incomeValuesWrapper = new MoneybackFormValuesWrapper
            {
                Control1SourcePurse = transfer.SourcePurse,
                Control2TargetPurse = transfer.TargetPurse,
                Control3Amount      = formattingService.FormatAmount(transfer.Amount),
                Control4Description = transfer.Description
            };

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

            form.ServiceCommand += (sender, args) =>
            {
                if (!MoneybackFormValuesWrapper.Control1SourcePurseCommandFindIdentifier.Equals(args.Command))
                {
                    return;
                }

                var purseNumber = (string)args.Argument;
                IdentifierDisplayHelper.ShowFindIdentifierForm(form, context, purseNumber);
            };

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper = new MoneybackFormValuesWrapper(list);

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

                if (TransferType.Protected == context.Transfer.Type)
                {
                    transferService.RejectProtection(transfer.PrimaryId);
                }
                else
                {
                    transferService.Moneyback(transfer.PrimaryId, valuesWrapper.Control5ReturnAmount);
                }

                return(new Dictionary <string, object>());
            };

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

            var template =
                TemplateLoader.LoadSubmitFormTemplate(context.ExtensionManager, ExtensionCatalog.CreateTransfer);

            var origin =
                new AccountDropDownListOrigin(context.UnityContainer)
            {
                SelectedAccountNumber = context.Account.Number
            };

            origin.FilterCriteria.HasMoney             = true;
            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Transfer;

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            var templateWrapper = new CreateTransferFormTemplateWrapper(template);

            templateWrapper.Control3FromPurse.Items.Clear();
            templateWrapper.Control3FromPurse.Items.AddRange(itemTemplates);

            var form = new SubmitForm();

            ErrorFormDisplayHelper.ApplyErrorAction(context.ExtensionManager, form);

            var incomeValuesWrapper =
                new CreateTransferFormValuesWrapper
            {
                Control1TransferId = context.Session.SettingsService.AllocateTransferId()
            };

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

            form.ServiceCommand += (sender, args) =>
            {
                if (!CreateTransferFormValuesWrapper.Control2ToPurseCommandFindIdentifier.Equals(args.Command))
                {
                    return;
                }

                IdentifierDisplayHelper.ShowFindIdentifierForm(form, context, (string)args.Argument);
            };

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper   = new CreateTransferFormValuesWrapper(list);
                var transferService = context.UnityContainer.Resolve <ITransferService>();

                var originalTransfer = new OriginalTransfer(valuesWrapper.Control1TransferId,
                                                            valuesWrapper.Control3FromPurse, valuesWrapper.Control2ToPurse, valuesWrapper.Control4Amount,
                                                            valuesWrapper.Control5Description);

                if (valuesWrapper.Control6UsePaymentProtection)
                {
                    originalTransfer.ProtectionPeriod = valuesWrapper.Control7ProtectionPeriod;

                    if (!valuesWrapper.Control9ProtectionByTime)
                    {
                        originalTransfer.ProtectionCode = valuesWrapper.Control8ProtectionCode;
                    }
                }

                transferService.CreateTransfer(originalTransfer);

                return(new Dictionary <string, object>());
            };

            form.FinalAction = objects =>
            {
                EventBroker.OnPurseChanged(new DataChangedEventArgs {
                    FreshDataRequired = true
                });
                return(true);
            };

            return(form);
        }