Esempio n. 1
0
        /// <summary>
        /// 金額轉國字
        /// </summary>
        /// <param name="amount"></param>
        /// <param name="amountUnit"></param>
        /// <returns></returns>
        public static string AmountToString(long amount, AmountUnit amountUnit)
        {
            int length = amount.ToString().Length - 1;

            if (amount < 0)
            {
                throw new ArgumentOutOfRangeException("amount", "數值必須為正整數");
            }
            else if (length > 13)
            {
                throw new ArgumentOutOfRangeException("amount", "數值不可超過13位數");
            }

            if (amountUnit == 0 || length > (int)amountUnit)
            {
                amountUnit = (AmountUnit)length;
            }
            string[]      numberTexts = { "零", "壹", "貳", "參", "肆", "伍", "陸", "柒", "捌", "玖" };
            string[]      typeMappings = { "", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟", "兆" };
            long          pow10, tempNum;
            List <string> result = new List <string>();

            for (int i = (int)amountUnit; i >= 0; i--)
            {
                pow10   = Convert.ToInt64(Math.Pow(10, i));
                tempNum = amount / pow10;
                amount -= tempNum * pow10;
                result.Add(numberTexts[tempNum]);
                if (typeMappings[i] != "")
                {
                    result.Add(typeMappings[i]);
                }
            }
            return(string.Join(" ", result));
        }
Esempio n. 2
0
            public void Apply(Order order)
            {
                var amountUnit = AmountUnit.ToDomainModel <AmountUnit>();

                order.AddItem(
                    ProductUnit.Of(
                        Products.ProductId.From(ProductId),
                        amountUnit),
                    Products.Amount.Of(
                        Amount,
                        amountUnit));
            }
Esempio n. 3
0
        public void CalculateProductPrice_ProductWithValidProps_ReturnsProductWithCalculatedPrice()
        {
            var calc     = new PriceCalculator();
            var kgAmount = new AmountUnit()
            {
                Id = 2, Name = "kg"
            };
            var prodInParam = new Product()
            {
                Id           = 2,
                Name         = "Sugar",
                CategoryId   = 1,
                MarketId     = 1,
                OriginId     = 1,
                PricePerUnit = 7.30,
                Amount       = 2,
                AmountUnit   = kgAmount,
                AmountUnitId = 2,
            };
            var expectedProduct = new Product()
            {
                Id           = 2,
                Name         = "Sugar",
                CategoryId   = 1,
                MarketId     = 1,
                OriginId     = 1,
                PricePerUnit = 7.30,
                Amount       = 2,
                AmountUnit   = kgAmount,
                AmountUnitId = 2,
                Price        = 14.60, //    calculated price
            };
            var result = calc.CalculatePrice(prodInParam);

            result.Price.Should().Be(expectedProduct.Price);
        }
Esempio n. 4
0
 private Amount(float count, AmountUnit unit)
 {
     Unit  = unit;
     Count = count < 0 ? 0 : count;
 }
Esempio n. 5
0
 public static IAmount Create(float count, AmountUnit unit)
 {
     return(new Amount(count, unit));
 }
Esempio n. 6
0
 public static IAmount Zero(AmountUnit unit)
 {
     return(new Amount(0, unit));
 }
Esempio n. 7
0
 public PurchaseAmount(double digit, AmountUnit amountUnit)
 {
     this._digit      = digit;
     this._amountUnit = amountUnit;
 }
Esempio n. 8
0
 public static ProductAmount Of(ProductId productId, int value, AmountUnit unit) =>
 new ProductAmount(productId, Amount.Of(value, unit));
Esempio n. 9
0
 private Amount(int value, AmountUnit unit)
 {
     Value = value;
     Unit  = unit;
 }
Esempio n. 10
0
 public static Amount Of(int value, AmountUnit unit) => new Amount(value, unit);
Esempio n. 11
0
 private ProductUnit(ProductId productId, AmountUnit unit)
 {
     ProductId = productId;
     Unit      = unit;
 }
Esempio n. 12
0
 public static ProductUnit Of(ProductId productId, AmountUnit unit) => new ProductUnit(productId, unit);