235 lines
9.6 KiB
VB.net
235 lines
9.6 KiB
VB.net
Imports System.Data.SqlClient
|
|
|
|
Public Class cGeschaeftsjahr
|
|
Property Mandant As String = ""
|
|
Property Niederlassung As String = ""
|
|
Property Benutzer As Integer = -1
|
|
Property Geschäftsjahr As Integer = -1
|
|
Property LfdBelegNr As Integer = 0
|
|
Property LfdJournalNr As Integer = 0
|
|
|
|
Dim SQL As New SQL
|
|
|
|
Public Sub New(Mandant As String, Niederlassung As String, Benutzer As Integer, Geschäftsjahr As Integer)
|
|
Me.Mandant = Mandant
|
|
Me.Niederlassung = Niederlassung
|
|
Me.Benutzer = Benutzer
|
|
Me.Geschäftsjahr = Geschäftsjahr
|
|
LOAD(Mandant, Niederlassung, Benutzer, Geschäftsjahr)
|
|
End Sub
|
|
|
|
|
|
Public Function INCREASE_BELEG() As Integer
|
|
|
|
If LfdBelegNr > 0 Then
|
|
LfdBelegNr += 1
|
|
|
|
'-------Falls Nr schon existiert (geleichzeitige Buchung)
|
|
Dim cnt_ = 0
|
|
While EXISTS_BelegNr(LfdBelegNr)
|
|
If cnt_ > 10 Then Exit While
|
|
LfdBelegNr += 1
|
|
cnt_ += 1
|
|
End While
|
|
'-------
|
|
|
|
|
|
SAVE()
|
|
Return LfdBelegNr
|
|
Else
|
|
LfdBelegNr = 1
|
|
SAVE()
|
|
Return LfdBelegNr
|
|
End If
|
|
|
|
|
|
End Function
|
|
|
|
'Public Function INCREASE_BELEG() As Integer
|
|
' If LfdBelegNr > 0 Then
|
|
' LfdBelegNr += 1
|
|
' Else
|
|
' LfdBelegNr = 1
|
|
' End If
|
|
|
|
' Return LfdBelegNr
|
|
'End Function
|
|
'Public Function INCREASE_JOURNAL() As Integer
|
|
' If LfdJournalNr > 0 Then
|
|
' LfdJournalNr += 1
|
|
' Else
|
|
' LfdJournalNr = 1
|
|
' End If
|
|
' SAVE()
|
|
' Return LfdJournalNr
|
|
'End Function
|
|
|
|
|
|
Public Function INCREASE_JOURNAL() As Integer
|
|
If LfdJournalNr > 0 Then
|
|
LfdJournalNr += 1
|
|
|
|
'-------Falls Nr schon existiert (geleichzeitige Buchung)
|
|
Dim cnt_ = 0
|
|
While EXISTS_JournalNr(LfdJournalNr)
|
|
If cnt_ > 10 Then Exit While
|
|
LfdJournalNr += 1
|
|
cnt_ += 1
|
|
End While
|
|
'-------
|
|
|
|
|
|
SAVE()
|
|
Return LfdJournalNr
|
|
Else
|
|
LfdJournalNr = 1
|
|
SAVE()
|
|
Return LfdJournalNr
|
|
End If
|
|
|
|
|
|
End Function
|
|
|
|
|
|
Public Function SAVE() As Boolean 'obj As Object, tablename As String, where As String) As Boolean
|
|
Dim list As List(Of VERAG_PROG_ALLGEMEIN.MyListItem2) = getParameterList()
|
|
|
|
Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM [tblGeschäftsjahr] WITH(updlock,serializable) WHERE [Mandant]=@Mandant AND Niederlassung=@Niederlassung AND Benutzer=@Benutzer AND Geschäftsjahr=@Geschäftsjahr) " &
|
|
" BEGIN " & getUpdateCmd() & " END " &
|
|
" Else " &
|
|
" BEGIN " & getInsertCmd() & " END " &
|
|
" commit tran "
|
|
'MsgBox(sqlstr)
|
|
Return SQL.doSQL(sqlstr, "FMZOLL", , list)
|
|
End Function
|
|
|
|
Public Sub LOAD(Mandant As String, Niederlassung As String, Benutzer As Integer, Geschäftsjahr As Integer)
|
|
Try
|
|
Using conn As SqlConnection = cSqlDb.GetNewOpenConnectionFMZOLL()
|
|
Using cmd As New SqlCommand("SELECT * FROM tblGeschäftsjahr WHERE [Mandant]=@Mandant AND Niederlassung=@Niederlassung AND Benutzer=@Benutzer AND Geschäftsjahr=@Geschäftsjahr ", conn)
|
|
cmd.Parameters.AddWithValue("@Mandant", Mandant)
|
|
cmd.Parameters.AddWithValue("@Niederlassung", Niederlassung)
|
|
cmd.Parameters.AddWithValue("@Benutzer", Benutzer)
|
|
cmd.Parameters.AddWithValue("@Geschäftsjahr", Geschäftsjahr)
|
|
|
|
Dim dr = cmd.ExecuteReader()
|
|
If dr.Read Then
|
|
Me.Mandant = cSqlDb.checkNullStr(dr.Item("Mandant"))
|
|
Me.Niederlassung = cSqlDb.checkNullStr(dr.Item("Niederlassung"))
|
|
Me.Benutzer = cSqlDb.checkNullStr(dr.Item("Benutzer"))
|
|
Me.Geschäftsjahr = cSqlDb.checkNullInteger(dr.Item("Geschäftsjahr"))
|
|
Me.LfdBelegNr = cSqlDb.checkNullInteger(dr.Item("LfdBelegNr"))
|
|
Me.LfdJournalNr = cSqlDb.checkNullInteger(dr.Item("LfdJournalNr"))
|
|
End If
|
|
dr.Close()
|
|
End Using
|
|
End Using
|
|
'Return Nothing
|
|
Catch ex As Exception
|
|
MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
|
|
End Try
|
|
' Return Nothing
|
|
End Sub
|
|
|
|
Public Function EXISTS_BelegNr(LfdBelegNr As Integer) As Boolean
|
|
Try
|
|
Using conn As SqlConnection = cSqlDb.GetNewOpenConnectionFMZOLL()
|
|
Using cmd As New SqlCommand("SELECT count(*) as COUNT FROM tblGeschäftsjahr WHERE [Mandant]=@Mandant AND Niederlassung=@Niederlassung AND Benutzer=@Benutzer AND Geschäftsjahr=@Geschäftsjahr AND LfdBelegNr=@LfdBelegNr ", conn)
|
|
cmd.Parameters.AddWithValue("@Mandant", Mandant)
|
|
cmd.Parameters.AddWithValue("@Niederlassung", Niederlassung)
|
|
cmd.Parameters.AddWithValue("@Benutzer", Benutzer)
|
|
cmd.Parameters.AddWithValue("@Geschäftsjahr", Geschäftsjahr)
|
|
cmd.Parameters.AddWithValue("@LfdBelegNr", LfdBelegNr)
|
|
|
|
Dim dr = cmd.ExecuteReader()
|
|
If dr.Read Then
|
|
If cSqlDb.checkNullInteger(dr.Item("COUNT")) > 0 Then Return True
|
|
End If
|
|
dr.Close()
|
|
End Using
|
|
End Using
|
|
|
|
Return False
|
|
Catch ex As Exception
|
|
MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
|
|
End Try
|
|
' Return Nothing
|
|
End Function
|
|
|
|
|
|
Public Function EXISTS_JournalNr(LfdJournalNr As Integer) As Boolean
|
|
Try
|
|
Using conn As SqlConnection = cSqlDb.GetNewOpenConnectionFMZOLL()
|
|
Using cmd As New SqlCommand("SELECT count(*) as COUNT FROM tblGeschäftsjahr WHERE [Mandant]=@Mandant AND Niederlassung=@Niederlassung AND Benutzer=@Benutzer AND Geschäftsjahr=@Geschäftsjahr AND LfdJournalNr=@LfdJournalNr ", conn)
|
|
cmd.Parameters.AddWithValue("@Mandant", Mandant)
|
|
cmd.Parameters.AddWithValue("@Niederlassung", Niederlassung)
|
|
cmd.Parameters.AddWithValue("@Benutzer", Benutzer)
|
|
cmd.Parameters.AddWithValue("@Geschäftsjahr", Geschäftsjahr)
|
|
cmd.Parameters.AddWithValue("@LfdJournalNr", LfdJournalNr)
|
|
|
|
Dim dr = cmd.ExecuteReader()
|
|
If dr.Read Then
|
|
If cSqlDb.checkNullInteger(dr.Item("COUNT")) > 0 Then Return True
|
|
End If
|
|
dr.Close()
|
|
End Using
|
|
End Using
|
|
|
|
Return False
|
|
Catch ex As Exception
|
|
MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
|
|
End Try
|
|
' Return Nothing
|
|
End Function
|
|
|
|
|
|
Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.MyListItem2)
|
|
Dim list As New List(Of VERAG_PROG_ALLGEMEIN.MyListItem2)
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem2("Mandant", Mandant))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem2("Niederlassung", Niederlassung))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem2("Benutzer", Benutzer))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem2("Geschäftsjahr", Geschäftsjahr))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem2("LfdBelegNr", LfdBelegNr))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.MyListItem2("LfdJournalNr", LfdJournalNr))
|
|
Return list
|
|
End Function
|
|
|
|
Public Function getUpdateCmd() As String
|
|
Try
|
|
Dim list As List(Of VERAG_PROG_ALLGEMEIN.MyListItem2) = getParameterList()
|
|
|
|
Dim str As String = ""
|
|
For Each i In list
|
|
str &= "[" & i.Text & "] = @" & i.Text.Replace("-", "").Replace(" ", "") & ","
|
|
Next
|
|
str = str.Substring(0, str.Length - 1) 'wg. ','
|
|
Return (" UPDATE [tblGeschäftsjahr] SET " & str & " WHERE [Mandant]=@Mandant AND Niederlassung=@Niederlassung AND Benutzer=@Benutzer AND Geschäftsjahr=@Geschäftsjahr ")
|
|
|
|
Catch ex As Exception
|
|
MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
|
|
End Try
|
|
Return ""
|
|
End Function
|
|
|
|
Public Function getInsertCmd() As String
|
|
Try
|
|
Dim list As List(Of VERAG_PROG_ALLGEMEIN.MyListItem2) = getParameterList()
|
|
Dim str As String = ""
|
|
Dim values As String = ""
|
|
For Each i In list
|
|
str &= "[" & i.Text & "],"
|
|
values &= "@" & i.Text.Replace("-", "").Replace(" ", "") & ","
|
|
Next
|
|
str = str.Substring(0, str.Length - 1) 'wg. ','
|
|
values = values.Substring(0, values.Length - 1) 'wg. ','
|
|
Return (" INSERT INTO [tblGeschäftsjahr] (" & str & ") VALUES(" & values & ") ")
|
|
Catch ex As Exception
|
|
MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
|
|
End Try
|
|
Return ""
|
|
End Function
|
|
|
|
|
|
|
|
End Class
|