diff --git a/VERAG_PROG_ALLGEMEIN/Classes/cWarenorte.vb b/VERAG_PROG_ALLGEMEIN/Classes/cWarenorte.vb new file mode 100644 index 00000000..aa5edf80 --- /dev/null +++ b/VERAG_PROG_ALLGEMEIN/Classes/cWarenorte.vb @@ -0,0 +1,183 @@ +Imports System.Data.SqlClient +Imports System.Reflection + +Public Class cWarenorte + + 'Property _BASE_id As Integer + Property wo_warenort As Object = Nothing + Property wo_bezeichnung As Object = Nothing + Property wo_firma As Object = Nothing + Property wo_aktiv As Boolean + Property wo_reihenfolge As Object = Nothing + Property wo_ort As Object = Nothing + Property wo_cluster As Object = Nothing + Property wo_grenzstelle As Object = Nothing + Property wo_knnr As Object = Nothing + + Public hasEntry = False + + Dim SQL As New SQL + + Sub New(wo_warenort) + Me.wo_warenort = wo_warenort + LOAD() + End Sub + + Sub New(wo_warenort, wo_firma) + Me.wo_warenort = wo_warenort + Me.wo_firma = wo_firma + LOAD() + End Sub + + + Sub New() + LOADALL() + End Sub + + + + 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("_BASE_id", _BASE_id,, True)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("wo_warenort", wo_warenort)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("wo_bezeichnung", wo_bezeichnung)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("wo_firma", wo_firma)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("wo_aktiv", wo_aktiv)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("wo_reihenfolge", wo_reihenfolge)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("wo_ort", wo_ort)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("wo_cluster", wo_cluster)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("wo_grenzstelle", wo_grenzstelle)) + list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("wo_knnr", wo_knnr)) + + Return list + End Function + + + + Public Function SAVE() As Boolean + Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList() + + Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM [tblWarenorte] WHERE wo_warenort=@wo_warenort AND wo_firma=@wo_firma) " & + " BEGIN " & getUpdateCmd() & " END " & + " Else " & + " BEGIN " & getInsertCmd() & " END " & + " commit tran " + + Return SQL.doSQLVarList(sqlstr, "AVISO", , list) + End Function + + Public Sub LOAD() + Try + hasEntry = False + Using conn As SqlConnection = SQL.GetNewOpenConnectionAVISO() + Using cmd As New SqlCommand("SELECT * FROM [tblWarenorte] WHERE wo_warenort=@wo_warenort AND wo_firma=@wo_firma ", conn) + cmd.Parameters.AddWithValue("@wo_warenort", wo_warenort) + cmd.Parameters.AddWithValue("@wo_firma", wo_firma) + Dim dr = cmd.ExecuteReader() + If dr.Read Then + For Each li In getParameterList() + Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable) + + If dr.Item(li.Text) Is DBNull.Value Then + propInfo.SetValue(Me, Nothing) + Else + propInfo.SetValue(Me, dr.Item(li.Text)) + End If + + Next + hasEntry = True + End If + dr.Close() + End Using + End Using + Catch ex As Exception + MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace) + End Try + End Sub + + Public Sub LOADALL() + Try + hasEntry = False + Using conn As SqlConnection = SQL.GetNewOpenConnectionAVISO() + Using cmd As New SqlCommand("SELECT * FROM [tblWarenorte] ", conn) + Dim dr = cmd.ExecuteReader() + If dr.Read Then + For Each li In getParameterList() + Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable) + + If dr.Item(li.Text) Is DBNull.Value Then + propInfo.SetValue(Me, Nothing) + Else + propInfo.SetValue(Me, dr.Item(li.Text)) + End If + + Next + hasEntry = True + End If + dr.Close() + End Using + End Using + Catch ex As Exception + MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace) + End Try + End Sub + + + + Public Function getUpdateCmd() As String + Try + Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList() + + Dim str As String = "" + For Each i In list + If Not i.isPrimaryParam Then + str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & "," + End If + Next + str = str.Substring(0, str.Length - 1) 'wg. ',' + Return (" UPDATE [tblWarenorte] SET " & str & " WHERE wo_warenort=@wo_warenort ") + + 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.SQLVariable) = getParameterList() + Dim str As String = "" + Dim values As String = "" + For Each i In list + If Not i.isPrimaryParam Then + str &= "[" & i.Text & "]," + values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & "," + End If + Next + str = str.Substring(0, str.Length - 1) 'wg. ',' + values = values.Substring(0, values.Length - 1) 'wg. ',' + Return (" INSERT INTO [tblWarenorte] (" & 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 + + Public Function deleteWarenort(ByVal warenort As String, ByVal firma As String) As Boolean + + Try + SQL.doSQL("DELETE FROM [tblWarenorte] WHERE wo_warenort = '" & warenort & "' AND wo_firma='" & firma & "'", "AVISO") + Return True + Catch ex As SqlException + MsgBox(System.Reflection.MethodInfo.GetCurrentMethod.Name & ": Datensatz kann nicht gelöscht werden!" & vbCrLf & vbCrLf & ex.Message, vbExclamation, "Fehler beim Löschen") + End Try + + Return False + + End Function + + + +End Class + diff --git a/VERAG_PROG_ALLGEMEIN/VERAG_PROG_ALLGEMEIN.vbproj b/VERAG_PROG_ALLGEMEIN/VERAG_PROG_ALLGEMEIN.vbproj index 55bfc85d..53391e77 100644 --- a/VERAG_PROG_ALLGEMEIN/VERAG_PROG_ALLGEMEIN.vbproj +++ b/VERAG_PROG_ALLGEMEIN/VERAG_PROG_ALLGEMEIN.vbproj @@ -365,6 +365,7 @@ +