IOverhead.SetCurrencyRates Method

Sets rates for any currency listed in Currencies sheet.
Function SetCurrencyRates( _ 
ByVal CurrencyRates As Dictionary(Of String, Double) _ 
) As Integer
This language is not supported or no code example is available.
int SetCurrencyRates( 
Dictionary<string, double> CurrencyRates 
)
This language is not supported or no code example is available.

Parameters

CurrencyRates
Dictionary<string, double>

A dictionary whose key is the currency name in uppercase (e.g. "USD"), and the value is the normalized rate expressed in the currency of the estimate (the rate of the currency of the estimate MUST be 1).

Return Value

int

The number of currency rates written.

Remarks
 

Unlike GetCurrencyRates, the supplied rates must be normalized, i.e., the rate of the currency of the estimate MUST be 1.

On the other hand, SetCurrencyRates method always expect the normalized rates. Otherwise, unexpected rates will be set! So always ensure that you pass normalized rates. You can use the NormalizeCurrencyRates method from the above example before each call to SetCurrencyRates.

The rates returned by the GetCurrencyRates are not guaranteed to be normalized. (Starting with QDV 7.23.1096 they are returned as normalized, but not in the older versions.) So to get the normalized values, you need to divide the returned values by the rate of the currency of the estimate:

 public static void EntryMethod(Qdv.UserApi.IEstimate es, Qdv.UserApi.ICallingContext context)
 {
 	var rates = es.CurrentVersion.Overhead.GetCurrencyRates();
 	rates = NormalizeCurrencyRates(es, rates);
 }
 
 /// <summary>
 /// Normalizes the rates according to the currency of the estimate.
 /// This means that the current currency of the estimate will have the value 1.
 /// </summary>
 /// <param name="es">The estimate.</param>
 /// <param name="rates">The rates to normalize.</param>
 /// <returns>Normalized rates.</returns>
 private static Dictionary<string, double> NormalizeCurrencyRates(IEstimate es, Dictionary<string, double> rates)
 {
 	var normalizedRates = new Dictionary<string, double>();
 	string masterCurrency = es.CurrentVersion.Overhead.GetCurrencyOfEstimate();
 	double masterCurrencyRate = 1;
 	rates.TryGetValue(masterCurrency, out masterCurrencyRate);
 	foreach (string currency in rates.Keys)
 	{
 		var rate = rates[currency];
 		rate /= masterCurrencyRate;
 		normalizedRates.Add(currency, rate);
 	}
 
 	return normalizedRates;
 }
 
 					

If the estimate currency is USD, then the option c) is normalized, because the rate of USD is 1.
 a)
 [EUR, 100]
 [USD, 200]
 [GBP, 400]
 b)
 [EUR, 1]
 [USD, 2]
 [GBP, 4]
 c)
 [EUR, 0.5]
 [USD, 1]
 [GBP, 2]
 					

The same rates may be expressed in multiple forms. The form where the current currency of the estimate has the value 1, is called normalized. This is what is displayed to the user in the Currency sheet. For example, all the following rates are the same:

Version
 
Available since QDV 7.13.0001.

.NET Framework

Supported in: 4.8, 4.7, 4.6, 4.5.2

In this article

Definition