comment cree une base de donnée en pureBasic

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
williamm
Messages : 54
Inscription : dim. 05/sept./2004 20:21

Message par williamm »

merci nico pour tonaide
mais ce que je veux essayer de faire
c'est que le nom de l'eleve apparait dans la liste
et quand on clique dessus une fiche apparait avec les renseignement .


peux tu me dire les commandes qu'il faut .


merci

williamm
williamm
Messages : 54
Inscription : dim. 05/sept./2004 20:21

Message par williamm »

pourquoi tu as mis procedure return 1

peux tu m'expliquer svp

williamm
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Message par nico »

Dans l'aide de Pure, rubrique procédure, il y a un exemple simple qui t'explique à quoi ça sert, ça devrait t'éclairer.

Sinon pour ton code, il faut absolument que tu sépares les différents traitements des messages pour les différentes fenêtres.

Exemple:

Code : Tout sélectionner

Procedure fenetre1()
  If OpenWindow(0, 100, 100, 400, 400, #PB_Window_SystemMenu , "Fenêtre 1")
    Repeat
      EventID.l = WaitWindowEvent()
      Select EventID
        Case #PB_Event_CloseWindow
          Quit = 1
      EndSelect    
    Until Quit = 1
  EndIf
EndProcedure

Procedure fenetre2()
  If OpenWindow(0, 100, 200, 200, 260, #PB_Window_SystemMenu , "Fenêtre 2")
    Repeat
      EventID.l = WaitWindowEvent()
      Select EventID
        Case #PB_Event_CloseWindow
          Quit = 1
      EndSelect    
    Until Quit = 1
  EndIf
EndProcedure

fenetre1()
fenetre2() 
:)
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

ça merdouille complètement , mais on peut afficher la fiche d'un élève choisi dans la liste.

Comme je n'y connais rien dans ce type d'appli ça m'intéressait d"y jeter un oeil :)

reprend le code en tenant compte des conseils de nico .

Je crois que je vais aussi me faire un exercice pour apprendre , je vais gérer une base de données livres , je risque de bientôt revenir sur le forum avec mes questions :)

Code : Tout sélectionner

; Logiciel de gestion d'eleves par Williamm-2004 
Enumeration 
  #Window_0 
  #Window_1 
  #Window_2  
EndEnumeration 

; constante de la liste d'eleves 

Enumeration 
  #ListIcon_0 
EndEnumeration 

; constante du menu 

Enumeration 
  #menu_Ajouter 
  #menu_Info 
  #menu_Quitter 
EndEnumeration 

;constante des gadgets pour la fenetre 1 

Enumeration 
  #ListIcon_0 
  #Text_Nom 
  #String_Nom 
  #Text_Prenom 
  #String_Prenom 
  #Text_Date 
  #String_Date 
  #Text_Ville 
  #String_Ville 
  #Button_Ajouter 
EndEnumeration 

; constante des fenetres 
;creation d'un eleve 
Structure eleve_struct ;ici on cré une structure avec les champs 
  Nom.s                ;qui t'intéresse 
  Prenom.s 
  date.s 
  Ville.s 
EndStructure 

NewList Items.eleve_struct() ;on cré une nouvelle liste 


;procedure de gestion des items 
Procedure.b item_clear() 
  ClearList(Items()) 
  ProcedureReturn 1 
EndProcedure 

;ajouter un eleve dans la liste 
Procedure.b item_add() 
  If AddElement(Items()) 
    Items()\Nom= GetGadgetText(#String_Nom)  
    Items()\Prenom= GetGadgetText(#String_Prenom) 
    Items()\date= GetGadgetText(#String_Date) 
    Items()\Ville= GetGadgetText(#String_Ville)  
    AddGadgetItem(#ListIcon_0, -1,Items()\Nom) ;on affiche le nom dans le ListIconGadget 
  EndIf 
  ProcedureReturn 1 
EndProcedure 



; police de la liste 

Global FontID1 
FontID1 = LoadFont(1, "Arial", 11, #PB_Font_Bold) 
FontID2 = LoadFont(2, "Arial", 12, #PB_Font_Bold) 


; procedure de du menu info 
Procedure info() 
  MessageRequester("A propos ","Gestion d'eleves par Williamm ",#MB_ICONINFORMATION) 
EndProcedure 





;procedure la fenetre principale 


Procedure Open_Window_0() 
  If OpenWindow(#Window_0 , 216, 0, 682, 624,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Gestion  d'eleves - copyright 2004 ") 
    If CreateGadgetList(WindowID()) 
      
      ListIconGadget(#ListIcon_0, 10, 10, 660, 600, "Nom des Eleves ", 656, #PB_ListIcon_CheckBoxes | #PB_ListIcon_GridLines) 
      SetGadgetFont(#ListIcon_0, FontID1) 
      If CreateMenu(0,WindowID()) 
        MenuTitle( "Fichier") 
        MenuItem (#menu_Ajouter ,"Ajouter un eleve ") 
        MenuItem(#menu_Info ,"Information ") 
        MenuItem(#menu_Quitter,"Quitter ") 
      EndIf 
      
    EndIf 
  EndIf 
EndProcedure 


; procedure de la fenetre ajouter 
Procedure Open_Window_1() 
  If OpenWindow(#Window_1, 339, 72, 444, 420,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_WindowCentered , "Ajouter Eleves ") 
    If CreateGadgetList(WindowID()) 
      TextGadget(#Text_Nom, 20, 40, 90, 30, "Nom : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Nom, FontID2) 
      StringGadget(#String_Nom, 110, 40, 210, 30, "") 
      SetGadgetFont(#String_Nom, FontID2) 
      TextGadget(#Text_Prenom, 10, 110, 90, 30, "Prenom : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Prenom, FontID2) 
      StringGadget(#String_Prenom, 110, 110, 210, 30, "") 
      SetGadgetFont(#String_Prenom, FontID2) 
      TextGadget(#Text_Date, 0, 170, 130, 50, "Date de naissance : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Date, FontID2) 
      StringGadget(#String_Date, 130, 180, 210, 30, "") 
      SetGadgetFont(#String_Date, FontID2) 
      TextGadget(#Text_Ville, 20, 250, 100, 30, "Ville : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Ville, FontID2) 
      StringGadget(#String_Ville, 120, 250, 210, 30, "") 
      SetGadgetFont(#String_Ville, FontID2) 
      ButtonGadget(#Button_Ajouter, 30, 340, 120, 40, "Ajouter ") 
      SetGadgetFont(#Button_Ajouter, FontID2) 
      
      Repeat 
        
        Event = WaitWindowEvent() 
        
        Select Event 
          Case #PB_EventCloseWindow 
            Fenetre = EventWindowID() 
            If Fenetre = #Window_1 
              Fermer_Window_1 = 1 
            EndIf 
            
          Case #PB_EventGadget 
            GadgetID = EventGadgetID() 
            If GadgetID = #Button_Ajouter 
              item_add()
              Fermer_Window_1 = 1 
            EndIf 
        EndSelect 
        
      Until Fermer_Window_1 = 1 
      
      CloseWindow(#Window_1) 
    EndIf 
  EndIf 
EndProcedure 


Procedure Open_Window_2(Element) 
  If OpenWindow(#Window_2, 339, 72, 444, 420,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_WindowCentered , "Fiche Eleve") 
    If CreateGadgetList(WindowID()) 
      TextGadget(#Text_Nom, 20, 40, 90, 30, "Nom : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Nom, FontID2) 
      StringGadget(#String_Nom, 110, 40, 210, 30, "") 
      SetGadgetFont(#String_Nom, FontID2) 
      TextGadget(#Text_Prenom, 10, 110, 90, 30, "Prenom : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Prenom, FontID2) 
      StringGadget(#String_Prenom, 110, 110, 210, 30, "") 
      SetGadgetFont(#String_Prenom, FontID2) 
      TextGadget(#Text_Date, 0, 170, 130, 50, "Date de naissance : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Date, FontID2) 
      StringGadget(#String_Date, 130, 180, 210, 30, "") 
      SetGadgetFont(#String_Date, FontID2) 
      TextGadget(#Text_Ville, 20, 250, 100, 30, "Ville : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Ville, FontID2) 
      StringGadget(#String_Ville, 120, 250, 210, 30, "") 
      SetGadgetFont(#String_Ville, FontID2) 
      ButtonGadget(#Button_Ajouter, 30, 340, 120, 40, "Quitter la fiche") 
      SetGadgetFont(#Button_Ajouter, FontID2) 
      ForEach Items()
        If Items()\Nom = GetGadgetItemText(#ListIcon_0, Element, 0) 
          SetGadgetText(#String_Nom,Items()\Nom)  
          SetGadgetText(#String_Prenom,Items()\Prenom) 
          SetGadgetText(#String_Date,Items()\date) 
          SetGadgetText(#String_Ville,Items()\Ville) 
          Break
        EndIf
      Next  
          
      Repeat 
        
        Event = WaitWindowEvent() 
        
        Select Event 
          Case #PB_EventCloseWindow 
            Fenetre = EventWindowID() 
            If Fenetre = #Window_2 
              Fermer_Window_2 = 1 
            EndIf 
            
          Case #PB_EventGadget 
            GadgetID = EventGadgetID() 
            If GadgetID = #Button_Ajouter 
              Fermer_Window_2 = 1 
            EndIf 
        EndSelect 
        
      Until Fermer_Window_2 = 1 
      
      CloseWindow(#Window_2) 
    EndIf 
  EndIf 
EndProcedure 
      


;boucle principale 

Open_Window_0() 

Repeat 
  Event = WaitWindowEvent() 
  Select Event 
    Case #PB_EventMenu 
      Select EventMenuID() 
        Case #menu_Info:info() 
        Case#menu_Ajouter:Open_Window_1() 
        Case#menu_Quitter :fermer_window_0= 1        
          
      EndSelect 
    Case #PB_EventGadget 
      Select EventGadgetID() 
        Case #ListIcon_0
        Position = GetGadgetState(#ListIcon_0)  
        Open_Window_2(Position)
      EndSelect      
    Case #PB_EventCloseWindow 
      Fenetre = EventWindowID() 
      If Fenetre = #Window_0 
        fermer_window_0 = 1 
      EndIf 
      
   
      
  EndSelect 
  
Until fermer_window_0 = 1 

End 
williamm
Messages : 54
Inscription : dim. 05/sept./2004 20:21

Message par williamm »

merci mais le programme marche mal car je rentre un eleve et apres ca marche plus .
beaucoup
mais une question coment sauvegarder et charger la base de donnée ?


merci beaucoup


williamm
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Message par nico »

Il faut utiliser les fonctions de lecture et d'écriture sur les fichiers.
Avatar de l’utilisateur
Crystal Noir
Messages : 892
Inscription : mar. 27/janv./2004 10:07

Message par Crystal Noir »

A une époque j'avais réussi à coupler Multimedia Fusion qui est un autre produit avec une base mysql.

Je pense qu'il doit être possible de faire pareil avec Purebasic. Je ne sais pas comment mais tout ce que je sais c'est que j'avais fait ca à l'époque en utilisant uniquement les fonctions réseaux et en envoyant sous forme de data des requêtes sql.

chuis sur qu'il y a moyen de faire ca avec pure. super pour gérer une base donnée Sql.

bon je l'avoue c pas le plus simple....
williamm
Messages : 54
Inscription : dim. 05/sept./2004 20:21

Message par williamm »

merci nico
mais le programme marche mal
quand je rentre un premier eleve ca marche mais apres pour le second
ca marche plus je peux plus quitter le programme
je pense que ça viens d'une boucle .
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

Code : Tout sélectionner

; Logiciel de gestion d'eleves par Williamm-2004 
Enumeration 
  #Window_0 
  #Window_1 
  #Window_2  
EndEnumeration 

; constante de la liste d'eleves 

Enumeration 
  #ListIcon_0 
EndEnumeration 

; constante du menu 

Enumeration 
  #menu_Ajouter 
  #menu_Info 
  #menu_Quitter 
EndEnumeration 

;constante des gadgets pour la fenetre 1 

Enumeration 
  #ListIcon_0 
  #Text_Nom 
  #String_Nom 
  #Text_Prenom 
  #String_Prenom 
  #Text_Date 
  #String_Date 
  #Text_Ville 
  #String_Ville 
  #Button_Ajouter 
EndEnumeration 

; constante des fenetres 
;creation d'un eleve 
Structure eleve_struct ;ici on cré une structure avec les champs 
  Nom.s                ;qui t'intéresse 
  Prenom.s 
  date.s 
  Ville.s 
EndStructure 

NewList Items.eleve_struct() ;on cré une nouvelle liste 


;procedure de gestion des items 
Procedure.b item_clear() 
  ClearList(Items()) 
  ProcedureReturn 1 
EndProcedure 

;ajouter un eleve dans la liste 
Procedure.b item_add() 
  If AddElement(Items()) 
    Items()\Nom= GetGadgetText(#String_Nom)  
    Items()\Prenom= GetGadgetText(#String_Prenom) 
    Items()\date= GetGadgetText(#String_Date) 
    Items()\Ville= GetGadgetText(#String_Ville)  
    AddGadgetItem(#ListIcon_0, -1,Items()\Nom) ;on affiche le nom dans le ListIconGadget 
  EndIf 
  ProcedureReturn 1 
EndProcedure 



; police de la liste 

Global FontID1 
FontID1 = LoadFont(1, "Arial", 11, #PB_Font_Bold) 
FontID2 = LoadFont(2, "Arial", 12, #PB_Font_Bold) 


; procedure de du menu info 
Procedure info() 
  MessageRequester("A propos ","Gestion d'eleves par Williamm ",#MB_ICONINFORMATION) 
EndProcedure 





;procedure la fenetre principale 


Procedure Open_Window_0() 
  If OpenWindow(#Window_0 , 216, 0, 682, 624,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Gestion  d'eleves - copyright 2004 ") 
    If CreateGadgetList(WindowID()) 
      
      ListIconGadget(#ListIcon_0, 10, 10, 660, 600, "Nom des Eleves ", 656, #PB_ListIcon_CheckBoxes | #PB_ListIcon_GridLines) 
      SetGadgetFont(#ListIcon_0, FontID1) 
      If CreateMenu(0,WindowID()) 
        MenuTitle( "Fichier") 
        MenuItem (#menu_Ajouter ,"Ajouter un eleve ") 
        MenuItem(#menu_Info ,"Information ") 
        MenuItem(#menu_Quitter,"Quitter ") 
      EndIf 
      
    EndIf 
  EndIf 
EndProcedure 


; procedure de la fenetre ajouter 
Procedure Open_Window_1() 
  If OpenWindow(#Window_1, 339, 72, 444, 420,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_WindowCentered , "Ajouter Eleves ") 
    If CreateGadgetList(WindowID()) 
      TextGadget(#Text_Nom, 20, 40, 90, 30, "Nom : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Nom, FontID2) 
      StringGadget(#String_Nom, 110, 40, 210, 30, "") 
      SetGadgetFont(#String_Nom, FontID2) 
      TextGadget(#Text_Prenom, 10, 110, 90, 30, "Prenom : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Prenom, FontID2) 
      StringGadget(#String_Prenom, 110, 110, 210, 30, "") 
      SetGadgetFont(#String_Prenom, FontID2) 
      TextGadget(#Text_Date, 0, 170, 130, 50, "Date de naissance : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Date, FontID2) 
      StringGadget(#String_Date, 130, 180, 210, 30, "") 
      SetGadgetFont(#String_Date, FontID2) 
      TextGadget(#Text_Ville, 20, 250, 100, 30, "Ville : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Ville, FontID2) 
      StringGadget(#String_Ville, 120, 250, 210, 30, "") 
      SetGadgetFont(#String_Ville, FontID2) 
      ButtonGadget(#Button_Ajouter, 30, 340, 120, 40, "Ajouter ") 
      SetGadgetFont(#Button_Ajouter, FontID2) 
      
      Repeat 
        
        Event = WaitWindowEvent() 
        
        Select Event 
          Case #PB_EventCloseWindow 
            Fenetre = EventWindowID() 
            If Fenetre = #Window_1 
              Fermer_Window_1 = 1 
            EndIf 
            
          Case #PB_EventGadget 
            GadgetID = EventGadgetID() 
            If GadgetID = #Button_Ajouter 
              item_add() 
              Fermer_Window_1 = 1 
            EndIf 
        EndSelect 
        
      Until Fermer_Window_1 = 1 
      
      CloseWindow(#Window_1) 
    EndIf 
  EndIf 
EndProcedure 


Procedure Open_Window_2(Element) 
  If OpenWindow(#Window_2, 339, 72, 444, 420,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_WindowCentered , "Fiche Eleve") 
    If CreateGadgetList(WindowID()) 
      TextGadget(#Text_Nom, 20, 40, 90, 30, "Nom : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Nom, FontID2) 
      StringGadget(#String_Nom, 110, 40, 210, 30, "") 
      SetGadgetFont(#String_Nom, FontID2) 
      TextGadget(#Text_Prenom, 10, 110, 90, 30, "Prenom : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Prenom, FontID2) 
      StringGadget(#String_Prenom, 110, 110, 210, 30, "") 
      SetGadgetFont(#String_Prenom, FontID2) 
      TextGadget(#Text_Date, 0, 170, 130, 50, "Date de naissance : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Date, FontID2) 
      StringGadget(#String_Date, 130, 180, 210, 30, "") 
      SetGadgetFont(#String_Date, FontID2) 
      TextGadget(#Text_Ville, 20, 250, 100, 30, "Ville : ", #PB_Text_Center) 
      SetGadgetFont(#Text_Ville, FontID2) 
      StringGadget(#String_Ville, 120, 250, 210, 30, "") 
      SetGadgetFont(#String_Ville, FontID2) 
      ButtonGadget(#Button_Ajouter, 30, 340, 120, 40, "Quitter la fiche") 
      SetGadgetFont(#Button_Ajouter, FontID2) 
      ForEach Items() 
        If Items()\Nom = GetGadgetItemText(#ListIcon_0, Element, 0) 
          SetGadgetText(#String_Nom,Items()\Nom)  
          SetGadgetText(#String_Prenom,Items()\Prenom) 
          SetGadgetText(#String_Date,Items()\date) 
          SetGadgetText(#String_Ville,Items()\Ville) 
          Break 
        EndIf 
      Next  
          
      Repeat 
        
        Event = WaitWindowEvent() 
        
        Select Event 
          Case #PB_EventCloseWindow 
            Fermer_Window_2 = 1
            
          Case #PB_EventGadget 
            GadgetID = EventGadgetID() 
            If GadgetID = #Button_Ajouter 
              Fermer_Window_2 = 1 
            EndIf 
        EndSelect 
        
      Until Fermer_Window_2 = 1 
      
      CloseWindow(#Window_2) 
    EndIf 
  EndIf 
EndProcedure 
      


;boucle principale 

Open_Window_0() 

Repeat 
  Event = WaitWindowEvent() 
  Select Event 
    Case #PB_EventMenu 
      Select EventMenuID() 
        Case #menu_Info:info() 
        Case#menu_Ajouter:Open_Window_1() 
        Case#menu_Quitter :fermer_window_0= 1        
          
      EndSelect 
    Case #PB_EventGadget 
      Select EventGadgetID() 
        Case #ListIcon_0 
        Position = GetGadgetState(#ListIcon_0)  
        Open_Window_2(Position) 
      EndSelect      
    Case #PB_EventCloseWindow 
      fermer_window_0 = 1
      
  EndSelect 
  
Until fermer_window_0 = 1 

End 

Le problème vient de ce code :

Code : Tout sélectionner

Fenetre = EventWindowID() 
If Fenetre = #Window_2 
  Fermer_Window_2 = 1 
EndIf
Il dtoi falloir indiqué la fenêtre en cours avec UseWindow (quand on quitte la procedure Open_Window_2() notamment)
Le plus étant de le supprimé et de le remplacer par

Code : Tout sélectionner

Fermer_Window_2 = 1
car la gestion de tes fenêtres est distincte
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

tu peux aussi ajouter un test sur l'élément de la listicon

ça évite d'ouvrir une fiche alors qu'il n'y a rien dans la liste.

Code : Tout sélectionner

        Case #ListIcon_0 
          Position = GetGadgetState(#ListIcon_0)  
          If Position >= 0 
            Open_Window_2(Position) 
          EndIf  
bon , et il reste des bugs à corriger , mais bon , ça va t'occuper pour le week-end :)

pis pour les sauvegardes , ça pourrait ressembler à un truc de ce genre , c'est à compléter , il existe des exemples avec SaveFileRequester() .

Code : Tout sélectionner

Procedure Sauve()
  ;SaveFileRequester()
  ;If CreateFile()
    ForEach Items()
      WriteStringN(Items()\Nom)
      WriteStringN(Items()\Prenom) 
      WriteStringN(Items()\date)
      WriteStringN(Items()\Ville)
    Next
   ; CloseFile()
  Else
    MessageRequester("Erreur","impossible de créer le fichier xxxx",0)
 EndIf   
EndProcedure  

Procedure Open()
  ;OpenFileRequester()
  ;If openFile()
    If AddElement(Items()) 
      Items()\Nom = ReadString() 
      Items()\Prenom = ReadString() 
      Items()\date = ReadString() 
      Items()\Ville = ReadString() 
      AddGadgetItem(#ListIcon_0, -1,Items()\Nom) ;on affiche le nom dans le ListIconGadget 
    EndIf 
  ; CloseFile()
Else
  MessageRequester("Erreur","impossible de créer le fichier xxxx",0)
EndIf   
EndProcedure  
Dernière modification par comtois le ven. 15/oct./2004 22:03, modifié 1 fois.
williamm
Messages : 54
Inscription : dim. 05/sept./2004 20:21

Message par williamm »

merci mais ca marche toujours pas il ya encore le meme probleme
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

en ajoutant

Code : Tout sélectionner

      While WindowEvent():Wend
dans la procédure fenêtre 1 , ça merdouille moins , je ne sais pas si c'est rationnel , mais bon ...

Code : Tout sélectionner

; Logiciel de gestion d'eleves par Williamm-2004 
Enumeration 
  #Window_0 
  #Window_1 
  #Window_2  
EndEnumeration 

; constante de la liste d'eleves 

Enumeration 
  #ListIcon_0 
EndEnumeration 

; constante du menu 

Enumeration 
  #menu_Ajouter 
  #menu_Info 
  #menu_Quitter 
EndEnumeration 

;constante des gadgets pour la fenetre 1 

Enumeration 
  #ListIcon_0 
  #Text_Nom 
  #String_Nom 
  #Text_Prenom 
  #String_Prenom 
  #Text_Date 
  #String_Date 
  #Text_Ville 
  #String_Ville 
  #Button_Ajouter 
EndEnumeration 

; constante des fenetres 
;creation d'un eleve 
Structure eleve_struct ;ici on cré une structure avec les champs 
  Nom.s                ;qui t'intéresse 
  Prenom.s 
  date.s 
  Ville.s 
EndStructure 

NewList Items.eleve_struct() ;on cré une nouvelle liste 


;procedure de gestion des items 
Procedure.b item_clear() 
  ClearList(Items()) 
  ProcedureReturn 1 
EndProcedure 

;ajouter un eleve dans la liste 
Procedure.b item_add() 
  If AddElement(Items()) 
    Items()\Nom= GetGadgetText(#String_Nom)  
    Items()\Prenom= GetGadgetText(#String_Prenom) 
    Items()\date= GetGadgetText(#String_Date) 
    Items()\Ville= GetGadgetText(#String_Ville)  
    AddGadgetItem(#ListIcon_0, -1,Items()\Nom) ;on affiche le nom dans le ListIconGadget 
  EndIf 
  ProcedureReturn 1 
EndProcedure 



; police de la liste 

Global FontID1 
FontID1 = LoadFont(1, "Arial", 11, #PB_Font_Bold) 
FontID2 = LoadFont(2, "Arial", 12, #PB_Font_Bold) 


; procedure de du menu info 
Procedure info() 
  MessageRequester("A propos ","Gestion d'eleves par Williamm ",#MB_ICONINFORMATION) 
EndProcedure 

Procedure Gadgets(texte$)
  TextGadget(#Text_Nom, 20, 40, 90, 30, "Nom : ", #PB_Text_Center) 
  SetGadgetFont(#Text_Nom, FontID2) 
  StringGadget(#String_Nom, 110, 40, 210, 30, "") 
  SetGadgetFont(#String_Nom, FontID2) 
  TextGadget(#Text_Prenom, 10, 110, 90, 30, "Prenom : ", #PB_Text_Center) 
  SetGadgetFont(#Text_Prenom, FontID2) 
  StringGadget(#String_Prenom, 110, 110, 210, 30, "") 
  SetGadgetFont(#String_Prenom, FontID2) 
  TextGadget(#Text_Date, 0, 170, 130, 50, "Date de naissance : ", #PB_Text_Center) 
  SetGadgetFont(#Text_Date, FontID2) 
  StringGadget(#String_Date, 130, 180, 210, 30, "") 
  SetGadgetFont(#String_Date, FontID2) 
  TextGadget(#Text_Ville, 20, 250, 100, 30, "Ville : ", #PB_Text_Center) 
  SetGadgetFont(#Text_Ville, FontID2) 
  StringGadget(#String_Ville, 120, 250, 210, 30, "") 
  SetGadgetFont(#String_Ville, FontID2) 
  ButtonGadget(#Button_Ajouter, 30, 340, 120, 40, texte$) 
  SetGadgetFont(#Button_Ajouter, FontID2) 
EndProcedure

;procedure la fenetre principale 
Procedure Open_Window_0() 
  If OpenWindow(#Window_0 , 216, 0, 682, 624,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Gestion  d'eleves - copyright 2004 ") 
    If CreateGadgetList(WindowID()) 
      
      ListIconGadget(#ListIcon_0, 10, 10, 660, 600, "Nom des Eleves ", 656, #PB_ListIcon_CheckBoxes | #PB_ListIcon_GridLines) 
      SetGadgetFont(#ListIcon_0, FontID1) 
      If CreateMenu(0,WindowID()) 
        MenuTitle( "Fichier") 
        MenuItem (#menu_Ajouter ,"Ajouter un eleve ") 
        MenuItem(#menu_Info ,"Information ") 
        MenuItem(#menu_Quitter,"Quitter ") 
      EndIf 
      
    EndIf 
  EndIf 
EndProcedure 


; procedure de la fenetre ajouter 
Procedure Open_Window_1() 
  If OpenWindow(#Window_1, 339, 72, 444, 420,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_WindowCentered , "Ajouter Eleves ") 
    If CreateGadgetList(WindowID()) 
      Gadgets("Ajouter l'élève")
      
      Repeat 
        
        Event = WaitWindowEvent() 
        
        Select Event 
          Case #PB_EventCloseWindow 
            Fermer_Window_1 = 1 
            
          Case #PB_EventGadget 
            GadgetID = EventGadgetID() 
            If GadgetID = #Button_Ajouter 
              item_add() 
              Fermer_Window_1 = 1 
            EndIf 
        EndSelect 
        
      Until Fermer_Window_1 = 1 
      
      CloseWindow(#Window_1) 
      While WindowEvent():Wend 
    EndIf 
  EndIf 
EndProcedure 


Procedure Open_Window_2(Element) 
  If OpenWindow(#Window_2, 339, 72, 444, 420,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_WindowCentered , "Fiche Eleve") 
    If CreateGadgetList(WindowID()) 
      Gadgets("Fermer la fiche")
      ForEach Items() 
        If Items()\Nom = GetGadgetItemText(#ListIcon_0, Element, 0) 
          SetGadgetText(#String_Nom,Items()\Nom)  
          SetGadgetText(#String_Prenom,Items()\Prenom) 
          SetGadgetText(#String_Date,Items()\date) 
          SetGadgetText(#String_Ville,Items()\Ville) 
          Break 
        EndIf 
      Next  
      
      Repeat 
        
        Event = WaitWindowEvent() 
        
        Select Event 
          Case #PB_EventCloseWindow 
            Fermer_Window_2 = 1 
            
          Case #PB_EventGadget 
            GadgetID = EventGadgetID() 
            If GadgetID = #Button_Ajouter 
              Fermer_Window_2 = 1 
            EndIf 
        EndSelect 
        
      Until Fermer_Window_2 = 1 
      
      CloseWindow(#Window_2) 
    EndIf 
  EndIf 
EndProcedure 
      


;boucle principale 

Open_Window_0() 

Repeat 
  Event = WaitWindowEvent() 
  Select Event 
    Case #PB_EventMenu 
      Select EventMenuID() 
        Case #menu_Info:info() 
        Case#menu_Ajouter:Open_Window_1() 
        Case#menu_Quitter :fermer_window_0= 1        
          
      EndSelect 
    Case #PB_EventGadget 
      Select EventGadgetID() 
        Case #ListIcon_0 
          Position = GetGadgetState(#ListIcon_0)  
          If Position>=0 
            Open_Window_2(Position) 
          EndIf 
      EndSelect      
    Case #PB_EventCloseWindow 
      fermer_window_0 = 1 
      
  EndSelect 
  
Until fermer_window_0 = 1 

End  
Dernière modification par comtois le sam. 16/oct./2004 8:30, modifié 1 fois.
Avatar de l’utilisateur
Crystal Noir
Messages : 892
Inscription : mar. 27/janv./2004 10:07

Message par Crystal Noir »

Apparement personne n'a retenu mon idée de coupler sql et pure c'est pas grave :jesors:
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

Crystal Noir a écrit :Apparement personne n'a retenu mon idée de coupler sql et pure c'est pas grave :jesors:
Si, c'est une bonne idée!... A condition de connaître SQL ET PureBasic :wink:
williamm
Messages : 54
Inscription : dim. 05/sept./2004 20:21

Message par williamm »

merci Comtois
ca marche mieux



wiliamm
Répondre