229 lines
8.6 KiB
VB.net
229 lines
8.6 KiB
VB.net
Imports System.Data.SqlClient
|
|
Imports System.Reflection
|
|
|
|
Public Class cKundenSicherheiten
|
|
|
|
Public Property sc_id As Integer
|
|
Public Property sc_kundenNr As String
|
|
Public Property sc_datum As Date?
|
|
|
|
Public Property sc_gueltigVon As Date?
|
|
Public Property sc_gueltigBis As Date?
|
|
|
|
Public Property sc_Art As String
|
|
Public Property sc_Sicherheitsgeber As String
|
|
Public Property sc_SicherheitsgeberLand As String
|
|
Public Property sc_Bemerkung As String
|
|
|
|
Public Property sc_Betrag As Decimal?
|
|
Public Property sc_Waehrung As String
|
|
Public Property sc_Mitarbeiter As String
|
|
Public Property sc_MitarbeiterId As Integer? = Nothing
|
|
Public Property sc_dsId As Integer? = Nothing
|
|
Public Property sc_storno As Boolean = False
|
|
Public Property sc_stornoDatum As Date? = Nothing
|
|
Public Property sc_stornoMaId As Integer? = Nothing
|
|
|
|
|
|
Public hasEntry As Boolean = False
|
|
|
|
Dim SQL As New SQL
|
|
|
|
Sub New(_sc_id As Integer)
|
|
sc_id = _sc_id
|
|
LOAD()
|
|
End Sub
|
|
|
|
Public Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
|
|
Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
|
|
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_id", sc_id,, True))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_kundenNr", sc_kundenNr))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_datum", sc_datum))
|
|
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_gueltigVon", sc_gueltigVon))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_gueltigBis", sc_gueltigBis))
|
|
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_Art", sc_Art))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_Sicherheitsgeber", sc_Sicherheitsgeber))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_SicherheitsgeberLand", sc_SicherheitsgeberLand))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_Bemerkung", sc_Bemerkung))
|
|
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_Betrag", sc_Betrag))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_Waehrung", sc_Waehrung))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_Mitarbeiter", sc_Mitarbeiter))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_MitarbeiterId", sc_MitarbeiterId))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_dsId", sc_dsId))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_storno", sc_storno))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_stornoDatum", sc_stornoDatum))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_stornoMaId", sc_stornoMaId))
|
|
|
|
Return list
|
|
End Function
|
|
|
|
Public Function SAVE() As Boolean
|
|
Dim list = getParameterList()
|
|
|
|
sc_MitarbeiterId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID
|
|
sc_Mitarbeiter = VERAG_PROG_ALLGEMEIN.cAllgemein.USRKURZNAME
|
|
|
|
Dim sqlstr As String =
|
|
"BEGIN TRAN " &
|
|
"IF EXISTS (SELECT 1 FROM tblKundenSicherheiten WHERE sc_id=@sc_id) " &
|
|
"BEGIN " & getUpdateCmd() & " END " &
|
|
"ELSE " &
|
|
"BEGIN " & getInsertCmd() & " END " &
|
|
"COMMIT TRAN"
|
|
|
|
Return SQL.doSQLVarList(sqlstr, "FMZOLL", , list)
|
|
End Function
|
|
|
|
Public Sub LOAD()
|
|
Try
|
|
hasEntry = False
|
|
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
|
|
Using cmd As New SqlCommand("SELECT * FROM tblKundenSicherheiten WHERE sc_id=@sc_id", conn)
|
|
cmd.Parameters.AddWithValue("@sc_id", sc_id)
|
|
Dim dr = cmd.ExecuteReader()
|
|
If dr.Read Then
|
|
For Each li In getParameterList()
|
|
Dim prop As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)
|
|
If dr(li.Text) Is DBNull.Value Then
|
|
prop.SetValue(Me, Nothing)
|
|
Else
|
|
prop.SetValue(Me, dr(li.Text))
|
|
End If
|
|
Next
|
|
hasEntry = True
|
|
End If
|
|
dr.Close()
|
|
End Using
|
|
End Using
|
|
Catch ex As Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
End Sub
|
|
|
|
Public Function getUpdateCmd() As String
|
|
Dim list = getParameterList()
|
|
Dim str As String = ""
|
|
|
|
For Each i In list
|
|
If Not i.isPrimaryParam Then
|
|
str &= "[" & i.Text & "] = @" & i.Scalarvariable & ","
|
|
End If
|
|
Next
|
|
|
|
str = str.Substring(0, str.Length - 1)
|
|
Return "UPDATE tblKundenSicherheiten SET " & str & " WHERE sc_id=@sc_id"
|
|
End Function
|
|
|
|
Public Function getInsertCmd() As String
|
|
Dim list = getParameterList()
|
|
Dim fields As String = ""
|
|
Dim values As String = ""
|
|
|
|
For Each i In list
|
|
If Not i.isPrimaryParam Then
|
|
fields &= "[" & i.Text & "],"
|
|
values &= "@" & i.Scalarvariable & ","
|
|
End If
|
|
Next
|
|
|
|
fields = fields.Substring(0, fields.Length - 1)
|
|
values = values.Substring(0, values.Length - 1)
|
|
|
|
Return "INSERT INTO tblKundenSicherheiten(" & fields & ") VALUES (" & values & ")"
|
|
End Function
|
|
|
|
Public Shared Function Load_List(kundenNr As String) As List(Of cKundenSicherheiten)
|
|
Dim list As New List(Of cKundenSicherheiten)
|
|
Dim SQL As New SQL
|
|
|
|
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
|
|
Using cmd As New SqlCommand("SELECT sc_id FROM tblKundenSicherheiten WHERE sc_kundenNr=@kn ORDER BY sc_gueltigVon DESC", conn)
|
|
cmd.Parameters.AddWithValue("@kn", kundenNr)
|
|
Dim dr = cmd.ExecuteReader()
|
|
While dr.Read()
|
|
list.Add(New cKundenSicherheiten(CInt(dr("sc_id"))))
|
|
End While
|
|
dr.Close()
|
|
End Using
|
|
End Using
|
|
|
|
Return list
|
|
End Function
|
|
|
|
Public Function DELETE() As Boolean
|
|
Try
|
|
Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_id", sc_id,, True))
|
|
|
|
Dim sqlstr As String =
|
|
"DELETE FROM tblKundenSicherheiten WHERE sc_id=@sc_id"
|
|
|
|
Return SQL.doSQLVarList(sqlstr, "FMZOLL", , list)
|
|
|
|
Catch ex As Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
Return False
|
|
End Function
|
|
|
|
Public Function STORNO() As Boolean
|
|
Try
|
|
Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
|
|
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("sc_id", sc_id,, True))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("stornoUser", VERAG_PROG_ALLGEMEIN.cAllgemein.USRID))
|
|
|
|
Dim sqlstr As String =
|
|
"UPDATE tblKundenSicherheiten SET " &
|
|
" sc_storno = 1, " &
|
|
" sc_stornoDatum = GETDATE(), " &
|
|
" sc_stornoUser = @stornoUser " &
|
|
"WHERE sc_id = @sc_id " &
|
|
" AND ISNULL(sc_storno,0) = 0"
|
|
|
|
Return SQL.doSQLVarList(sqlstr, "FMZOLL", , list)
|
|
|
|
Catch ex As Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
|
|
Return False
|
|
End Function
|
|
|
|
Public Shared Function GetSummeSicherheitenAktuell(kundenNr As String, Optional stichtag As Date = Nothing) As Decimal
|
|
Try
|
|
If stichtag = Nothing Then stichtag = Date.Today
|
|
Dim SQL As New SQL
|
|
|
|
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
|
|
Using cmd As New SqlCommand("
|
|
SELECT ISNULL(SUM(sc_Betrag),0)
|
|
FROM tblKundenSicherheiten
|
|
WHERE sc_kundenNr = @kn
|
|
AND (sc_gueltigVon IS NULL OR sc_gueltigVon <= @dt)
|
|
AND (sc_gueltigBis IS NULL OR sc_gueltigBis >= @dt)
|
|
AND sc_storno=0 ", conn)
|
|
|
|
cmd.Parameters.AddWithValue("@kn", kundenNr)
|
|
cmd.Parameters.AddWithValue("@dt", stichtag)
|
|
|
|
Return Convert.ToDecimal(cmd.ExecuteScalar())
|
|
End Using
|
|
End Using
|
|
|
|
Catch ex As Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(
|
|
ex.Message,
|
|
ex.StackTrace,
|
|
System.Reflection.MethodInfo.GetCurrentMethod.Name
|
|
)
|
|
End Try
|
|
|
|
Return 0D
|
|
End Function
|
|
|
|
End Class |