185 lines
6.1 KiB
VB.net
185 lines
6.1 KiB
VB.net
Imports System.Data.SqlClient
|
|
Imports System.ComponentModel
|
|
Imports System.Collections.ObjectModel
|
|
|
|
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 = "DISPO")
|
|
Select Case conn
|
|
Case "DISPO" : connection = cSqlDb.GetNewOpenConnection()
|
|
' Case "FMZOLL" : connection = cSqlDb.GetNewOpenConnectionFMZOLL()
|
|
End Select
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
Public Sub initBinding(sql, table)
|
|
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 Sub newEntry(kdNr, kfz, sdlNr)
|
|
Try
|
|
row_kdNr = kdNr
|
|
row_kfz = kfz
|
|
row_sdlNr = sdlNr
|
|
|
|
Dim row = bindingdataTable.NewRow()
|
|
bindingdataTable.Rows.Add(row)
|
|
|
|
bindingSource.MoveLast()
|
|
|
|
Catch ex As Exception
|
|
MsgBox(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
|
|
' MsgBox(": Es ist ei")
|
|
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 row_kdNr As String = ""
|
|
Public row_sdlNr As String = ""
|
|
Public row_kfz As String = ""
|
|
|
|
Public Sub bindingdataTable_TableNewRow_SDLLeistungen(sender As Object, e As DataTableNewRowEventArgs)
|
|
|
|
End Sub
|
|
|
|
Public Sub bindingdataTable_TableNewRow_Adressen(sender As Object, e As DataTableNewRowEventArgs)
|
|
|
|
End Sub
|
|
|
|
Sub binddata(o As Object, bindingParam As String, bindingSource As BindingSource, dataName As String, Optional bindingNullValue As String = "")
|
|
o.DataBindings.Clear()
|
|
o.DataBindings.Add(New Binding(bindingParam, bindingSource, dataName, True, DataSourceUpdateMode.OnPropertyChanged, bindingNullValue))
|
|
End Sub
|
|
|
|
|
|
End Class
|
|
|
|
|
|
|
|
Public Class cBindingContainer
|
|
Implements INotifyPropertyChanged
|
|
|
|
|
|
Public Event PropertyChanged As PropertyChangedEventHandler _
|
|
Implements INotifyPropertyChanged.PropertyChanged
|
|
|
|
Protected Sub OnPropertyChangedInt(ByVal name As Integer)
|
|
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
|
|
End Sub
|
|
|
|
Protected Sub OnPropertyChangedDbl(ByVal name As Double)
|
|
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
|
|
End Sub
|
|
|
|
|
|
'These variables must be initialized for databinding to work.
|
|
'This is because manual initialization forces .Net to initialize the
|
|
'variables before activating the databindings.
|
|
'Otherwise, .Net tries to activate the databindings before automatic
|
|
'initialization takes place and then the databindings fail.
|
|
|
|
|
|
|
|
Private doubleValue As Double = -1
|
|
Private integerValue As Integer = -1
|
|
|
|
|
|
'These events will allow the databinding mechanism in .Net to receive
|
|
'notifications when the values change.
|
|
'It is important that you name them exactly the same as the property name
|
|
'(including capitalization) and add the word "Changed" to the end with a capital C.
|
|
'And the event must be declared as "EventHandler"
|
|
Public Event ItemDBChanged As EventHandler
|
|
Public Event ItemINTChanged As EventHandler
|
|
|
|
Public Property doubleProp() As Double
|
|
Get
|
|
Return Me.doubleValue
|
|
End Get
|
|
Set(ByVal Value As Double)
|
|
Me.doubleValue = Value
|
|
'raise the event so databinding is notified
|
|
OnPropertyChangedDbl(Value)
|
|
End Set
|
|
End Property
|
|
|
|
Public Property integerProp() As Integer
|
|
Get
|
|
Return Me.integerValue
|
|
End Get
|
|
Set(ByVal Value As Integer)
|
|
Me.integerValue = Value
|
|
'raise the event so databinding is notified
|
|
RaiseEvent ItemINTChanged(Me, New EventArgs)
|
|
OnPropertyChangedint(Value)
|
|
End Set
|
|
End Property
|
|
|
|
|
|
End Class
|