28 lines
948 B
C#
28 lines
948 B
C#
namespace RhSolutions.AddIn;
|
||
|
||
public static class CurrencyFunctions
|
||
{
|
||
private static readonly ICurrencyClient currencyClient =
|
||
RhSolutionsAddIn.ServiceProvider.GetRequiredService<ICurrencyClient>();
|
||
|
||
[ExcelFunction(Name = "КУРСЕВРО")]
|
||
public static object GetEuroCurrencyRate(double dateField)
|
||
{
|
||
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
|
||
var functionName = nameof(GetEuroCurrencyRate);
|
||
var parameters = new object[] { date };
|
||
|
||
var exchangeRate = ExcelAsyncUtil.RunTask(functionName, parameters, async () =>
|
||
{
|
||
var requestResult = await currencyClient.GetExchangeRate(date); return requestResult ?? -1m;
|
||
});
|
||
|
||
if (exchangeRate is not decimal)
|
||
{
|
||
return "Загрузка...";
|
||
}
|
||
|
||
return (decimal)exchangeRate < 0 ? ExcelError.ExcelErrorNA : exchangeRate;
|
||
}
|
||
}
|