/// <summary> /// Gets the currency information. /// </summary> /// <param name="isoCurrency">The iso currency.</param> /// <returns>The currency</returns> /// <exception cref="System.ArgumentException"></exception> public static Currency GetCurrencyInfo(string isoCurrency) { var r = GetRegionFromCache(isoCurrency); if (r == null) { foreach (var c in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { var reg = new RegionInfo(c.LCID); if (String.Compare(isoCurrency, reg.ISOCurrencySymbol, StringComparison.OrdinalIgnoreCase) == 0) { var currency = new Currency { CurrencyEnglishName = reg.CurrencyEnglishName, CurrencyNativeName = reg.CurrencyNativeName, CurrencySymbol = reg.CurrencySymbol, IsoCurrencySymbol = reg.ISOCurrencySymbol }; SaveRegionInCache(isoCurrency, currency); return currency; } } throw new ArgumentException(); } return r; }
public void TestCreationOfBasicMoney() { var currentSymbol = CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol; var currentRegion = new RegionInfo(CultureInfo.CurrentCulture.LCID); var currentCode = currentRegion.ISOCurrencySymbol; var currentEnglishName = currentRegion.CurrencyEnglishName; var currentDigits = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits; //Locale specific formatting var money1 = new Money(2000.1234567m, CurrencyCodes.USD); Assert.AreEqual("$2,000.12", money1.ToString()); //Default currency var money2 = new Money(3000m); Assert.AreEqual(currentCode, money2.CurrencyCode); Assert.AreEqual(currentSymbol, money2.CurrencySymbol); Assert.AreEqual(currentEnglishName, money2.CurrencyName); Assert.AreEqual(currentDigits, money2.DecimalDigits); //Implicit casting of int, decimal and double to Money var money3 = new Money(5.0d); var money4 = new Money(5.0m); var money5 = new Money(5); Money money6 = 5.0d; Money money7 = 5.0m; Money money8 = 5; Money money9 = 5.0f; Money money10 = 5.0; Assert.IsTrue(money3 == money4 && money4 == money5 && money5 == money6 && money6 == money7 && money7 == money8 && money8 == money9 && money9 == money10); //Generic 3char currency code formatting instead of locale based with symbols Assert.AreEqual("USD2,000", money1.ToString(true)); }
public decimal CalculateShippingCost(float packageWeightInKilograms, Size<float> packageDimensionsInInches, RegionInfo destination) { Contract.Requires<ArgumentOutOfRangeException>(packageWeightInKilograms > 0f, "Package weight must be positive and non-zero"); Contract.Requires<ArgumentOutOfRangeException>(packageDimensionsInInches.X > 0f && packageDimensionsInInches.Y > 0f, "Package dimensions must be positive and non-zero"); return decimal.MinusOne; }
/// <summary> /// Dots the net framework fallback. /// </summary> /// <param name="storeAlias">The store alias.</param> /// <returns></returns> protected virtual List<Country> DotNETFrameworkFallback(string storeAlias) { Store store = StoreHelper.GetByAlias(storeAlias); CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture; if (store != null) { Thread.CurrentThread.CurrentCulture = store.CultureInfo; Thread.CurrentThread.CurrentUICulture = store.CultureInfo; } var cultureList = new Dictionary<string, string>(); foreach (var culture in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { var region = new RegionInfo(culture.LCID); if (!(cultureList.ContainsKey(region.TwoLetterISORegionName))) cultureList.Add(region.TwoLetterISORegionName, region.DisplayName); } List<Country> countries = cultureList.Select(culture => new Country {Name = culture.Value, Code = culture.Key}).Where(country => !string.IsNullOrEmpty(country.Name)).OrderBy(country => country.Name).ToList(); if (store != null) { Thread.CurrentThread.CurrentCulture = currentCulture; Thread.CurrentThread.CurrentUICulture = currentUICulture; } return countries; }
public void PosTest1() { CultureInfo myCulture = new CultureInfo("en-US"); RegionInfo regionInfo = new RegionInfo(myCulture.Name); string strCurrencySymbol = regionInfo.CurrencySymbol; Assert.Equal("$", strCurrencySymbol); }
private static void RegisterCustomCulture(string customCultureName, string parentCultureName) { Console.WriteLine("Registering {0}", customCultureName); try { CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder(customCultureName, CultureAndRegionModifiers.None); CultureInfo ci = new CultureInfo(parentCultureName); cib.LoadDataFromCultureInfo(ci); RegionInfo ri = new RegionInfo(parentCultureName); cib.LoadDataFromRegionInfo(ri); cib.Register(); Console.WriteLine("Success."); } catch (InvalidOperationException) { // This is OK, means that this is already registered. Console.WriteLine("The custom culture {0} was already registered", customCultureName); } catch (Exception ex) { Console.WriteLine("Registering the custom culture {0} failed", customCultureName); Console.WriteLine(ex); } Console.WriteLine(); }
public static RegistrationResults RegisterCultureBasedOn(string newCultureCode, string languageCode, string regionCode) { var baseCulture = new CultureInfo(languageCode); var baseRegionInfo = new RegionInfo(regionCode); return RegisterCultureBasedOn(newCultureCode, baseCulture, baseRegionInfo); }
public string FormatCurrency(decimal amount, Currency targetCurrency, bool includeSymbol = true) { //find out the culture for the target currency var culture = CultureInfo.GetCultures(CultureTypes.SpecificCultures).FirstOrDefault(c => { var r = new RegionInfo(c.LCID); return string.Equals(r.ISOCurrencySymbol, targetCurrency.CurrencyCode, StringComparison.CurrentCultureIgnoreCase); }); //the format of display var format = targetCurrency.DisplayFormat; var locale = targetCurrency.DisplayLocale; if (culture == null) { if (!string.IsNullOrEmpty(locale)) { culture = new CultureInfo(locale); } } if (string.IsNullOrEmpty(format)) { format = culture == null || !includeSymbol ? "{0:N}" : "{0:C}"; } return culture == null ? string.Format(format, amount): string.Format(culture, format, amount); }
public void PosTest3() { CultureInfo myCultur = new CultureInfo("en-IE"); string culture = myCultur.Name; RegionInfo myRegInfo = new RegionInfo(culture); Assert.False(myRegInfo.Name != "en-IE" && myRegInfo.Name != "IE"); }
public void PosTest2() { CultureInfo myCultur = new CultureInfo("zh-CN"); string culture = myCultur.Name; RegionInfo myRegInfo = new RegionInfo(culture); Assert.True(myRegInfo.Name == "zh-CN" || myRegInfo.Name == "CN"); }
public void PosTest4() { CultureInfo myCultur = new CultureInfo("en-GB"); string culture = myCultur.Name; RegionInfo myRegInfo = new RegionInfo(culture); Assert.True(myRegInfo.Name == "en-GB" || myRegInfo.Name == "GB"); }
private void PopulateCurrencies() { List<ListItem> items = new List<ListItem>(); foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { if (ci.IsNeutralCulture != true) { RegionInfo region = new RegionInfo(ci.LCID); string currencyName = region.CurrencyEnglishName; string currencySymbol = region.CurrencySymbol; string format = string.Format("{0} [{1}]", currencyName, currencySymbol); ListItem item = new ListItem(); item.Text = format; item.Value = format; // Add to our list if (!items.Contains(item)) items.Add(item); } } // Sort array items = items.OrderBy(li => li.Text).ToList(); // Add to our list ddlCurrenciesSymbol.Items.AddRange(items.ToArray()); }
public CreateCultureResponse CreateCulture(CreateCultureRequest request) { var response = new CreateCultureResponse(); if (request.Data != null) { var culture = CultureInfo.GetCultureInfo(request.Data.Code); var region = new RegionInfo(culture.LCID); //locate associted info var language = Uow.Languages.Get(o => o.Iso3.Equals(culture.ThreeLetterISOLanguageName), null, null).FirstOrDefault(); var country = Uow.Countries.Get(o => o.Iso3.Equals(region.ThreeLetterISORegionName), null, null).FirstOrDefault(); // insert culture Uow.Cultures.Add(new Culture { Id = request.Data.Id, ParentCultureId = request.Data.ParentCulture.Id, Code = request.Data.Code, Language = language ?? new Language { Id = culture.LCID, Iso2 = culture.TwoLetterISOLanguageName, Iso3 = culture.ThreeLetterISOLanguageName, Localizations = new Collection<LanguageLocalized> { new LanguageLocalized { LanguageId = culture.LCID, CultureId = CultureInfo.InvariantCulture.LCID, Name = culture.NativeName } } }, Country = country ?? new Country { Id = region.GeoId, Iso2 = region.TwoLetterISORegionName, Iso3 = region.ThreeLetterISORegionName, Localizations = new Collection<CountryLocalized> { new CountryLocalized { CountryId = region.GeoId, CultureId = CultureInfo.InvariantCulture.LCID, Name = region.NativeName } } }, _localizations = new List<CultureLocalized> { new CultureLocalized{ Id = request.Data.Id, CultureId = CultureInfo.InvariantCulture.LCID, Name = request.Data.Name} }, }); Uow.Commit(); } else { throw new Exception("Cannot create empty element"); } return response; }
/// <summary> /// Populates the list of currencies /// </summary> private void PopulateCurrencies() { ddlCurrencySymbol.Items.Clear(); foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { if (!ci.IsNeutralCulture) { RegionInfo region = new RegionInfo(ci.LCID); ListItem item = new ListItem(); item.Value = region.CurrencySymbol; item.Text = string.Format("{0} [{1}]", region.CurrencyNativeName, region.CurrencySymbol); ddlCurrencySymbol.Items.Add(item); } } // Select the current culture RegionInfo currentRegion = new RegionInfo(CultureInfo.CurrentCulture.LCID); if (currentRegion != null) { ListItem item = ddlCurrencySymbol.Items.FindByValue(currentRegion.CurrencySymbol); if (item != null) ddlCurrencySymbol.SelectedValue = item.Value; } }
public static RegistrationResults RegisterCultureBasedOn(string newCultureCode, CultureInfo baseCulture, RegionInfo baseRegionInfo) { if (string.IsNullOrEmpty(newCultureCode) || baseCulture == null || baseRegionInfo == null) { return RegistrationResults.WrongCultureFromat; } try { var cultureInfoBuilder = new CultureAndRegionInfoBuilder(newCultureCode, CultureAndRegionModifiers.Neutral); cultureInfoBuilder.LoadDataFromCultureInfo(baseCulture); cultureInfoBuilder.LoadDataFromRegionInfo(baseRegionInfo); cultureInfoBuilder.Register(); } catch (Exception ex) { return RegistrationResults.AlreadyRegistered; } return RegistrationResults.JustRegistered; }
public SlimTvFanartProvider() { _settings = ServiceRegistration.Get<ISettingsManager>().Load<SlimTvLogoSettings>(); _dataFolder = ServiceRegistration.Get<IPathManager>().GetPath("<DATA>\\Logos\\"); var currentCulture = ServiceRegistration.Get<ILocalization>().CurrentCulture; _country = new RegionInfo(currentCulture.LCID); }
private PromoPrint() { InitializeComponent(); try { txtPrinterName.Text = Settings.VoucherPrinterName.ToUpper(); IIssueTicket objCashDeskOperator = IssueTicketBusinessObject.CreateInstance(); string CurrencySymbol = new RegionInfo(CurrentSiteCulture).CurrencySymbol; lblPromoTickAmt.Content = "Promotional Voucher Amount in " + CurrencySymbol + ":"; lblTotPromoTickVal.Content = "Total Promotional Voucher Value in " + CurrencySymbol + ":"; if (Settings.VoucherPrinterName.ToUpper() == "COUPONEXPRESS") txtSerialNumber.Text = objCashDeskOperator.GetPrinterInformation(); else lblSerialNumber.Visibility = Visibility.Collapsed; txtPromoTickAmt.TextChanged += new TextChangedEventHandler(txtPromoTickAmt_TextChanged); txtPromoTickAmt.AddHandler(TextBox.PreviewKeyDownEvent, new KeyEventHandler(txtPromoTickAmt_KeyDown), true); var d = Convert.ToDecimal(1.1); decimal.TryParse(d.ToString(new CultureInfo(ExtensionMethods.CurrentCurrenyCulture)), NumberStyles.Currency, new CultureInfo(ExtensionMethods.CurrentCurrenyCulture), out d); sFormat = d.ToString(new CultureInfo(ExtensionMethods.CurrentCurrenyCulture)).Substring(1, 1); } catch (Exception ex) { ExceptionManager.Publish(ex); } }
public static IEnumerable<RegionInfo> GetCountryList() { //create a new Generic list to hold the country names returned Dictionary<string, RegionInfo> regions = new Dictionary<string, RegionInfo>(); //create an array of CultureInfo to hold all the cultures found, these include the users local cluture, and all the //cultures installed with the .Net Framework CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); //loop through all the cultures found foreach (CultureInfo culture in cultures) { //pass the current culture's Locale ID (http://msdn.microsoft.com/en-us/library/0h88fahh.aspx) //to the RegionInfo contructor to gain access to the information for that culture RegionInfo region = new RegionInfo(culture.LCID); //make sure out generic list doesnt already //contain this country if (!(regions.ContainsKey(region.EnglishName))) //not there so add the EnglishName (http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.englishname.aspx) //value to our generic list regions.Add(region.EnglishName, region); } return regions.Values; }
protected override void OnInit(EventArgs e) { base.OnInit(e); _dlInstalledLanguages = new DropDownList(); foreach (var language in umbraco.cms.businesslogic.language.Language.GetAllAsList()) { var culture = new CultureInfo(language.CultureAlias); if (culture.IsNeutralCulture) continue; var currencyRegion = new RegionInfo(culture.LCID); var value = language.FriendlyName + " " + currencyRegion.ISOCurrencySymbol + " (" + currencyRegion.CurrencySymbol + " - " + currencyRegion.CurrencyEnglishName + ")"; _dlInstalledLanguages.Items.Add(new ListItem(value, language.id.ToString(CultureInfo.InvariantCulture))); } _dlInstalledLanguages.SelectedValue = _data.Value.ToString(); var user = User.GetCurrent(); if (!user.IsAdmin()) _dlInstalledLanguages.Enabled = false; if (ContentTemplateContainer != null) ContentTemplateContainer.Controls.Add(_dlInstalledLanguages); }
public VoucherDetails(string strBarCode) { InitializeComponent(); this.BarCode = strBarCode; txtSiteCode.IsReadOnly = true; txtEffectiveDate.IsReadOnly = true; txtExpiryDate.IsReadOnly = true; txtBarCode.IsReadOnly = true; txtVoucherType.IsReadOnly = true; txtPrintedDevice.IsReadOnly = true; txtRedeemDevice.IsReadOnly = true; txtVoidDevice.IsReadOnly = true; txtErrorDevice.IsReadOnly = true; txtPrintedDate.IsReadOnly = true; txtRedeemDate.IsReadOnly = true; txtVoidDate.IsReadOnly = true; txtAmount.IsReadOnly = true; txtStatus.IsReadOnly = true; txtErrorDescription.IsReadOnly = true; txtIssuedUserName.IsReadOnly = true; txtRedeemUser.IsReadOnly = true; txtVoidUser.IsReadOnly = true; txtRedeemSiteCode.IsReadOnly = true; string CurrencySymbol = new RegionInfo(CurrentSiteCulture).CurrencySymbol; lblAmount.Content=lblAmount.Content+" in "+CurrencySymbol+" :"; GetVoucherInformation(); }
public User(string name, RegionInfo country, string type) { this._name = name; this._country = country; this._notification = null; this._properties = new Dictionary<string, string>(); }
public void FormatAmountWithCorrectCurrencySymbolWhenUsingCurrencySymbolConstructor() { foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.AllCultures)) { // Arrange if (cultureInfo.LCID.Equals(127) || cultureInfo.IsNeutralCulture) { continue; } var amount = 10.00M; var regionInfo = new RegionInfo(cultureInfo.LCID); var currencySymbol = regionInfo.CurrencySymbol; var expected = string.Format(cultureInfo, "{0:C}", amount); var money = new Money(amount, cultureInfo.Name); // Act var moneyAsString = money.ToStringWithCurrencySymbol(); Console.WriteLine($"Culture Name: {cultureInfo.Name}\t\tCurrency Symbol: {currencySymbol}\t\tToString: {moneyAsString}"); // Assert Assert.That(moneyAsString.Equals(expected)); } }
public IEnumerable<CultureInfo> GetAllCulturesInRegion(RegionInfo region) { if (region == null) { return new CultureInfo[0]; } return m_allRegions[region]; }
public void PosTest2() { RegionInfo regionInfo = new RegionInfo("zh-CN"); string strCurrencySymbol = regionInfo.CurrencySymbol; Assert.True(strCurrencySymbol.Equals("\u00A5") || strCurrencySymbol.Equals("\uffe5")); // \u00A5 is Latin-1 Supplement (Windows), \uffe5 is Halfwidth and Fullwidth Forms (ICU) // String.Normalize(NormalizationForm.FormKD) could also be used if it was ported }
private static string GetValidatorExpression(RegionInfo region) { switch(region.TwoLetterISORegionName) { case "GB" : return @"^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$"; default : throw new MissingRegionSpecificValidatorException("A telephone number validator does not exist for this region."); } }
private static string GetValidatorExpression(RegionInfo region) { switch(region.TwoLetterISORegionName) { case "GB" : return @"^[A-Za-z]{1,2}[\d]{1,2}([A-Za-z])?\s?[\d][A-Za-z]{2}$"; default : throw new MissingRegionSpecificValidatorException("A post code validator does not exist for this region."); } }
public void TestInvalidRegion() { string name = "HELLOWORLD"; Assert.Throws<ArgumentException>(() => { RegionInfo myRegInfo = new RegionInfo(name); }); }
public void TestNull() { string name = null; Assert.Throws<ArgumentNullException>(() => { RegionInfo myRegInfo = new RegionInfo(name); }); }
partial void Changed__CreateUser_Region(RegionInfo oldValue, RegionInfo newValue) { CreateUser_Cultures = m_languageService .GetAllCulturesInRegion(newValue) .OrderBy(c => c.EnglishName) .ToArray(); CreateUser_Culture = null; }
public void PropertyShouldBeAssigned() { var regionInfo = new RegionInfo("RU-ru"); var expectedDenomination = 1.2m; var coin = new Coin(expectedDenomination, regionInfo); Assert.AreEqual(expectedDenomination, coin.Denomination); Assert.AreEqual(regionInfo.ISOCurrencySymbol, coin.Currency); }
public static string GetCurrencySymbol(string code) { System.Globalization.RegionInfo regionInfo = (from culture in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.InstalledWin32Cultures) where culture.Name.Length > 0 && !culture.IsNeutralCulture let region = new System.Globalization.RegionInfo(culture.LCID) where String.Equals(region.ISOCurrencySymbol, code, StringComparison.InvariantCultureIgnoreCase) select region).First(); return(regionInfo.CurrencySymbol); }
public static System.Globalization.CultureInfo GetCultureInfoFromISOCurrencyCode(string code) { foreach (System.Globalization.CultureInfo ci in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures)) { System.Globalization.RegionInfo ri = new System.Globalization.RegionInfo(ci.LCID); if (ri.ISOCurrencySymbol == code) { return(ci); } } return(null); }
/* * Returns the {@code Currency} instance for this {@code Locale}'s country. * * @param locale * the {@code Locale} of a country. * @return the {@code Currency} used in the country defined by the locale parameter. * * @throws IllegalArgumentException * if the locale's country is not a supported ISO 3166 Country. */ public static Currency getInstance(Locale locale) { try { if (null == locale) { throw new java.lang.NullPointerException(); } System.Globalization.RegionInfo ri = new System.Globalization.RegionInfo(locale.getCountry()); String currencyCode = ri.ISOCurrencySymbol; return(getInstance(currencyCode)); } catch (ArgumentException ae) { throw new java.lang.IllegalArgumentException(ae.Message); } }
public override View GetView(int position, View convertView, ViewGroup parent) { var view = convertView ?? _activity.LayoutInflater.Inflate(Resource.Layout.item_browse, parent, false); var contactName = view.FindViewById <TextView>(Resource.Id.contactName); var contactImage = view.FindViewById <ImageView>(Resource.Id.imageView1); var courierDescription = view.FindViewById <TextView>(Resource.Id.courierDescription); var quotePriceAndCourierKM = view.FindViewById <TextView>(Resource.Id.quotePriceAndCourierKM); var courierImage = view.FindViewById <ImageView>(Resource.Id.courierImage); Context mContext = Android.App.Application.Context; ImageManager imageManager = new ImageManager(mContext); TelephonyManager tm = (TelephonyManager)mContext.GetSystemService(Context.TelephonyService); string countryCode = string.Format("en-{0}", tm.SimCountryIso.ToUpper()); System.Globalization.RegionInfo RegionInfo = new System.Globalization.RegionInfo(new CultureInfo(countryCode, false).LCID); //// Replace the contents of the view with that element ////var myHolder = holder as MyViewHolder; courierDescription.Text = _quoteList[position].CourierName; contactName.Text = string.Format("{0} {1} - {2} KM", RegionInfo.CurrencySymbol, _quoteList[position].Price.ToString("F"), _quoteList[position].CourierKmDistance.ToString("F")); if (!string.IsNullOrEmpty(_quoteList[position].CourierProfilePicture)) { contactImage.SetImageBitmap(imageManager.ConvertStringToBitMap(_quoteList[position].CourierProfilePicture)); } else { contactImage.SetImageResource(Resource.Drawable.profile_generic); } return(view); }
// // methods public override bool Equals(object value) { RegionInfo other = value as RegionInfo; return(other != null && lcid == other.lcid); }
public override bool Equals(object value) { RegionInfo info = value as RegionInfo; return((info != null) && this.Name.Equals(info.Name)); }