-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ArticlePackingUnit.ps1
More file actions
67 lines (64 loc) · 2.77 KB
/
Get-ArticlePackingUnit.ps1
File metadata and controls
67 lines (64 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function Get-ArticlePackingUnit {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[string]$barcode
,
[Parameter(Mandatory = $false)]
[string]$articleNo
,
[Parameter(Mandatory = $false)]
[ValidateScript({ Test-ValidateId -id $_ })]
[int]$articleId
,
[Parameter(Mandatory = $false)]
[guid]$articleUid
,
[Parameter(Mandatory = $false)]
[ValidateScript({ Test-ValidateConn -conn $_ })]
$conn
,
[Parameter(Mandatory = $false)]
[ValidateScript({ Test-ValidatePathUDL -path $_ })]
[string]$udl
,
[Parameter(Mandatory = $false)]
[ValidateScript({ Test-ValidateConnStr -connStr $_ })]
[string]$connStr
)
Begin {
Write-Verbose -Message ((Get-ResStr 'STARTING_FUNCTION') -f $myInvocation.Mycommand)
Test-ValidateSingle -validParams (Get-SingleArticleKeys) @PSBoundParameters
Test-ValidateSingle -validParams (Get-SingleConnection) @PSBoundParameters
New-Variable -Name 'firstEntry' -Scope 'Private' -Value ($null)
New-Variable -Name 'key' -Scope 'Private' -Value ([string]'')
New-Variable -Name 'myConn' -Scope 'Private' -Value ($null)
New-Variable -Name 'paramsArticle' -Scope 'Private' -Value ([System.Collections.Hashtable]@{})
New-Variable -Name 'rs' -Scope 'Private' -Value ($null)
New-Variable -Name 'sql' -Scope 'Private' -Value ([string]'')
New-Variable -Name 'sqlFrag' -Scope 'Private' -Value ([string]'')
New-Variable -Name 'value' -Scope 'Private' -Value ([string]'')
New-Variable -Name 'result' -Scope 'Private' -Value ([int32]0)
$initialVariables = Get-CurrentVariables -Debug:$DebugPreference
}
Process {
$myConn = Get-Conn -conn $conn -udl $udl -connStr $connStr
$paramsArticle = Get-UsedParameters -validParams (Get-SingleArticleKeys) -boundParams $PSBoundParameters
$firstEntry = $paramsArticle.GetEnumerator() | Select-Object -First 1
$key = Test-ValidateMapping -strValue ($firstEntry.Key) -mapping (Get-MappingArticleKeys)
$value = $firstEntry.Value
$value = [string]$value.replace("'","''") # Escape Single Quote in Strings
$sqlFrag = "$key = '$value'"
[string]$sql = "SELECT VerpackEH [PackingUnit] FROM Artikel WHERE $sqlFrag"
$rs = $myConn.Execute($sql)
$rs = Get-AdoRs -recordset $rs
if ($rs) {
[int]$result = $rs.fields('PackingUnit').Value
}
}
End {
Get-CurrentVariables -InitialVariables $initialVariables -Debug:$DebugPreference
Return $result
}
# Test: Get-ArticlePackingUnit -barcode '4014751021005' -udl 'C:\temp\Eulanda_1 Eulanda.udl'
}