Projektdateien hinzufügen.
This commit is contained in:
130
Aviso/cBinding.vb
Normal file
130
Aviso/cBinding.vb
Normal file
@@ -0,0 +1,130 @@
|
||||
Imports System.Data.SqlClient
|
||||
Imports VERAG_PROG_ALLGEMEIN
|
||||
Public Class cBinding
|
||||
Public bindingDataAdapter As New SqlDataAdapter
|
||||
Public WithEvents bindingdataTable As New DataTable
|
||||
Public bindingdataSet As New DataSet
|
||||
Public WithEvents bindingSource As New BindingSource
|
||||
Dim connection As SqlConnection
|
||||
|
||||
Sub New(Optional conn As String = "FMZOLL")
|
||||
|
||||
Select Case conn
|
||||
Case "AVISO" : connection = cDatenbankAVISO.GetNewOpenConnection()
|
||||
Case "FMZOLL" : connection = cDatenbankAVISO.GetNewOpenConnectionFMZOLL()
|
||||
End Select
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
Public Sub initBinding(sql As String, table As String)
|
||||
Try
|
||||
|
||||
bindingSource.CancelEdit()
|
||||
bindingSource.ResetBindings(False)
|
||||
bindingSource = New BindingSource
|
||||
bindingdataTable.Clear()
|
||||
bindingdataTable = New DataTable
|
||||
bindingdataSet.Clear()
|
||||
|
||||
Try
|
||||
Me.bindingDataAdapter = New SqlDataAdapter(sql, connection)
|
||||
Catch ex As SqlException
|
||||
MessageBox.Show("Der Connection-String kann nicht verarbeitet werden. Wenden Sie sich an den Programmbetreuer.")
|
||||
End Try
|
||||
Me.bindingDataAdapter.FillSchema(bindingdataSet, SchemaType.Source, table)
|
||||
Me.bindingDataAdapter.Fill(bindingdataSet, table)
|
||||
Me.bindingdataTable = Me.bindingdataSet.Tables(table)
|
||||
Me.bindingSource.DataSource = Me.bindingdataTable
|
||||
|
||||
Me.bindingdataTable.Locale = System.Globalization.CultureInfo.InvariantCulture
|
||||
Catch ex As Exception
|
||||
MsgBox(ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Sub setARITHABORTOn()
|
||||
Try
|
||||
Using cmd As New SqlCommand("SET ARITHABORT ON", connection)
|
||||
cmd.ExecuteNonQuery()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
MsgBox("Fehler in setARITHABORTOn: " & ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
Public Function updateBinding(Optional tablename As String = "") As Boolean
|
||||
If tablename = "" Then tablename = bindingdataTable.TableName
|
||||
Try
|
||||
bindingSource.EndEdit() 'Beendet die Bearbeitung
|
||||
Dim modrows As Integer = 0
|
||||
For Each row As DataRow In bindingdataTable.Rows
|
||||
If row.RowState = DataRowState.Modified Then
|
||||
|
||||
modrows += 1
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Dim builder As New SqlCommandBuilder(bindingDataAdapter)
|
||||
|
||||
If Not modrows = bindingDataAdapter.Update(bindingdataSet, tablename) Then
|
||||
' MsgBox(tablename & ": Es ist ein SQL-Fehler beim Updaten der Daten aufgetreten!")
|
||||
End If
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
MsgBox("Es ist ein SQL-Fehler beim Updaten der Daten aufgetreten:" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & "Die Werte werden zurückgesetzt!", MsgBoxStyle.OkCancel, "Datenbank-Fehler")
|
||||
Me.bindingSource.ResetBindings(False)
|
||||
End Try
|
||||
Return False
|
||||
End Function
|
||||
|
||||
|
||||
Public Function updateBinding2(Optional tablename As String = "", Optional ContinueUpdateOnError As Boolean = False) As Boolean
|
||||
If tablename = "" Then tablename = bindingdataTable.TableName
|
||||
|
||||
Try
|
||||
bindingSource.EndEdit() 'Beendet die Bearbeitung
|
||||
Dim modrows As Integer = 0
|
||||
For Each row As DataRow In bindingdataTable.Rows
|
||||
If row.RowState = DataRowState.Modified Then
|
||||
' MsgBox(": Es ist ei")
|
||||
modrows += 1
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Dim builder As New SqlCommandBuilder(bindingDataAdapter)
|
||||
bindingDataAdapter.ContinueUpdateOnError = False
|
||||
' bindingDataAdapter.FillLoadOption = LoadOption.OverwriteChanges
|
||||
' MsgBox(bindingDataAdapter.Update(bindingdataSet, tablename))
|
||||
If Not modrows = bindingDataAdapter.Update(bindingdataSet, tablename) Then
|
||||
'MsgBox(tablename & ": Es ist ein SQL-Fehler beim Updaten der Daten aufgetreten!")
|
||||
End If
|
||||
Me.bindingdataSet.AcceptChanges()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
MsgBox("Es ist ein SQL-Fehler beim Updaten der Daten aufgetreten:" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & "Die Werte werden zurückgesetzt!", MsgBoxStyle.OkCancel, "Datenbank-Fehler")
|
||||
|
||||
Me.bindingSource.ResumeBinding()
|
||||
End Try
|
||||
Return False
|
||||
End Function
|
||||
|
||||
Sub binddata(o As Object, bindingParam As String, bindingSource As BindingSource, dataName As String, bindingNullValue As String)
|
||||
o.DataBindings.Clear()
|
||||
|
||||
o.DataBindings.Add(New Binding(bindingParam, bindingSource, dataName, True, DataSourceUpdateMode.OnPropertyChanged, bindingNullValue))
|
||||
|
||||
|
||||
End Sub
|
||||
Sub binddata(o As Object, bindingParam As String, bindingSource As BindingSource, dataName As String)
|
||||
o.DataBindings.Clear()
|
||||
o.DataBindings.Add(New Binding(bindingParam, bindingSource, dataName, True, DataSourceUpdateMode.OnPropertyChanged))
|
||||
End Sub
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user