diff --git a/RhSolutions.AddIn/AddIn/RhSolutionsFunction.cs b/RhSolutions.AddIn/AddIn/RhSolutionsFunction.cs index bfac0b1..68acb10 100644 --- a/RhSolutions.AddIn/AddIn/RhSolutionsFunction.cs +++ b/RhSolutions.AddIn/AddIn/RhSolutionsFunction.cs @@ -185,4 +185,34 @@ public class RhSolutionsFunction } } } + + [ExcelFunction(Description = "Получить курс евро по ЦБ")] + public static object КУРСЕВРО([ExcelArgument(Name = "ДАТА", Description = "Дата в формате Excel (необязательно)")] double dateField) + { + ICurrencyClient currencyClient = RhSolutionsAddIn.ServiceProvider.GetRequiredService(); + + if (ExcelAsyncUtil.Run("Database request", dateField, delegate + { + DateTime date = dateField == 0 ? DateTime.Now : DateTime.FromOADate(dateField); + var exchangeRate = currencyClient.GetCurrencyCourse(date) + .GetAwaiter() + .GetResult(); + + return exchangeRate ?? -1m; + }) is not decimal requestResult) + { + return "Загрузка..."; + } + else + { + if (requestResult < 0) + { + return ExcelError.ExcelErrorNA; + } + else + { + return Math.Round(requestResult, 2); + } + } + } } \ No newline at end of file