public SwissQRCode()
        {
            InitializeComponent();

            // >> swissqrbarcode-example-builder
            SwissQRCodeValueStringBuilder qrCodeValue = new SwissQRCodeValueStringBuilder(
                new Iban("CH4431999123000889012", IbanType.QRIBAN),
                SwissQRCodeCurrency.EUR,
                new Contact("Max Muster & Söhne",
                            new StructuredAddress("CH", "8000", "Seldwyla", "Musterstrasse", "123")),
                new Reference(ReferenceType.QRR, "210000000003139471430009017"),
                new AdditionalInformation("Order from 15.03.2021", "//S1/10/1234/11/201021/30/102673386/32/7.7/40/0:30"),
                new Contact("Simon Muster", new StructuredAddress("CH", "8000", "Seldwyla", "Musterstrasse", "1")),
                (decimal)1949.75,
                new AlternativeProcedure("Name AV1: UV;UltraPay005;12345", "Name AV2: XY;XYService;54321"));
            // << swissqrbarcode-example-builder

            // >> swissqrbarcode-example-validate
            string errors = qrCodeValue.Validate();

            if (string.IsNullOrEmpty(errors))
            {
                this.Barcode.Value = qrCodeValue.BuildValue();
            }
            // << swissqrbarcode-example-validate
        }
Example #2
0
        private void GenerateBarcodeValue()
        {
            AdditionalInformation additionalInfo = this.hasAdditionalInfo ?
                                                   new AdditionalInformation(this.unstructuredMessage, this.billingInformation)
                : null;

            Contact debtor = this.hasDebtor ?
                             new Contact(this.debtorName,
                                         new StructuredAddress(this.debtorCountry,
                                                               this.debtorZipCode,
                                                               this.debtorCity,
                                                               this.debtorStreet,
                                                               this.debtorHouseNumber))
                : null;

            decimal?amount = null;

            if (this.hasAmount)
            {
                amount = this.amount;
            }

            AlternativeProcedure procedure = this.hasAlternativeProcedures ?
                                             new AlternativeProcedure(this.alternativeProcedure1, this.alternativeProcedure2)
                : null;

            SwissQRCodeValueStringBuilder qRCodeValue = new SwissQRCodeValueStringBuilder(
                new Iban(this.ibanText, (IbanType)Enum.Parse(typeof(IbanType), this.ibanTypeString, true)),
                (SwissQRCodeCurrency)Enum.Parse(typeof(SwissQRCodeCurrency), this.codeCurrencyString, true),
                new Contact(this.creditorName,
                            new StructuredAddress(this.creditorCountry,
                                                  this.creditorZipCode,
                                                  this.creditorCity,
                                                  this.creditorStreet,
                                                  this.creditorHouseNumber)),
                new Reference((ReferenceType)Enum.Parse(typeof(ReferenceType), this.referenceTypeString, true), this.reference),

                additionalInfo,
                debtor,
                amount,
                procedure);

            this.Errors = qRCodeValue.Validate();

            if (!string.IsNullOrEmpty(this.errors))
            {
                this.Value = null;
            }
            else
            {
                this.Value = qRCodeValue.BuildValue();
            }
        }
        private void GenerateValue()
        {
            AdditionalInformation additionalInfo = new AdditionalInformation(this.unstructuredMessage, this.billingInformation);

            Contact debtor = new Contact(this.debtorName,
                                         new StructuredAddress(this.debtorCountry,
                                                               this.debtorZipCode,
                                                               this.debtorCity,
                                                               this.debtorStreet,
                                                               this.debtorHouseNumber));
            var amount = this.amount;

            SwissQRCodeValueStringBuilder qRCodeValue = new SwissQRCodeValueStringBuilder(
                new Iban(this.ibanText, IbanType.IBAN),
                (SwissQRCodeCurrency)Enum.Parse(typeof(SwissQRCodeCurrency), this.codeCurrencyString, true),
                new Contact(this.creditorName,
                            new StructuredAddress(this.creditorCountry,
                                                  this.creditorZipCode,
                                                  this.creditorCity,
                                                  this.creditorStreet,
                                                  this.creditorHouseNumber)),
                new Reference(ReferenceType.NON, string.Empty),

                additionalInfo,
                debtor,
                amount,
                null);

            var errors = qRCodeValue.Validate();

            if (!string.IsNullOrEmpty(errors))
            {
                this.isValid      = false;
                this.errorMessage = errors;
            }
            else
            {
                this.isValid      = true;
                this.errorMessage = string.Empty;
                this.value        = qRCodeValue.BuildValue();
            }
        }