Imports VERAGMonitoring.cUserSettings

Public Class frmSettings
    Private BRG As New cBrgDb
    Dim cMonitoringBrg As cMonitoringBrg
    Private Sub frmSettings_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Normal
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.ControlBox = False
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None

        If Not Environment.UserName = "developer1" Then btnSaveToDB.Visible = False
        getFields_UserSettings()
        cMonitoringBrg = BRG.getMonitoringData()
        initFields()
        getFields_UserSettings()
    End Sub

    Sub initFields()
        txtBrgVV_de_summe.Text = cMonitoringBrg.brgusrset_gvvDe_summe
        txtBrgVV_de_tag_warn1.Text = cMonitoringBrg.brgusrset_gvvDe_tag_warn1
        txtBrgVV_de_tag_warn2.Text = cMonitoringBrg.brgusrset_gvvDe_tag_warn2
        txtBrgVV_de_woche_warn1.Text = cMonitoringBrg.brgusrset_gvvDe_woche_warn1
        txtBrgVV_de_woche_warn2.Text = cMonitoringBrg.brgusrset_gvvDe_woche_warn2

        txtBrgVV_at_summe.Text = cMonitoringBrg.brgusrset_gvvAt_summe
        txtBrgVV_at_tag_warn1.Text = cMonitoringBrg.brgusrset_gvvAt_tag_warn1
        txtBrgVV_at_tag_warn2.Text = cMonitoringBrg.brgusrset_gvvAt_tag_warn2
        txtBrgVV_at_woche_warn1.Text = cMonitoringBrg.brgusrset_gvvAt_woche_warn1
        txtBrgVV_at_woche_warn2.Text = cMonitoringBrg.brgusrset_gvvAt_woche_warn2

        txtBrgVV_at_imex_summe.Text = cMonitoringBrg.brgusrset_gvvAt_imex_de_summe
        txtBrgVV_at_imex_tag_warn1.Text = cMonitoringBrg.brgusrset_gvvAt_imex_tag_warn1
        txtBrgVV_at_imex_tag_warn2.Text = cMonitoringBrg.brgusrset_gvvAt_imex_tag_warn2
        txtBrgVV_at_imex_woche_warn1.Text = cMonitoringBrg.brgusrset_gvvAt_imex_woche_warn1
        txtBrgVV_at_imex_woche_warn2.Text = cMonitoringBrg.brgusrset_gvvAt_imex_woche_warn2


        txtAufschub_de_VeragAG_summe.Text = cMonitoringBrg.brgusrset_aufschub_AG_de_summe
        txtAufschub_de_VeragAG_warn1.Text = cMonitoringBrg.brgusrset_aufschub_AG_de_warn1
        txtAufschub_de_VeragAG_warn2.Text = cMonitoringBrg.brgusrset_aufschub_AG_de_warn2

        txtAufschub_at_VeragAG_summe.Text = cMonitoringBrg.brgusrset_aufschub_AG_at_summe
        txtAufschub_at_VeragAG_warn1.Text = cMonitoringBrg.brgusrset_aufschub_AG_at_warn1
        txtAufschub_at_VeragAG_warn2.Text = cMonitoringBrg.brgusrset_aufschub_AG_at_warn2

        txtAufschub_at_VeragZS_summe.Text = cMonitoringBrg.brgusrset_aufschub_ZS_at_summe
        txtAufschub_at_VeragZS_warn1.Text = cMonitoringBrg.brgusrset_aufschub_ZS_at_warn1
        txtAufschub_at_VeragZS_warn2.Text = cMonitoringBrg.brgusrset_aufschub_ZS_at_warn2

        txtAufschub_at_VeragCS_summe.Text = cMonitoringBrg.brgusrset_aufschub_CS_at_summe
        txtAufschub_at_VeragCS_warn1.Text = cMonitoringBrg.brgusrset_aufschub_CS_at_warn1
        txtAufschub_at_VeragCS_warn2.Text = cMonitoringBrg.brgusrset_aufschub_CS_at_warn2

    End Sub
    Sub setFields()
        cMonitoringBrg.brgusrset_gvvDe_summe = getDouble(txtBrgVV_de_summe.Text)
        cMonitoringBrg.brgusrset_gvvDe_tag_warn1 = getDouble(txtBrgVV_de_tag_warn1.Text)
        cMonitoringBrg.brgusrset_gvvDe_tag_warn2 = getDouble(txtBrgVV_de_tag_warn2.Text)
        cMonitoringBrg.brgusrset_gvvDe_woche_warn1 = getDouble(txtBrgVV_de_woche_warn1.Text)
        cMonitoringBrg.brgusrset_gvvDe_woche_warn2 = getDouble(txtBrgVV_de_woche_warn2.Text)

        cMonitoringBrg.brgusrset_gvvAt_summe = getDouble(txtBrgVV_at_summe.Text)
        cMonitoringBrg.brgusrset_gvvAt_tag_warn1 = getDouble(txtBrgVV_at_tag_warn1.Text)
        cMonitoringBrg.brgusrset_gvvAt_tag_warn2 = getDouble(txtBrgVV_at_tag_warn2.Text)
        cMonitoringBrg.brgusrset_gvvAt_woche_warn1 = getDouble(txtBrgVV_at_woche_warn1.Text)
        cMonitoringBrg.brgusrset_gvvAt_woche_warn2 = getDouble(txtBrgVV_at_woche_warn2.Text)

        cMonitoringBrg.brgusrset_gvvAt_imex_de_summe = txtBrgVV_at_imex_summe.Text
        cMonitoringBrg.brgusrset_gvvAt_imex_tag_warn1 = txtBrgVV_at_imex_tag_warn1.Text
        cMonitoringBrg.brgusrset_gvvAt_imex_tag_warn2 = txtBrgVV_at_imex_tag_warn2.Text
        cMonitoringBrg.brgusrset_gvvAt_imex_woche_warn1 = txtBrgVV_at_imex_woche_warn1.Text
        cMonitoringBrg.brgusrset_gvvAt_imex_woche_warn2 = txtBrgVV_at_imex_woche_warn2.Text

        cMonitoringBrg.brgusrset_aufschub_AG_de_summe = getDouble(txtAufschub_de_VeragAG_summe.Text)
        cMonitoringBrg.brgusrset_aufschub_AG_de_warn1 = getDouble(txtAufschub_de_VeragAG_warn1.Text)
        cMonitoringBrg.brgusrset_aufschub_AG_de_warn2 = getDouble(txtAufschub_de_VeragAG_warn2.Text)

        cMonitoringBrg.brgusrset_aufschub_AG_at_summe = getDouble(txtAufschub_at_VeragAG_summe.Text)
        cMonitoringBrg.brgusrset_aufschub_AG_at_warn1 = getDouble(txtAufschub_at_VeragAG_warn1.Text)
        cMonitoringBrg.brgusrset_aufschub_AG_at_warn2 = getDouble(txtAufschub_at_VeragAG_warn2.Text)

        cMonitoringBrg.brgusrset_aufschub_ZS_at_summe = getDouble(txtAufschub_at_VeragZS_summe.Text)
        cMonitoringBrg.brgusrset_aufschub_ZS_at_warn1 = getDouble(txtAufschub_at_VeragZS_warn1.Text)
        cMonitoringBrg.brgusrset_aufschub_ZS_at_warn2 = getDouble(txtAufschub_at_VeragZS_warn2.Text)

        cMonitoringBrg.brgusrset_aufschub_CS_at_summe = getDouble(txtAufschub_at_VeragCS_summe.Text)
        cMonitoringBrg.brgusrset_aufschub_CS_at_warn1 = getDouble(txtAufschub_at_VeragCS_warn1.Text)
        cMonitoringBrg.brgusrset_aufschub_CS_at_warn2 = getDouble(txtAufschub_at_VeragCS_warn2.Text)
    End Sub

    Sub setFields_UserSettings()
        setProperty("txtBrgVV_de_tag_warn1", txtBrgVV_de_tag_warn1.Text)
        setProperty("txtBrgVV_de_tag_warn2", txtBrgVV_de_tag_warn2.Text)
        setProperty("txtBrgVV_de_woche_warn1", txtBrgVV_de_woche_warn1.Text)
        setProperty("txtBrgVV_de_woche_warn2", txtBrgVV_de_woche_warn2.Text)
        setProperty("txtBrgVV_at_tag_warn1", txtBrgVV_at_tag_warn1.Text)
        setProperty("txtBrgVV_at_tag_warn2", txtBrgVV_at_tag_warn2.Text)
        setProperty("txtBrgVV_at_woche_warn1", txtBrgVV_at_woche_warn1.Text)
        setProperty("txtBrgVV_at_woche_warn2", txtBrgVV_at_woche_warn2.Text)
        setProperty("txtAufschub_de_VeragAG_warn1", txtAufschub_de_VeragAG_warn1.Text)
        setProperty("txtAufschub_de_VeragAG_warn2", txtAufschub_de_VeragAG_warn2.Text)
        setProperty("txtAufschub_at_VeragAG_warn1", txtAufschub_at_VeragAG_warn1.Text)
        setProperty("txtAufschub_at_VeragAG_warn2", txtAufschub_at_VeragAG_warn2.Text)
        setProperty("txtAufschub_at_VeragZS_warn1", txtAufschub_at_VeragZS_warn1.Text)
        setProperty("txtAufschub_at_VeragZS_warn2", txtAufschub_at_VeragZS_warn2.Text)
        setProperty("txtAufschub_at_VeragCS_warn1", txtAufschub_at_VeragCS_warn1.Text)
        setProperty("txtAufschub_at_VeragCS_warn2", txtAufschub_at_VeragCS_warn2.Text)


        setProperty("txtBrgVV_at_imex_tag_warn1", txtBrgVV_at_imex_tag_warn1.Text)
        setProperty("txtBrgVV_at_imex_tag_warn2", txtBrgVV_at_imex_tag_warn2.Text)
        setProperty("txtBrgVV_at_imex_woche_warn1", txtBrgVV_at_imex_woche_warn1.Text)
        setProperty("txtBrgVV_at_imex_woche_warn2", txtBrgVV_at_imex_woche_warn2.Text)
    End Sub

    Sub getFields_UserSettings()
        For Each c In Me.Controls
            If c.GetType.Name = "TextBox" Then
                If getProperty(c.Name) <> "" Then c.text = getProperty(c.Name)
            End If
        Next
    End Sub
    Function getDouble(s As String) As Double
        Try
            Return CDbl(s)
        Catch
            Return 0.0
        End Try
    End Function
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        setFields_UserSettings()
    End Sub

    Private Sub frmSettings_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        Me.Top = My.Computer.Screen.WorkingArea.Height - Me.Height
        Me.Left = My.Computer.Screen.WorkingArea.Width - Me.Width
        initWaehrung()
    End Sub
    Sub initWaehrung()
        For Each c In Me.Controls
            If c.GetType.Name = "TextBox" Then
                Try : DirectCast(c, TextBox).Text = String.Format("{0:C}", CDbl(DirectCast(c, TextBox).Text)) : Catch : End Try
            End If
        Next
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Close()
        frmMain.Show()
    End Sub


    Private Sub txtAtTag_atlas_TextChanged(sender As Object, e As EventArgs) Handles txtBrgVV_de_summe.LostFocus, txtBrgVV_de_tag_warn1.LostFocus, txtBrgVV_de_tag_warn2.LostFocus, txtBrgVV_de_woche_warn1.LostFocus, txtBrgVV_de_woche_warn2.LostFocus, txtBrgVV_at_summe.LostFocus, txtBrgVV_at_tag_warn1.LostFocus, txtBrgVV_at_tag_warn2.LostFocus, txtBrgVV_at_woche_warn1.LostFocus, txtBrgVV_at_woche_warn2.LostFocus, txtAufschub_de_VeragAG_summe.LostFocus, txtAufschub_de_VeragAG_warn1.LostFocus, txtAufschub_de_VeragAG_warn2.LostFocus, txtAufschub_at_VeragAG_summe.LostFocus, txtAufschub_at_VeragAG_warn1.LostFocus, txtAufschub_at_VeragAG_warn2.LostFocus, txtAufschub_at_VeragZS_summe.LostFocus, txtAufschub_at_VeragZS_warn1.LostFocus, txtAufschub_at_VeragZS_warn2.LostFocus, txtAufschub_at_VeragCS_summe.LostFocus, txtAufschub_at_VeragCS_warn1.LostFocus, txtAufschub_at_VeragCS_warn2.LostFocus,
             txtBrgVV_at_imex_summe.LostFocus, txtBrgVV_at_imex_tag_warn1.LostFocus, txtBrgVV_at_imex_tag_warn2.LostFocus, txtBrgVV_at_imex_woche_warn1.LostFocus, txtBrgVV_at_imex_woche_warn2.LostFocus
        If sender.Text <> "" Then Try : sender.Text = String.Format("{0:C}", CDbl(sender.Text)) : Catch : End Try
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles btnSaveToDB.Click
        setFields()
        BRG.setMonitoringData(cMonitoringBrg)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        cMonitoringBrg = BRG.getMonitoringData()
        initFields()
        initWaehrung()
    End Sub
End Class