Public Class ClassBWProfilExport

    Private _originalProfilname As String
    Private _originalSQLAnweisung As String
    Private _originaldays As String
    Private _originalFormat As String
    Private _originalPath As String
    Private _originalEmail As Boolean
    Private _originalEmailto As String
    Private _originalEmailAbsender As String
    Private _originalEmailBetreff As String
    Private _originalEmailBody As String
    Private _originalemailfrom As String
    Private _originalemailsmtp As String
    Private _originalemailuser As String
    Private _originalemailPW As String
    Private _originalemailbest As String
    Private _originallastExport As String

    Private _profilname As String
    Private _SQLAnweisung As String
    Private _days As String
    Private _Format As String
    Private _Path As String
    Private _Email As Boolean

    Private _Emailto As String
    Private _EmailBetreff As String
    Private _EmailBody As String
    Private _emailfrom As String
    Private _EmailAbsender As String
    Private _emailsmtp As String
    Private _emailuser As String
    Private _emailPW As String
    Private _emailbest As String
    Public _lastExport As String

    Private _saved As Boolean
    ''' <summary>
    ''' Konstruktor zum Anlegen oder Laden eines Profils
    ''' </summary>
    ''' <param name="profilname">Profilname</param>
    ''' <param name="dokumenttyp_string"></param>
    ''' <param name="windreamSuche"></param>
    ''' <remarks></remarks>
    Sub New(ByVal profilname As String, _
            ByVal SQLAnweisung As String, _
              ByVal days As String, ByVal Format As String, ByVal Pfad As String, ByVal email As Boolean, ByVal emailto As String, ByVal emailBetreff As String, ByVal emailBody As String, _
              ByVal emailfrom As String, ByVal emailAbsender As String, ByVal emailsmtp As String, ByVal emailuser As String, ByVal emailPW As String, ByVal emailbest As String, ByVal lastExport As String)

        Me._originalProfilname = profilname
        Me._originalSQLAnweisung = SQLAnweisung
        Me._originaldays = days
        Me._originalFormat = Format
        Me._originalPath = Pfad
        Me._originalEmail = email


        Me._originalEmailto = emailto
        Me._originalEmailBetreff = emailBetreff
        Me._originalEmailBody = emailBody
        Me._originalemailfrom = emailfrom
        Me._originalEmailAbsender = emailAbsender
        Me._originalemailsmtp = emailsmtp
        Me._originalemailuser = emailuser
        Me._originalemailPW = emailPW
        Me._originalemailbest = emailbest
        Me._originallastExport = lastExport


        Me._profilname = profilname
        Me._SQLAnweisung = SQLAnweisung
        Me._days = days
        Me._Format = Format
        Me._Path = Pfad
        Me._Email = email
        Me._Emailto = emailto
        Me._EmailBetreff = emailBetreff
        Me._EmailBody = emailBody
        Me._emailfrom = emailfrom
        Me._EmailAbsender = emailAbsender
        Me._emailsmtp = emailsmtp
        Me._emailuser = emailuser
        Me._emailPW = emailPW
        Me._emailbest = emailbest
        Me._lastExport = lastExport

        Me._saved = True
    End Sub


    ''' <summary>
    ''' Konstruktor ohne Tätigkeit
    ''' </summary>
    ''' <remarks>wenn im Konstruktor kein Parameter übergeben wurde soll auch nichts gemacht werden</remarks>
    Sub New()
    End Sub



    ''' <summary>
    ''' Speichert das Profil
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Save(ByVal mitMeldung As Boolean)

        Try
            ' wenn das Profil nicht gespeichert ist
            If Not Me.IsSaved Then
                ' wenn ein Profilname für dieses Profil gesetzt ist
                If Me._profilname IsNot Nothing And Me._originalProfilname IsNot Nothing Then
                    ' XML-Datei initialisieren
                    Dim xml As New Xml.XmlDocument()
                    ' Profil initialisieren
                    Dim xmlProfil As Xml.XmlElement

                    ' XML-Datei öffnen und laden
                    xml.Load(My.Settings.conFile_Reporting)

                    ' den XML-Knoten des Profils laden
                    xmlProfil = xml.SelectSingleNode("//Settings/Profile/Profil[@profilname='" & Me._originalProfilname & "']")

                    ' wenn der Knoten NICHT gefunden wurde -> Vorgang abbrechen
                    If xmlProfil Is Nothing Then Return False

                    ' die neuen Werte den Originalwerten zuweisen
                    Me._originalProfilname = Me._profilname
                    Me._originalSQLAnweisung = Me._SQLAnweisung
                    Me._originaldays = Me._days
                    Me._originalemailbest = Me._emailbest

                    ' die neuen Werte in die XML-Datei schreiben
                    xmlProfil.Attributes("profilname").Value = Me._profilname
                    xmlProfil.Attributes("sqlanweisung").Value = Me._SQLAnweisung
                    xmlProfil.Attributes("days").Value = Me._days
                    xmlProfil.Attributes("format").Value = Me._Format
                    xmlProfil.Attributes("path").Value = Me._Path
                    xmlProfil.Attributes("email").Value = Me._Email
                    xmlProfil.Attributes("emailto").Value = Me._Emailto
                    xmlProfil.Attributes("emailBetreff").Value = Me._EmailBetreff
                    xmlProfil.Attributes("emailBody").Value = Me._EmailBody
                    xmlProfil.Attributes("emailfrom").Value = Me._emailfrom
                    xmlProfil.Attributes("emailabsender").Value = Me._EmailAbsender
                    xmlProfil.Attributes("emailsmtp").Value = Me._emailsmtp
                    xmlProfil.Attributes("emailuser").Value = Me._emailuser
                    xmlProfil.Attributes("emailPW").Value = Me._emailPW
                    xmlProfil.Attributes("emailbest").Value = Me._emailbest
                    xmlProfil.Attributes("lastExport").Value = Me._lastExport
                    ' XML-Datei speichern
                    xml.Save(My.Settings.conFile_Reporting)

                    ' Profil auf gespeichert setzen
                    Me._saved = True

                    If mitMeldung = True Then MsgBox("Das Profil '" & Me._originalProfilname & "' wurde erfolgreich gespeichert.", MsgBoxStyle.Information, "Profil gespeichert")

                    Return True
                Else
                    If mitMeldung = True Then MsgBox("Es wurde kein Profilname für das Profil definiert.", MsgBoxStyle.Information, "Profil konnte nicht gespeichert werden")
                    Return False
                End If
            End If

            Return False

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler beim Speichern eines Profils")
            Return False
        End Try


    End Function

    ''' <summary>
    ''' Setzt im aktuellen Profil alle Einstellungen auf die Originalwerte zurück.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SetBackToOriginal()
        Me._profilname = _originalProfilname
        Me._SQLAnweisung = _originalSQLAnweisung
        Me._days = _originaldays
        Me._Format = _originalFormat
        Me._Path = _originalPath
        Me._Email = _originalEmail
        Me._Emailto = _originalEmailto
        Me._EmailBetreff = _originalEmailBetreff
        Me._EmailBody = _originalEmailBody
        Me._emailfrom = _originalemailfrom
        Me._emailsmtp = _originalemailsmtp
        Me._emailuser = _originalemailuser
        Me._emailPW = _originalemailPW
        Me._emailbest = _originalemailbest
        Me._lastExport = _originallastExport

        Me._originalProfilname = Me._profilname

    End Sub

    ''' <summary>
    ''' Setzt das Profil auf geändert.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub setChanged()
        ' Profil auf geändert setzen
        Me._saved = False
    End Sub

    ''' <summary>
    ''' Setzt das Profil auf gespeichert.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub setSaved()
        ' Profil auf gespeichert setzen
        Me._saved = True
    End Sub




    Public ReadOnly Property HasChanges() As Boolean
        Get
            If Me._profilname = Me._originalProfilname And _
                Me._days = _originaldays And _
                Me._Format = _originalFormat And _
                Me._Path = _originalPath And _
                Me._SQLAnweisung = _originalSQLAnweisung And _
                Me._Email = _originalEmail And _
                Me._EmailAbsender = _originalEmailAbsender And _
                Me._Emailto = _originalEmailto And _
                Me._EmailBetreff = _originalEmailBetreff And _
                Me._EmailBody = _originalEmailBody And _
                Me._emailfrom = _originalemailfrom And _
                Me._emailsmtp = _originalemailsmtp And _
                Me._emailuser = _originalemailuser And _
                Me._emailPW = _originalemailPW And
                Me._emailbest = _originalemailbest And
                Me._lastExport = _originallastExport Then
                Return False
            Else
                Return True
            End If
        End Get
    End Property

    Public ReadOnly Property IsSaved() As Boolean
        Get
            Return Me._saved
        End Get
    End Property


    Public Property OriginalProfilname() As String
        Get
            Return Me._originalProfilname
        End Get
        Set(ByVal value As String)
            Me._originalProfilname = value
        End Set
    End Property

    Public Property Profilname() As String
        Get
            Return Me._profilname
        End Get
        Set(ByVal value As String)
            Me._profilname = value

            ' Profil auf geändert setzen
            Me.setChanged()
        End Set
    End Property
    Public Property OriginalvSQL_Anweisung() As String
        Get
            Return Me._originalSQLAnweisung
        End Get
        Set(ByVal value As String)
            Me._originalSQLAnweisung = value
        End Set
    End Property

    Public Property vSQL_Anweisung() As String
        Get
            Return Me._SQLAnweisung
        End Get
        Set(ByVal value As String)
            Me._SQLAnweisung = value
            Me.setChanged()
        End Set
    End Property
    Public Property originaldays() As String
        Get
            Return Me._originaldays
        End Get
        Set(ByVal value As String)
            Me._originaldays = value
        End Set
    End Property

    Public Property Days() As String
        Get
            Return Me._days
        End Get
        Set(ByVal value As String)
            Me._days = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalFormat() As String
        Get
            Return Me._originalFormat
        End Get
        Set(ByVal value As String)
            Me._originalFormat = value
        End Set
    End Property

    Public Property Format() As String
        Get
            Return Me._Format
        End Get
        Set(ByVal value As String)
            Me._Format = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalpath() As String
        Get
            Return Me._originalPath
        End Get
        Set(ByVal value As String)
            Me._originalPath = value
        End Set
    End Property

    Public Property Path() As String
        Get
            Return Me._Path
        End Get
        Set(ByVal value As String)
            Me._Path = value
            Me.setChanged()
        End Set
    End Property

    Public Property originalEmail() As String
        Get
            Return Me._originalEmail
        End Get
        Set(ByVal value As String)
            Me._originalEmail = value
        End Set
    End Property

    Public Property Email() As String
        Get
            Return Me._Email
        End Get
        Set(ByVal value As String)
            Me._Email = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalEmailabsender() As String
        Get
            Return Me._originalEmailAbsender
        End Get
        Set(ByVal value As String)
            Me._originalEmailAbsender = value
        End Set
    End Property

    Public Property EmailAbsender() As String
        Get
            Return Me._EmailAbsender
        End Get
        Set(ByVal value As String)
            Me._EmailAbsender = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalEmailto() As String
        Get
            Return Me._originalEmailto
        End Get
        Set(ByVal value As String)
            Me._originalEmailto = value
        End Set
    End Property

    Public Property Emailto() As String
        Get
            Return Me._Emailto
        End Get
        Set(ByVal value As String)
            Me._Emailto = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalEmailBetreff() As String
        Get
            Return Me._originalEmailBetreff
        End Get
        Set(ByVal value As String)
            Me._originalEmailBetreff = value
        End Set
    End Property

    Public Property EmailBetreff() As String
        Get
            Return Me._EmailBetreff
        End Get
        Set(ByVal value As String)
            Me._EmailBetreff = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalEmailBody() As String
        Get
            Return Me._originalEmailBody
        End Get
        Set(ByVal value As String)
            Me._originalEmailBody = value
        End Set
    End Property

    Public Property EmailBody() As String
        Get
            Return Me._EmailBody
        End Get
        Set(ByVal value As String)
            Me._EmailBody = value
            Me.setChanged()
        End Set
    End Property
    ''#####
    Public Property originalEmailfrom() As String
        Get
            Return Me._originalemailfrom
        End Get
        Set(ByVal value As String)
            Me._originalemailfrom = value
        End Set
    End Property

    Public Property Emailfrom() As String
        Get
            Return Me._emailfrom
        End Get
        Set(ByVal value As String)
            Me._emailfrom = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalEmailSMTP() As String
        Get
            Return Me._originalemailsmtp
        End Get
        Set(ByVal value As String)
            Me._originalemailsmtp = value
        End Set
    End Property

    Public Property EmailSMTP() As String
        Get
            Return Me._emailsmtp
        End Get
        Set(ByVal value As String)
            Me._emailsmtp = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalEmailUser() As String
        Get
            Return Me._originalemailuser
        End Get
        Set(ByVal value As String)
            Me._originalemailuser = value
        End Set
    End Property

    Public Property EmailUser() As String
        Get
            Return Me._emailuser
        End Get
        Set(ByVal value As String)
            Me._emailuser = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalEmailPW() As String
        Get
            Return Me._originalemailPW
        End Get
        Set(ByVal value As String)
            Me._originalemailPW = value
        End Set
    End Property

    Public Property EmailPW() As String
        Get
            Return Me._emailPW
        End Get
        Set(ByVal value As String)
            Me._emailPW = value
            Me.setChanged()
        End Set
    End Property
    Public Property originalEmailBest() As String
        Get
            Return Me._originalemailbest
        End Get
        Set(ByVal value As String)
            Me._originalemailbest = value
        End Set
    End Property

    Public Property emailbest() As String
        Get
            Return Me._emailbest
        End Get
        Set(ByVal value As String)
            Me._emailbest = value
            Me.setChanged()
        End Set
    End Property
    Public Property lastExport() As String
        Get
            Return Me._lastExport
        End Get
        Set(ByVal value As String)
            Me._lastExport = value
            Me.setChanged()
        End Set
    End Property

End Class
