You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
7.7 KiB

Imports System
Imports System.Data
Imports System.Data.SqlTypes
Imports System.Data.SqlClient
Imports System.Security.Principal
Namespace edokaDB
Public Class clsMyMitarbeiter
Inherits edokaDB.clsMitarbeiter
#Region "Deklarationen"
Private m_xtgnummer As String
Property xtgnummer() As String
Get
Return m_xtgnummer
End Get
Set(ByVal Value As String)
m_xtgnummer = Value
End Set
End Property
#End Region
Public Function SelectWithTGNummer() As DataTable
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
scmCmdToExecute.CommandText = "dbo.[sp_mitarbeiter_SelectWithTGNummer]"
scmCmdToExecute.CommandType = CommandType.StoredProcedure
Dim dtToReturn As DataTable = New DataTable("mitarbeiter")
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
' // Use base class' connection object
scmCmdToExecute.Connection = m_scoMainConnection
Try
scmCmdToExecute.Parameters.Add(New SqlParameter("@stgnummer", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, m_xtgnummer))
scmCmdToExecute.Parameters.Add(New SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode))
If m_bMainConnectionIsCreatedLocal Then
' // Open connection.
m_scoMainConnection.Open()
Else
If m_cpMainConnectionProvider.bIsTransactionPending Then
scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction
End If
End If
' // Execute query.
sdaAdapter.Fill(dtToReturn)
m_iErrorCode = New SqlInt32(CType(scmCmdToExecute.Parameters.Item("@iErrorCode").Value, SqlInt32))
If Not m_iErrorCode.Equals(New SqlInt32(LLBLError.AllOk)) Then
' // Throw error.
Throw New Exception("Stored Procedure 'pr_mitarbeiter_SelectAllWithTGNummer' reported the ErrorCode: " & m_iErrorCode.ToString())
End If
Globals.CurrentMitarbeiterdata = dtToReturn
Return dtToReturn
Catch ex As Exception
MsgBox(ex.Message)
' // some error occured. Bubble it to caller and encapsulate Exception object
Throw New Exception("clsMitarbeiter::SelectWithTGNummer::Error occured." + ex.Message, ex)
Finally
If m_bMainConnectionIsCreatedLocal Then
' // Close connection.
m_scoMainConnection.Close()
End If
scmCmdToExecute.Dispose()
sdaAdapter.Dispose()
End Try
End Function
' Angemelderter Mitarbeiter auslesen, wenn keine Mitarbeiter vorhandne, Funktion mit False verlassen
Public Function Get_Mitarbeiter() As Boolean
Dim mandant As New edokaDB.clsMandant()
Me.cpMainConnectionProvider = Globals.conn
Dim MitarbeiterData As DataTable
Dim CheckState As Boolean
Get_Mitarbeiter = True
Me.xtgnummer = get_username
Globals.TGNummer = Me.xtgnummer
MitarbeiterData = Me.SelectWithTGNummer
If MitarbeiterData.Rows.Count = 0 Then
Get_Mitarbeiter = False
Else
Globals.DoLog = MitarbeiterData.Rows(0).Item("journalisierung")
Globals.MitarbeiterNr = MitarbeiterData.Rows(0).Item("mitarbeiternr")
Globals.Sprache = MitarbeiterData.Rows(0).Item("Sprache")
If MitarbeiterData.Rows(0).Item("fuermandant") = 0 Then
Select_Mandant()
Else
mandant.cpMainConnectionProvider = conn
mandant.iMandantnr = New SqlInt32(MitarbeiterData.Rows(0).Item("fuermandant"))
mandant.SelectOne()
Globals.MandantNr = mandant.iMandantnr.Value
Globals.MandantText = mandant.sBezeichnung.Value
End If
End If
mandant.Dispose()
MitarbeiterData.Dispose()
End Function
Public Function SelectAllMandantMitarbeiter() As DataTable
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
scmCmdToExecute.CommandText = "dbo.[sp_mandantmitarbeiter_Select]"
scmCmdToExecute.CommandType = CommandType.StoredProcedure
Dim dtToReturn As DataTable = New DataTable("mitarbeiter")
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
' // Use base class' connection object
scmCmdToExecute.Connection = m_scoMainConnection
Try
scmCmdToExecute.Parameters.Add(New SqlParameter("@mandantnr", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, Globals.MandantNr))
scmCmdToExecute.Parameters.Add(New SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode))
If m_bMainConnectionIsCreatedLocal Then
' // Open connection.
m_scoMainConnection.Open()
Else
If m_cpMainConnectionProvider.bIsTransactionPending Then
scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction
End If
End If
' // Execute query.
sdaAdapter.Fill(dtToReturn)
m_iErrorCode = New SqlInt32(CType(scmCmdToExecute.Parameters.Item("@iErrorCode").Value, SqlInt32))
If Not m_iErrorCode.Equals(New SqlInt32(LLBLError.AllOk)) Then
' // Throw error.
Throw New Exception("Stored Procedure 'pr_mitarbeiter_SelectAll' reported the ErrorCode: " & m_iErrorCode.ToString())
End If
Return dtToReturn
Catch ex As Exception
' // some error occured. Bubble it to caller and encapsulate Exception object
Throw New Exception("clsMitarbeiter::SelectAll::Error occured." + ex.Message, ex)
Finally
If m_bMainConnectionIsCreatedLocal Then
' // Close connection.
m_scoMainConnection.Close()
End If
scmCmdToExecute.Dispose()
sdaAdapter.Dispose()
End Try
End Function
Dim ouser As New WindowsPrincipal(WindowsIdentity.GetCurrent)
Private Function Get_Username() As String
With ouser.Identity.Name
Return (.Substring(.IndexOf("\") + 1))
End With
End Function
Public Sub SelectMitarbeiterWithNr(ByVal MaNr As Long)
Dim mitarbeiterdata As DataTable
Me.iMitarbeiternr = New SqlInt32(CType(MaNr, Int32))
Me.cpMainConnectionProvider = conn
mitarbeiterdata = Me.SelectOne
Globals.MitarbeiterNr = mitarbeiterdata.Rows(0).Item("mitarbeiternr")
Globals.Sprache = mitarbeiterdata.Rows(0).Item("sprache")
End Sub
Private Sub Select_Mandant()
Dim f As New Selektion_Mandant()
f.ShowDialog()
End Sub
End Class
End Namespace