/// <summary> /// When a row is bound, do a few things. /// <list type="bullet"> /// <item>Add the totals to the footer row</item> /// <item>Calculate the price based on quantity-gratis</item> /// <item>Handle null years coming in</item> /// </list> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gvCart_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[0].Attributes["colspan"] = (e.Row.Cells.Count - 1).ToString(); for (int i = 1; i < e.Row.Cells.Count - 1; i++) { e.Row.Cells[i].Visible = false; } e.Row.Cells[e.Row.Cells.Count - 1].Text = CurrencyFormatter.FormatCurrency(NWTD.Orders.Cart.CartTotal(this.CheckoutCartHelper.Cart), this.CheckoutCartHelper.Cart.BillingCurrency); } if (e.Row.RowType == DataControlRowType.DataRow) { LineItem item = e.Row.DataItem as LineItem; Entry entry = CatalogContext.Current.GetCatalogEntry(item.CatalogEntryId); Literal litYear = e.Row.FindControl("litYear") as Literal; if (litYear != null) { float year = 0f; float.TryParse(entry.ItemAttributes["Year"].ToString(), out year); if (year > 0) { litYear.Text = year.ToString("#"); } } Literal tbQuantityCharged = e.Row.FindControl("litQuantityCharged") as Literal; tbQuantityCharged.Text = item["Gratis"] == null?item.Quantity.ToString("n0") : (item.Quantity - (decimal)item["Gratis"]).ToString("n0"); } }
/// <summary> /// Get the shipping cost. /// </summary> /// <param name="shippingMethod">The shipping method.</param> /// <param name="shipment">The shipment.</param> /// <param name="currency">The currency.</param> /// <returns>The shipping cost.</returns> public static Money GetShippingCost(Mediachase.Commerce.Orders.Dto.ShippingMethodDto.ShippingMethodRow shippingMethod, Shipment shipment, Currency currency) { Money result = new Money(0, currency); var type = Type.GetType(shippingMethod.ShippingOptionRow.ClassName); if (type == null) { throw new TypeInitializationException(shippingMethod.ShippingOptionRow.ClassName, null); } var message = string.Empty; var provider = (IShippingGateway)Activator.CreateInstance(type, new MarketStorage().GetCurrentMarket()); var shipmentRate = provider.GetRate(shippingMethod.ShippingMethodId, shipment, ref message); if (shipmentRate != null) { var shipmentRateMoney = shipmentRate.Money; if (!shipmentRateMoney.Currency.Equals(currency)) { //The shipment and the shipping method base price are in different currency, need to convert first result = CurrencyFormatter.ConvertCurrency(shipmentRateMoney, currency); } else { result = shipmentRateMoney; } } return(result); }
protected override void OnNavigatedTo(NavigationEventArgs e) { // 百分比格式化 PercentFormatter percentFormatter = new PercentFormatter(); // PercentFormatter percentFormatter = new PercentFormatter(new[] { "zh-Hans-CN" }, "CN"); lblMsg.Text = percentFormatter.Format(3.1415926); lblMsg.Text += Environment.NewLine; // 千分比格式化 PermilleFormatter permilleFormatter = new PermilleFormatter(); // PermilleFormatter permilleFormatter = new PermilleFormatter(new[] { "zh-Hans-CN" }, "CN"); lblMsg.Text += permilleFormatter.Format(3.1415926); lblMsg.Text += Environment.NewLine; // 数字格式化 DecimalFormatter decimalFormatter = new DecimalFormatter(); // DecimalFormatter decimalFormatter = new DecimalFormatter(new[] { "zh-Hans-CN" }, "CN"); lblMsg.Text += decimalFormatter.Format(3.1415926); lblMsg.Text += Environment.NewLine; // 货币格式化 CurrencyFormatter currencyFormatter = new CurrencyFormatter("CNY"); // CurrencyFormatter currencyFormatter = new CurrencyFormatter("CNY", new[] { "zh-Hans-CN" }, "CN"); lblMsg.Text += currencyFormatter.Format(3.1415926); }
private void LoadNumbers() { DecimalFormatter formatter = new DecimalFormatter(); formatter.IsGrouped = true; formatter.IsDecimalPointAlwaysDisplayed = true; DecimalFormatterTextblock.Text = formatter.Format(12345.00); // Determine the current user's default currency. string currency = GlobalizationPreferences.Currencies[0]; // Create currency formatter with current preferences CurrencyFormatter defaultCurrencyFormatter = new CurrencyFormatter(currency); DefaultCurrencyTextblock.Text = defaultCurrencyFormatter.Format(1234.56); // Create currency formatter for USD CurrencyFormatter usdCurrencyFormatter = new CurrencyFormatter("USD"); USDCurrencyTextblock.Text = usdCurrencyFormatter.Format(1234.56); // Create currency formatter for EUR CurrencyFormatter eurITCurrencyFormatter = new CurrencyFormatter("EUR", new[] { "it-IT" }, "IT"); EurItCurrencyTextblock.Text = eurITCurrencyFormatter.Format(1234.56); }
/// <summary> /// Binds the cart total to the control /// </summary> protected void BindTotal() { decimal total = NWTD.Orders.Cart.CartTotal(this.Cart); string currencyCode = this.Cart.BillingCurrency; this.litTotal.Text = CurrencyFormatter.FormatCurrency(total, currencyCode); }
/// <summary> /// Binds the table. /// </summary> private void BindTable() { // Bind Price if (ListPrice != null) { if (ListPrice.Amount > SalePrice.Amount) { ListPriceValue.Text = ListPrice.FormattedPrice; SalePriceValue.Text = SalePrice.FormattedPrice; DiscountPrice.Text = CurrencyFormatter.FormatCurrency(ListPrice.Amount - SalePrice.Amount, SalePrice.CurrencyCode); DiscountPricePanel.Visible = true; ListPricePanel.Visible = true; } else { SalePriceValue.Text = SalePrice.FormattedPrice; } } else { ListPriceValue.Text = "0"; SalePriceValue.Text = "0"; DiscountPricePanel.Visible = false; ListPricePanel.Visible = false; } SalePriceLabel.Visible = ShowPriceLabel; ListPriceLabel.Visible = ShowPriceLabel; }
public async Task GetMoneyAsync(SocketUser user = null) { user ??= Context.User; Context.TryGetUser(user.Id, out ArcadeUser account); if (await CatchEmptyAccountAsync(account)) { return; } var provider = new CurrencyFormatter(); var result = new StringBuilder(); if (user != null) { if (user != Context.User) { result.AppendLine($"> **Wallet: {account.Username}**"); } } if (account.Debt > 0) { result.AppendLine(string.Format(provider, "{0:D}", account.Debt)); } else if (account.Balance > 0) { result.AppendLine(string.Format(provider, "{0:O}", account.Balance)); } result.AppendLine(string.Format(provider, "{0:C}", account.ChipBalance)); result.AppendLine(string.Format(provider, "{0:T}", account.TokenBalance)); await Context.Channel.SendMessageAsync(result.ToString()); }
public ActionResult UpdatePayment(CheckoutPage currentPage, CheckoutViewModel viewModel, IPaymentMethod paymentOption) { if (!paymentOption.ValidateData()) { return(View(viewModel)); } if (paymentOption is GiftCardPaymentOption) { var giftCard = _giftCardService.GetGiftCard(((GiftCardPaymentOption)paymentOption).SelectedGiftCardId); var paymentTotal = CurrencyFormatter.ConvertCurrency(new Money(viewModel.OrderSummary.PaymentTotal, CartWithValidationIssues.Cart.Currency), Currency.USD); if (paymentTotal > giftCard.RemainBalance) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Not enought money in Gift Card")); } } viewModel.Payment = paymentOption; _checkoutService.CreateAndAddPaymentToCart(CartWithValidationIssues.Cart, viewModel); _orderRepository.Save(CartWithValidationIssues.Cart); var model = CreateCheckoutViewModel(currentPage); model.OrderSummary = _orderSummaryViewModelFactory.CreateOrderSummaryViewModel(CartWithValidationIssues.Cart); if (Request.IsAuthenticated) { model.BillingAddressType = 1; } else { model.BillingAddressType = 0; } return(PartialView("_AddPayment", model)); }
/// <summary> /// 使用すべきフォーマッタを返します。 /// </summary> /// <param name="description">項目定義</param> /// <returns>フォーマッタ</returns> public static IFormatter Create(PropertyDescrption description = null) { if (description == null) { return(InactionFormatter.GetInstance()); } switch (description.Unit) { case "円": case "百万円": return(CurrencyFormatter.GetInstance()); case "%": return(RatioFormatter.GetInstance()); case "株": case "倍": case "日": case "ヶ月": case "人": return(NumericFormatter.GetInstance()); case "年": default: return(InactionFormatter.GetInstance()); } }
/// <summary> /// Binds to the controls that expose pricing. /// </summary> private void BindPricing() { Price listPrice = StoreHelper.GetSalePrice(Entry, 1); Price salePrice = StoreHelper.GetDiscountPrice(Entry, CatalogName); // Check for nulls. if (listPrice != null && salePrice != null) { // Compare list and sale prices. if (listPrice.Amount > salePrice.Amount) { ListPriceLabel.Text = listPrice.FormattedPrice; PriceLabel.Text = salePrice.FormattedPrice; DiscountPrice.Text = CurrencyFormatter.FormatCurrency(listPrice.Amount - salePrice.Amount, salePrice.CurrencyCode); this.ProductInfoSavingsDiv.Visible = true; } else { this.ProductInfoSavingsDiv.Visible = false; PriceLabel.Text = salePrice.FormattedPrice; } } else { ListPriceLabel.Text = "0"; PriceLabel.Text = "0"; this.ProductInfoSavingsDiv.Visible = false; } }
public void TestFormat() { var formatter = CurrencyFormatter.GetInstance(); var yen = new PropertyDescrption("any", "any", "円"); var millionYen = new PropertyDescrption("any", "any", "百万円"); string formatted; // 円 // カンマの処理だけ formatted = formatter.Format("1", yen); Assert.AreEqual("1", formatted); formatted = formatter.Format("10000", yen); Assert.AreEqual("10,000", formatted); formatted = formatter.Format("-1000000", yen); Assert.AreEqual("-1,000,000", formatted); formatted = formatter.Format("", yen); Assert.AreEqual("", formatted); // 百万円 // 単位の調整もやる formatted = formatter.Format("1000000", millionYen); Assert.AreEqual("1", formatted); formatted = formatter.Format("1000000000", millionYen); Assert.AreEqual("1,000", formatted); formatted = formatter.Format("-1000000000000", millionYen); Assert.AreEqual("-1,000,000", formatted); formatted = formatter.Format("999999", millionYen); Assert.AreEqual("0", formatted); formatted = formatter.Format("", millionYen); Assert.AreEqual("", formatted); }
/// <summary> /// Binds the table. /// </summary> private void BindTable() { // Bind Price if (LineItem != null) { string currencyCode = LineItem.Parent.Parent.BillingCurrency; if (LineItem.LineItemDiscountAmount > 0) { ListPriceLabel.Text = CurrencyFormatter.FormatCurrency(LineItem.ListPrice, currencyCode); //PriceLabel.Text = CurrencyFormatter.FormatCurrency(LineItem.PlacedPrice - LineItem.LineItemDiscountAmount, currencyCode); PriceLabel.Text = CurrencyFormatter.FormatCurrency(LineItem.ExtendedPrice / LineItem.Quantity, currencyCode); DiscountPrice.Text = CurrencyFormatter.FormatCurrency(LineItem.LineItemDiscountAmount, currencyCode); DiscountPricePanel.Visible = true; ListPricePanel.Visible = true; } else { PriceLabel.Text = CurrencyFormatter.FormatCurrency(LineItem.ListPrice, currencyCode); } } else { ListPriceLabel.Text = "0"; PriceLabel.Text = "0"; DiscountPricePanel.Visible = false; ListPricePanel.Visible = false; } }
public static Money ConvertCurrency(Money money, Currency currency) { var retVal = !CurrencyFormatter.CanBeConverted(money.Currency, currency) ? money : CurrencyFormatter.ConvertCurrency(money, currency); return(retVal); }
/// <summary> /// Creates the price. /// </summary> /// <param name="amount">The amount.</param> /// <param name="currencyCode">The currency code.</param> /// <returns></returns> public static Price CreatePrice(decimal amount, string currencyCode) { Price price = new Price(); price.FormattedPrice = CurrencyFormatter.FormatCurrency(amount, currencyCode); price.Amount = amount; price.CurrencyCode = currencyCode; return(price); }
public object Convert(object value, Type targetType, object parameter, string language) { var cf = new CurrencyFormatter("GBP") { Mode = CurrencyFormatterMode.UseSymbol, IsGrouped = true, FractionDigits = 0 }; return(cf.Format(System.Convert.ToUInt32(value))); }
private void setDollarLabelAmounts() { for (var i = 0; i < this.dollarAmountLabels.Count; i++) { var currentBorder = this.dollarAmountLabels.ElementAt(i); var textBlock = (TextBlock)currentBorder.Child; textBlock.Text = CurrencyFormatter.FormatNoDecimals(this.manager.GameTypeAmounts.ElementAt(i)); } }
protected override async Task OnInitializedAsync() { Log.Debug("Summary.OnInitializedAsync"); BindEvents(); SortDescriptor = new SortDescriptor <SummarySortType>(SummarySortType.ByCategory, SortDirection.Ascending); await base.OnInitializedAsync(); formatter = new CurrencyFormatter(await Queries.QueryAsync(new ListAllCurrency())); }
protected override async Task OnInitializedAsync() { Log.Debug("Summary.OnInitializedAsync"); BindEvents(); SortDescriptor = new SortDescriptor <SummarySortType>(SummarySortType.ByCategory, SortDirection.Ascending); await base.OnInitializedAsync(); formatter = await CurrencyFormatterFactory.CreateAsync(); }
public void CreateMappings(IProfileExpression configuration) { configuration.CreateMap <Receipt, ReceiptViewModel>() .ForMember(dest => dest.Products, options => { options.MapFrom(src => src.Products.Select(pr => pr.Product)); }) .ForMember(r => r.TotalPrice, opt => opt.MapFrom(src => CurrencyFormatter.Convert(src.TotalPrice))) .ForMember(r => r.Discount, opt => opt.MapFrom(src => CurrencyFormatter.Convert(src.Discount))) .ForMember(r => r.TotalPriceWithDiscount, opt => opt.MapFrom(src => CurrencyFormatter.Convert(src.TotalPriceWithDiscount))); }
protected override async Task OnInitializedAsync() { PagingContext = new PagingContext(LoadDataAsync, Loading); BindEvents(); MonthModel = new MonthModel(Year, Month); CurrencyFormatter = new CurrencyFormatter(await Queries.QueryAsync(new ListAllCurrency())); Reload(); }
protected async override Task OnInitializedAsync() { EventHandlers.Add <LocallyStoredExpenseCreated>(this); EventHandlers.Add <LocallyStoredExpensesPublished>(this); CurrencyFormatter = new CurrencyFormatter(await Queries.QueryAsync(new ListAllCurrency())); await base.OnInitializedAsync(); await LoadAsync(); }
/// <summary> /// Gets the shipment subtotal. /// </summary> /// <param name="shipment">The shipment.</param> /// <returns></returns> protected string GetShipmentSubtotal(Shipment shipment) { decimal price = 0m; foreach (LineItem item in this.GetShipmentLineItems(shipment)) { price += item.ExtendedPrice; } return(CurrencyFormatter.FormatCurrency(price, OrderGroup.BillingCurrency)); }
protected async Task LoadMonthSummaryAsync() { if (SelectedMonth != null) { Categories = await Queries.QueryAsync(new ListMonthCategoryWithOutcome(SelectedMonth)); TotalAmout = await Queries.QueryAsync(new GetTotalMonthOutcome(SelectedMonth)); formatter = new CurrencyFormatter(await Queries.QueryAsync(new ListAllCurrency())); } }
protected async Task LoadItemSummaryAsync() { if (SelectedItem != null) { Categories = await Queries.QueryAsync(CreateCategoriesQuery(SelectedItem)); TotalAmout = await Queries.QueryAsync(CreateTotalQuery(SelectedItem)); formatter = new CurrencyFormatter(await Queries.QueryAsync(new ListAllCurrency())); Sort(); } }
/// <summary> /// Calculates the line item total /// </summary> protected void BindTotal() { if (_lineItem == null) { litTotal.Text = string.Empty; return; } decimal total = NWTD.Orders.Cart.LineItemTotal(this._lineItem); string currencyCode = LineItem.Parent.Parent.BillingCurrency; this.litTotal.Text = CurrencyFormatter.FormatCurrency(total, currencyCode); }
protected async override Task OnParametersSetAsync() { await base.OnParametersSetAsync(); Title = $"List of Exchange Rates for {TargetCurrency}."; if (isShown) { Models = await Queries.QueryAsync(new ListTargetCurrencyExchangeRates(TargetCurrency)); CurrencyFormatter = new CurrencyFormatter(await Queries.QueryAsync(new ListAllCurrency())); isShown = false; } }
/// <summary> /// Gets the shipment discount total. /// </summary> /// <param name="shipment">The shipment.</param> /// <returns></returns> protected string GetShipmentDiscountTotal(Shipment shipment) { decimal price = 0m; foreach (LineItem item in this.GetShipmentLineItems(shipment)) { price += item.LineItemDiscountAmount; } price += shipment.ShippingDiscountAmount; return(CurrencyFormatter.FormatCurrency(price, OrderGroup.BillingCurrency)); }
/// <summary> /// Binds the data. /// </summary> private void BindData(bool validate) { // Make sure to check that prices has not changed if (!CartHelper.IsEmpty && validate) { CartHelper.Reset(); CartHelper.RunWorkflow("CartValidate"); // If cart is empty, remove it from the database if (CartHelper.IsEmpty) { CartHelper.Delete(); } CartHelper.Cart.AcceptChanges(); } ShoppingCart.DataSource = CartHelper.LineItems; // Calculate sub total decimal subTotalPrice = 0; foreach (LineItem item in CartHelper.LineItems) { subTotalPrice += item.ExtendedPrice; } // Bind Order Level Discounts if (CartHelper.OrderForm.Discounts.Count > 0) { DiscountList.DataSource = CartHelper.OrderForm.Discounts; DiscountList.DataBind(); DiscountTr.Visible = true; TotalDiscount.Text = CurrencyFormatter.FormatCurrency(CartHelper.OrderForm.DiscountAmount, CartHelper.Cart.BillingCurrency); } else { DiscountTr.Visible = false; } SubTotal.Text = CurrencyFormatter.FormatCurrency(subTotalPrice, CartHelper.Cart.BillingCurrency); bool isEmpty = CartHelper.IsEmpty; CartSummary.Visible = !isEmpty; UpdateCartButton.Visible = !isEmpty; CheckoutButton.Visible = !isEmpty; CouponSummary.Visible = !isEmpty; ShoppingCart.DataBind(); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { if (String.IsNullOrEmpty(DataArgument) || String.IsNullOrEmpty(CurrencyArgument)) { return; } string formattedCurrency = CurrencyFormatter.FormatCurrency(Decimal.Parse(((GridServerTemplateContainer)this.Parent).DataItem[DataArgument].ToString()), ((GridServerTemplateContainer)this.Parent).DataItem[CurrencyArgument].ToString()); if (!String.IsNullOrEmpty(formattedCurrency)) { MyText.Text = String.Format(FormatString, formattedCurrency); } }
/// <summary> /// This is the click handler for the 'Display' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Display_Click(object sender, RoutedEventArgs e) { // This scenario uses the Windows.Globalization.NumberFormatting.CurrencyFormatter class // to format a number as a currency. // Keep results of the scenario in a StringBuilder StringBuilder results = new StringBuilder(); // Determine the current user's default currency. string currency = GlobalizationPreferences.Currencies[0]; // Generate numbers used for formatting. ulong wholeNumber = 12345; double fractionalNumber = 12345.67; // Create currency formatter initialized with current number formatting preferences. CurrencyFormatter defaultCurrencyFormatter = new CurrencyFormatter(currency); CurrencyFormatter usdCurrencyFormatter = new CurrencyFormatter(CurrencyIdentifiers.USD); CurrencyFormatter eurFRCurrencyFormatter = new CurrencyFormatter(CurrencyIdentifiers.EUR, new[] { "fr-FR" }, "FR"); CurrencyFormatter eurIECurrencyFormatter = new CurrencyFormatter(CurrencyIdentifiers.EUR, new[] { "gd-IE" }, "IE"); CurrencyFormatter currencyFormatEuroModeSwitch = new CurrencyFormatter(CurrencyIdentifiers.EUR); // Format numbers as currency. results.AppendLine("Fixed number (" + fractionalNumber + ")"); results.AppendLine("With user's default currency: " + defaultCurrencyFormatter.Format(fractionalNumber)); results.AppendLine("Formatted US Dollar: " + usdCurrencyFormatter.Format(fractionalNumber)); results.AppendLine("Formatted Euro (fr-FR defaults): " + eurFRCurrencyFormatter.Format(fractionalNumber)); results.AppendLine("Formatted Euro (gd-IE defaults): " + eurIECurrencyFormatter.Format(fractionalNumber)); // Format currency with fraction digits always included. usdCurrencyFormatter.FractionDigits = 2; results.AppendLine("Formatted US Dollar (with fractional digits): " + usdCurrencyFormatter.Format(wholeNumber)); // Format currenccy with grouping. usdCurrencyFormatter.IsGrouped = true; results.AppendLine("Formatted US Dollar (with grouping separators): " + usdCurrencyFormatter.Format(fractionalNumber)); // Format using currency code instead of currency symbol currencyFormatEuroModeSwitch.Mode = CurrencyFormatterMode.UseCurrencyCode; results.AppendLine("Formatted Euro (as currency code): " + currencyFormatEuroModeSwitch.Format(fractionalNumber)); // Switch so we can now format using currency symbol currencyFormatEuroModeSwitch.Mode = CurrencyFormatterMode.UseSymbol; results.AppendLine("Formatted Euro (as symbol): " + currencyFormatEuroModeSwitch.Format(fractionalNumber)); // Display the results OutputTextBlock.Text = results.ToString(); }