Imports IntraSell_DLL
Imports IntraSell_Net_Base

Public Class NachrichtenEinstellungen
    Inherits AbstractForm

    Dim localeSettings As New IntraSell_DLL.ClassSettings

    Private Sub MyBase_Verlassen() Handles MyBase.Verlassen
        Me.Close()
    End Sub

    Private Sub WerbeNachrichtReminderEinstellungen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Me.ParentBindingNavigator.Visible = False
            LadeDaten()
            CheckState()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub


    Private Sub ButtonSpeichern_Click(sender As Object, e As EventArgs) Handles ButtonSpeichern.Click
        Try
            SpeichereDaten()
            CheckState()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub LadeDaten()
        Try
            Me.TextBoxNachricht.Text = IO.File.ReadAllText(VorlagenNamen.VORLAGE_VORGANG_SMS_REMINDER)
            Me.TextBoxSMSKey.Text = VarValue_Default(Variablen.SMS_API_KEY, Messages.ModuleSMS_SMS_Key_Anfrage)
            Me.CheckBox_Sofort.Checked = VarValue_Default(Variablen.Order_Confirmation, True)
            Me.CheckBox_1Std.Checked = VarValue_Default(Variablen.Order_Feedback, False)
            Me.CheckBox_Neukunden.Checked = VarValue_Default(Variablen.Event_Neukunde, False)
            Me.CheckBox_1Wochen.Checked = VarValue_Default(Variablen.Reminder_1Woche, True)
            Me.CheckBox_2Wochen.Checked = VarValue_Default(Variablen.Reminder_2Woche, True)
            Me.CheckBox_4Wochen.Checked = VarValue_Default(Variablen.Reminder_4Woche, True)
            Me.TextBox_Whatsapp_Nummer.Text = VarValue_Default(Variablen.FIRMA_WHATSAPP_NUMMER, "436XXXXXXXXX")
            CheckState()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub CheckState()
        Try
            Dim istWebOrderAktiv As Boolean = VarValue_Default("WEBORDER_AKTIV", "false")
            Dim PcHatSignaturEinheit = localeSettings.ReadBoolean(Variablen.PcHatSignaturEinheit, True)
            Dim warnings As String = ""

            If Not istWebOrderAktiv Then
                warnings += $"Für diese Funktion Aktiviere die WebOrder. (Einstellung WEBORDER_AKTIV){vbNewLine}"
            End If

            If Not PcHatSignaturEinheit Then
                warnings += $"Dieser PC führt keine Tasks aus (Einstellung PcHatSignaturEinheit). {vbNewLine}Hier werden keine Nachrichten generiert!"
            End If
            If warnings <> "" Then
                Me.LabelWarnings.Text = warnings
                Me.LabelWarnings.ForeColor = Color.Red
            Else
                Me.LabelWarnings.ForeColor = Color.Green
            End If
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub SpeichereDaten()
        Try
            IO.File.WriteAllText(VORLAGE_VORGANG_SMS_REMINDER, Me.TextBoxNachricht.Text)
            IO.File.WriteAllText(ClassSettings.GetDataPath() + VORLAGE_VORGANG_SMS_REMINDER, Me.TextBoxNachricht.Text)


            SetVarValue(Variablen.SMS_API_KEY, Me.TextBoxSMSKey.Text)
            SetVarValue(Variablen.Order_Confirmation, Me.CheckBox_Sofort.Checked)
            SetVarValue(Variablen.Order_Feedback, Me.CheckBox_1Std.Checked)
            SetVarValue(Variablen.Event_Neukunde, Me.CheckBox_Neukunden.Checked)
            SetVarValue(Variablen.Reminder_1Woche, Me.CheckBox_1Wochen.Checked)
            SetVarValue(Variablen.Reminder_2Woche, Me.CheckBox_2Wochen.Checked)
            SetVarValue(Variablen.Reminder_4Woche, Me.CheckBox_4Wochen.Checked)
            SetVarValue(Variablen.FIRMA_WHATSAPP_NUMMER, Me.TextBox_Whatsapp_Nummer.Text)
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        Try
            TextBoxNachricht.Focus()
            TextBoxNachricht.SelectedText = ListBox1.SelectedItem
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub

    Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click

    End Sub

    Private Sub ButtonVorlage_Click(sender As Object, e As EventArgs) Handles ButtonVorlage.Click
        Try
            Dim ve As New VorlageEditor(VORLAGE_VORGANG_SMS_REMINDER) With {
                .MdiParent = MdiParent
            }
            ve.ShowDialog()
            LadeDaten()
        Catch ex As Exception
            HandleAppError(ex)
        End Try
    End Sub
End Class