Page 1 sur 2

[Résolu] Comment mettre à jour des optionGadget

Publié : mer. 25/avr./2018 9:19
par Micoute
Bonjour à tous,

je viens de nouveau m'éclairer à vos savoirs, car j'ai un problème dont je ne trouve pas de solution.

Etant diabétique, il m'arrive d'en rencontrer d'autres et on m'a conseillé d'aller à l'association des diabétiques de la Manche, jusqu'à là c'est du bla bla.
Le problème, si ça en est un, c'est que j'ai dit que je faisais des programmes avec mon ordinateur, on m'a donc proposé d'en fabriquer un pour aider les gens qui ignorent qu'ils le sont.

Le soucis est que si on veut modifier des données déjà saisies, pour les StringGadget pas de soucis, mais les OptionGadget et CheckBoxGadget, la c'est plus compliqué, si je fais un Debug Diabete_Connu, j'ai la réponse Oui ou Non,
mais si je marque Select Patients()\Diabete_connu : Case "Oui" : SetGadgetState(#Opt_Diab_Connu_Oui, #True) : Case "Non" : SetGadgetState(#Opt_Diab_Connu_non, #True) : EndSelect, ça ne fonctionne pas, idem pour les boites à cocher.

C'est pourquoi je me tourne vers vous pour bénéficier de votre aide bienveillante et je vous en remercie beaucoup.

la base de donnée est fabriquée par le programme.

Code : Tout sélectionner

;fiche générale de saisie
;par Micoute
;commencé le 23/03/2018
;avec PB 5.62 (x86) et Windows 10 (x64)

Enumeration Fichiers
  #FichierJSON
EndEnumeration

Enumeration Fenetres
  #Fenetre_saisie
EndEnumeration

Enumeration Gadgets
  #Txt_Titre
  #Txt_Age
  #Txt_Glyc
  #Txt_DiabConnu
  #Txt_DernRepas
  #Txt_sex
  #Txt_Pds
  #Txt_Taille
  #Txt_HorLim
  #Txt_Signature
  #Str_Age
  #Str_Glyc
  #Opt_Diab_Connu_non
  #Opt_Diab_Connu_Oui
  #Opt_dern_repas_a_jeun
  #Opt_DernRepasNaJeun04h
  #Opt_DernRepas_Njeun_4h
  #Opt_Sex_H
  #Opt_Sex_F
  #Str_Pds
  #Str_Taille
  #Chk_HorLim_oui
  #Chk_HorLim_non
  #Lst_Patients
  #Btn_Nouveau
  #Btn_Maj
  #Btn_Supprimer
  #Btn_Sauvegarder
  #Btn_Quitter
EndEnumeration

Enumeration Polices
  #ArialBlack28
  #Arial12
  #Arial20  
  #Arial25
EndEnumeration

;Structures d'un patient
Structure sPatient
  Age.s
  Glycemie.s
  Diabete_connu.s
  Dernier_repas.s
  Sexe.s
  Poids.s
  Taille.s
  Hors_limite.s
EndStructure

;Cration d'une liste vierge pour les patients
Global NewList Patients.sPatient()
Global Evenement, Brosse
Global.s Fichier_Patients = #PB_Compiler_FilePath + "Bdd\Patients.json"
Global Diabete_connu.s = "", Dernier_repas.s = "", Sexe.s = "", Hors_Limite.s = ""

;Déclaration des traitements
Declare Programme_principal() ;Ouverture de l'application
Declare Charger_Patients()    ;Chargement des patients enregistrés
Declare Gestion_Evenements()  ;Gestionnaire de contrôle de la saisie
Declare Nouveau_Patient()     ;Inscrire un nouveau patient
Declare Selection_Patient()   ;Un patient est sélectionné dans la liste
Declare Supprimer_Patient()   ;Suppression d'un patient
Declare Sauvegarder_Patients();Sauvegarde des patients
Declare Maj_Patient()         ;Gestionnaire de mise à jour des patients
Declare Quitter()             ;Fermeture de l'application
Declare$ Diabete_connu()
Declare$ Dernier_repas()
Declare$ Sexe()
Declare$ Hors_Limite()

Programme_principal()

Procedure myCallback(WindowID, Message, wParam, lParam)
  Shared Brosse
  Resultat = #PB_ProcessPureBasicEvents
  Select Message
    Case #WM_CTLCOLORSTATIC
      SetBkMode_(wParam,#TRANSPARENT)
      Resultat = Brosse
  EndSelect
  ProcedureReturn Resultat
EndProcedure 

Procedure MonOptionCouleur(GADGET,X, Y, L, H, message.s, COUL_FOND, COUL_TXT)
  Brosse = CreateSolidBrush_(COUL_FOND) ;; COULEUR DU FOND
  SetTextColor_(wParam, COUL_TXT)       ;; COULEUR DU TEXTE
                                        ;OptionGadget(GADGET, X, Y, L, H, "")
  
EndProcedure

Procedure Programme_principal()
  If OpenWindow(#Fenetre_saisie, 0, 0, 1050, 870, "AFD 50", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    TextGadget(#Txt_Titre, 10, 10, 1030, 60, UCase("fiche générale de saisie"), #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_Age, 50, 150, 80, 50, "Âge", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_Glyc, 130, 150, 130, 50, "Glycémie mg/dL", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_DiabConnu, 270, 150, 110, 50, "Diabète connu", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_DernRepas, 450, 150, 130, 50, "Dernier repas", #SS_CENTERIMAGE)
    TextGadget(#Txt_sex, 600, 150, 90, 50, "Sexe", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_Pds, 690, 150, 100, 50, "Poids (Kgs)", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_Taille, 790, 150, 90, 50, "Taille (cm)", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_HorLim, 900, 150, 90, 50, "Hors Limite", #PB_Text_Center|#SS_CENTERIMAGE)
    StringGadget(#Str_Age, 50, 80, 80, 60, "")  
    StringGadget(#Str_Glyc, 140, 80, 130, 60, "")
    ctnDiabete = ContainerGadget(#PB_Any, 280, 80, 50, 50)
    OptionGadget(#Opt_Diab_Connu_non, 0, 0, 50, 25, "Non")
    OptionGadget(#Opt_Diab_Connu_Oui, 0, 30, 50, 25, "Oui")
    CloseGadgetList()
    ctnDernRep = ContainerGadget(#PB_Any, 370, 80, 220, 75)
    OptionGadget(#Opt_dern_repas_a_jeun, 0, 0, 150, 25, "à jeun strict")
    OptionGadget(#Opt_DernRepasNaJeun04h, 0, 30, 150, 25, "Non à jeun (0-4H)")
    OptionGadget(#Opt_DernRepas_Njeun_4h, 160, 30, 70, 25, "(+4H)")
    CloseGadgetList()
    CtnSexe = ContainerGadget(#PB_Any, 600, 80, 80, 50)
    OptionGadget(#Opt_Sex_H, 0, 0, 80, 25, "Homme")
    OptionGadget(#Opt_Sex_F, 0, 30, 80, 25, "Femme")
    CloseGadgetList()
    StringGadget(#Str_Pds, 690, 80, 100, 60, "")
    StringGadget(#Str_Taille, 800, 80, 90, 60, "")
    ctnHorLim = ContainerGadget(#PB_Any, 900, 80, 90, 50)
    CheckBoxGadget(#Chk_HorLim_oui, 0, 0, 90, 25, "Oui")
    CheckBoxGadget(#Chk_HorLim_non, 0, 30, 90, 25, "Non")
    CloseGadgetList()
    ListIconGadget(#Lst_Patients, 40, 200, 970, 540, "Âge", 80, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#LVS_NOCOLUMNHEADER)
    AddGadgetColumn(#Lst_Patients, 1, "Glycémie", 130)
    AddGadgetColumn(#Lst_Patients, 2, "Diabète connu", 140)
    AddGadgetColumn(#Lst_Patients, 3, "Dernier repas", 210)
    AddGadgetColumn(#Lst_Patients, 4, "Sexe", 90)
    AddGadgetColumn(#Lst_Patients, 5, "Poids", 100)
    AddGadgetColumn(#Lst_Patients, 6, "Taille", 90)
    AddGadgetColumn(#Lst_Patients, 7, "Hors limite", 90)
    ButtonGadget(#Btn_Nouveau, 40, 750, 190, 40, "Nouveau")
    ButtonGadget(#Btn_Maj, 240, 750, 190, 40, "Mise à jour")
    ButtonGadget(#Btn_Supprimer, 440, 750, 190, 40, "Supprimer")
    ButtonGadget(#Btn_Sauvegarder, 640, 750, 190, 40, "Sauvegarder")
    ButtonGadget(#Btn_Quitter, 840, 750, 170, 40, "Quitter")
    TextGadget(#Txt_Signature, 10, WindowHeight(#Fenetre_saisie) - 70, 1030, 60, "Logiciel crée par MicouteSoft © 2018", #PB_Text_Center|#SS_CENTERIMAGE)
    ; Polices
    LoadFont(#ArialBlack28, "Arial Black", 28, #PB_Font_Bold|#PB_Font_HighQuality)
    LoadFont(#Arial12, "Arial", 12, #PB_Font_Bold|#PB_Font_HighQuality)
    LoadFont(#Arial20, "Arial", 20, #PB_Font_Bold|#PB_Font_HighQuality)
    LoadFont(#Arial25, "Arial", 25, #PB_Font_Bold|#PB_Font_HighQuality)
    SetGadgetFont(#Btn_Nouveau, FontID(#Arial12))
    SetGadgetFont(#Btn_Maj, FontID(#Arial12))
    SetGadgetFont(#Btn_Supprimer, FontID(#Arial12))
    SetGadgetFont(#Btn_Sauvegarder, FontID(#Arial12))
    SetGadgetFont(#Btn_Quitter, FontID(#Arial12))    
    SetGadgetFont(#Txt_Titre, FontID(#ArialBlack28))
    SetGadgetFont(#Txt_Age, FontID(#Arial12))
    SetGadgetFont(#Txt_Glyc, FontID(#Arial12))
    SetGadgetFont(#Txt_DiabConnu, FontID(#Arial12))
    SetGadgetFont(#Txt_DernRepas, FontID(#Arial12))
    SetGadgetFont(#Txt_sex, FontID(#Arial12))
    SetGadgetFont(#Txt_Pds, FontID(#Arial12))
    SetGadgetFont(#Txt_Taille, FontID(#Arial12))
    SetGadgetFont(#Txt_HorLim, FontID(#Arial12))
    SetGadgetFont(#Str_Age, FontID(#ArialBlack28))
    SetGadgetFont(#Str_Glyc, FontID(#ArialBlack28))
    SetGadgetFont(#Str_Pds, FontID(#ArialBlack28))
    SetGadgetFont(#Str_Taille, FontID(#ArialBlack28))
    SetGadgetFont(#Chk_HorLim_oui, FontID(#Arial12))
    SetGadgetFont(#Chk_HorLim_non, FontID(#Arial12))
    SetGadgetFont(#Opt_Diab_Connu_non, FontID(#Arial12))
    SetGadgetFont(#Opt_Diab_Connu_Oui, FontID(#Arial12))
    SetGadgetFont(#Opt_Sex_H, FontID(#Arial12))
    SetGadgetFont(#Opt_Sex_F, FontID(#Arial12))
    SetGadgetFont(#Opt_dern_repas_a_jeun, FontID(#Arial12))
    SetGadgetFont(#Opt_DernRepasNaJeun04h, FontID(#Arial12))
    SetGadgetFont(#Opt_DernRepas_Njeun_4h, FontID(#Arial12))
    SetGadgetFont(#Lst_Patients, FontID(#Arial12))
    For i = #Btn_Nouveau To #Btn_Quitter
      SetGadgetFont(i, FontID(#Arial20))
    Next i  
    SetGadgetFont(#Txt_Signature, FontID(#Arial20))
    ;Couleurs
    SetWindowColor(#Fenetre_saisie, $FC9C91)
    MonOptionCouleur(#Opt_Diab_Connu_non, 280, 130, 50, 25, "Non", GetWindowColor(#Fenetre_saisie), $FDD5D0)
    SetGadgetColor(ctnDiabete, #PB_Gadget_BackColor, GetWindowColor(#Fenetre_saisie))
    SetGadgetColor(ctnDernRep, #PB_Gadget_BackColor, GetWindowColor(#Fenetre_saisie))
    SetGadgetColor(CtnSexe, #PB_Gadget_BackColor, GetWindowColor(#Fenetre_saisie))
    SetGadgetColor(ctnHorLim, #PB_Gadget_BackColor, GetWindowColor(#Fenetre_saisie))
    
    i = #Txt_Titre
    While i <= #Txt_Signature
      SetGadgetColor(i, #PB_Gadget_FrontColor, $B61704)
      i + 1
    Wend
    i = #Str_Age
    While i <= #Chk_HorLim_oui
      SetGadgetColor(i, #PB_Gadget_BackColor, $FDD5D0)
      i + 1
    Wend
    
    SetWindowCallback(@myCallback())
    
    HideGadget(#Str_Age, #True)
    HideGadget(#Str_Glyc, #True)
    HideGadget(#Opt_Diab_Connu_non, #True)
    HideGadget(#Opt_Diab_Connu_Oui, #True)
    HideGadget(#Opt_dern_repas_a_jeun, #True)
    HideGadget(#Opt_DernRepasNaJeun04h, #True)
    HideGadget(#Opt_DernRepas_Njeun_4h, #True)
    HideGadget(#Opt_Sex_H, #True)
    HideGadget(#Opt_Sex_F, #True)
    HideGadget(#Str_Pds, #True)
    HideGadget(#Str_Taille, #True)
    HideGadget(#Chk_HorLim_oui, #True)
    HideGadget(#Chk_HorLim_non, #True)    
    
    HideGadget(#Btn_Supprimer, #True)
    HideGadget(#Btn_Sauvegarder, #True)
    DisableGadget(#Btn_Maj, #True)
    
    ;{ Déclancheurs
    
    ;Contrôle de la saisie (Le nom est obligatoire)
    BindGadgetEvent(#Str_Age, @Gestion_Evenements())
    
    ;Mise en place d'un nouveau contact
    BindGadgetEvent(#Btn_Nouveau, @Nouveau_Patient()) 
    
    ;Un contact est selectionné dans la liste
    BindGadgetEvent(#Lst_Patients, @Selection_Patient())
    
    ;Ajout ou modification d'un contact
    BindGadgetEvent(#Btn_Maj, @Maj_Patient()) 
    
    ;Supression d'un contact
    BindGadgetEvent(#Btn_Supprimer, @Supprimer_Patient()) 
    
    ;Entrer dans le mode saisie
    ;BindGadgetEvent(#Btn_Saisie, @Edition())
    
    ;Fermeture de l'application et sauvegarde des Patients
    ;BindEvent(#PB_Event_CloseWindow, @SauvegardePatients()) 
    BindGadgetEvent(#Btn_Sauvegarder, @Sauvegarder_Patients()) 
    
    ;Fermeture de l'application sans sauvegarder
    BindGadgetEvent(#Btn_Quitter, @Quitter())
    
    ;Lectures des Patients 
    Charger_Patients()
    
    ;L'application est prête pour la saisie d'un contact
    ;Nouveau_Patient()
  EndIf
EndProcedure


;Chargement des patients existants
Procedure Charger_Patients()
  If ReadFile(#FichierJSON, Fichier_Patients)
    CloseFile(#FichierJSON)
    
    ;Lecture du fichier Json
    LoadJSON(#FichierJSON, Fichier_Patients, #PB_JSON_NoCase)
    
    ;Extraction de la chaine JSON vers la liste chaînée Patients
    ExtractJSONList(JSONValue(#FichierJSON), Patients())
    
    ;Affichage de la liste des patients
    ForEach Patients()
      With Patients()
        AddGadgetItem(#Lst_Patients, -1, \Age + #LF$ + \Glycemie + #LF$ + \Diabete_connu + #LF$ + \Dernier_repas + #LF$ + \Sexe + #LF$ + \Poids + #LF$ + \Taille + #LF$ + \Hors_limite)
        SetGadgetItemData(#Lst_Patients, CountGadgetItems(#Lst_Patients)-1, ListIndex(Patients()))
      EndWith
    Next
  EndIf    
EndProcedure
;Gestionnaire de contrôle de la saisie
Procedure Gestion_Evenements()
  Protected Evenement = EventType()
  
  Select Evenement
    Case #PB_EventType_Change
      If Trim(GetGadgetText(#Str_Age)) <> ""
        DisableGadget(#Btn_Nouveau, #False)
        DisableGadget(#Btn_Maj, #False)
      Else
        DisableGadget(#Btn_Nouveau, #True)
        DisableGadget(#Btn_Maj, #True)
      EndIf
  EndSelect    
EndProcedure
;Nouveau patient (remise à zéro des champs de saisie)
Procedure Nouveau_Patient()
  Select EventType()
    Case #PB_EventType_LeftClick
      SetWindowData(#Fenetre_saisie, 0) ;C'est une création
      
      HideGadget(#Str_Age, #False)
      HideGadget(#Str_Glyc, #False)
      HideGadget(#Opt_Diab_Connu_non, #False)
      HideGadget(#Opt_Diab_Connu_Oui, #False)
      HideGadget(#Opt_dern_repas_a_jeun, #False)
      HideGadget(#Opt_DernRepasNaJeun04h, #False)
      HideGadget(#Opt_DernRepas_Njeun_4h, #False)
      HideGadget(#Opt_Sex_H, #False)
      HideGadget(#Opt_Sex_F, #False)
      HideGadget(#Str_Pds, #False)
      HideGadget(#Str_Taille, #False)
      HideGadget(#Chk_HorLim_oui, #False)
      HideGadget(#Chk_HorLim_non, #False)
      
      SetGadgetText(#Str_Age, "")
      SetGadgetText(#Str_Glyc, "")
      SetGadgetState(#Opt_Diab_Connu_non, #False)
      SetGadgetState(#Opt_Diab_Connu_Oui, #False)
      SetGadgetState(#Opt_Sex_H, #False)
      SetGadgetState(#Opt_Sex_F, #False)
      SetGadgetText(#Str_Pds, "")
      SetGadgetText(#Str_Taille, "")
      SetGadgetState(#Chk_HorLim_non, #False)
      SetGadgetState(#Chk_HorLim_oui, #False)
      
      DisableGadget(#Btn_Nouveau, #True)
      DisableGadget(#Btn_Maj, #True)
      DisableGadget(#Btn_Supprimer, #True)
      
      SetGadgetText(#Btn_Maj, "Ajouter")
      SetActiveGadget(#Str_Age)
  EndSelect
EndProcedure
;Un patient est sélectionné dans la liste
Procedure Selection_Patient()
  Select EventType()
    Case #PB_EventType_LeftClick
      Protected Item = GetGadgetState(#Lst_Patients)
      
      If item <> -1
        SelectElement(Patients(), GetGadgetItemData(#Lst_Patients, Item))
        With Patients()
          SetGadgetText(#Str_Age, \Age)
          SetGadgetText(#Str_Glyc, \Glycemie)
          SetGadgetState(#Opt_Diab_Connu_non, #False)
          SetGadgetState(#Opt_Diab_Connu_Oui, #False)
          SetGadgetState(#Opt_dern_repas_a_jeun, #False)
          SetGadgetState(#Opt_DernRepasNaJeun04h, #False)
          SetGadgetState(#Opt_DernRepas_Njeun_4h, #False)
          SetGadgetState(#Opt_Sex_H, #False)
          SetGadgetState(#Opt_Sex_F, #False)
          SetGadgetText(#Str_Pds, "")
          SetGadgetText(#Str_Taille, "")
          SetGadgetState(#Chk_HorLim_non, #False)
          SetGadgetState(#Chk_HorLim_oui, #False)
        EndWith
        HideGadget(#Btn_Supprimer, #False)
      EndIf
      
      ;C'est une modification
      SetWindowData(#Fenetre_saisie, 1)
      
      DisableGadget(#Btn_Nouveau, #False)
      DisableGadget(#Btn_Maj, #False)
      DisableGadget(#Btn_Supprimer, #False)
      
      SetGadgetText(#Btn_Maj, "Modifier")
      SetActiveGadget(#Str_Age)
  EndSelect    
EndProcedure
;Suppression d'un patient
Procedure Supprimer_Patient()
  Select EventType()
    Case #PB_EventType_LeftClick
      If MessageRequester("Information", "Etes vous sûr de supprimer un contact ?" + #CRLF$ + "cette action est irrémédiable !", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
        SetWindowData(#Fenetre_saisie, 3) ;C'est une suppression
        Maj_Patient()
      EndIf
  EndSelect  
EndProcedure
;Gestionnaire de mise à jour des Patients 
Procedure Maj_Patient()
  Select EventType()
    Case #PB_EventType_LeftClick
      Protected.s Age, Glycemie, Diabete_connu, Dernier_repas, Sexe, Poids, Taille, Hors_limite
      
      
      HideGadget(#Str_Age, #True)
      HideGadget(#Str_Glyc, #True)
      HideGadget(#Opt_Diab_Connu_non, #True)
      HideGadget(#Opt_Diab_Connu_Oui, #True)
      HideGadget(#Opt_dern_repas_a_jeun, #True)
      HideGadget(#Opt_DernRepasNaJeun04h, #True)
      HideGadget(#Opt_DernRepas_Njeun_4h, #True)
      HideGadget(#Opt_Sex_H, #True)
      HideGadget(#Opt_Sex_F, #True)
      HideGadget(#Str_Pds, #True)
      HideGadget(#Str_Taille, #True)
      HideGadget(#Chk_HorLim_oui, #True)
      HideGadget(#Chk_HorLim_non, #True)
      
      Age = GetGadgetText(#Str_Age)
      Glycemie = GetGadgetText(#Str_Glyc)
      Diabete_connu = Diabete_connu()
      Dernier_repas = Dernier_repas()
      Sexe = Sexe()
      Poids = GetGadgetText(#Str_Pds)
      Taille = GetGadgetText(#Str_Taille)
      Hors_Limite = Hors_Limite()
      
      HideGadget(#Btn_Sauvegarder, #False)
      
      Select GetWindowData(#Fenetre_saisie)
        Case 0 ;Création d'un contact
          AddElement(Patients())
          With Patients()
            \Age = Age
            \Glycemie = Glycemie
            \Diabete_connu = Diabete_connu
            \Dernier_repas = Dernier_repas
            \Sexe = Sexe
            \Poids = Poids
            \Taille = Taille
            \Hors_limite = Hors_limite
            AddGadgetItem(#Lst_Patients, -1, \Age + #LF$ + \Glycemie + #LF$ + \Diabete_connu + #LF$ +  \Dernier_repas + #LF$ +  \Sexe + #LF$ +  \Poids + #LF$ + \Taille + #LF$ +  \Hors_limite)
            SetGadgetItemData(#Lst_Patients, CountGadgetItems(#Lst_Patients)-1, ListIndex(Patients()))
          EndWith
          
        Case 1 ;Modification d'un contact
          DisableGadget(#Btn_Sauvegarder, #False)
          
          Select Patients()\Diabete_connu
            Case "Oui"
              SetGadgetState(#Opt_Diab_Connu_Oui, #True)
            Case "Non"
              SetGadgetState(#Opt_Diab_Connu_non, #True)
          EndSelect
          
          Select Patients()\Hors_limite
            Case "Oui"
              SetGadgetState(#Chk_HorLim_oui, 1)
            Case "Non"
              SetGadgetState(#Chk_HorLim_non, 1)
          EndSelect    
          
          With Patients()
            \Age = Age
            \Glycemie = Glycemie
            \Diabete_connu = Diabete_connu
            \Dernier_repas = Dernier_repas
            \Sexe = Sexe
            \Poids = Poids
            \Taille = Taille
            \Hors_limite = Hors_limite
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Age, 0)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Glycemie, 1)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Diabete_connu, 2)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Dernier_repas, 3)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Sexe, 4)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Poids, 5)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Taille, 6)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Hors_limite, 7)
          EndWith
          Nouveau_Patient()
          
        Case 3 ;Suppression d'un contact
          RemoveGadgetItem(#Lst_Patients, ListIndex(Patients()))
          DeleteElement(Patients())
          
          ;Mise à jour des index de liaison ListIconGadget <-> Patients()
          ForEach(Patients())
            SetGadgetItemData(#Lst_Patients, ListIndex(Patients()), ListIndex(Patients()))
          Next
          
      EndSelect
  EndSelect
EndProcedure
Procedure Sauvegarder_Patients()
  Select EventType()
    Case #PB_EventType_LeftClick
      
      ;Création d'un objet JSON
      CreateJSON(#FichierJSON)
      
      ;Insertion de la liste chainée "Contacts" dans l'objet JSON
      InsertJSONList(JSONValue(#FichierJSON), Patients())
      
      ;Sauvegarde du fichier
      SaveJSON(#FichierJSON, Fichier_Patients, #PB_JSON_PrettyPrint)
      
      Quitter()
      
  EndSelect  
EndProcedure

Procedure Quitter()
  Select EventType()
    Case #PB_EventType_LeftClick
      End
  EndSelect    
EndProcedure
Procedure$ Diabete_connu()
  If GetGadgetState(#Opt_Diab_Connu_non) = #True
    Diabete_connu = "Non"
  ElseIf GetGadgetState(#Opt_Diab_Connu_Oui) = #True
    Diabete_connu = "Oui"
  EndIf
  ProcedureReturn Diabete_connu
EndProcedure
Procedure$ Dernier_repas()
  If GetGadgetState(#Opt_dern_repas_a_jeun) = #True
    Dernier_repas = "à jeun strict"
  ElseIf GetGadgetState(#Opt_DernRepasNaJeun04h) = #True
    Dernier_repas = "non à jeun (0 et 4h)"
  ElseIf GetGadgetState(#Opt_DernRepas_Njeun_4h) = #True
    Dernier_repas = "non à jeun (+de4h)"
  EndIf
  ProcedureReturn Dernier_repas
EndProcedure
Procedure$ Sexe()
  If GetGadgetState(#Opt_Sex_H) = #True
    Sexe = "Homme"
  ElseIf GetGadgetState(#Opt_Sex_F) = #True
    Sexe = "Femme"
  EndIf
  ProcedureReturn Sexe
EndProcedure
Procedure$ Hors_Limite()
  If GetGadgetState(#Chk_HorLim_oui)
    Hors_limite = "Oui"
  ElseIf GetGadgetState(#Chk_HorLim_non) = #True
    Hors_limite = "Non"
  EndIf
  ProcedureReturn Hors_Limite
EndProcedure
;-Boucle
Repeat
  Evenement = WaitWindowEvent()
  Select Evenement
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Chk_HorLim_oui, #Chk_HorLim_non
          Hors_Limite()
        Case #Opt_Diab_Connu_non, #Opt_Diab_Connu_Oui
          Diabete_connu()
        Case #Opt_Sex_H, #Opt_Sex_F
          Sexe()
        Case #Opt_dern_repas_a_jeun, #Opt_DernRepasNaJeun04h, #Opt_DernRepas_Njeun_4h
          Dernier_repas()
      EndSelect
      
    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #Fenetre_saisie
          CloseWindow(#Fenetre_saisie)
          Break
      EndSelect
  EndSelect
ForEver

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 10:27
par MLD
Bonjour Micoute

Si j'ai bien compris tu souhaite récupérer le texte du gadget ?
Ou alors j'ai rien compris

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 11:49
par Micoute
Non, pas pour les options, ni les boîtes à cocher. Quand je fais ma saisie si le patient ignore qu'il est diabétique, je clique sur l'option "Non" et je mets dans ma liste de patients le texte, mais quand je veux modifier si le texte est "Non", il faut que ça me fasse un SetGadgetState(#Opt_Diab_Connu_non, #True) ou SetGadgetState(#Opt_Diab_Connu_oui, #True) si c'est oui. Idem pour les autres gadgets à état.

Merci beaucoup pour ta participation.

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 13:24
par MLD
@Micoute
Je ne comprend toujours pas très bien. :roll:
La modif de texte tu la fait dans un string? et tu souhaite modifier a ce moment l'option du gadgetoption ?

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 13:36
par falsam
Le souci de Micoute est qu'il ne sait pas récupérer les valeurs des OptionGadget() quand il traduit ces valeurs booléennes par des libéllées dans le ListIconGadget.

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 14:12
par MLD
@Micoute
ce n'est pas ceci que tu cherche
Resultat = GetGadgetState(#Gadget) (1 coché si non 0) :?: :?:

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 14:57
par Micoute
Si, c'exactement ça, mais ça ne fonctionne pas et c'est pourquoi je ne comprends pas.

Ce que je veux faire exactement, c'est lire le libellé dans la liste et agir sur les OptionGadget en conséquence seulement quand je veux modifier la saisie.

Merci encore.

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 15:08
par Ar-S
Je n'ai pas testé le code mais lorsque tu veux faire un truc du genre "seulement quand"
Tu peux utiliser un flag quelconque

Code : Tout sélectionner

; 2 consantes
#ModifOK = 1
#ModifNON = 2
; 1 global
Global.b EtatModif
;Tu peux ensuite faire du 
If EtatModif = #ModifOK
; tu peux modifier
elseif EtatModif = #ModifNON
tu DiablheGadget() ceux que tu ne veux pas voir modifier
endif

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 15:29
par MLD
@Micoute
tu ne modifie pas les données directement sur ta liste ? passe tu par un stringGadget?

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 16:02
par Marc56
Tu veux donc en fonction de la ligne cliquée en mode "modifier" réafficher l'état des optionsGadgets ?

Comme ta structure est faite de chaines avec Oui/Non, c'est plus compliqué, mais tu peux le faire comme ceci

Code : Tout sélectionner

          If \Diabete_connu = "Oui"
              SetGadgetState(#Opt_Diab_Connu_non, #True)
          ElseIf \Diabete_connu = "Non"
              SetGadgetState(#Opt_Diab_Connu_Oui, #True)
          EndIf
:idea: Dans ce type de structure, on met plutôt les valeurs numériques 0 et 1 pour les boites à cocher, comme cela il suffit de faire

Code : Tout sélectionner

SetGadgetState(#Opt_Diab_Connu_non, \Diabete_connu)
pour avoir la case cochée ou pas car les constantes #True = 1 et #False = 0. Tu ne fais ensuite la conversion Oui/Non que dans la liste.

Ta structure serait mieux avec

Code : Tout sélectionner

Structure sPatient
  Age.s
  Glycemie.c ; .s
  Diabete_connu.c  ; .s
  Dernier_repas.c  ; .s 
  Sexe.s
  Poids.s
  Taille.s
  Hors_limite.c ; .s
EndStructure
:wink:

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 16:11
par Micoute
Je vais essayer de faire avec ça, on verra bien, merci tout de même.

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 16:20
par Marc56
Et tu gagnes aussi en lisibilité en stockant en numérique:

Dernier_repas.c
0 = à jeun strict
1 = non à jeun (0 et 4h)
2 = non à jeun (+ de 4h)


Edit: Cet exemple s'appliquerait dans le cas d'une combobox ou d'une liste

Code : Tout sélectionner

  Select GetGadgetState(#Opt_dern_repas_a_jeun)
    Case 0 : Dernier_repas = "à jeun strict"
    Case 1 : Dernier_repas = "non à jeun (0 et 4h)"
    Case 2 : Dernier_repas = "non à jeun (+ de 4h)"
  EndSelect

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 16:25
par MLD
@Micoute
Marc56 a la bonne solution :wink:
Si tu passe par un stringGadget pour une modif tu passe par #PB_EventType_Change pour modifier les options :lol:
Bon courage

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : mer. 25/avr./2018 17:28
par Micoute
Oui, tu as raison ça fonctionne beaucoup mieux comme ça, pourquoi toujours réinventer la roue ?

Un grand merci à tous ceux qui ont collaboré.

Re: Comment mettre à jour des optionGadget et CheckBoxGadget

Publié : jeu. 26/avr./2018 9:59
par zaphod_b
Salut Micoute, désolé, j'arrive trop tard.

J'utilise le libellé des gadgets pour la mise à jour.
Ca implique qu'on stocke en mémoire le même libellé que le gadget.

j'ai mis -zaph en commentaire dans les parties modifiées.
J'espère que c'est ce que tu cherches.
Mais peut-etre j'ai rien compris.

Problème : le hors limite (checkbox oui/non) = peuvent être cochées toutes les deux ensemble.
Et aussi pas de vérification de la validité des chiffres saisis : exemple glycémie 455 !!!!!
La fenêtre est un peu grande pour mon écran.

C'est bien comme appli (ce serait mieux en version android ou web) pour les assos de diab ou les écoles de diab.

Code : Tout sélectionner

;fiche générale de saisie
;par Micoute
;commencé le 23/03/2018
;avec PB 5.62 (x86) et Windows 10 (x64)

Enumeration Fichiers
  #FichierJSON
EndEnumeration

Enumeration Fenetres
  #Fenetre_saisie
EndEnumeration

Enumeration Gadgets
  #Txt_Titre
  #Txt_Age
  #Txt_Glyc
  #Txt_DiabConnu
  #Txt_DernRepas
  #Txt_sex
  #Txt_Pds
  #Txt_Taille
  #Txt_HorLim
  #Txt_Signature
  #Str_Age
  #Str_Glyc
  #Opt_Diab_Connu_non
  #Opt_Diab_Connu_Oui
  #Opt_dern_repas_a_jeun
  #Opt_DernRepasNaJeun04h
  #Opt_DernRepas_Njeun_4h
  #Opt_Sex_H
  #Opt_Sex_F
  #Str_Pds
  #Str_Taille
  #Chk_HorLim_oui
  #Chk_HorLim_non
  #Lst_Patients
  #Btn_Nouveau
  #Btn_Maj
  #Btn_Supprimer
  #Btn_Sauvegarder
  #Btn_Quitter
EndEnumeration

Enumeration Polices
  #ArialBlack28
  #Arial12
  #Arial20 
  #Arial25
EndEnumeration

;Structures d'un patient
Structure sPatient
  Age.s
  Glycemie.s
  Diabete_connu.s
  Dernier_repas.s
  Sexe.s
  Poids.s
  Taille.s
  Hors_limite.s
EndStructure

;Cration d'une liste vierge pour les patients
Global NewList Patients.sPatient()
Global Evenement, Brosse
Global.s Fichier_Patients = GetPathPart(ProgramFilename()) + "Patients.json"
Global Diabete_connu.s = "", Dernier_repas.s = "", Sexe.s = "", Hors_Limite.s = ""

;Déclaration des traitements
Declare Programme_principal() ;Ouverture de l'application
Declare Charger_Patients()    ;Chargement des patients enregistrés
Declare Gestion_Evenements()  ;Gestionnaire de contrôle de la saisie
Declare Nouveau_Patient()     ;Inscrire un nouveau patient
Declare Selection_Patient()   ;Un patient est sélectionné dans la liste
Declare Supprimer_Patient()   ;Suppression d'un patient
Declare Sauvegarder_Patients();Sauvegarde des patients
Declare Maj_Patient()         ;Gestionnaire de mise à jour des patients
Declare Quitter()             ;Fermeture de l'application
Declare$ Diabete_connu()
Declare$ Dernier_repas()
Declare$ Sexe()
Declare$ Hors_Limite()

Programme_principal()

Procedure myCallback(WindowID, Message, wParam, lParam)
  Shared Brosse
  Resultat = #PB_ProcessPureBasicEvents
  Select Message
    Case #WM_CTLCOLORSTATIC
      SetBkMode_(wParam,#TRANSPARENT)
      Resultat = Brosse
  EndSelect
  ProcedureReturn Resultat
EndProcedure

Procedure MonOptionCouleur(GADGET,X, Y, L, H, message.s, COUL_FOND, COUL_TXT)
  Brosse = CreateSolidBrush_(COUL_FOND) ;; COULEUR DU FOND
  SetTextColor_(wParam, COUL_TXT)       ;; COULEUR DU TEXTE
                                        ;OptionGadget(GADGET, X, Y, L, H, "")
 
EndProcedure

Procedure Programme_principal()
  If OpenWindow(#Fenetre_saisie, 0, 0, 1050, 870, "AFD 50", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    TextGadget(#Txt_Titre, 10, 10, 1030, 60, UCase("fiche générale de saisie"), #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_Age, 50, 150, 80, 50, "Âge", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_Glyc, 130, 150, 130, 50, "Glycémie mg/dL", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_DiabConnu, 270, 150, 110, 50, "Diabète connu", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_DernRepas, 450, 150, 130, 50, "Dernier repas", #SS_CENTERIMAGE)
    TextGadget(#Txt_sex, 600, 150, 90, 50, "Sexe", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_Pds, 690, 150, 100, 50, "Poids (Kgs)", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_Taille, 790, 150, 90, 50, "Taille (cm)", #PB_Text_Center|#SS_CENTERIMAGE)
    TextGadget(#Txt_HorLim, 900, 150, 90, 50, "Hors Limite", #PB_Text_Center|#SS_CENTERIMAGE)
    StringGadget(#Str_Age, 50, 80, 80, 60, "") 
    StringGadget(#Str_Glyc, 140, 80, 130, 60, "")
    ctnDiabete = ContainerGadget(#PB_Any, 280, 80, 50, 50)
    OptionGadget(#Opt_Diab_Connu_non, 0, 0, 50, 25, "Non")
    OptionGadget(#Opt_Diab_Connu_Oui, 0, 30, 50, 25, "Oui")
    CloseGadgetList()
    ctnDernRep = ContainerGadget(#PB_Any, 370, 80, 220, 75)
    OptionGadget(#Opt_dern_repas_a_jeun, 0, 0, 150, 25, "à jeun strict")
    OptionGadget(#Opt_DernRepasNaJeun04h, 0, 30, 150, 25, "Non à jeun (0-4H)")
    OptionGadget(#Opt_DernRepas_Njeun_4h, 160, 30, 70, 25, "(+4H)")
    CloseGadgetList()
    CtnSexe = ContainerGadget(#PB_Any, 600, 80, 80, 50)
    OptionGadget(#Opt_Sex_H, 0, 0, 80, 25, "Homme")
    OptionGadget(#Opt_Sex_F, 0, 30, 80, 25, "Femme")
    CloseGadgetList()
    StringGadget(#Str_Pds, 690, 80, 100, 60, "")
    StringGadget(#Str_Taille, 800, 80, 90, 60, "")
    ctnHorLim = ContainerGadget(#PB_Any, 900, 80, 90, 50)
    CheckBoxGadget(#Chk_HorLim_oui, 0, 0, 90, 25, "Oui")
    CheckBoxGadget(#Chk_HorLim_non, 0, 30, 90, 25, "Non")
    CloseGadgetList()
    ListIconGadget(#Lst_Patients, 40, 200, 970, 540, "Âge", 80, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#LVS_NOCOLUMNHEADER)
    AddGadgetColumn(#Lst_Patients, 1, "Glycémie", 130)
    AddGadgetColumn(#Lst_Patients, 2, "Diabète connu", 140)
    AddGadgetColumn(#Lst_Patients, 3, "Dernier repas", 210)
    AddGadgetColumn(#Lst_Patients, 4, "Sexe", 90)
    AddGadgetColumn(#Lst_Patients, 5, "Poids", 100)
    AddGadgetColumn(#Lst_Patients, 6, "Taille", 90)
    AddGadgetColumn(#Lst_Patients, 7, "Hors limite", 90)
    ButtonGadget(#Btn_Nouveau, 40, 750, 190, 40, "Nouveau")
    ButtonGadget(#Btn_Maj, 240, 750, 190, 40, "Mise à jour")
    ButtonGadget(#Btn_Supprimer, 440, 750, 190, 40, "Supprimer")
    ButtonGadget(#Btn_Sauvegarder, 640, 750, 190, 40, "Sauvegarder")
    ButtonGadget(#Btn_Quitter, 840, 750, 170, 40, "Quitter")
    TextGadget(#Txt_Signature, 10, WindowHeight(#Fenetre_saisie) - 70, 1030, 60, "Logiciel crée par MicouteSoft © 2018", #PB_Text_Center|#SS_CENTERIMAGE)
    ; Polices
    LoadFont(#ArialBlack28, "Arial Black", 28, #PB_Font_Bold|#PB_Font_HighQuality)
    LoadFont(#Arial12, "Arial", 12, #PB_Font_Bold|#PB_Font_HighQuality)
    LoadFont(#Arial20, "Arial", 20, #PB_Font_Bold|#PB_Font_HighQuality)
    LoadFont(#Arial25, "Arial", 25, #PB_Font_Bold|#PB_Font_HighQuality)
    SetGadgetFont(#Btn_Nouveau, FontID(#Arial12))
    SetGadgetFont(#Btn_Maj, FontID(#Arial12))
    SetGadgetFont(#Btn_Supprimer, FontID(#Arial12))
    SetGadgetFont(#Btn_Sauvegarder, FontID(#Arial12))
    SetGadgetFont(#Btn_Quitter, FontID(#Arial12))   
    SetGadgetFont(#Txt_Titre, FontID(#ArialBlack28))
    SetGadgetFont(#Txt_Age, FontID(#Arial12))
    SetGadgetFont(#Txt_Glyc, FontID(#Arial12))
    SetGadgetFont(#Txt_DiabConnu, FontID(#Arial12))
    SetGadgetFont(#Txt_DernRepas, FontID(#Arial12))
    SetGadgetFont(#Txt_sex, FontID(#Arial12))
    SetGadgetFont(#Txt_Pds, FontID(#Arial12))
    SetGadgetFont(#Txt_Taille, FontID(#Arial12))
    SetGadgetFont(#Txt_HorLim, FontID(#Arial12))
    SetGadgetFont(#Str_Age, FontID(#ArialBlack28))
    SetGadgetFont(#Str_Glyc, FontID(#ArialBlack28))
    SetGadgetFont(#Str_Pds, FontID(#ArialBlack28))
    SetGadgetFont(#Str_Taille, FontID(#ArialBlack28))
    SetGadgetFont(#Chk_HorLim_oui, FontID(#Arial12))
    SetGadgetFont(#Chk_HorLim_non, FontID(#Arial12))
    SetGadgetFont(#Opt_Diab_Connu_non, FontID(#Arial12))
    SetGadgetFont(#Opt_Diab_Connu_Oui, FontID(#Arial12))
    SetGadgetFont(#Opt_Sex_H, FontID(#Arial12))
    SetGadgetFont(#Opt_Sex_F, FontID(#Arial12))
    SetGadgetFont(#Opt_dern_repas_a_jeun, FontID(#Arial12))
    SetGadgetFont(#Opt_DernRepasNaJeun04h, FontID(#Arial12))
    SetGadgetFont(#Opt_DernRepas_Njeun_4h, FontID(#Arial12))
    SetGadgetFont(#Lst_Patients, FontID(#Arial12))
    For i = #Btn_Nouveau To #Btn_Quitter
      SetGadgetFont(i, FontID(#Arial20))
    Next i 
    SetGadgetFont(#Txt_Signature, FontID(#Arial20))
    ;Couleurs
    SetWindowColor(#Fenetre_saisie, $FC9C91)
    MonOptionCouleur(#Opt_Diab_Connu_non, 280, 130, 50, 25, "Non", GetWindowColor(#Fenetre_saisie), $FDD5D0)
    SetGadgetColor(ctnDiabete, #PB_Gadget_BackColor, GetWindowColor(#Fenetre_saisie))
    SetGadgetColor(ctnDernRep, #PB_Gadget_BackColor, GetWindowColor(#Fenetre_saisie))
    SetGadgetColor(CtnSexe, #PB_Gadget_BackColor, GetWindowColor(#Fenetre_saisie))
    SetGadgetColor(ctnHorLim, #PB_Gadget_BackColor, GetWindowColor(#Fenetre_saisie))
   
    i = #Txt_Titre
    While i <= #Txt_Signature
      SetGadgetColor(i, #PB_Gadget_FrontColor, $B61704)
      i + 1
    Wend
    i = #Str_Age
    While i <= #Chk_HorLim_oui
      SetGadgetColor(i, #PB_Gadget_BackColor, $FDD5D0)
      i + 1
    Wend
   
    SetWindowCallback(@myCallback())
   
    HideGadget(#Str_Age, #True)
    HideGadget(#Str_Glyc, #True)
    HideGadget(#Opt_Diab_Connu_non, #True)
    HideGadget(#Opt_Diab_Connu_Oui, #True)
    HideGadget(#Opt_dern_repas_a_jeun, #True)
    HideGadget(#Opt_DernRepasNaJeun04h, #True)
    HideGadget(#Opt_DernRepas_Njeun_4h, #True)
    HideGadget(#Opt_Sex_H, #True)
    HideGadget(#Opt_Sex_F, #True)
    HideGadget(#Str_Pds, #True)
    HideGadget(#Str_Taille, #True)
    HideGadget(#Chk_HorLim_oui, #True)
    HideGadget(#Chk_HorLim_non, #True)   
   
    HideGadget(#Btn_Supprimer, #True)
    HideGadget(#Btn_Sauvegarder, #True)
    DisableGadget(#Btn_Maj, #True)
   
    ;{ Déclancheurs
   
    ;Contrôle de la saisie (Le nom est obligatoire)
    BindGadgetEvent(#Str_Age, @Gestion_Evenements())
   
    ;Mise en place d'un nouveau contact
    BindGadgetEvent(#Btn_Nouveau, @Nouveau_Patient())
   
    ;Un contact est selectionné dans la liste
    BindGadgetEvent(#Lst_Patients, @Selection_Patient())
   
    ;Ajout ou modification d'un contact
    BindGadgetEvent(#Btn_Maj, @Maj_Patient())
   
    ;Supression d'un contact
    BindGadgetEvent(#Btn_Supprimer, @Supprimer_Patient())
   
    ;Entrer dans le mode saisie
    ;BindGadgetEvent(#Btn_Saisie, @Edition())
   
    ;Fermeture de l'application et sauvegarde des Patients
    ;BindEvent(#PB_Event_CloseWindow, @SauvegardePatients())
    BindGadgetEvent(#Btn_Sauvegarder, @Sauvegarder_Patients())
   
    ;Fermeture de l'application sans sauvegarder
    BindGadgetEvent(#Btn_Quitter, @Quitter())
   
    ;Lectures des Patients
    Charger_Patients()
   
    ;L'application est prête pour la saisie d'un contact
    ;Nouveau_Patient()
  EndIf
EndProcedure


;Chargement des patients existants
Procedure Charger_Patients()
  If ReadFile(#FichierJSON, Fichier_Patients)
    CloseFile(#FichierJSON)
   
    ;Lecture du fichier Json
    LoadJSON(#FichierJSON, Fichier_Patients, #PB_JSON_NoCase)
   
    ;Extraction de la chaine JSON vers la liste chaînée Patients
    ExtractJSONList(JSONValue(#FichierJSON), Patients())
   
    ;Affichage de la liste des patients
    ForEach Patients()
      With Patients()
        AddGadgetItem(#Lst_Patients, -1, \Age + #LF$ + \Glycemie + #LF$ + \Diabete_connu + #LF$ + \Dernier_repas + #LF$ + \Sexe + #LF$ + \Poids + #LF$ + \Taille + #LF$ + \Hors_limite)
        SetGadgetItemData(#Lst_Patients, CountGadgetItems(#Lst_Patients)-1, ListIndex(Patients()))
      EndWith
    Next
  EndIf   
EndProcedure
;Gestionnaire de contrôle de la saisie
Procedure Gestion_Evenements()
  Protected Evenement = EventType()
 
  Select Evenement
    Case #PB_EventType_Change
      If Trim(GetGadgetText(#Str_Age)) <> ""
        DisableGadget(#Btn_Nouveau, #False)
        DisableGadget(#Btn_Maj, #False)
      Else
        DisableGadget(#Btn_Nouveau, #True)
        DisableGadget(#Btn_Maj, #True)
      EndIf
  EndSelect   
EndProcedure
;Nouveau patient (remise à zéro des champs de saisie)
Procedure Nouveau_Patient()
  Select EventType()
    Case #PB_EventType_LeftClick
      SetWindowData(#Fenetre_saisie, 0) ;C'est une création
     
      HideGadget(#Str_Age, #False)
      HideGadget(#Str_Glyc, #False)
      HideGadget(#Opt_Diab_Connu_non, #False)
      HideGadget(#Opt_Diab_Connu_Oui, #False)
      HideGadget(#Opt_dern_repas_a_jeun, #False)
      HideGadget(#Opt_DernRepasNaJeun04h, #False)
      HideGadget(#Opt_DernRepas_Njeun_4h, #False)
      HideGadget(#Opt_Sex_H, #False)
      HideGadget(#Opt_Sex_F, #False)
      HideGadget(#Str_Pds, #False)
      HideGadget(#Str_Taille, #False)
      HideGadget(#Chk_HorLim_oui, #False)
      HideGadget(#Chk_HorLim_non, #False)
     
      SetGadgetText(#Str_Age, "")
      SetGadgetText(#Str_Glyc, "")
      SetGadgetState(#Opt_Diab_Connu_non, #False)
      SetGadgetState(#Opt_Diab_Connu_Oui, #False)
      SetGadgetState(#Opt_Sex_H, #False)
      SetGadgetState(#Opt_Sex_F, #False)
      SetGadgetText(#Str_Pds, "")
      SetGadgetText(#Str_Taille, "")
      SetGadgetState(#Chk_HorLim_non, #False)
      SetGadgetState(#Chk_HorLim_oui, #False)
     
      DisableGadget(#Btn_Nouveau, #True)
      DisableGadget(#Btn_Maj, #True)
      DisableGadget(#Btn_Supprimer, #True)
     
      SetGadgetText(#Btn_Maj, "Ajouter")
      SetActiveGadget(#Str_Age)
  EndSelect
EndProcedure
;Un patient est sélectionné dans la liste
Procedure Selection_Patient()
  Select EventType()
    Case #PB_EventType_LeftClick
      Protected Item = GetGadgetState(#Lst_Patients)
     
      If item <> -1
        SelectElement(Patients(), GetGadgetItemData(#Lst_Patients, Item))
        With Patients()
          SetGadgetText(#Str_Age, \Age)
          SetGadgetText(#Str_Glyc, \Glycemie)
          ;-zaph
          If \Diabete_connu<>""
          If \Diabete_connu=GetGadgetText(#Opt_Diab_Connu_non)
            SetGadgetState(#Opt_Diab_Connu_non, #True)
          Else
            SetGadgetState(#Opt_Diab_Connu_Oui, #True)
          EndIf
          EndIf
          ;-zaph
          If \Dernier_repas<>""
          If \Dernier_repas=GetGadgetText(#Opt_dern_repas_a_jeun)
            SetGadgetState(#Opt_dern_repas_a_jeun, #True)
          EndIf  
          If \Dernier_repas=GetGadgetText(#Opt_DernRepasNaJeun04h)
            SetGadgetState(#Opt_DernRepasNaJeun04h, #True)
          EndIf 
          If \Dernier_repas=GetGadgetText(#Opt_DernRepas_Njeun_4h)
            SetGadgetState(#Opt_DernRepas_Njeun_4h, #True)
          EndIf 
          EndIf
          ;-zaph
          If \Sexe<>""
            If \Sexe=GetGadgetText(#Opt_Sex_F)
              SetGadgetState(#Opt_Sex_F, #True)
            Else
              SetGadgetState(#Opt_Sex_H, #True)
            EndIf            
          EndIf
          ;
          SetGadgetText(#Str_Pds, \Poids)
          SetGadgetText(#Str_Taille, \Taille)
          ;-zaph
          If \Hors_limite<>""
            If \Hors_limite=GetGadgetText(#Chk_HorLim_non)
              SetGadgetState(#Chk_HorLim_non, #True)
            Else
              SetGadgetState(#Chk_HorLim_oui, #True)
            EndIf            
          EndIf
          ;SetGadgetState(#Chk_HorLim_non, #False)
          ;SetGadgetState(#Chk_HorLim_oui, #False)
        EndWith
        HideGadget(#Btn_Supprimer, #False)
      EndIf
     
      ;C'est une modification
      SetWindowData(#Fenetre_saisie, 1)
     
      DisableGadget(#Btn_Nouveau, #False)
      DisableGadget(#Btn_Maj, #False)
      DisableGadget(#Btn_Supprimer, #False)
     
      SetGadgetText(#Btn_Maj, "Modifier")
      SetActiveGadget(#Str_Age)
  EndSelect   
EndProcedure
;Suppression d'un patient
Procedure Supprimer_Patient()
  Select EventType()
    Case #PB_EventType_LeftClick
      If MessageRequester("Information", "Etes vous sûr de supprimer un contact ?" + #CRLF$ + "cette action est irrémédiable !", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
        SetWindowData(#Fenetre_saisie, 3) ;C'est une suppression
        Maj_Patient()
      EndIf
  EndSelect 
EndProcedure
;Gestionnaire de mise à jour des Patients
Procedure Maj_Patient()
  Select EventType()
    Case #PB_EventType_LeftClick
      Protected.s Age, Glycemie, Diabete_connu, Dernier_repas, Sexe, Poids, Taille, Hors_limite
     
     
      HideGadget(#Str_Age, #True)
      HideGadget(#Str_Glyc, #True)
      HideGadget(#Opt_Diab_Connu_non, #True)
      HideGadget(#Opt_Diab_Connu_Oui, #True)
      HideGadget(#Opt_dern_repas_a_jeun, #True)
      HideGadget(#Opt_DernRepasNaJeun04h, #True)
      HideGadget(#Opt_DernRepas_Njeun_4h, #True)
      HideGadget(#Opt_Sex_H, #True)
      HideGadget(#Opt_Sex_F, #True)
      HideGadget(#Str_Pds, #True)
      HideGadget(#Str_Taille, #True)
      HideGadget(#Chk_HorLim_oui, #True)
      HideGadget(#Chk_HorLim_non, #True)
     
      Age = GetGadgetText(#Str_Age)
      Glycemie = GetGadgetText(#Str_Glyc)
      Diabete_connu = Diabete_connu()
      Dernier_repas = Dernier_repas()
      Sexe = Sexe()
      Poids = GetGadgetText(#Str_Pds)
      Taille = GetGadgetText(#Str_Taille)
      Hors_Limite = Hors_Limite()
     
      HideGadget(#Btn_Sauvegarder, #False)
     
      Select GetWindowData(#Fenetre_saisie)
        Case 0 ;Création d'un contact
          AddElement(Patients())
          With Patients()
            \Age = Age
            \Glycemie = Glycemie
            \Diabete_connu = Diabete_connu
            \Dernier_repas = Dernier_repas
            \Sexe = Sexe
            \Poids = Poids
            \Taille = Taille
            \Hors_limite = Hors_limite
            AddGadgetItem(#Lst_Patients, -1, \Age + #LF$ + \Glycemie + #LF$ + \Diabete_connu + #LF$ +  \Dernier_repas + #LF$ +  \Sexe + #LF$ +  \Poids + #LF$ + \Taille + #LF$ +  \Hors_limite)
            SetGadgetItemData(#Lst_Patients, CountGadgetItems(#Lst_Patients)-1, ListIndex(Patients()))
          EndWith
         
        Case 1 ;Modification d'un contact
          DisableGadget(#Btn_Sauvegarder, #False)
         
          Select Patients()\Diabete_connu
            Case "Oui"
              SetGadgetState(#Opt_Diab_Connu_Oui, #True)
            Case "Non"
              SetGadgetState(#Opt_Diab_Connu_non, #True)
          EndSelect
         
          Select Patients()\Hors_limite
            Case "Oui"
              SetGadgetState(#Chk_HorLim_oui, 1)
            Case "Non"
              SetGadgetState(#Chk_HorLim_non, 1)
          EndSelect   
         
          With Patients()
            \Age = Age
            \Glycemie = Glycemie
            \Diabete_connu = Diabete_connu
            \Dernier_repas = Dernier_repas
            \Sexe = Sexe
            \Poids = Poids
            \Taille = Taille
            \Hors_limite = Hors_limite
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Age, 0)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Glycemie, 1)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Diabete_connu, 2)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Dernier_repas, 3)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Sexe, 4)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Poids, 5)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Taille, 6)
            SetGadgetItemText(#Lst_Patients, ListIndex(Patients()), \Hors_limite, 7)
          EndWith
          Nouveau_Patient()
         
        Case 3 ;Suppression d'un contact
          RemoveGadgetItem(#Lst_Patients, ListIndex(Patients()))
          DeleteElement(Patients())
         
          ;Mise à jour des index de liaison ListIconGadget <-> Patients()
          ForEach(Patients())
            SetGadgetItemData(#Lst_Patients, ListIndex(Patients()), ListIndex(Patients()))
          Next
         
      EndSelect
  EndSelect
EndProcedure
Procedure Sauvegarder_Patients()
  Select EventType()
    Case #PB_EventType_LeftClick
     
      ;Création d'un objet JSON
      CreateJSON(#FichierJSON)
     
      ;Insertion de la liste chainée "Contacts" dans l'objet JSON
      InsertJSONList(JSONValue(#FichierJSON), Patients())
     
      ;Sauvegarde du fichier
      SaveJSON(#FichierJSON, Fichier_Patients, #PB_JSON_PrettyPrint)
     
      Quitter()
     
  EndSelect 
EndProcedure

Procedure Quitter()
  Select EventType()
    Case #PB_EventType_LeftClick
      End
  EndSelect   
EndProcedure
Procedure$ Diabete_connu()
  If GetGadgetState(#Opt_Diab_Connu_non) = #True
    Diabete_connu = "Non"
  ElseIf GetGadgetState(#Opt_Diab_Connu_Oui) = #True
    Diabete_connu = "Oui"
  EndIf
  ProcedureReturn Diabete_connu
EndProcedure
;-zaph
Procedure$ Dernier_repas()
  If GetGadgetState(#Opt_dern_repas_a_jeun) = #True
    Dernier_repas = "à jeun strict"
  ElseIf GetGadgetState(#Opt_DernRepasNaJeun04h) = #True
    Dernier_repas = "Non à jeun (0-4H)"
  ElseIf GetGadgetState(#Opt_DernRepas_Njeun_4h) = #True
    Dernier_repas = "(+4H)"
  EndIf
  ProcedureReturn Dernier_repas
EndProcedure
Procedure$ Sexe()
  If GetGadgetState(#Opt_Sex_H) = #True
    Sexe = "Homme"
  ElseIf GetGadgetState(#Opt_Sex_F) = #True
    Sexe = "Femme"
  EndIf
  ProcedureReturn Sexe
EndProcedure
Procedure$ Hors_Limite()
  If GetGadgetState(#Chk_HorLim_oui)
    Hors_limite = "Oui"
  ElseIf GetGadgetState(#Chk_HorLim_non) = #True
    Hors_limite = "Non"
  EndIf
  ProcedureReturn Hors_Limite
EndProcedure
;-Boucle
Repeat
  Evenement = WaitWindowEvent()
  Select Evenement
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Chk_HorLim_oui, #Chk_HorLim_non
          Hors_Limite()
        Case #Opt_Diab_Connu_non, #Opt_Diab_Connu_Oui
          Diabete_connu()
        Case #Opt_Sex_H, #Opt_Sex_F
          Sexe()
        Case #Opt_dern_repas_a_jeun, #Opt_DernRepasNaJeun04h, #Opt_DernRepas_Njeun_4h
          Dernier_repas()
      EndSelect
     
    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #Fenetre_saisie
          CloseWindow(#Fenetre_saisie)
          Break
      EndSelect
  EndSelect
ForEver