' Copyright (C) 2025  P4pillon.org
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as
' published by the Free Software Foundation, either version 3 of the
' License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program.  If not, see <https://www.gnu.org/licenses/>.
Public Class Mes_Couleurs

    Public Picked_Color As Color
 
   



    Private Sub panel_Click(sender As Object, e As EventArgs) Handles Comptoir_1.Click, Comptoir_2.Click, Comptoir_3.Click, Comptoir_4.Click
        Bandeau_info_bas_show("Choix couleur fond")
        Try
            set_a_panel_color(sender.name)
        Catch ex As Exception
        End Try
        Bandeau_info_bas_hide()
    End Sub

    Public Sub set_a_panel_color(ByVal Color_Item As String)
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, Color_Item)
        Mes_Couleurs_selecteur.ShowDialog()
        Me.ColorsTableAdapter.Insert(current_User.ID, Color_Item, Picked_Color.Name)
        Load_Config()
    End Sub
    Public Sub Set_Container_backcolor(ByVal Container As Control, ByVal clr As Color)
        Container.BackColor = clr
        'For Each truc As Control In Container.Controls
        '    Try
        '        truc.BackColor = clr
        '    Catch ex As Exception
        '    End Try
        'Next
    End Sub

    Public Sub Set_Container_Labels_Color(ByVal Container As Control, ByVal clr As Color)
        Container.ForeColor = clr
        For Each truc As Control In Container.Controls
            Try
                'If truc.GetType.ToString = "System.Windows.Forms.TextBox" Then
                '    Dim truc2 = CType(truc, System.Windows.Forms.TextBox)
                '    truc2.ForeColor = clr
                If truc.GetType.ToString = "System.Windows.Forms.Label" Then
                    Dim truc2 = CType(truc, System.Windows.Forms.Label)
                    truc2.ForeColor = clr
                ElseIf truc.GetType.ToString = "System.Windows.Forms.LinkLabel" Then
                    Dim truc2 = CType(truc, System.Windows.Forms.LinkLabel)
                    truc2.LinkColor = clr


                End If
            Catch ex As Exception
            End Try
        Next
    End Sub
    Public Sub Set_Container_Textbox_BackColor(ByVal Container As Control, ByVal clr As Color)
        For Each truc As Control In Container.Controls
            Try
                If truc.GetType.ToString = "System.Windows.Forms.TextBox" Then
                    Dim truc2 = CType(truc, System.Windows.Forms.TextBox)
                    truc2.BackColor = clr
                ElseIf truc.GetType.ToString = "System.Windows.Forms.MaskedTextBox" Then
                    Dim truc2 = CType(truc, System.Windows.Forms.MaskedTextBox)
                    truc2.BackColor = clr
                End If
            Catch ex As Exception
            End Try
        Next
    End Sub
    Public Sub Set_Container_Textbox_ForeColor(ByVal Container As Control, ByVal clr As Color)
        For Each truc As Control In Container.Controls
            Try
                If truc.GetType.ToString = "System.Windows.Forms.TextBox" Then
                    Dim truc2 = CType(truc, System.Windows.Forms.TextBox)
                    truc2.ForeColor = clr
                End If
            Catch ex As Exception
            End Try
        Next
    End Sub
    Public Sub Load_Config()

        Reinit_MyMsgBoxColors()
        Dim data = Me.ColorsTableAdapter.GetDataBy_ID_User(current_User.ID)
        For r = 0 To data.Rows.Count - 1
            If data(r).Color_Item = "Comptoir_1" Then
                COMPTOIR_MAIN.BackColor = Color.FromName(data(r).Color_Name)
                COMPTOIR_MAIN.Dates_Label.BackColor = Color.FromName(data(r).Color_Name)
                Set_Container_backcolor(COMPTOIR_MAIN.AssuréGroupBox, Color.FromName(data(r).Color_Name))
                Set_Container_backcolor(COMPTOIR_MAIN.Détail_Bénéficiaire_Panel, Color.FromName(data(r).Color_Name))
                COMPTOIR_MAIN.Vente.BackgroundColor = Color.FromName(data(r).Color_Name)
                Set_Container_backcolor(COMPTOIR_MAIN.Panel_Facturation, Color.FromName(data(r).Color_Name))
                Set_Container_backcolor(Comptoir_1, Color.FromName(data(r).Color_Name))


            ElseIf data(r).Color_Item = "Comptoir_2" Then
                Set_Container_backcolor(COMPTOIR_MAIN.Panel1, Color.FromName(data(r).Color_Name))
                Set_Container_backcolor(COMPTOIR_MAIN.Panel_Prescripteur, Color.FromName(data(r).Color_Name))
                Set_Container_backcolor(Comptoir_2, Color.FromName(data(r).Color_Name))

            ElseIf data(r).Color_Item = "Comptoir_3" Then
                Set_Container_backcolor(COMPTOIR_MAIN.Commandes_Panel, Color.FromName(data(r).Color_Name))
                Set_Container_backcolor(Comptoir_3, Color.FromName(data(r).Color_Name))

            ElseIf data(r).Color_Item = "Comptoir_4" Then
                COMPTOIR_MAIN.MenuStrip1.BackColor = Color.FromName(data(r).Color_Name)
                For Each c As ToolStripMenuItem In COMPTOIR_MAIN.MenuStrip1.Items
                    c.BackColor = Color.FromName(data(r).Color_Name)
                    If TypeOf (c) Is ToolStripMenuItem Then
                        For Each menu As ToolStripItem In DirectCast(c, ToolStripMenuItem).DropDownItems
                            menu.BackColor = Color.FromName(data(r).Color_Name)
                        Next
                    End If
                Next
                Comptoir_4.BackColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Comptoir_1_label" Then
                Set_Container_Labels_Color(COMPTOIR_MAIN.AssuréGroupBox, Color.FromName(data(r).Color_Name))
                Set_Container_Labels_Color(COMPTOIR_MAIN.Détail_Bénéficiaire_Panel, Color.FromName(data(r).Color_Name))
                Set_Container_Labels_Color(COMPTOIR_MAIN.Panel_Facturation, Color.FromName(data(r).Color_Name))
                Comptoir_1_label.LinkColor = Color.FromName(data(r).Color_Name)
                COMPTOIR_MAIN.Dates_Label.ForeColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Comptoir_2_label" Then
                Set_Container_Labels_Color(COMPTOIR_MAIN.Panel1, Color.FromName(data(r).Color_Name))
                Set_Container_Labels_Color(COMPTOIR_MAIN.Panel_Prescripteur, Color.FromName(data(r).Color_Name))
                Comptoir_2_label.LinkColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Comptoir_3_label" Then
                Set_Container_Labels_Color(COMPTOIR_MAIN.Commandes_Panel, Color.FromName(data(r).Color_Name))
                Comptoir_3_label.LinkColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Comptoir_4_label" Then
                For Each c As ToolStripMenuItem In COMPTOIR_MAIN.MenuStrip1.Items
                    c.ForeColor = Color.FromName(data(r).Color_Name)
                    If TypeOf (c) Is ToolStripMenuItem Then
                        For Each menu As ToolStripItem In DirectCast(c, ToolStripMenuItem).DropDownItems
                            menu.ForeColor = Color.FromName(data(r).Color_Name)
                        Next
                    End If
                Next
                Comptoir_4_label.LinkColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Comptoir_1_TextBox_Forecolor" Then
                Set_Container_Textbox_ForeColor(COMPTOIR_MAIN.AssuréGroupBox, Color.FromName(data(r).Color_Name))
                Set_Container_Textbox_ForeColor(COMPTOIR_MAIN.Détail_Bénéficiaire_Panel, Color.FromName(data(r).Color_Name))
                Set_Container_Textbox_ForeColor(COMPTOIR_MAIN.Panel_Facturation, Color.FromName(data(r).Color_Name))
                Comptoir_1_TextBox.ForeColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Comptoir_2_TextBox_Forecolor" Then
                Set_Container_Textbox_ForeColor(COMPTOIR_MAIN.Panel1, Color.FromName(data(r).Color_Name))
                Set_Container_Textbox_ForeColor(COMPTOIR_MAIN.Panel_Prescripteur, Color.FromName(data(r).Color_Name))
                Comptoir_2_TextBox.ForeColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Comptoir_1_TextBox_Backcolor" Then
                Set_Container_Textbox_BackColor(COMPTOIR_MAIN.AssuréGroupBox, Color.FromName(data(r).Color_Name))
                Set_Container_Textbox_BackColor(COMPTOIR_MAIN.Détail_Bénéficiaire_Panel, Color.FromName(data(r).Color_Name))
                Set_Container_Textbox_BackColor(COMPTOIR_MAIN.Panel_Facturation, Color.FromName(data(r).Color_Name))
                Comptoir_1_TextBox.BackColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Comptoir_2_TextBox_Backcolor" Then
                Set_Container_Textbox_BackColor(COMPTOIR_MAIN.Panel1, Color.FromName(data(r).Color_Name))
                Set_Container_Textbox_BackColor(COMPTOIR_MAIN.Panel_Prescripteur, Color.FromName(data(r).Color_Name))
                Comptoir_2_TextBox.BackColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "MyMsgBox_Panel" Then
                MyMsg_Box.BackColor = Color.FromName(data(r).Color_Name)
                MyInptBox.BackColor = Color.FromName(data(r).Color_Name)
                MyMsg_Box.Title_Label.BackColor = Color.FromName(data(r).Color_Name)
                MyInptBox.Title_Label.BackColor = Color.FromName(data(r).Color_Name)
                MyMsgBox_Panel.BackColor = Color.FromName(data(r).Color_Name)
                MyMsgBox_Title_Label.BackColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "MyMsgBox_Button_Forecolor" Then
                MyMsg_Box.ONE_Button.ForeColor = Color.FromName(data(r).Color_Name)
                MyMsg_Box.TWO_Button.ForeColor = Color.FromName(data(r).Color_Name)
                MyMsg_Box.THREE_Button.ForeColor = Color.FromName(data(r).Color_Name)
                MyInptBox.OK_Button.ForeColor = Color.FromName(data(r).Color_Name)
                MyMsgBox_Button.ForeColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "MyMsgBox_Button_Backcolor" Then
                MyMsg_Box.ONE_Button.BackColor = Color.FromName(data(r).Color_Name)
                MyMsg_Box.TWO_Button.BackColor = Color.FromName(data(r).Color_Name)
                MyMsg_Box.THREE_Button.BackColor = Color.FromName(data(r).Color_Name)
                MyInptBox.OK_Button.BackColor = Color.FromName(data(r).Color_Name)
                MyMsgBox_Button.BackColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "MyMsgBox_RichTextBox_Forecolor" Then
                MyMsg_Box.RichTextBox1.ForeColor = Color.FromName(data(r).Color_Name)
                MyInptBox.RichTextBox1.ForeColor = Color.FromName(data(r).Color_Name)
                MyMsgBox_RichTextBox.ForeColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "MyMsgBox_RichTextBox_Backcolor" Then
                MyMsg_Box.RichTextBox1.BackColor = Color.FromName(data(r).Color_Name)
                MyInptBox.RichTextBox1.BackColor = Color.FromName(data(r).Color_Name)
                MyMsgBox_RichTextBox.BackColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "MyMsgBox_Title_Label" Then
                MyMsg_Box.Title_Label.ForeColor = Color.FromName(data(r).Color_Name)
                MyInptBox.Title_Label.ForeColor = Color.FromName(data(r).Color_Name)
                MyMsgBox_Title_Label.ForeColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Bandeau_Info_bas" Then
                'couleur chargée en Bandeau_info_bas2_Load
                Bandeau_Info_bas.BackColor = Color.FromName(data(r).Color_Name)

            ElseIf data(r).Color_Item = "Bandeau_Info_bas_label" Then
                'couleur chargée en Bandeau_info_bas2_Load
                Bandeau_Info_bas_label.LinkColor = Color.FromName(data(r).Color_Name)
            End If
        Next
    End Sub





    Private Sub LinkLabel_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Comptoir_1_label.LinkClicked, Comptoir_2_label.LinkClicked, Comptoir_3_label.LinkClicked, Comptoir_4_label.LinkClicked
        Bandeau_info_bas_show("Choix couleurs label")
        Try
            set_a_Text_color(sender.name)
        Catch ex As Exception
        End Try
        Bandeau_info_bas_hide()
    End Sub
    Public Sub set_a_Text_color(ByVal Color_Item As String)
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, Color_Item)
        Mes_Couleurs_selecteur.ShowDialog()
        Me.ColorsTableAdapter.Insert(current_User.ID, Color_Item, Picked_Color.Name)
        Load_Config()
    End Sub

    Private Sub Mes_Couleurs_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        round2(Bandeau_Info_bas)
        ID_User_Label.Text = current_User.ID
        Load_Config()
    End Sub

    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_1")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_2")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_3")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_4")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_1_label")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_2_label")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_3_label")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_4_label")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_1_Forecolor")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_2_Forecolor")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_1_Backcolor")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Comptoir_2_Backcolor")
    End Sub

    Private Sub TextBox_Click(sender As Object, e As EventArgs) Handles Comptoir_1_TextBox.Click, Comptoir_2_TextBox.Click
        Bandeau_info_bas_show("Choix couleurs zone de texte")
        Try
            MyMsg_Box.Presentation("Officine ?", "Choix couleur texte ?", True, "Oui", True, "Non", False, "")
            If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
                set_a_Text_color(sender.name & "_Forecolor")
            End If
            MyMsg_Box.Presentation("Officine ?", "Choix couleur fond de texte ?", True, "Oui", True, "Non", False, "")
            If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
                set_a_Text_color(sender.name & "_Backcolor")
            End If
        Catch ex As Exception
        End Try
        Bandeau_info_bas_hide()
    End Sub




    Private Sub MyMsgBox_Title_Label_Click(sender As Object, e As EventArgs) Handles MyMsgBox_Title_Label.Click
        Bandeau_info_bas_show("Choix couleurs label")
        Try
            set_a_Text_color(sender.name)
        Catch ex As Exception
        End Try
        Bandeau_info_bas_hide()
    End Sub

    Private Sub MyMsgBox_RichTextBox_Click(sender As Object, e As EventArgs) Handles MyMsgBox_RichTextBox.Click
        Bandeau_info_bas_show("Choix couleurs zone de texte")
        Try
            MyMsg_Box.Presentation("Officine ?", "Choix couleur texte ?", True, "Oui", True, "Non", False, "")
            If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
                set_a_Text_color(sender.name & "_Forecolor")
            End If
            MyMsg_Box.Presentation("Officine ?", "Choix couleur fond de texte ?", True, "Oui", True, "Non", False, "")
            If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
                set_a_Text_color(sender.name & "_Backcolor")
            End If
        Catch ex As Exception
        End Try
        Bandeau_info_bas_hide()
    End Sub

    Private Sub MyMsgBox_Panel_Click(sender As Object, e As EventArgs) Handles MyMsgBox_Panel.Click
        Bandeau_info_bas_show("Choix couleur fond")
        Try
            set_a_panel_color(sender.name)
        Catch ex As Exception
        End Try
        Bandeau_info_bas_hide()
    End Sub






    Private Sub MyMsgBox_Button_Click(sender As Object, e As EventArgs) Handles MyMsgBox_Button.Click
        Bandeau_info_bas_show("Choix couleurs boutons")
        Try
            MyMsg_Box.Presentation("Officine ?", "Choix couleur texte ?", True, "Oui", True, "Non", False, "")
            If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
                set_a_Text_color(sender.name & "_Forecolor")
            End If
            MyMsg_Box.Presentation("Officine ?", "Choix couleur fond de texte ?", True, "Oui", True, "Non", False, "")
            If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
                set_a_Text_color(sender.name & "_Backcolor")
            End If
        Catch ex As Exception
        End Try
        Bandeau_info_bas_hide()
    End Sub

    Private Sub LinkLabel2_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "MyMsgBox_Panel")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "MyMsgBox_Button_Forecolor")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "MyMsgBox_Button_Backcolor")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "MyMsgBox_RichTextBox_Forecolor")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "MyMsgBox_RichTextBox_Backcolor")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "MyMsgBox_Title_Label")


    End Sub

    Private Sub Bandeau_Info_bas_Click(sender As Object, e As EventArgs) Handles Bandeau_Info_bas.Click
        Bandeau_info_bas_show("Choix couleur fond")
        Try
            set_a_panel_color(sender.name)
        Catch ex As Exception
        End Try
        Bandeau_info_bas_hide()
    End Sub

    Private Sub LinkLabel3_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Bandeau_Info_bas_label.LinkClicked
        Bandeau_info_bas_show("Choix couleurs texte")
        Try
            set_a_Text_color(sender.name)
        Catch ex As Exception
        End Try
        Bandeau_info_bas_hide()
    End Sub

    Private Sub LinkLabel4_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel4.LinkClicked
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Bandeau_Info_bas")
        Me.ColorsTableAdapter.Delete_Item(current_User.ID, "Bandeau_Info_bas_label")
    End Sub

    Public Sub Reinit_MyMsgBoxColors()
        MyMsg_Box.Title_Label.ForeColor = Color.YellowGreen
        MyMsg_Box.Title_Label.BackColor = Color.FromArgb(70, 70, 70)
        MyMsg_Box.BackColor = Color.FromArgb(70, 70, 70)
        MyMsg_Box.RichTextBox1.ForeColor = Color.Black
        MyMsg_Box.RichTextBox1.BackColor = Color.White
        MyMsg_Box.ONE_Button.BackColor = Color.DarkCyan
        MyMsg_Box.ONE_Button.ForeColor = Color.White
        MyMsg_Box.TWO_Button.BackColor = Color.DarkCyan
        MyMsg_Box.TWO_Button.ForeColor = Color.White
        MyMsg_Box.THREE_Button.BackColor = Color.DarkCyan
        MyMsg_Box.THREE_Button.ForeColor = Color.White
        MyInptBox.Title_Label.ForeColor = Color.YellowGreen
        MyInptBox.Title_Label.BackColor = Color.FromArgb(70, 70, 70)
        MyInptBox.BackColor = Color.FromArgb(70, 70, 70)
        MyInptBox.RichTextBox1.ForeColor = Color.Black
        MyInptBox.RichTextBox1.BackColor = Color.White
        MyInptBox.OK_Button.BackColor = Color.DarkCyan
        MyInptBox.OK_Button.ForeColor = Color.White
    End Sub

    Private Sub ComboBox1_Click(sender As Object, e As EventArgs) Handles ComboBox1.Click
        ComboBox1.Items.Clear()

        Dim themes = Me.ColorsTableAdapter.enum_themes
        For r = 0 To themes.Rows.Count - 1
            ComboBox1.Items.Add(Mid(themes(r).ID_User, 1, InStr(themes(r).ID_User, "@THEME") - 1))

        Next

    End Sub

 
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim data = Me.ColorsTableAdapter.GetDataBy_ID_User(ComboBox1.SelectedItem.ToString & "@THEME")
        Me.ColorsTableAdapter.Delete_ID_User(current_User.ID)
        For r = 0 To data.Rows.Count - 1
            Me.ColorsTableAdapter.Insert(current_User.ID, data(r).Color_Item, data(r).Color_Name)
        Next
        Load_Config()
    End Sub
End Class