Commit 8ccb5220 authored by globa's avatar globa

Переход с SQLite на PG

parent a638e8c7
$db = ".\db.sqlite"
. ".\EventLog.ps1"
# Install-Module -Name SimplySql
# Подключение файла с конфигурацией
$configFile = ".\config.ps1"
......@@ -9,7 +9,9 @@ if (Test-Path $configFile) {
} else {
Write-Host "Файл с конфигурацией не найден"
}
#
Open-PostGreConnection -Server 'dbpg-node01.ciu.nstu.ru' -Database 'addata' -Credential $credentials
#
# Telegram URLs
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$URL_get = "https://api.telegram.org/bot$token/getUpdates"
......@@ -34,6 +36,7 @@ function getUpdates($URL)
# проверяем что text есть
if($text)
{
# confirm
Invoke-RestMethod "$($URL)?offset=$($($data.update_id)+1)" -Method Get | Out-Null
......@@ -81,8 +84,11 @@ while($true)
if($return)
{
if($return.chat_id -in $ids){
$response = Invoke-SqliteQuery -DataBase $db -Query "SELECT * From inventory WHERE inventory_num LIKE @inventory_num" -SqlParameters @{"inventory_num" = $($return["text"].ToUpper())}
if($response -ne $null){
if (Test-SqlConnection -ne $true) {
Open-PostGreConnection -Server 'dbpg-node01.ciu.nstu.ru' -Database 'addata' -Credential $credentials
}
$response = Invoke-SqlQuery -Query "SELECT * From inventory.mtb WHERE inventory_num LIKE @inventory_num" -Parameters @{"inventory_num" = $($return["text"].ToUpper())}
if($null -ne $response){
foreach($r in $response){
$TimeSpan = [math]::Round(((Get-Date) - [DateTime]::ParseExact($r.date,'dd.MM.yyyy',$null)).Days / 365, 0)
$text = "<b> $($r.inventory_num)</b>
......@@ -90,7 +96,7 @@ while($true)
МОЛ: <b>$($r.MOL)</b>
Подразделение: <b>$($r.department)</b>
Дата принятия к учету: <b>$($r.date) ( $($TimeSpan) $(Get-YearEnding($TimeSpan)) )</b>
Цена / Остаточная стоимость: <b>$($r.price) ₽ / $($r.residual_price) ₽</b>"
Цена / Остаточная стоимость: <b>$($r.price) ₽ / $($r.lowprice) ₽</b>"
Write-Host $text
sendMessage $URL_set $return.chat_id $text
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment