From c5895f78c2e475682cb7773e437e000c8413142e Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 17 May 2023 08:11:24 +0300 Subject: [PATCH] =?UTF-8?q?Add=20=3D=D0=9A=D0=A3=D0=A0=D0=A1=D0=95=D0=92?= =?UTF-8?q?=D0=A0=D0=9E()=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AddIn/RhSolutionsFunction.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) 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