Public Class frmEnrobage

    Private Sub frmEnrobage_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call affichage()
    End Sub
    Private Sub frmEnrobage_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing

    End Sub
    Private Sub Affichage()
        With Beton
            'condition d'environnement
            Select Case .EN206
                Case 1
                    RbtnEN206_2004.Checked = True
                Case 2
                    RbtnEN206_2022.Checked = True
            End Select
            If .X0_ClassExpo = True Then
                ChkbX0.Checked = True
            Else
                If .XC1 = True Then RbtnXc1.Checked = True
                If .XC2 = True Then RbtnXc2.Checked = True
                If .XC3 = True Then RbtnXc3.Checked = True
                If .XC4 = True Then RbtnXc4.Checked = True
                If .XD1 = True Then RbtnXd1.Checked = True
                If .XD2 = True Then RbtnXd2.Checked = True
                If .XD3 = True Then RbtnXd3.Checked = True
                If .XS1 = True Then RbtnXs1.Checked = True
                If .XS2 = True Then RbtnXs2.Checked = True
                If .XS3 = True Then RbtnXs3.Checked = True
                If .XF1 = True Then RbtnXf1.Checked = True
                If .XF2 = True Then RbtnXf2.Checked = True
                If .XF3 = True Then RbtnXf3.Checked = True
                If .XF4 = True Then RbtnXf4.Checked = True
                If .XA1 = True Then RbtnXa1.Checked = True
                If .XA2 = True Then RbtnXa2.Checked = True
                If .XA3 = True Then RbtnXa3.Checked = True
                If .Sulfates = True Then ChkbSulfate.Checked = True
            End If
            If .OuvrageBP = True Then ChkbOuvrageBP.Checked = True
        End With

    End Sub

    Private Sub BtnCalcul_Click(sender As Object, e As EventArgs) Handles BtnCalcul.Click
        Dim Verif As Boolean = True
        Try
            'lecture des données
            Call Lecture_Formulaire(Verif)
            If Verif = False Then Exit Sub
            Call Calcul_ValeursLimitesBeton(Verif)
            If Verif = False Then Exit Sub
            My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)      'signale la fin des calculs
            Call Affichage_Resultat()
        Catch ex As Exception
            MessageBox.Show("Erreur: " & Environment.NewLine & ex.Message & Environment.NewLine & ex.StackTrace, "Calcul valeurs limites classes d'exposition", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub Affichage_Resultat()
        Dim msg As String = String.Empty
        'writer de sortie du RTF
        Dim sw As New System.IO.StringWriter
        'crée un writer de RTF avec une police par défaut
        Dim rtf As New To_Rtf.RtfAnsiTextWriter(sw, New Font(FontFamily.GenericSerif, 12, FontStyle.Regular))
        Call Affichage_Exigences_EN206_1(msg, rtf) 'le rtf ne sert à rien mais je ne sais pas le mettre en optional       
        TxtAffichage.Text = msg
    End Sub

    Private Sub ChkbX0_CheckedChanged(sender As Object, e As EventArgs) Handles ChkbX0.CheckedChanged
        If ChkbX0.Checked = True Then
            RbtnXc1.Checked = False
            RbtnXc2.Checked = False
            RbtnXc3.Checked = False
            RbtnXc4.Checked = False
            RbtnXd1.Checked = False
            RbtnXd2.Checked = False
            RbtnXd3.Checked = False
            RbtnXs1.Checked = False
            RbtnXs2.Checked = False
            RbtnXs3.Checked = False
            RbtnXf1.Checked = False
            RbtnXf2.Checked = False
            RbtnXf3.Checked = False
            RbtnXf4.Checked = False
            RbtnXa1.Checked = False
            RbtnXa2.Checked = False
            RbtnXa3.Checked = False
            GbCarbo.Enabled = False
            GBChimique.Enabled = False
            GbChlorure.Enabled = False
            GbGel.Enabled = False
            GbMer.Enabled = False
        Else
            GbCarbo.Enabled = True
            GBChimique.Enabled = True
            GbChlorure.Enabled = True
            GbGel.Enabled = True
            GbMer.Enabled = True
        End If
    End Sub



    Private Sub BtnHlpEnrobageProjet_Click(sender As Object, e As EventArgs) Handles BtnHlpEnrobageProjet.Click
        Dim frm1 As frmAide
        frm1 = New frmAide
        Aff.FichierAide = 19
        frm1.Show()
    End Sub


    ''' <summary>Lecture des données renseignées du formulaire</summary>
    ''' <param name="Verif">Renvoi False si pb d'exécution du programme</param>
    Private Sub Lecture_Formulaire(ByRef Verif As Boolean)
        With Beton
            Dim Coche_Expo As Boolean = False
            If RbtnEN206_2004.Checked = True Then .EN206 = 1
            If RbtnEN206_2022.Checked = True Then .EN206 = 2
            If ChkbOuvrageBP.Checked = True Then .OuvrageBP = True Else .OuvrageBP = False
            If ChkbX0.Checked = True Then
                .X0_ClassExpo = True : Coche_Expo = True
            Else
                If RbtnXc1.Checked = True Then .XC1 = True : Coche_Expo = True Else .XC1 = False
                If RbtnXc2.Checked = True Then .XC2 = True : Coche_Expo = True Else .XC2 = False
                If RbtnXc3.Checked = True Then .XC3 = True : Coche_Expo = True Else .XC3 = False
                If RbtnXc4.Checked = True Then .XC4 = True : Coche_Expo = True Else .XC4 = False
                If RbtnXd1.Checked = True Then .XD1 = True : Coche_Expo = True Else .XD1 = False
                If RbtnXd2.Checked = True Then .XD2 = True : Coche_Expo = True Else .XD2 = False
                If RbtnXd3.Checked = True Then .XD3 = True : Coche_Expo = True Else .XD3 = False
                If RbtnXs1.Checked = True Then .XS1 = True : Coche_Expo = True Else .XS1 = False
                If RbtnXs2.Checked = True Then .XS2 = True : Coche_Expo = True Else .XS2 = False
                If RbtnXs3.Checked = True Then .XS3 = True : Coche_Expo = True Else .XS3 = False
                If RbtnXf1.Checked = True Then .XF1 = True : Coche_Expo = True Else .XF1 = False
                If RbtnXf2.Checked = True Then .XF2 = True : Coche_Expo = True Else .XF2 = False
                If RbtnXf3.Checked = True Then .XF3 = True : Coche_Expo = True Else .XF3 = False
                If RbtnXf4.Checked = True Then .XF4 = True : Coche_Expo = True Else .XF4 = False
                If RbtnXa1.Checked = True Then .XA1 = True : Coche_Expo = True Else .XA1 = False
                If RbtnXa2.Checked = True Then .XA2 = True : Coche_Expo = True Else .XA2 = False
                If RbtnXa3.Checked = True Then .XA3 = True : Coche_Expo = True Else .XA3 = False
                If ChkbSulfate.Checked = True Then .Sulfates = True Else .Sulfates = False
            End If
            If .EN206 = 0 Then
                MessageBox.Show("La référence de prise en compte de la durabilité via l'EN206-1 n'a pas été indiquée !", "Module lecture de données", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Verif = False
            End If
            If Coche_Expo = False Then
                MessageBox.Show("Aucune classe d'exposition n'a été cochée !", "Module lecture de données", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Verif = False
            End If
        End With
    End Sub

    Private Sub BtnOK_Click(sender As Object, e As EventArgs) Handles BtnOK.Click
        Dim Verif As Boolean = True
        Try
            Call Lecture_Formulaire(Verif)
            If Verif = False Then Exit Sub
            Call Calcul_ValeursLimitesBeton(Verif)
            If Verif = False Then Exit Sub
            Me.Dispose()
            Me.Finalize()
        Catch ex As Exception
            MessageBox.Show("Erreur: " & Environment.NewLine & ex.Message & Environment.NewLine & ex.StackTrace, "Calcul valeurs limites classes d'exposition", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub BtnAnnuler_Click(sender As Object, e As EventArgs) Handles BtnAnnuler.Click
        Me.Dispose()
        Me.Finalize()
    End Sub

    Private Sub BtnCeribFib_Click(sender As Object, e As EventArgs) Handles BtnCeribFib.Click
        Dim PDFExe As String

        Try
            'Dim KEY As Microsoft.Win32.RegistryKey = My.Computer.Registry.ClassesRoot.OpenSubKey(PDFExe) '"acroPDF.PDF")
            PDFExe = CType(Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\OpenWithList", "C", ""), String)   'récupère le reader par défaut
            If PDFExe Is Nothing Then 'KEY
                MessageBox.Show("Impossible d'accèder au lecteur pdf par défaut!" & Environment.NewLine & "Affichage document Classes d'exposition CERIB FIB annulé.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Exit Sub
            End If
            Dim SousDossier1 As String = My.Application.Info.DirectoryPath 'répertoire dans lequel se trouve le logiciel Poutre BA
            Dim startInfo As New ProcessStartInfo(PDFExe) '"AcroRd32.exe")
            startInfo.WindowStyle = ProcessWindowStyle.Normal
            startInfo.Arguments = SousDossier1 & "\Les Classes d'exposition CERIB FIB.pdf"
            Process.Start(startInfo.Arguments)

        Catch ex As Exception
            Dim msg As String = String.Empty
            msg = "Impossible d'afficher le manuel d'utilisation" & Environment.NewLine & "Exception: " & Environment.NewLine & ex.Message & Environment.NewLine & ex.StackTrace
            MessageBox.Show(msg, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub

    Private Sub BtnEffacer_Click(sender As Object, e As EventArgs) Handles BtnEffacer.Click
        TxtAffichage.Text = ""
    End Sub
End Class