Public Class frmBGExportProfilhinzufuegen
    Private Shared _Instance As frmBGExportProfilhinzufuegen = Nothing

    Public Shared Function Instance() As frmBGExportProfilhinzufuegen
        If _Instance Is Nothing OrElse _Instance.IsDisposed = True Then
            _Instance = New frmBGExportProfilhinzufuegen
        End If
        _Instance.BringToFront()
        Return _Instance
    End Function

    Private Sub frmNIProfilhinzufuegen_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ' die Textfelder löschen
        Me.txtProfilname.Text = ""
        Me.txtSQL.Text = ""

        ' Standardbuttons festlegen
        Me.AcceptButton = Me.btnOK
        Me.CancelButton = Me.btnAbbrechen
    End Sub
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click


        ' wenn mindestens ein Profilname und ein Dokumententyp angegeben wurde
        If Me.txtProfilname.Text <> "" And _
           Me.txtSQL.Text <> "" And _
           Me.txtSpeicherort.Text <> "" Then

            If Me.CheckBox1.Checked = False Then
                If Me.CheckBox2.Checked = False Then
                    If Me.CheckBox3.Checked = False Then
                        If Me.CheckBox4.Checked = False Then
                            If Me.CheckBox5.Checked = False Then
                                If Me.CheckBox6.Checked = False Then
                                    If Me.CheckBox7.Checked = False Then
                                        MsgBox("Bitte definieren Sie mindestens einen Wochentag an dem der Export durchgeführt werden soll.", MsgBoxStyle.Information, "Eingabe erwartet")
                                        Exit Sub
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If

            If Not ClassBWProfileExport.Exists(Me.txtProfilname.Text) Then
                ' das Profil hinzufügen
                ClassBWProfileExport.Add(Me.txtProfilname.Text, _
                                   Me.txtSQL.Text, Me.txtDays.Text, Me.cmbDateiformat.SelectedItem, Me.txtSpeicherort.Text, Me.chkEmail.Checked, Me.txtEmailto.Text, Me.txtBetreff.Text, Me.txtBody.Text, _
                                   Me.txtMail_from.Text, Me.txtAbsender.Text, Me.txtSMTP.Text, Me.txtUser.Text, Me.txtPasswort.Text, "")
                Me.Close()
            Else
                MsgBox("Es existiert bereits ein Profil mit diesem Namen.", MsgBoxStyle.Information, "Ungültiger Profilname")
            End If
        Else
            ' sonst eine Fehlermeldung ausgeben
            MsgBox("Bitte geben Sie für jedes Pflichtfeld einen Wert an, da ohne diese Angaben kein Profil erstellt werden kann.", MsgBoxStyle.Information, "Eingabe erwartet")
        End If
    End Sub

    Private Sub btnAbbrechen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbbrechen.Click
        ' Formular schließen
        Me.Close()
    End Sub
    Private Sub btnDialogSpeicherort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDialogSpeicherort.Click
        If Me.FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.txtSpeicherort.Text = Me.FolderBrowserDialog1.SelectedPath
        End If
    End Sub

    Private Sub chkEmail_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkEmail.CheckedChanged
        If chkEmail.Checked Then
            Me.grbEmail.Enabled = True
            Me.txtEmailto.Focus()
        Else
            Me.grbEmail.Enabled = False
        End If
    End Sub

    Private Sub txtMail_from_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMail_from.TextChanged
        If Me.txtMail_from.Text <> "" Then
            Me.txtAbsender.Text = Me.txtMail_from.Text
        End If
    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked Then
            Me.txtDays.Text = "1" & txtDays.Text.Substring(1)
        Else
            Me.txtDays.Text = "0" & txtDays.Text.Substring(1)
        End If
    End Sub

    Private Sub CheckBox2_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked Then
            Me.txtDays.Text = txtDays.Text.Substring(0, 1) & "1" & txtDays.Text.Substring(2)
        Else
            Me.txtDays.Text = txtDays.Text.Substring(0, 1) & "0" & txtDays.Text.Substring(2)
        End If
    End Sub

    Private Sub CheckBox3_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox3.CheckedChanged
        If CheckBox3.Checked Then
            Me.txtDays.Text = txtDays.Text.Substring(0, 2) & "1" & txtDays.Text.Substring(3)
        Else
            Me.txtDays.Text = txtDays.Text.Substring(0, 2) & "0" & txtDays.Text.Substring(3)
        End If
    End Sub

    Private Sub CheckBox4_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox4.CheckedChanged
        If CheckBox3.Checked Then
            Me.txtDays.Text = txtDays.Text.Substring(0, 3) & "1" & txtDays.Text.Substring(4)
        Else
            Me.txtDays.Text = txtDays.Text.Substring(0, 3) & "0" & txtDays.Text.Substring(4)
        End If
    End Sub

    Private Sub CheckBox5_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox5.CheckedChanged
        If CheckBox3.Checked Then
            Me.txtDays.Text = txtDays.Text.Substring(0, 4) & "1" & txtDays.Text.Substring(4)
        Else
            Me.txtDays.Text = txtDays.Text.Substring(0, 4) & "0" & txtDays.Text.Substring(4)
        End If
    End Sub

    Private Sub CheckBox6_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox6.CheckedChanged
        If CheckBox6.Checked Then
            Me.txtDays.Text = txtDays.Text.Substring(0, 5) & "1" & txtDays.Text.Substring(6)
        Else
            Me.txtDays.Text = txtDays.Text.Substring(0, 5) & "0" & txtDays.Text.Substring(6)
        End If
    End Sub

    Private Sub CheckBox7_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox7.CheckedChanged
        If CheckBox7.Checked Then
            Me.txtDays.Text = txtDays.Text.Substring(0, 6) & "1"
        Else
            Me.txtDays.Text = txtDays.Text.Substring(0, 6) & "0"
        End If
    End Sub
End Class