public string GetTextRepresentation(decimal number, ICurrencyInfo currencyInfo) { if (number > Settings.MAX_VALUE) { throw new ArgumentException($"Number has to be lower than or equal to {Settings.MAX_VALUE}"); } if (number < Settings.MIN_VALUE) { throw new ArgumentException($"Number has to be greater than or equal to {Settings.MIN_VALUE}"); } if ((int)number - number < -0.99M) { throw new ArgumentException($"Number has to have at most {Settings.MAX_DECIMAL_PLACES} decimal places"); } StringBuilder sb = new StringBuilder(); int integerPart = (int)number; int remainingIntegerPart = integerPart; int powerLevel = (int)Math.Floor(Math.Log10((double)Settings.MAX_VALUE) + 1) - 3; while (powerLevel > 0) { int currentPart = remainingIntegerPart / (int)Math.Pow(10, powerLevel); if (currentPart > 0) { sb.Append($"{ConvertPartLowerThanThousand(currentPart)} {Settings.POWERS_REPRESENTATIONS[powerLevel / 3]} "); } remainingIntegerPart -= currentPart * (int)Math.Pow(10, powerLevel); powerLevel -= 3; } if (remainingIntegerPart > 1 || (remainingIntegerPart == 0 && number < 1)) { sb.Append($"{ConvertPartLowerThanThousand(remainingIntegerPart)} {currencyInfo.WholesName}{Settings.PLURAL_SUFFIX} "); } else if (remainingIntegerPart == 1) { sb.Append($"{ConvertPartLowerThanThousand(remainingIntegerPart)} {currencyInfo.WholesName} "); } int decimalPartAsInt = (int)((number - integerPart) * 100); if (decimalPartAsInt > 1) { sb.Append($"and {ConvertPartLowerThanThousand(decimalPartAsInt)} {currencyInfo.FractionalsName}{Settings.PLURAL_SUFFIX} "); } else if (decimalPartAsInt == 1) { sb.Append($"and {ConvertPartLowerThanThousand(decimalPartAsInt)} {currencyInfo.FractionalsName} "); } return(sb.ToString().Trim()); }
/// <summary> /// Gets detailed currency information as per passed currency code. /// </summary> /// <param name="currencyCode"></param> /// <returns></returns> public ICurrencyInfo DetailedCurrencyInfo(string currencyCode) { ICurrencyInfo currInfo = this.Application.BusinessLogic.Utility.CreateCurrencyInfo(); currInfo.PosCurrencyRate = GetExchangeRate(ApplicationSettings.Terminal.StoreCurrency, currencyCode); string queryString = "SELECT AMOUNT, TYPE, CURRENCY FROM RETAILSTORECASHDECLARATIONTABLE WHERE " + "DATAAREAID = @DATAAREAID AND CURRENCY = @CURRENCYCODE AND STOREID = @STOREID ORDER BY AMOUNT"; List <ICurrencyItemInfo> currencyItemInfoList = new List <ICurrencyItemInfo>(); SqlConnection connection = Application.Settings.Database.Connection; try { using (SqlCommand command = new SqlCommand(queryString, connection)) { SqlParameter dataAreaIdParm = command.Parameters.Add("@DATAAREAID", SqlDbType.NVarChar, 4); dataAreaIdParm.Value = Application.Settings.Database.DataAreaID; SqlParameter currencyCodeParm = command.Parameters.Add("@CURRENCYCODE", SqlDbType.NVarChar, 3); currencyCodeParm.Value = currencyCode; SqlParameter storeIDParm = command.Parameters.Add("@STOREID", SqlDbType.NVarChar, 10); storeIDParm.Value = ApplicationSettings.Terminal.StoreId; if (connection.State != ConnectionState.Open) { connection.Open(); } using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { while (reader.Read()) { ICurrencyItemInfo currItem = this.Application.BusinessLogic.Utility.CreateCurrencyItemInfo(); currItem.CurrValue = reader.GetDecimal(reader.GetOrdinal("AMOUNT")); currItem.CurrType = (CurrType)reader.GetInt32(reader.GetOrdinal("TYPE")); currencyItemInfoList.Add(currItem); } currInfo.CurrencyItems = currencyItemInfoList.ToArray(); } } } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } return(currInfo); }
private void LoadData() { if (GridSource == null) { // Load curreny info and create a datasource for the grid ICurrencyInfo currInfo = Dialog.InternalApplication.Services.Currency.DetailedCurrencyInfo(this.currencyCode); this.GridSource = new List <DenominationViewModel>(currInfo.CurrencyItems.Length); foreach (ICurrencyItemInfo currItem in currInfo.CurrencyItems) { DenominationViewModel vm = new DenominationViewModel() { Denomination = currItem.CurrValue, DenominationText = Dialog.InternalApplication.Services.Rounding.RoundForDisplay(currItem.CurrValue, false, false) }; this.GridSource.Add(vm); } } this.gridDenom.DataSource = this.GridSource; UpdateTotal(); }
public ETH(ICurrencyInfo currentValue) { _currentValue = currentValue; }
public BTC(ICurrencyInfo currentValue) { _currentValue = currentValue; }
public void Update(ICurrencyInfo info) { Console.WriteLine($"OMG current value of X is: {info.CurrentValue}! I will buy all of it!"); }