Attribute VB_Name = "BaumatSu"
Option Explicit
Public liste_ar(10000) As liste_ar_element
Public liste_lnr(500) As liste_nr_element
Public liste_knr(500) As liste_nr_element
Public cnt_ar As Integer
Public suerg_ar As String
Public suerg_lnr As String
Public suerg_knr As String
Public sema_arsu As Boolean
Public LNRSucheSKTOK As Integer
Public KNRSucheKGRP As String


Type liste_ar_element
     ANR As String
     Bez1 As String
     ABTNR As String
End Type

Type liste_nr_element
     NR As String
     KBEZ As String
     Name As String
     PLZ As String
     Straße As String
End Type

Function liste_ar_pack(ByVal ad1 As String) As liste_ar_element
  On Error Resume Next
  With liste_ar_pack
     .ANR = Piece(ad1, tr, 1)
     .Bez1 = Piece(ad1, tr, 2)
     .ABTNR = Piece(ad1, tr, 3)
  End With
  On Error GoTo 0
End Function

Function liste_lnr_pack(ByVal LNR As String, ByVal KBEZ As String, ByVal Name As String, ByVal PLZ As String, ByVal Straße As String) As liste_nr_element
  On Error Resume Next
   With liste_lnr_pack
      .NR = LNR
      .KBEZ = KBEZ
      .Name = Name
      .PLZ = PLZ
      .Straße = Straße
   End With
  On Error GoTo 0
End Function

Function liste_knr_pack(ByVal KNR As String, ByVal KBEZ As String, ByVal Name As String, ByVal PLZ As String, ByVal Straße As String) As liste_nr_element
  On Error Resume Next
   With liste_knr_pack
      .NR = KNR
      .KBEZ = KBEZ
      .Name = Name
      .PLZ = PLZ
      .Straße = Straße
   End With
  On Error GoTo 0
End Function

Sub getarsu()
Dim ad As String, ad1 As String
Dim qsw As Boolean
Dim i As Byte
StatusText "BaumatSU.getarsu", "Start"
sema_arsu = True
FMArtsu.MousePointer = 11
If cnt_ar = 0 Then
  ad = dbcall("D GETARF^BMCLSU(""" + FMArtsu.SKBEZ.Text + """,""" + Piece(FMArtsu.SHGRP.Text, " ", 1) + """,""" + Piece(FMArtsu.SUGRP.Text, " ", 1) + """,""" + Piece(FMArtsu.SLNR.Text, " ", 1) + """,""" + Piece(FMArtsu.SABTNR.Text, " ", 1) + """,""" + FMArtsu.SAKTIV.Text + """,""" + FMArtsu.SGEL.Text + """)")
 Else
  ad = dbcall("D GETARN^BMCLSU")
End If
FMArtsu.MousePointer = 0

qsw = False
For i = 1 To 4
   ad1 = Piece(ad, Chr(255), i)
   If ad1 = "" Then qsw = True: Exit For
   cnt_ar = cnt_ar + 1
   liste_ar(cnt_ar) = liste_ar_pack(ad1)
Next

If qsw Then
   FMArtsu.ARTSULI.ListCount = cnt_ar
   FMArtsu.ARTSULI.ReDraw
   FMArtsu.ARTSULI.ItemSelect = cnt_ar
   FMArtsu.ARTSULI.ReDraw
Else
   FMArtsu.ARTSULI.ListCount = cnt_ar * 1.5
End If
sema_arsu = False
StatusText "BaumatSU.getarsu", "Ende"
End Sub

Sub getlnrsu()
Dim rs As CacheObject.ResultSet
Dim i As Integer
 StatusText "BaumatSU.getlnrsu", "Start"
 LockEIN
  i = 0
  On Error GoTo OnError
  Set rs = WWS_Server.ResultSet("BM.Windows", "KkrSuche")
  Call rs.Execute(Firma, "L", FMLnrsu.SKBEZ.Text, Piece(FMLnrsu.SSKTOK.Text, "|", 1, "1"))
  Do While rs.Next()
    i = i + 1
    liste_lnr(i) = liste_lnr_pack(rs.GetData(1), rs.GetData(2), Umlaut(rs.GetData(3), "BAUMAT"), rs.GetData(4), Umlaut(rs.GetData(5), "BAUMAT"))
    If i >= 500 Then GoTo NichtWeiterLesen
  Loop
  On Error GoTo 0
NichtWeiterLesen:
  ObjektSchließen rs
 LockAUS
 FMLnrsu.LNRSULI.ListCount = i
 FMLnrsu.LNRSULI.ReDraw
 StatusText "BaumatSU.getlnrsu", "Ende"
Exit Sub
OnError:
 CacheFehlermeldung err, "BaumatSu.getlnrsu Suche Lieferantennummer"
 StatusText "BaumatSU.getlnrsu", "Ende mit Fehler"
 On Error GoTo 0
End Sub

Sub getknrsu()
Dim rs As CacheObject.ResultSet
Dim i As Integer
 StatusText "BaumatSU.getknrsu", "Start"
 LockEIN
  i = 0
  On Error GoTo OnError
  Set rs = WWS_Server.ResultSet("BM.Windows", "KkrSuche")
  Call rs.Execute(Firma, "K", FMKnrsu.SKBEZ.Text, Left(FMKnrsu.SKGRP.Text, 2), FMKnrsu.PLZ.Text)
  Do While rs.Next()
    i = i + 1
    liste_knr(i) = liste_knr_pack(rs.GetData(1), rs.GetData(2), Umlaut(rs.GetData(3), "BAUMAT"), rs.GetData(4), Umlaut(rs.GetData(5), "BAUMAT"))
    If i >= 500 Then GoTo NichtWeiterLesen
  Loop
  On Error GoTo 0
NichtWeiterLesen:
  ObjektSchließen rs
 LockAUS
 FMKnrsu.KNRSULI.ListCount = i
 FMKnrsu.KNRSULI.ReDraw
 StatusText "BaumatSU.getknrsu", "Ende"
Exit Sub
OnError:
 CacheFehlermeldung err, "BaumatSu getknrsu Kundennummer Suche"
 StatusText "BaumatSU.getknrsu", "Ende mit Fehler"
 On Error GoTo 0
End Sub


Function bm_ar_su() As String
StatusText "BaumatSU.bm_ar_su", "Start"
suerg_ar = ""
FMArtsu.Show 1
bm_ar_su = suerg_ar
StatusText "BaumatSU.bm_ar_su", "Ende"
End Function

Function bm_lnr_su() As String
StatusText "BaumatSU.bm_lnr_su", "Start"
suerg_lnr = ""
FMLnrsu.Show 1
bm_lnr_su = suerg_lnr
StatusText "BaumatSU.bm_lnr_su", "Ende"
End Function

Function bm_knr_su() As String
StatusText "BaumatSU.bm_knr_su", "Start"
suerg_knr = ""
FMKnrsu.Show 1
bm_knr_su = suerg_knr
StatusText "BaumatSU.bm_knr_su", "Ende"
End Function
