aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-05-17 08:11:24 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-05-17 08:11:24 +0300
commitc5895f78c2e475682cb7773e437e000c8413142e (patch)
tree829943d22443454bf35338ea833220cef76b53b1
parent9f0ef900051521df2eef2c1c3607fcf8898717da (diff)
Add =КУРСЕВРО() function
-rw-r--r--RhSolutions.AddIn/AddIn/RhSolutionsFunction.cs30
1 files changed, 30 insertions, 0 deletions
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<ICurrencyClient>();
+
+ 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