Пример #1
0
        public string Print(int firstWidth = -1, int latterWidth = -1, AmountPrintEnum flags = AmountPrintEnum.AMOUNT_PRINT_NO_FLAGS)
        {
            int  outWidth = 0;
            bool outRight = false;

            if (firstWidth > 0 && (Type != ValueTypeEnum.Amount || AsAmount.IsZero) && Type != ValueTypeEnum.Balance && Type != ValueTypeEnum.String)
            {
                outWidth = firstWidth;

                if (flags.HasFlag(AmountPrintEnum.AMOUNT_PRINT_RIGHT_JUSTIFY))
                {
                    outRight = true;
                }
            }

            string result = Storage != null?Storage.Print(firstWidth, latterWidth, flags) : String.Empty;    // "" means VOID

            if (outWidth > 0)
            {
                string format = String.Format("{{0,{0}{1}}}", outRight ? "" : "-", outWidth);
                return(String.Format(format, result));
            }
            else
            {
                return(result);
            }
        }
Пример #2
0
            public PrintAmountFromBalance(bool first, int firstWidth, int latterWidth, AmountPrintEnum flags)
            {
                Str = new StringBuilder();

                First       = first;
                FirstWidth  = firstWidth;
                LatterWidth = latterWidth;
                Flags       = flags;
            }
Пример #3
0
        /**
         * Printing methods.  A balance may be output to a stream using the
         * `print' method.  There is also a global operator<< defined which
         * simply calls print for a balance on the given stream.  There is
         * one form of the print method, which takes two required arguments
         * and one arguments with a default value:
         *
         * print(ostream, int first_width, int latter_width) prints a
         * balance to the given output stream, using each commodity's
         * default display characteristics.  The first_width parameter
         * specifies the width that should be used for printing amounts
         * (since they are likely to vary in width).  The latter_width, if
         * specified, gives the width to be used for each line after the
         * first.  This is useful when printing in a column which falls at
         * the right-hand side of the screen.
         *
         * In addition to the width constraints, balances will also print
         * with commodities in alphabetized order, regardless of the
         * relative amounts of those commodities.  There is no option to
         * change this behavior.
         */
        public string Print(int firstWidth = -1, int latterWidth = -1, AmountPrintEnum flags = AmountPrintEnum.AMOUNT_PRINT_NO_FLAGS)
        {
            PrintAmountFromBalance amountPrinter = new PrintAmountFromBalance(true, firstWidth, latterWidth == 1 ? firstWidth : latterWidth, flags);

            MapSortedAmounts(amount => amountPrinter.HandleAmount(amount));

            if (amountPrinter.First)
            {
                amountPrinter.Close();
            }

            return(amountPrinter.Str.ToString());
        }