FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC

Développement d'applications avec le langage Panoramic
 
AccueilAccueil  RechercherRechercher  Dernières imagesDernières images  S'enregistrerS'enregistrer  MembresMembres  Connexion  
Derniers sujets
» Form(résolu)
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar leclode Aujourd'hui à 17:59

» trop de fichiers en cours
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar Marc Aujourd'hui à 11:42

» Bataille navale SM
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar jjn4 Hier à 17:39

» Une calculatrice en une ligne de programme
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar jean_debord Hier à 8:01

» Gestion d'un système client-serveur.
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar Pedro Jeu 25 Avr 2024 - 19:31

» Les maths du crocodile
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar jean_debord Jeu 25 Avr 2024 - 10:37

» Naissance de Crocodile Basic
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar jean_debord Jeu 25 Avr 2024 - 8:45

» Editeur EliP 6 : Le Tiny éditeur avec 25 onglets de travail
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar Froggy One Mer 24 Avr 2024 - 18:38

» Dessine-moi une galaxie
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar jjn4 Lun 22 Avr 2024 - 13:47

» Erreur END_SUB
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar jjn4 Lun 22 Avr 2024 - 13:43

» Bug sur DIM_LOCAL ?
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar papydall Dim 21 Avr 2024 - 23:30

» 2D_fill_color(résolu)
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar leclode Sam 20 Avr 2024 - 8:32

» Consommation gaz électricité
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar leclode Mer 17 Avr 2024 - 11:07

» on_key_down (résolu)
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar leclode Mar 16 Avr 2024 - 11:01

» Sous-programme(résolu)
Une Base de Données Relationnelle (BDR) en Panoramic Emptypar jjn4 Jeu 4 Avr 2024 - 14:42

Navigation
 Portail
 Index
 Membres
 Profil
 FAQ
 Rechercher
Rechercher
 
 

Résultats par :
 
Rechercher Recherche avancée
Avril 2024
LunMarMerJeuVenSamDim
1234567
891011121314
15161718192021
22232425262728
2930     
CalendrierCalendrier
Le deal à ne pas rater :
Funko POP! Jumbo One Piece Kaido Dragon Form : où l’acheter ?
Voir le deal

 

 Une Base de Données Relationnelle (BDR) en Panoramic

Aller en bas 
2 participants
AuteurMessage
Klaus

Klaus


Nombre de messages : 12274
Age : 74
Localisation : Ile de France
Date d'inscription : 29/12/2009

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptyJeu 7 Avr 2011 - 13:56

Je me suis amusé à coder une petite base de données relationnelle, entièrement en Panoramic, et gérée entièrement en mémoire. Elle gère des affirmations telles que
<Jack> est <auteur> de <Panoramic>
<Klaus> est <auteur> de <KGF.dll>
<pivert> est <espèce> de <oiseau>
etc. On voit: un <objet> est mis en <relation> avec un autre <objet>.

L'intérêt, c'est qu'on peut d'une part, vérifier si une relation est vraie:
la question: Est-ce que <Klaus> est <auteur> de <Panoramic> retourne faux
la question: Est-ce que <pivert> est <espèce> de <oiseau> retourne vrai
et d'autre part, on peut poser des questions partielles:
Remplir les champs <> <auteur> <> retourne:
auteur relie
Jack à Panoramic
Klaus à KGF.dll

Le nombre d'objets n'est pas limité, ni la longueur des noms, ni le nombre des relations. Il y a ussi des fonctions pour renommer une entité, supprimer une entité ou infirmer une relation. Il y a aussi une fonction donnant toutes les informations connues sur une entité. Voici le code:
Code:
' BDR.bas - Base de Données Relationnelle

label valider, change_fonction
label affirmer, verifier, completer, infirmer, renommer, supprimer, informer
label joindre, retirer, copier, unir, couper, soustraire, lister, vider
label memoriser, ajouter, oublier, creer, chercher
label creer_entite, chercher_triade1, chercher_triade2, chercher_triade3
label info_1xx, info_xrx, info_xx2
label chercher_entite
label chercher_triade_partielle_1Rx, chercher_triade_partielle_1x2
label chercher_triade_partielle_xR2
label chercher_triade_partielle_1xx, chercher_triade_partielle_xx2
label chercher_triade_partielle_xRx
label chercher_nom_par_id
label sauvegarder, restaurer, restaurer_1
label chercher_element, ajouter_element, chercher_collection, creer_collection
label lister_elements
label aide, aide_general, aide_relations, aide_collections, aide_donnees

dim debug%
dim n_entite% , i%, j%, nom$, nom1$, nom2$, rel$, s$, oper%, t%, s1$, s2$
dim sr$, s3$, id%, id1%, idr%, id2%, inex%, triade$, libre%, zero$, file$
dim flag_1020%, start_1020%, cnt%, idx%, nomx$, ic%, k%
dim data_1$, data_r$, data_2$, data$

zero$ = "0000000000"
debug% = 0

width 0,1100 : height 0,800
caption 0,"BDR V1.07' du 14/4/2011"

    form  30 : hide 30 : top 30,40 : left 30,350 : width 30,900 : height 30,750
    caption 30,"Aide sur BDR" : command_target_is 30
    button 31 : top 31,10 : left 31,10 : caption 31,"Général" : on_click 31,aide_general
    button 32 : top 32,10 : left 32,150 : caption 32,"Relations" : on_click 32,aide_relations
    button 33 : top 33,10 : left 33,290 : caption 33,"Collections" : on_click 33,aide_collections
    button 34 : top 34,10 : left 34,430 : caption 34,"Données" : on_click 34,aide_donnees
    alpha 41 : top 41,15 : left 41,10 : font_size 41,10 : font_bold 41
    alpha 42 : top 42,15 : left 42,10 : font_size 42,10 : font_bold 42
    alpha 43 : top 43,15 : left 43,10 : font_size 43,10 : font_bold 43
    alpha 44 : top 44,15 : left 44,10 : font_size 44,10 : font_bold 44
    container 51 : caption 51,"Général" : parent 41,51 : top 51,40 : left 51,10 : width 51,830 : height 51,650
    container 52 : caption 52,"Relations" : parent 42,52 : hide 52 : top 52,40 : left 52,10 : width 52,830 : height 52,650
    container 53 : caption 53,"Collections" : parent 43,53 : hide 53 : top 53,40 : left 53,10 : width 53,830 : height 53,650
    container 54 : caption 54,"Données" : parent 44,54 : hide 54 : top 54,40 : left 54,10 : width 54,830 : height 54,650
    command_target_is 0
   
    s$ = "Ce programme réalise une petite Base de Données Relationnelle (BDR) en mémoire."+chr$(13)+chr$(13)
    s$ = s$ + "Les éléments gérées par la base sont des <entités>. Ces entités peuvent être mises en <relation>"+chr$(13)
    s$ = s$ + "les unes avec les autres, et peuvent être associées en <collections>."+chr$(13)+chr$(13)
    s$ = s$ + "Une relation est elle-même une entité, mais elle a une particularité: elle lie deux entités A et B d'une"+chr$(13)
    s$ = s$ + "manière univoque:  A --> (R) --> B. On dit que A est en relation R avec B (Martin est père de Paul)."+chr$(13)+chr$(13)
    s$ = s$ + "Une collection est un ensemble non ordonné d'entités, sans recourir aux relations. Ce sont des ensembles"+chr$(13)
    s$ = s$ + "dans le sens mathématique:  A €  {B}. On dit que A est élément de B (canard est élément de oiseaux)."+chr$(13)+chr$(13)
    s$ = s$ + "Les commandes sont données par une combo de sélection des comandes, et des champs paramètres qui sont"+chr$(13)
    s$ = s$ + "affichés en fonction de la commande choisie. Il y a de 1 à 3 paramètres recevant chacun le nom d'une"+chr$(13)
    s$ = s$ + "entité. Les paramètres présentés sont toujours requis; selon les commandes, les entités concernées doivent"+chr$(13)
    s$ = s$ + "exister ou pas, être une collection ou pas, etc. Le sens des paramètres est noté entre <...>, précédés des"+chr$(13)
    s$ = s$ + "lettres suivantes:"+chr$(13)
    s$ = s$ + "    E - entité doit Exister"+chr$(13)
    s$ = s$ + "    I - entité doit être Inexistant"+chr$(13)
    s$ = s$ + "    C - entité doit être une Collection"+chr$(13)
    s$ = s$ + "    P - entité Peut exister"+chr$(13)
    s$ = s$ + "    O - entité optionnelle"+chr$(13)
    s$ = s$ + "Les commandes générales sont les suivantes:"+chr$(13)
    s$ = s$ + "    Créer              créer une entité"+chr$(13)
    s$ = s$ + "        I<nom entité>"+chr$(13)
    s$ = s$ + "        L'entité sera créée."+chr$(13)
    s$ = s$ + "    Renommer          change le nom d'une entité"+chr$(13)
    s$ = s$ + "        E<ancien nom> I<nouveau nom>"+chr$(13)
    s$ = s$ + "        Le nouveau nom remplace l'ancien."+chr$(13)
    s$ = s$ + "    Supprimer          supprime une entité."+chr$(13)
    s$ = s$ + "        E<nom à supprimer>"+chr$(13)
    s$ = s$ + "        L'entité sera supprimé, ainsi que toute référence par des relations, et toute appartenance"+chr$(13)
    s$ = s$ + "        aux collections. Si elle est elle-même une collection, ses éléments seront libérés."+chr$(13)
    s$ = s$ + "    Que sait-on sur    affiche toutes les informations connues sur une entité."+chr$(13)
    s$ = s$ + "        E<nom à interroger>"+chr$(13)
    s$ = s$ + "        On affiche l'ensemble des informations connues pour l'entité ciblée, y compris son contexte"+chr$(13)
    s$ = s$ + "        relationnel ainsi que ses appartenances aux collections ou ses membres si elle est collection."+chr$(13)+chr$(13)
    s$ = s$ + "Les boutons <Sauvegarder> et <Restaurer> permettent d'enregistrer ou de réouvrir une BDR."
    caption 41,s$

    s$ = ""
    s$ = s$ + "Les fonctions suivantes gèrent les structures des relations."+chr$(13)+chr$(13)
    s$ = s$ + "J'affirme              crée une relation A --> R --> B"+chr$(13)
    s$ = s$ + "    P<nom A> P<Nom R> P<nom B>"+chr$(13)
    s$ = s$ + "    On crée la relation R entre A et B. Les entités A,R et B peuvent exister. Chaque entité inexistante sera créée,"+chr$(13)
    s$ = s$ + "    sinon, elle est réutilisée. Une entité A ou B peut également être <relation>, comme dans l'exemple suivant:"+chr$(13)
    s$ = s$ + "    <Martin> est <père> de <Sylvain>"+chr$(13)
    s$ = s$ + "    <Martin> est <tuteur> de <Véronique>"+chr$(13)
    s$ = s$ + "    <père> est <responsable> de <enfants>"+chr$(13)
    s$ = s$ + "    <tuteur> est <responsable> de <enfants>"+chr$(13)
    s$ = s$ + "Et on voit dans cet exemple que les relations <père> et <tuteur> sont liées par"+chr$(13)
    s$ = s$ + "la relation <responsable> à l'entité objet <enfants>."+chr$(13)+chr$(13)
    s$ = s$ + "<Est-ce que>.          vérifie une relation"+chr$(13)
    s$ = s$ + "    E<nom A> E<nm R> E<nom B>"+chr$(13)
    s$ = s$ + "    la véracité de la relation A --> R --> B est vérifiée. Le résultat est Vrai ou Faux"+chr$(13)+chr$(13)
    s$ = s$ + "<Complète les champs>. cherche les éléments manquants d'une relation"+chr$(13)
    s$ = s$ + "    OE<nom A> OE<nom R> OE<nom B°"+chr$(13)
    s$ = s$ + "Le programme affiche dans la liste de droite un résultat textuel de la recherche, en affichant tous"+chr$(13)
    s$ = s$ + "les résultats possibles."+chr$(13)+chr$(13)
    s$ = s$ + "J'infirme que          annule une relation"+chr$(13)
    s$ = s$ + "    E<nom A> E<nom R> E<nom B>"+chr$(13)
    s$ = s$ + "Si la relation existe, elle est supprimée."+chr$(13)
    caption 42,s$
   
    s$ = ""
    s$ = s$ + "Les fonctions suivantes gèrent le contexte des collections. Elles servent à placer une entité dans une"+chr$(13)
    s$ = s$ + "collection ou à le retirer, effectuer la maintenance des collections, et effectuer les opérations"+chr$(13)
    s$ = s$ + "mathématiques d'union (unir), d'intersection (couper) et différence (soustraire) entre deux collections."+chr$(13)+chr$(13)
    s$ = s$ + "Joindre                introduire une entité dans une collection"+chr$(13)
    s$ = s$ + "    P<nom élément> P<nom collection>"+chr$(13)
    s$ = s$ + "    Si les entites n'existent pas, elles sont créées. L'entité élément est introduite dans la collection"+chr$(13)+chr$(13)
    s$ = s$ + "Retirer                enlever une entité d'une collection"+chr$(13)
    s$ = s$ + "    E<nom élément> E<nom collection>"+chr$(13)
    s$ = s$ + "    Si l'entité élément est membre de la collection, il sera retiré."+chr$(13)+chr$(13)
    s$ = s$ + "Copier                créer un duplicata d'une collection"+chr$(13)
    s$ = s$ + "    E<nom collection origine> I<nom collection destinationW"+chr$(13)
    s$ = s$ + "    La collection destination sera créée, et tous les éléments de la collection origine y seront introduits."+chr$(13)+chr$(13)
    s$ = s$ + "Unir                  effectuer l'union entre deux collections"+chr$(13)
    s$ = s$ + "    E<nom collection A> E<nom collection B>"+chr$(13)
    s$ = s$ + "    La collection B sera remplacée par l'union des collections A et B."+chr$(13)+chr$(13)
    s$ = s$ + "Couper                effectuer l'intersection entre deux collections"+chr$(13)
    s$ = s$ + "    E<nom collection A> E<nom collection B>"+chr$(13)
    s$ = s$ + "    La collection B sera remplacée par l'intersection des collections A et B."+chr$(13)+chr$(13)
    s$ = s$ + "Soustraire            effectuer la différence entre deux collections"+chr$(13)
    s$ = s$ + "    E<nom collection A> E<nom collection B>"+chr$(13)
    s$ = s$ + "    La collection B sera remplacée par la différence des collections B moins A."+chr$(13)+chr$(13)
    s$ = s$ + "Lister                afficher le contenu d'une collection"+chr$(13)
    s$ = s$ + "    E<nom collection>"+chr$(13)
    s$ = s$ + "    On affiche l'ensemble des éléments de la collection."+chr$(13)+chr$(13)
    s$ = s$ + "Vider                  vider une collection"+chr$(13)
    s$ = s$ + "    E<nom collection>"+chr$(13)
    s$ = s$ + "    On retire l'ensemble des éléments de la collection."+chr$(13)
    caption 43,s$
   
    s$ = ""
    s$ = s$ + "Les fonctions de données permettent de gérer des données sous forme de chaîne de caractères. On peut le affecter"+chr$(13)
    s$ = s$ + "des données à n'importe quelle entité, et on peut les effacer sans toucher aux autres informations de l'entité."+chr$(13)+chr$(13)
    s$ = s$ + "Mémoriser les données    mémoriser des données pour une entité"+chr$(13)
    s$ = s$ + "    <chaîne de caractères> E<nom d'entité>"+chr$(13)
    s$ = s$ + "    La chaîne de caractères sera mémorisée pour cette entité."+chr$(13)+chr$(13)
    s$ = s$ + "Ajouter les données        ajouter des données aux données d'une entité"+chr$(13)
    s$ = s$ + "    <chaîne de caractères> E<nom d'entité>"+chr$(13)
    s$ = s$ + "    La chaîne de caractères sera ajoutée à la fin des données de cette entité."+chr$(13)+chr$(13)
    s$ = s$ + "Oublier les données      mémoriser des données pour une entité"+chr$(13)
    s$ = s$ + "    E<nom d'entité>"+chr$(13)
    s$ = s$ + "    Toutes les données de cette entité seront effacées."+chr$(13)+chr$(13)
    s$ = s$ + "Chercher les données"+chr$(13)
    s$ = s$ + "    <données à chercher>"+chr$(13)
    s$ = s$ + "    On cherche toutes les entités dont les données contiennent la chaîne de caractères spécifiée."+chr$(13)+chr$(13)
    caption 44,s$

if debug%=0
    dlist 1000  : ' liste interne pour résultats intermédiaires
    dlist 1001  : ' entités chronologiques (id,nom)
    dlist 1002  : ' entités triées (nom,id)
    dlist 1011  : ' triades (A,R,B)
    dlist 1012  : ' triades (R,B,A)
    dlist 1013  : ' triades (B,A,R)
    dlist 1014  : ' elements pour les collections
    dlist 1015  : ' collections pour les éléments
else
    list 1000  : ' liste interne pour résultats intermédiaires
        top 1000,420 : left 1000,10 : height 1000,300
    list 1001  : ' entités chronologiques (id,nom)
        top 1001,100 : left 1001,10 : height 1001,300
    list 1002  : ' entités triées (nom,id)
        top 1002,100 : left 1002,140 : height 1002,300
    list 1011  : ' triades (A,R,B)
        top 1011,100 : left 1011,270 : height 1011,300 : width 1011,60
    list 1012  : ' triades (R,B,A)
        top 1012,100 : left 1012,340 : height 1012,300 : width 1012,60
    list 1013  : ' triades (B,A,R)
        top 1013,100 : left 1013,410 : height 1013,300 : width 1013,60
    list 1014  : ' elements pour les collections
        top 1014,100 : left 1014,480 : height 1014,300 : width 1014,100
    list 1015  : ' collections pour les éléments
        top 1015,100 : left 1015,590 : height 1015,300 : width 1015,100

end_if
memo 1020  : ' liste de résultats
    top 1020,100 : left 1020,710 : height 1020,300 : width 1020,300
    bar_vertical 1020 : bar_horizontal 1020
sort_on 1002 : sort_on 1011 : sort_on 1012 : sort_on 1013 : sort_on 1014 : sort_on 1015

combo 10 : top 10,10 : left 10,10 : on_change 10,change_fonction
item_add 10,"J'affirme que"
item_add 10,"Est-ce que"
item_add 10,"Complète les champs"
item_add 10,"J'infirme que"
item_add 10,"Créer"
item_add 10,"Renommer"
item_add 10,"Supprimer"
item_add 10,"Que sait-on sur"
item_add 10,"Joindre"
item_add 10,"Retirer"
item_add 10,"Copier"
item_add 10,"Unir"
item_add 10,"Couper"
item_add 10,"Soustraire"
item_add 10,"Lister"
item_add 10,"Vider"
item_add 10,"Mémoriser les données"
item_add 10,"Ajouter les données"
item_add 10,"Oublier les données"
item_add 10,"Chercher les données"

text 10,"J'affirme que"
edit 1 : top 1,40 : left 1,10
alpha 2 : top 2,40 : left 2,140 : caption 2,"est"
edit 3 : top 3,40 : left 3,180
alpha 4 : top 4,40 : left 4,310 : caption 4,"de"
edit 5 : top 5,40 : left 5,350
button 6 : top 6,40 : left 6,490 : caption 6,"Valider"
on_click 6,valider
button 7 : top 7,40 : left 7,600 : caption 7,"Sauvegarder"
on_click 7,sauvegarder
button 8 : top 8,40 : left 8,710 : caption 8,"Restaurer"
on_click 8,restaurer
button 9 : top 9,40 : left 9,820 : caption 9,"Aide"
on_click 9,aide

save_dialog 20
open_dialog 21
filter 20,"Sauvegardes|*.bdr"
filter 21,"Sauvegardes|*.bdr"

end

change_fonction:
s$ = text$(10)
oper% = 0
for i%=1 to count(10)
    if text$(10)=item_read$(10,i%) then oper% = i%
next i%
for i%=1 to 5
    show i%
next i%
caption 2,"est"
select oper%
    case 5  : hide 2 : hide 3 : hide 4 : hide 5
    case 6  : hide 4 : hide 5 : caption 2,"en"
    case 7  : hide 2 : hide 3 : hide 4 : hide 5
    case 8  : hide 2 : hide 3 : hide 4 : hide 5
    case 9  : hide 4 : hide 5 : caption 2,"à"
    case 10 : hide 4 : hide 5 : caption 2,"de"
    case 11 : hide 4 : hide 5 : caption 2,"dans"
    case 12 : hide 4 : hide 5 : caption 2,"à"
    case 13 : hide 4 : hide 5 : caption 2,"de"
    case 14 : hide 4 : hide 5 : caption 2,"à"
    case 15 : hide 2 : hide 3 : hide 4 : hide 5
    case 16 : hide 2 : hide 3 : hide 4 : hide 5
    case 17:  hide 4 : hide 5 : caption 2,"dans"
    case 18:  hide 4 : hide 5 : caption 2,"dans"
    case 19:  hide 2 : hide 3 : hide 4 : hide 5
    case 20:  hide 2 : hide 3 : hide 4 : hide 5
end_select
return

valider:
s$ = text$(10)
for i%=1 to count(10)
    if text$(10)=item_read$(10,i%) then oper% = i%
next i%
if (oper%<3 ) or (oper%=4)
    for i%=1 to 3
        if trim$(text$(i%*2-1))=""
            j% = message_error_ok("Le champ "+str$(i%)+" n'est pas renseigné.")
            return
        end_if
    next i%
end_if
nom1$ = text$(1)
rel$ = text$(3)
nom2$ = text$(5)
select oper%
' fonctions relationnelles
    case 1: gosub affirmer
    case 2: gosub verifier
    case 3: gosub completer
    case 4: gosub infirmer
    case 5: gosub creer
    case 6: gosub renommer
    case 7: gosub supprimer
    case 8: gosub informer
' fonctions des collections
    case 9: gosub joindre
    case 10: gosub retirer
    case 11: gosub copier
    case 12: gosub unir
    case 13: gosub couper
    case 14: gosub soustraire
    case 15: gosub lister
    case 16: gosub vider
' fonctions des données
    case 17: gosub memoriser
    case 18: gosub ajouter
    case 19: gosub oublier
    case 20: gosub chercher
end_select
return

chercher:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
s$ = trim$(text$(1))
if s$=""
    j% = message_error_ok("Il n'y a pas de données à chercher.")
    return
end_if
clear 1020
for i%=1 to count(1001)
    s1$ = item_read$(1001,i%)
    s2$ = mid$(s1$,instr(s1$,";")+1,len(s1$))
    if instr(s2$,s$)>0
        s2$ = mid$(s1$,instr(s1$,",")+1,len(s1$))
        item_add 1020,"  "+left$(s2$,instr(s2$,";")-1)
    end_if
next i%
if count(1020)>0
    item_insert 1020,1,"Entités contenant "+s$+":"
else
    item_add 1020,"Aucune entite ne contient "+s$
end_if
return

creer:
nom$ = nom1$
gosub chercher_entite
if inex%=0
    j% = message_error_ok("L'entité "+nom$+" existe déjà.")
    return
end_if
data$ = ""
gosub creer_entite
return

joindre:
data$ = ""
nom$ = nom1$
gosub creer_entite
id1% = id%
nom$ = rel$
gosub creer_entite
idr% = id%
nom$ = rel$
gosub chercher_collection
if inex%=1 then gosub creer_collection
gosub chercher_element
if inex%=1 then gosub ajouter_element
return

retirer:
if count(1002)<2
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
nom$ = rel$
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
if count(1014)>0
    s1$ = ","+str$(id1%)+","
    k% = count(1014)
    i% = 0
    while i%<k%
        i% = i% + 1
        s$ = item_read$(1014,i%) + ","
        if left$(s$,10)=right$(zero$+str$(idr%),10)
            j% = instr(s$,s1$)
            if j%>0
                s$ = left$(s$,j%) + mid$(s$,j%+len(s1$),len(s$))
                if len(s$)=j%
                    sort_off 1014
                    item_delete 1014,i%
                    sort_on 1014
                    i% = i% - 1
                    k% = k% - 1
                else
                    sort_off 1014
                    item_delete 1014,i%
                    item_insert 1014,i%,mid$(s$,1,len(s$)-1)
                    sort_on 1014
                end_if
            end_if
        end_if
    end_while
end_if
if count(1015)>0
    j% = count(1015)
    i% = 0
    s$ = right$(zero$+str$(id1%),10)+","+str$(idr%)
    while i%<j%
        i% = i% + 1
        if item_read$(1015,i%)=s$
            sort_off 1015
            item_delete 1015,i%
            sort_on 1015
            i% = i% - 1
            j% = j% - 1
        end_if
    end_while
end_if
return

copier:
if count(1002)<2
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
nom$ = text$(3)
if trim$(nom$)=""
    j% = message_error_ok("L'entité destination manque.")
    return
end_if
gosub chercher_entite
if inex%=0
    j% = message_error_ok("L'entité "+nom$+" existe déjà.")
    return
end_if
rel$ = nom$
nom$ = rel$
gosub creer_entite
idr% = id%
s1$ = right$(zero$+str$(id1%),10) + ","
for i%=1 to count(1014)
    s$ = item_read$(1014,i%)
    if left$(s$,11)=s1$
        s$ = right$(zero$+str$(idr%),10)+mid$(s$,11,len(s$))
        item_add 1014,s$
        s$ = mid$(s$,12,len(s$)) + ","
        s1$ = str$(idr%)
        repeat
            i% = instr(s$,",")
            if i%>0
                id% = val(left$(s$,i%-1))
                s$ = mid$(s$,i%+1,len(s$))
                item_add 1015,right$(zero$+str$(id%),10)+","+s1$
            end_if
        until i%=0
        return
    end_if
next i%
return

unir:
couper:
soustraire:
if count(1002)<2
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
clear 1000
s1$ = right$(zero$+str$(idr%),10)
s2$ = right$(zero$+str$(id1%),10)
' déplacer les éléments de REL dans temporaire
j% = count(1015)
i% = 0
sort_off 1015
while i%<j%
    i% = i% + 1
    s$ = item_read$(1015,i%)
    if val(mid$(s$,12,len(s$)))=idr%
        item_add 1000,s$
        item_delete 1015,i%
        i% = i% - 1
        j% = j% - 1
    end_if
end_while
sort_on 1015
' traiter les éléments de NOM1
for i%=1 to count(1015)
    s$ = item_read$(1015,i%)
    if oper%=11
        if val(mid$(s$,12,len(s$)))=id1%
            s3$ = left$(s$,11) + str$(idr%)
            inex% = 1
            for j%=1 to count(1000)
                if s3$=item_read$(1000,j%)
                    inex% = 0
                    exit_for
                end_if
            next j%
            if inex%=1 then item_add 1000,s3$
        end_if
    end_if
    if oper%=12
        if val(mid$(s$,12,len(s$)))=id1%
            s3$ = left$(s$,11) + str$(idr%)
            inex% = 1
            for j%=1 to count(1000)
                if s3$=item_read$(1000,j%)
                    item_delete 1000,j%
                    item_insert 1000,j%,"*"+s3$
                    exit_for
                end_if
            next j%
        end_if
    end_if
    if oper%=13
        if val(mid$(s$,12,len(s$)))=id1%
            s3$ = left$(s$,11) + str$(idr%)
            inex% = 1
            for j%=1 to count(1000)
                if s3$=item_read$(1000,j%)
                    item_delete 1000,j%
                    exit_for
                end_if
            next j%
        end_if
    end_if
next i%
if oper%=12 : ' cas "couper"
    j% = count(1000)
    i% = 0
    while i%<j%
        i% = i% + 1
        s$ = item_read$(1000,i%)
        item_delete 1000,i%
        if left$(s$,1)="*"
            item_insert 1000,i%,mid$(s$,2,len(s$))
        else
            i% = i% - 1
            j% = j% - 1
        end_if
    end_while
end_if
' reffacer tous les éléments de REL
j% = count(1015)
i% = 0
sort_off 1015
while i%<j%
    i% = i% + 1
    s$ = item_read$(1015,i%)
    if val(mid$(s$,12,len(s$)))=idr%
        item_delete 1015,i%
        i% = i% - 1
        j% = j% - 1
    end_if
end_while
sort_on 1015
' replacer tous les éléments dans REL
s1$ = ""
for i%=1 to count(1000)
    s$ = item_read$(1000,i%)
    item_add 1015,s$
    s1$ = s1$ + ","+str$(val(left$(s$,10)))
next i%
' remplacer la liste des éléments de REL
j% = count(1014)
i% = 0
while i%<j%
    i% = i% + 1
    s$ = item_read$(1014,i%)
    if val(left$(s$,10))=idr%
        s$ = left$(s$,10) + s1$
        sort_off 1014
        item_delete 1014,i%
        sort_on 1014
        item_add 1014,s$
        return
    end_if
end_while
return

lister:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
clear 1020
item_add 1020,nom1$+" est une collection comprenant:"
for i%=1 to count(1015)
    s$ = item_read$(1015,i%)
    if val(mid$(s$,12,len(s$)))=id1%
        id% = val(left$(s$,10))
        gosub chercher_nom_par_id
        item_add 1020,"  "+nom$
    end_if
next i%
return

vider:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
j% = count(1015)
i% = 0
sort_off 1015
while i%<j%
    i% = i% + 1
    s$ = item_read$(1015,i%)
    if val(mid$(s$,12,len(s$)))=id1%
        item_delete 1015,i%
        i% = i% - 1
        j% = j% - 1
    end_if
end_while
sort_on 1015
for i%=1 to count(1014)
    s$ = item_read$(1014,i%)
    if val(left$(s$,10))=id1%
        sort_off 1014
        item_delete 1014,i%
        sort_on 1014
        return
    end_if
next i%
return

chercher_element:
inex% = 0
s$ = right$(zero$+str$(id1%),10)+","+str$(idr%)
if count(1015)>0
    for i%=1 to count(1015)
        if item_read$(1015,i%)=s$ then return
    next i%
end_if
inex% = 1
return

lister_elements:
inex% = 1
s$ = right$(zero$+str$(id1%),10)+","
if count(1015)>0
    for i%=1 to count(1015)
        if left$(item_read$(1015,i%),11)=s$
            if inex%=1 then item_add 1020,nomx$+" est élément de:"
            inex% = 0
            id% = val(mid$(item_read$(1015,i%),12,10))
            gosub chercher_nom_par_id
            item_add 1020,"  "+nom$
        end_if
    next i%
end_if
return

ajouter_element:
item_add 1015,s$
s$ = item_read$(1014,ic%)
s$ = s$ + "," + str$(id1%)
sort_off 1014
item_delete 1014,ic%
item_insert 1014,ic%,s$
return

chercher_collection:
inex% = 0
if count(1014)>0
    for ic%=1 to count(1014)
        if val(left$(item_read$(1014,ic%),10))=idr% then return
    next ic%
end_if
inex% = 1
return

creer_collection:
item_add 1014,right$(zero$+str$(idr%),10)
ic% = count(1014)
return


affirmer:
nom$ = nom1$
data$ = ""
gosub creer_entite
id1% = id%
nom$ = rel$
gosub creer_entite
idr% = id%
nom$ = nom2$
gosub creer_entite
id2% = id%
gosub chercher_triade1
if inex%=1
    item_add 1011,triade$
    item_add 1012,str$(idr%)+","+str$(id2%)+","+str$(id1%)
    item_add 1013,str$(id2%)+","+str$(id1%)+","+str$(idr%)
end_if
return

infirmer:
if count(1002)<3
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
nom$ = text$(5)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom2$ = nom$
id2% = id%
gosub chercher_triade1
if inex%=0
    item_delete 1011,i%
    gosub chercher_triade2
    if inex%=0 then item_delete 1012,i%
    gosub chercher_triade3
    if inex%=0 then item_delete 1013,i%
    j% = message_information_ok("La relation a été annulée.")
else
    j% = message_information_ok(nom1$+" n'est pas "+rel$+" de "+nom2$)
end_if
return

verifier:
if count(1002)<3
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
nom$ = text$(5)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom2$ = nom$
id2% = id%
gosub chercher_triade1
if inex%=0
    j% = message_information_ok(nom1$+" est bien "+rel$+" de "+nom2$)
else
    j% = message_information_ok(nom1$+" n'est pas "+rel$+" de "+nom2$)
end_if
return

renommer:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(3)
gosub chercher_entite
if inex%=0
    j% = message_error_ok("L'entité "+nom$+" existe déjà.")
    return
end_if
nom2$ = nom$
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
sort_off 1002
item_delete 1002,i%
item_insert 1002,i%,nom2$+","+str$(id1%)
sort_on 1002
item_delete 1001,id1%
item_insert 1001,id1%,right$(zero$+str$(id1%),10)+","+nom2$+";"+data_2$
return

supprimer:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
' supprimer l'entité elle-même
item_delete 1002,i%
item_delete 1001,id1%
item_insert 1001,id1%,right$(zero$+str$(id1%),10)+",----------"+";"
' supprimer les informations relationnelles
s1$ = str$(id1%)
for t%=1 to 3
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if (instr(s$,s1$+",")>0) or (instr(s$,","+s1$)>0)
            item_delete 1010+t%,i%
            i% = i% - 1
            if i%=count(1010+t%) then exit_for
        end_if
    next i%
next t%
' supprimer les informations de collection
if count(1014)>0
    k% = count(1014)
    i% = 0
    while i%<k%
        i% = i% + 1
        s$ = item_read$(1014,i%) + ","
        s1$ = ","+str$(id1%)+","
        j% = instr(s$,s1$)
        if j%>0
            s$ = left$(s$,j%) + mid$(s$,j%+len(s1$),len(s$))
            if len(s$)=j%
                sort_off 1014
                item_delete 1014,i%
                sort_on 1014
                i% = i% - 1
                k% = k% - 1
            else
                sort_off 1014
                item_delete 1014,i%
                item_insert 1014,i%,mid$(s$,1,len(s$)-1)
                sort_on 1014
            end_if
        end_if
    end_while
end_if
if count(1015)>0
    j% = count(1015)
    i% = 0
    while i%<j%
        i% = i% + 1
        s$ = item_read$(1015,i%)
        if val(left$(s$,10))=id1%
            sort_off 1015
            item_delete 1015,i%
            sort_on 1015
            i% = i% - 1
            j% = j% - 1
        else
            s$ = mid$(s$,12,len(s$))
            if val(s$)=id1%
                sort_off 1015
                item_delete 1015,i%
                sort_on 1015
                i% = i% - 1
                j% = j% - 1
            end_if
        end_if
    end_while
end_if
return

informer:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
data_1$ = data$
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nomx$ = nom$
idx% = id%
gosub chercher_nom_par_id
clear 1020
item_add 1020,nom$+" a les données:"
item_add 1020,"  "+data$
flag_1020% = 0
' lister les informations relationnelles
start_1020% = count(1020)+1
id1% = idx%
nom1$ = nomx$
gosub info_1xx
start_1020% = count(1020)+1
idr% = idx%
rel$ = nomx$
gosub info_xrx
start_1020% = count(1020)+1
id2% = idx%
nom2$ = nomx$
gosub info_xx2
' lister les informations des collections
idr% = idx%
gosub chercher_collection
if inex%=0
    item_add 1020,nomx$+" est collection de:"
    s$ = item_read$(1014,ic%)
    s$ = mid$(s$,12,len(s$))
    repeat
        i% = instr(s$,",")
        if i%>0
            id% = val(left$(s$,i%-1))
            gosub chercher_nom_par_id
            item_add 1020,"  "+nom$
            s$ = mid$(s$,i%+1,len(s$))
        end_if
    until i%=0
    id% = val(s$)
    gosub chercher_nom_par_id
    item_add 1020,"  "+nom$
end_if
gosub lister_elements

return

completer:
flag_1020% = 1
start_1020% = 1
nom1$ = trim$(text$(1))
rel$ = trim$(text$(3))
nom2$ = trim$(text$(5))
if nom1$=""
' [?,x,x] on cherche nom1
    if rel$=""
    ' [?,?,x] on cherche rel
        if nom2$=""
        ' [?,?,?] on cherche nom2
            j% = message_error_ok("La recherche est trop vaste.")
            return
        else
        ' [?,?,$] on a nom2 ==> on cherche nom1 et rel pour nom2
            nom$ = nom2$
            gosub chercher_entite
            id2% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            gosub info_xx2
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
        end_if
    else
    ' [?,$,x] on a rel
        if nom2$=""
        ' [?,$,?] on cherche nom1 et nom2 pour rel
            nom$ = rel$
            gosub chercher_entite
            idr% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            gosub info_xrx
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
        else
        ' [?,$,$] on a nom2 ==> on cherche nom1 pour rel et nom2
            nom$ = rel$
            gosub chercher_entite
            idr% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            nom$ = nom2$
            gosub chercher_entite
            id2% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            triade$ = str$(idr%)+","+str$(id2%)+","
            t% = 2
            gosub chercher_triade_partielle_xR2
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
            for i%=1 to count(1020)
                id% = val(item_read$(1020,i%))
                gosub chercher_nom_par_id
                item_delete 1020,i%
                item_insert 1020,i%,nom$
            next i%
            item_insert 1020,1,rel$ + " de " + nom2$ + ":"
        end_if
    end_if
else
' on a nom1
    if rel$=""
    ' [$,?,x] on cherche rel et nom1
        if nom2$=""
        ' [$,?,?] on cherche nom2 et rel pour nom1
            nom$ = nom1$
            gosub chercher_entite
            id1% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            gosub info_1xx
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
        else
        ' [$,?,$] on a nom2 ==> on cherche rel pour nom1 et nom2
            nom$ = nom1$
            gosub chercher_entite
            id1% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            nom$ = nom2$
            gosub chercher_entite
            id2% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            triade$ = str$(id2%)+","+str$(id1%)+","
            t% = 3
            gosub chercher_triade_partielle_1x2
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
            for i%=1 to count(1020)
                id% = val(item_read$(1020,i%))
                gosub chercher_nom_par_id
                item_delete 1020,i%
                item_insert 1020,i%,nom$
            next i%
            item_insert 1020,1,nom1$ + " est pour " + nom2$ + ":"
        end_if
    else
    ' on a rel
        if nom2$=""
        ' [$,$,?] on cherche nom2 pour nom1 et rel
            nom$ = nom1$
            gosub chercher_entite
            id1% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            nom$ = rel$
            gosub chercher_entite
            idr% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+rel$+" n'existe pas.")
                return
            end_if
            triade$ = str$(id1%)+","+str$(idr%)+","
            t% = 1
            gosub chercher_triade_partielle_1Rx
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
            for i%=1 to count(1020)
                id% = val(item_read$(1020,i%))
                gosub chercher_nom_par_id
                item_delete 1020,i%
                item_insert 1020,i%,nom$
            next i%
            item_insert 1020,1,nom1$ + " est " + rel$ + " de: "
        else
        ' [$,$,$] on a nom2 ==> on ne cherche rien !
            j% = message_error_ok("Il n'y a rien à compléter.")
            return
        end_if
    end_if
end_if
return

info_1xx:
            triade$ = str$(id1%)+","
            t% = 1
            gosub chercher_triade_partielle_1xx
            if inex%=1 then return
            for i%=start_1020% to count(1020)
                s3$ = item_read$(1020,i%)
                id% = val(left$(s3$,instr(s3$,",")-1))
                gosub chercher_nom_par_id
                sr$ = nom$ + " de "
                id% = val(mid$(s3$,instr(s3$,",")+1,20))
                gosub chercher_nom_par_id
                sr$ = sr$ + nom$
                item_delete 1020,i%
                item_insert 1020,i%,"  "+sr$
            next i%
            item_insert 1020,start_1020%,nom1$ + " est: "
return

info_xrx:
            triade$ = str$(idr%)+","
            t% = 2
            gosub chercher_triade_partielle_xRx
            if inex%=1 then return
            for i%=start_1020% to count(1020)
                s3$ = item_read$(1020,i%)
                id% = val(left$(s3$,instr(s3$,",")-1))
                gosub chercher_nom_par_id
                sr$ = " à " + nom$
                id% = val(mid$(s3$,instr(s3$,",")+1,20))
                gosub chercher_nom_par_id
                sr$ = nom$ + sr$
                item_delete 1020,i%
                item_insert 1020,i%,"  "+sr$
            next i%
            item_insert 1020,start_1020%,rel$ + " lie:"
return

info_xx2:
            triade$ = str$(id2%)+","
            t% = 3
            gosub chercher_triade_partielle_xx2
            if inex%=1 then return
            for i%=start_1020% to count(1020)
                s3$ = item_read$(1020,i%)
                id% = val(left$(s3$,instr(s3$,",")-1))
                gosub chercher_nom_par_id
                sr$ = nom$ + " est "
                id% = val(mid$(s3$,instr(s3$,",")+1,20))
                gosub chercher_nom_par_id
                sr$ = sr$ + nom$
                item_delete 1020,i%
                item_insert 1020,i%,"  "+sr$
            next i%
            item_insert 1020,start_1020%,"Pour "+nom2$+":"
return

creer_entite:
if count(1002)>0
    for i%=1 to count(1002)
        s$ = item_read$(1002,i%)
        if left$(s$,instr(s$,",")-1)=nom$
            id% = val(mid$(s$,instr(s$,",")+1,10 ))
            return
        end_if
    next i%
end_if
    n_entite% = n_entite% + 1
    id% = n_entite%
    if data$="" then data$ = "[]"
    item_add 1001,right$(zero$+str$(id%),10)+","+nom$+";"+data$
    item_add 1002,nom$+","+str$(id%)
return

chercher_entite:
if count(1002)>0
    for i%=1 to count(1002)
        s$ = item_read$(1002,i%)
        if left$(s$,instr(s$,",")-1)=nom$
            id% = val(mid$(s$,instr(s$,",")+1,10 ))
            inex% = 0
            return
        end_if
    next i%
end_if
inex% = 1
return

chercher_triade1:
triade$ = str$(id1%)+","+str$(idr%)+","+str$(id2%)
if count(1011)>0
    inex% = 0
    for i%=1 to count(1011)
        if item_read$(1011,i%)=triade$ then return
    next i%
end_if
inex% = 1
return

chercher_triade2:
triade$ = str$(idr%)+","+str$(id2%)+","+str$(id1%)
if count(1012)>0
    inex% = 0
    for i%=1 to count(1012)
        if item_read$(1012,i%)=triade$ then return
    next i%
end_if
inex% = 1
return

chercher_triade3:
triade$ = str$(id2%)+","+str$(id1%)+","+str$(idr%)
if count(1013)>0
    inex% = 0
    for i%=1 to count(1013)
        if item_read$(1013,i%)=triade$ then return
    next i%
end_if
inex% = 1
return

chercher_triade_partielle_1Rx:
inex% = 1
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%) then item_add 1020,mid$(s$,j%+1,20)
    next i%
end_if
if count(1020)>0 then inex% = 0
return

chercher_triade_partielle_1x2:
inex% = 1
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%) then item_add 1020,mid$(s$,j%+1,20)
    next i%
end_if
if count(1020)>0 then inex% = 0
return

chercher_triade_partielle_xR2:
inex% = 1
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%) then item_add 1020,mid$(s$,j%+1,20)
    next i%
end_if
if count(1020)>0 then inex% = 0
return

chercher_triade_partielle_1xx:
inex% = 1
cnt% = 0
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%)
            s$ = mid$(s$,instr(s$,",")+1,20)
            item_add 1020,s$
            cnt% = cnt% + 1
        end_if
    next i%
end_if
if cnt%>0 then inex% = 0
return

chercher_triade_partielle_xx2:
inex% = 1
cnt% = 0
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%)
            s$ = mid$(s$,instr(s$,",")+1,20)
            item_add 1020,s$
            cnt% = cnt% + 1
        end_if
    next i%
end_if
if cnt%>0 then inex% = 0
return

chercher_triade_partielle_xRx:
inex% = 1
cnt% = 0
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%)
            s$ = mid$(s$,instr(s$,",")+1,20)
            item_add 1020,s$
            cnt% = cnt% + 1
        end_if
    next i%
end_if
if cnt%>0 then inex% = 0
return

chercher_nom_par_id:
s2$ = item_read$(1001,id%)
nom$ = mid$(s2$,instr(s2$,",")+1,instr(s2$,";[")-instr(s2$,",")-1)
data$ = mid$(s2$,instr(s2$,";[")+1,instr(s2$,"]")-instr(s2$,";["))
return

sauvegarder:
file$ = file_name$(20)
if left$(file$,1)="_" then return
i% = instr(file$,".")
if i%>0 then file$ = left$(file$,i%-1)
file_open_write 2,file$+".bdr"
file_writeln 2,str$(n_entite%)
file_close 2
for i%=1 to count(1001)
    s$ = item_read$(1001,i%)
    if instr(s$,";[")=0
        item_delete 1001,i%
        item_insert 1001,i%,s$+";[]"
    end_if
next i%
file_save 1001,file$+"_01.bdx"
file_save 1002,file$+"_02.bdx"
file_save 1011,file$+"_11.bdx"
file_save 1012,file$+"_12.bdx"
file_save 1013,file$+"_13.bdx"
file_save 1014,file$+"_14.bdx"
file_save 1015,file$+"_15.bdx"
return

restaurer:
file$ = file_name$(21)
if file$<>"_"
    file_open_read 2,file$
    file_readln 2,s$
    file_close 2
    n_entite% = val(s$)
    file$ = left$(file$,instr(file$,".bdr")-1)
    file_load 1001,file$+"_01.bdx"
    file_load 1002,file$+"_02.bdx"
    file_load 1011,file$+"_11.bdx"
    file_load 1012,file$+"_12.bdx"
    file_load 1013,file$+"_13.bdx"
    on_error_goto restaurer_1
    file_load 1014,file$+"_14.bdx"
    file_load 1015,file$+"_15.bdx"
restaurer_1:
    off_error_goto
end_if
return

memoriser:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
if trim$(text$(1))=""
    j% = message_error_ok("Il n'y a pas de données.")
    return
end_if
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
gosub chercher_nom_par_id
data_r$ = data$
s$ = item_read$(1001,id%)
item_delete 1001,id%
item_insert 1001,id%,left$(s$,instr(s$,";[")) + "[" + text$(1) + "]"
return

ajouter:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
if trim$(text$(1))=""
    j% = message_error_ok("Il n'y a pas de données.")
    return
end_if
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
gosub chercher_nom_par_id
data_r$ = mid$(data$,2,len(data$)-2)
s$ = item_read$(1001,id%)
item_delete 1001,id%
item_insert 1001,id%,left$(s$,instr(s$,";[")) + "[" + data_r$+text$(1) + "]"
return

oublier:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
s$ = item_read$(1001,id%)
item_delete 1001,id%
item_insert 1001,id%,left$(s$,instr(s$,";[")) + "[]"
return

aide:
show 30
return

aide_general:
hide 52 : hide 53 : hide 54 : show 51
return

aide_relations:
hide 51 : hide 53 : hide 54 : show 52
return

aide_collections:
hide 51 : hide 52 : hide 54 : show 53
return

aide_donnees:
hide 51 : hide 52 : hide 53 : show 54
return

Base de données exemple: animaux.bdr (fichier ZIP à décompresser dans le répertoire de BDR.bas):
http://www.upshare.me/files/FtsUgjl1302788856.html

EDIT: version 1.02 éditée et complétée le 6/4/2011 à 12:08
remplacé le 7/4/2011 à 17:12
version 1.03 le 9/4/2011 à 15:54
version 1.04 le 10/4/2011 à 10:16
version 1.05 le 12/4/2011 à 00:59
version 1.06 le 13/4/2011 à 14;18
version 1.07 le 14/4/2011 à 15:51


Dernière édition par Klaus le Ven 15 Avr 2011 - 0:51, édité 8 fois
Revenir en haut Aller en bas
http://klauspanoramic.comxa.com/index.html
659_minifly




Nombre de messages : 590
Age : 75
Localisation : Valenciennes Nord
Date d'inscription : 29/04/2010

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptyJeu 7 Avr 2011 - 14:52

Bonjour
Manque les def des labels valider et de change_fonction
A+
Revenir en haut Aller en bas
Klaus

Klaus


Nombre de messages : 12274
Age : 74
Localisation : Ile de France
Date d'inscription : 29/12/2009

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptyJeu 7 Avr 2011 - 17:12

bizarre. En tout cas, le source est mis à jour dans le premier post.
Revenir en haut Aller en bas
http://klauspanoramic.comxa.com/index.html
659_minifly




Nombre de messages : 590
Age : 75
Localisation : Valenciennes Nord
Date d'inscription : 29/04/2010

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptyJeu 7 Avr 2011 - 17:29

C'est l'erreur que j'ai eu en lançant le programme dans Panoramic.

comme ils sont au départ j'ai du sauté la ligne.

Excuse moi
Revenir en haut Aller en bas
Klaus

Klaus


Nombre de messages : 12274
Age : 74
Localisation : Ile de France
Date d'inscription : 29/12/2009

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptySam 9 Avr 2011 - 15:57

Nouvelle version V1.03 !

Nouveautés:
1. Gestion des collections. Il s'agit d'ensembles non ordonnées d'entités, dans le sens mathématique du terme, avec la possibilité de faire des unions, intersections et différences.
2. Nouveau système d'aide, avec l'ouverture d'"une fenêtre séparée pouvant rester à l'écran pendant le fonctionnement, et pouvant être rappelée à tout moment.

Lisez bien l'aide - la doc s'y trouve !
Revenir en haut Aller en bas
http://klauspanoramic.comxa.com/index.html
Invité
Invité




Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptySam 9 Avr 2011 - 18:48

J'ai réduis la fenêtre :


Code:
' BDR.bas - Base de Données Relationnelle

label valider, change_fonction
label affirmer, verifier, completer, infirmer, renommer, supprimer, informer
label joindre, retirer, copier, unir, couper, soustraire, lister, vider
label creer_entite, chercher_triade1, chercher_triade2, chercher_triade3
label info_1xx, info_xrx, info_xx2
label chercher_entite
label chercher_triade_partielle_1Rx, chercher_triade_partielle_1x2
label chercher_triade_partielle_xR2
label chercher_triade_partielle_1xx, chercher_triade_partielle_xx2
label chercher_triade_partielle_xRx
label chercher_nom_par_id
label sauvegarder, restaurer, restaurer_1
label chercher_element, ajouter_element, chercher_collection, creer_collection
label lister_elements
label aide, aide_general, aide_relations, aide_collections

dim debug%
dim n_entite% , i%, j%, nom$, nom1$, nom2$, rel$, s$, oper%, t%, s1$, s2$
dim sr$, s3$, id%, id1%, idr%, id2%, inex%, triade$, libre%, zero$, file$
dim flag_1020%, start_1020%, cnt%, idx%, nomx$, ic%, k%

zero$ = "0000000000"
debug% = 0

width 0,430 : height 0,314
caption 0,"BDR V1.03 du 9/4/2011"

if debug%=0
    dlist 1000  : ' liste interne pour résultats intermédiaires
    dlist 1001  : ' entités chronologiques (id,nom)
    dlist 1002  : ' entités triées (nom,id)
    dlist 1011  : ' triades (A,R,B)
    dlist 1012  : ' triades (R,B,A)
    dlist 1013  : ' triades (B,A,R)
    dlist 1014  : ' elements pour les collections
    dlist 1015  : ' collections pour les éléments
    form  30 : hide 30 : top 30,40 : left 30,350 : width 30,900 : height 30,750
    caption 30,"Aide sur BDR" : command_target_is 30
    button 31 : top 31,10 : left 31,10 : caption 31,"Général" : on_click 31,aide_general
    button 32 : top 32,10 : left 32,150 : caption 32,"Relations" : on_click 32,aide_relations
    button 33 : top 33,10 : left 33,290 : caption 33,"Collections" : on_click 33,aide_collections
    alpha 41 : top 41,15 : left 41,10 : font_size 41,10 : font_bold 41
    alpha 42 : top 42,15 : left 42,10 : font_size 42,10 : font_bold 42
    alpha 43 : top 43,15 : left 43,10 : font_size 43,10 : font_bold 43
    container 51 : caption 51,"Général" : parent 41,51 : top 51,40 : left 51,10 : width 51,830 : height 51,650
    container 52 : caption 52,"Relations" : parent 42,52 : hide 52 : top 52,40 : left 52,10 : width 52,830 : height 52,650
    container 53 : caption 53,"Collections" : parent 43,53 : hide 53 : top 53,40 : left 53,10 : width 53,830 : height 53,650
    command_target_is 0

    s$ = "Ce programme réalise une petite Base de Données Relationnelle (BDR) en mémoire."+chr$(13)+chr$(13)
    s$ = s$ + "Les éléments gérées par la base sont des <entités>. Ces entités peuvent être mises en <relation>"+chr$(13)
    s$ = s$ + "les unes avec les autres, et peuvent être associées en <collections>."+chr$(13)+chr$(13)
    s$ = s$ + "Une relation est elle-même une entité, mais elle a une particularité: elle lie deux entités A et B d'une"+chr$(13)
    s$ = s$ + "manière univoque:  A --> (R) --> B. On dit que A est en relation R avec B (Martin est père de Paul)."+chr$(13)+chr$(13)
    s$ = s$ + "Une collection est un ensemble non ordonné d'entités, sans recourir aux relations. Ce sont des ensembles"+chr$(13)
    s$ = s$ + "dans le sens mathématique:  A €  {B}. On dit que A est élément de B (canard est élément de oiseaux)."+chr$(13)+chr$(13)
    s$ = s$ + "Les commandes sont données par une combo de sélection des comandes, et des champs paramètres qui sont"+chr$(13)
    s$ = s$ + "affichés en fonction de la commande choisie. Il y a de 1 à 3 paramètres recevant chacun le nom d'une"+chr$(13)
    s$ = s$ + "entité. Les paramètres présentés sont toujours requis; selon les commandes, les entités concernées doivent"+chr$(13)
    s$ = s$ + "exister ou pas, être une collection ou pas, etc. Le sens des paramètres est noté entre <...>, précédés des"+chr$(13)
    s$ = s$ + "lettres suivantes:"+chr$(13)
    s$ = s$ + "    E - entité doit Exister"+chr$(13)
    s$ = s$ + "    I - entité doit être Inexistant"+chr$(13)
    s$ = s$ + "    C - entité doit être une Collection"+chr$(13)+chr$(13)
    s$ = s$ + "    P - entité Peut exister"+chr$(13)
    s$ = s$ + "    O - entité optionnelle"+chr$(13)
    s$ = s$ + "Les commandes générales sont les suivantes:"+chr$(13)
    s$ = s$ + "    Renommer          change le nom d'une entité"+chr$(13)
    s$ = s$ + "        E<ancien nom> I<nouveau nom>"+chr$(13)
    s$ = s$ + "        Le nouveau nom remplace l'ancien."+chr$(13)
    s$ = s$ + "    Supprimer          supprime une entité."+chr$(13)
    s$ = s$ + "        E<nom à supprimer>"+chr$(13)
    s$ = s$ + "        L'entité sera supprimé, ainsi que toute référence par des relations, et toute appartenance"+chr$(13)
    s$ = s$ + "        aux collections. Si elle est elle-même une collection, ses éléments seront libérés."+chr$(13)
    s$ = s$ + "    Que sait-on sur    affiche toutes les informations connues sur une entité."+chr$(13)
    s$ = s$ + "        E<nom à interroger>"+chr$(13)
    s$ = s$ + "        On affiche l'ensemble des informations connues pour l'entité ciblée, y compris son contexte"+chr$(13)
    s$ = s$ + "        relationnel ainsi que ses appartenances aux collections ou ses membres si elle est collection."+chr$(13)+chr$(13)
    s$ = s$ + "Les boutons <Sauvegarder> et <Restaurer> permettent d'enregistrer ou de réouvrir une BDR."
    caption 41,s$

    s$ = ""
    s$ = s$ + "Les fonctions suivantes gèrent les structures des relations."+chr$(13)+chr$(13)
    s$ = s$ + "J'affirme              crée une relation A --> R --> B"+chr$(13)
    s$ = s$ + "    P<nom A> P<Nom R> P<nom B>"+chr$(13)
    s$ = s$ + "    On crée la relation R entre A et B. Les entités A,R et B peuvent exister. Chaque entité inexistante sera créée,"+chr$(13)
    s$ = s$ + "    sinon, elle est réutilisée. Une entité A ou B peut également être <relation>, comme dans l'exemple suivant:"+chr$(13)
    s$ = s$ + "    <Martin> est <père> de <Sylvain>"+chr$(13)
    s$ = s$ + "    <Martin> est <tuteur> de <Véronique>"+chr$(13)
    s$ = s$ + "    <père> est <responsable> de <enfants>"+chr$(13)
    s$ = s$ + "    <tuteur> est <responsable> de <enfants>"+chr$(13)
    s$ = s$ + "Et on voit dans cet exemple que les relations <père> et <tuteur> sont liées par"+chr$(13)
    s$ = s$ + "la relation <responsable> à l'entité objet <enfants>."+chr$(13)+chr$(13)
    s$ = s$ + "<Est-ce que>.          vérifie une relation"+chr$(13)
    s$ = s$ + "    E<nom A> E<nm R> E<nom B>"+chr$(13)
    s$ = s$ + "    la véracité de la relation A --> R --> B est vérifiée. Le résultat est Vrai ou Faux"+chr$(13)+chr$(13)
    s$ = s$ + "<Complète les champs>. cherche les éléments manquants d'une relation"+chr$(13)
    s$ = s$ + "    OE<nom A> OE<nom R> OE<nom B°"+chr$(13)
    s$ = s$ + "Le programme affiche dans la liste de droite un résultat textuel de la recherche, en affichant tous"+chr$(13)
    s$ = s$ + "les résultats possibles."+chr$(13)+chr$(13)
    s$ = s$ + "J'infirme que          annule une relation"+chr$(13)
    s$ = s$ + "    E<nom A> E<nom R> E<nom B>"+chr$(13)
    s$ = s$ + "Si la relation existe, elle est supprimée."+chr$(13)
    caption 42,s$

    s$ = ""
    s$ = s$ + "Les fonctions suivantes gèrent le contexte des collections. Elles servent à placer une entité dans une"+chr$(13)
    s$ = s$ + "collection ou à le retirer, effectuer la maintenance des collections, et effectuer les opérations"+chr$(13)
    s$ = s$ + "mathématiques d'union (unir), d'intersection (couper) et différence (soustraire) entre deux collections."+chr$(13)+chr$(13)
    s$ = s$ + "Joindre                introduire une entité dans une collection"+chr$(13)
    s$ = s$ + "    P<nom élément> P<nom collection>"+chr$(13)
    s$ = s$ + "    Si les entites n'existent pas, elles sont créées. L'entité élément est introduite dans la collection"+chr$(13)+chr$(13)
    s$ = s$ + "Retirer                enlever une entité d'une collection"+chr$(13)
    s$ = s$ + "    E<nom élément> E<nom collection>"+chr$(13)
    s$ = s$ + "    Si l'entité élément est membre de la collection, il sera retiré."+chr$(13)+chr$(13)
    s$ = s$ + "Copier                créer un duplicata d'une collection"+chr$(13)
    s$ = s$ + "    E<nom collection origine> I<nom collection destinationW"+chr$(13)
    s$ = s$ + "    La collection destination sera créée, et tous les éléments de la collection origine y seront introduits."+chr$(13)+chr$(13)
    s$ = s$ + "Unir                  effectuer l'union entre deux collections"+chr$(13)
    s$ = s$ + "    E<nom collection A> E<nom collection B>"+chr$(13)
    s$ = s$ + "    La collection B sera remplacée par l'union des collections A et B."+chr$(13)+chr$(13)
    s$ = s$ + "Couper                effectuer l'intersection entre deux collections"+chr$(13)
    s$ = s$ + "    E<nom collection A> E<nom collection B>"+chr$(13)
    s$ = s$ + "    La collection B sera remplacée par l'intersection des collections A et B."+chr$(13)+chr$(13)
    s$ = s$ + "Soustraire            effectuer la différence entre deux collections"+chr$(13)
    s$ = s$ + "    E<nom collection A> E<nom collection B>"+chr$(13)
    s$ = s$ + "    La collection B sera remplacée par la différence des collections B moins A."+chr$(13)+chr$(13)
    s$ = s$ + "Lister                afficher le contenu d'une collection"+chr$(13)
    s$ = s$ + "    E<nom collection>"+chr$(13)
    s$ = s$ + "    On affiche l'ensemble des éléments de la collection."+chr$(13)+chr$(13)
    s$ = s$ + "Vider                  vider une collection"+chr$(13)
    s$ = s$ + "    E<nom collection>"+chr$(13)
    s$ = s$ + "    On retire l'ensemble des éléments de la collection."+chr$(13)
    caption 43,s$

else
    list 1000  : ' liste interne pour résultats intermédiaires
        top 1000,420 : left 1000,10 : height 1000,300
    list 1001  : ' entités chronologiques (id,nom)
        top 1001,100 : left 1001,10 : height 1001,300
    list 1002  : ' entités triées (nom,id)
        top 1002,100 : left 1002,140 : height 1002,300
    list 1011  : ' triades (A,R,B)
        top 1011,100 : left 1011,270 : height 1011,300 : width 1011,60
    list 1012  : ' triades (R,B,A)
        top 1012,100 : left 1012,340 : height 1012,300 : width 1012,60
    list 1013  : ' triades (B,A,R)
        top 1013,100 : left 1013,410 : height 1013,300 : width 1013,60
    list 1014  : ' elements pour les collections
        top 1014,100 : left 1014,480 : height 1014,300 : width 1014,100
    list 1015  : ' collections pour les éléments
        top 1015,100 : left 1015,590 : height 1015,300 : width 1015,100

end_if
memo 1020  : ' liste de résultats
top 1020,55 : left 1020,5 : height 1020,200 : width 1020,412 : bar_both 1020
sort_on 1002 : sort_on 1011 : sort_on 1012 : sort_on 1013 : sort_on 1014 : sort_on 1015

alpha 101
left 101,5
top 101,5
caption 101,"Fonction :"

combo 10 : top 10,3 : left 10,55 : on_change 10,change_fonction
item_add 10,"J'affirme que"
item_add 10,"Est-ce que"
item_add 10,"Complète les champs"
item_add 10,"J'infirme que"
item_add 10,"Renommer"
item_add 10,"Supprimer"
item_add 10,"Que sait-on sur"
item_add 10,"Joindre"
item_add 10,"Retirer"
item_add 10,"Copier"
item_add 10,"Unir"
item_add 10,"Couper"
item_add 10,"Soustraire"
item_add 10,"Lister"
item_add 10,"Vider"

text 10,"J'affirme que"
edit 1 : top 1,29 : left 1,5
alpha 2 : top 2,31 : left 2,130 : caption 2,"est"
edit 3 : top 3,29 : left 3,150
alpha 4 : top 4,31 : left 4,275 : caption 4,"de"
edit 5 : top 5,29 : left 5,295
main_menu 100
sub_menu 6 : parent 6,100 : caption 6,"Valider"
on_click 6,valider
sub_menu 7 : parent 7,100 : caption 7,"Sauvegarder"
on_click 7,sauvegarder
sub_menu 8 : parent 8,100 : caption 8,"Restaurer"
on_click 8,restaurer
sub_menu 9 : parent 9,100 : caption 9,"Aide"
on_click 9,aide

save_dialog 20
open_dialog 21
filter 20,"Sauvegardes|*.bdr"
filter 21,"Sauvegardes|*.bdr"

end

change_fonction:
s$ = text$(10)
oper% = 0
for i%=1 to count(10)
    if text$(10)=item_read$(10,i%) then oper% = i%
next i%
for i%=1 to 5
    show i%
next i%
caption 2,"est"
select oper%
    case 5  : hide 4 : hide 5 : caption 2,"en"
    case 6  : hide 2 : hide 3 : hide 4 : hide 5
    case 7  : hide 2 : hide 3 : hide 4 : hide 5
    case 8  : hide 4 : hide 5 : caption 2,"à"
    case 9 : hide 4 : hide 5 : caption 2,"de"
    case 10 : hide 4 : hide 5 : caption 2,"dans"
    case 11 : hide 4 : hide 5 : caption 2,"à"
    case 12 : hide 4 : hide 5 : caption 2,"de"
    case 13 : hide 4 : hide 5 : caption 2,"à"
    case 14 : hide 2 : hide 3 : hide 4 : hide 5
    case 15 : hide 2 : hide 3 : hide 4 : hide 5
end_select
return

valider:
s$ = text$(10)
for i%=1 to count(10)
    if text$(10)=item_read$(10,i%) then oper% = i%
next i%
if (oper%<3 ) or (oper%=4)
    for i%=1 to 3
        if trim$(text$(i%*2-1))=""
            j% = message_error_ok("Le champ "+str$(i%)+" n'est pas renseigné.")
            return
        end_if
    next i%
end_if
nom1$ = text$(1)
rel$ = text$(3)
nom2$ = text$(5)
select oper%
' fonctions relationnelles
    case 1: gosub affirmer
    case 2: gosub verifier
    case 3: gosub completer
    case 4: gosub infirmer
    case 5: gosub renommer
    case 6: gosub supprimer
    case 7: gosub informer
' fonctions des collections
    case 8: gosub joindre
    case 9: gosub retirer
    case 10: gosub copier
    case 11: gosub unir
    case 12: gosub couper
    case 13: gosub soustraire
    case 14: gosub lister
    case 15: gosub vider
end_select
return

joindre:
nom$ = nom1$
gosub creer_entite
id1% = id%
nom$ = rel$
gosub creer_entite
idr% = id%
nom$ = rel$
gosub chercher_collection
if inex%=1 then gosub creer_collection
gosub chercher_element
if inex%=1 then gosub ajouter_element
return

retirer:
if count(1002)<2
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
nom$ = rel$
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
if count(1014)>0
    s1$ = ","+str$(id1%)+","
    k% = count(1014)
    i% = 0
    while i%<k%
        i% = i% + 1
        s$ = item_read$(1014,i%) + ","
        if left$(s$,10)=right$(zero$+str$(idr%),10)
            j% = instr(s$,s1$)
            if j%>0
                s$ = left$(s$,j%) + mid$(s$,j%+len(s1$),len(s$))
                if len(s$)=j%
                    sort_off 1014
                    item_delete 1014,i%
                    sort_on 1014
                    i% = i% - 1
                    k% = k% - 1
                else
                    sort_off 1014
                    item_delete 1014,i%
                    item_insert 1014,i%,mid$(s$,1,len(s$)-1)
                    sort_on 1014
                end_if
            end_if
        end_if
    end_while
end_if
if count(1015)>0
    j% = count(1015)
    i% = 0
    s$ = right$(zero$+str$(id1%),10)+","+str$(idr%)
    while i%<j%
        i% = i% + 1
        if item_read$(1015,i%)=s$
            sort_off 1015
            item_delete 1015,i%
            sort_on 1015
            i% = i% - 1
            j% = j% - 1
        end_if
    end_while
end_if
return

copier:
if count(1002)<2
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
nom$ = text$(3)
if trim$(nom$)=""
    j% = message_error_ok("L'entité destination manque.")
    return
end_if
gosub chercher_entite
if inex%=0
    j% = message_error_ok("L'entité "+nom$+" existe déjà.")
    return
end_if
rel$ = nom$
nom$ = rel$
gosub creer_entite
idr% = id%
s1$ = right$(zero$+str$(id1%),10) + ","
for i%=1 to count(1014)
    s$ = item_read$(1014,i%)
    if left$(s$,11)=s1$
        s$ = right$(zero$+str$(idr%),10)+mid$(s$,11,len(s$))
        item_add 1014,s$
        s$ = mid$(s$,12,len(s$)) + ","
        s1$ = str$(idr%)
        repeat
            i% = instr(s$,",")
            if i%>0
                id% = val(left$(s$,i%-1))
                s$ = mid$(s$,i%+1,len(s$))
                item_add 1015,right$(zero$+str$(id%),10)+","+s1$
            end_if
        until i%=0
        return
    end_if
next i%
return

unir:
couper:
soustraire:
if count(1002)<2
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
clear 1000
s1$ = right$(zero$+str$(idr%),10)
s2$ = right$(zero$+str$(id1%),10)
' déplacer les éléments de REL dans temporaire
j% = count(1015)
i% = 0
sort_off 1015
while i%<j%
    i% = i% + 1
    s$ = item_read$(1015,i%)
    if val(mid$(s$,12,len(s$)))=idr%
        item_add 1000,s$
        item_delete 1015,i%
        i% = i% - 1
        j% = j% - 1
    end_if
end_while
sort_on 1015
' traiter les éléments de NOM1
for i%=1 to count(1015)
    s$ = item_read$(1015,i%)
    if oper%=11
        if val(mid$(s$,12,len(s$)))=id1%
            s3$ = left$(s$,11) + str$(idr%)
            inex% = 1
            for j%=1 to count(1000)
                if s3$=item_read$(1000,j%)
                    inex% = 0
                    exit_for
                end_if
            next j%
            if inex%=1 then item_add 1000,s3$
        end_if
    end_if
    if oper%=12
        if val(mid$(s$,12,len(s$)))=id1%
            s3$ = left$(s$,11) + str$(idr%)
            inex% = 1
            for j%=1 to count(1000)
                if s3$=item_read$(1000,j%)
                    item_delete 1000,j%
                    item_insert 1000,j%,"*"+s3$
                    exit_for
                end_if
            next j%
        end_if
    end_if
    if oper%=13
        if val(mid$(s$,12,len(s$)))=id1%
            s3$ = left$(s$,11) + str$(idr%)
            inex% = 1
            for j%=1 to count(1000)
                if s3$=item_read$(1000,j%)
                    item_delete 1000,j%
                    exit_for
                end_if
            next j%
        end_if
    end_if
next i%
if oper%=12 : ' cas "couper"
    j% = count(1000)
    i% = 0
    while i%<j%
        i% = i% + 1
        s$ = item_read$(1000,i%)
        item_delete 1000,i%
        if left$(s$,1)="*"
            item_insert 1000,i%,mid$(s$,2,len(s$))
        else
            i% = i% - 1
            j% = j% - 1
        end_if
    end_while
end_if
' reffacer tous les éléments de REL
j% = count(1015)
i% = 0
sort_off 1015
while i%<j%
    i% = i% + 1
    s$ = item_read$(1015,i%)
    if val(mid$(s$,12,len(s$)))=idr%
        item_delete 1015,i%
        i% = i% - 1
        j% = j% - 1
    end_if
end_while
sort_on 1015
' replacer tous les éléments dans REL
s1$ = ""
for i%=1 to count(1000)
    s$ = item_read$(1000,i%)
    item_add 1015,s$
    s1$ = s1$ + ","+str$(val(left$(s$,10)))
next i%
' remplacer la liste des éléments de REL
j% = count(1014)
i% = 0
while i%<j%
    i% = i% + 1
    s$ = item_read$(1014,i%)
    if val(left$(s$,10))=idr%
        s$ = left$(s$,10) + s1$
        sort_off 1014
        item_delete 1014,i%
        sort_on 1014
        item_add 1014,s$
        return
    end_if
end_while
return

lister:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
clear 1020
item_add 1020,nom1$+" est une collection comprenant:"
for i%=1 to count(1015)
    s$ = item_read$(1015,i%)
    if val(mid$(s$,12,len(s$)))=id1%
        id% = val(left$(s$,10))
        gosub chercher_nom_par_id
        item_add 1020,"  "+nom$
    end_if
next i%
return

vider:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
idr% = id%
gosub chercher_collection
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'est pas une collection.")
    return
end_if
j% = count(1015)
i% = 0
sort_off 1015
while i%<j%
    i% = i% + 1
    s$ = item_read$(1015,i%)
    if val(mid$(s$,12,len(s$)))=id1%
        item_delete 1015,i%
        i% = i% - 1
        j% = j% - 1
    end_if
end_while
sort_on 1015
for i%=1 to count(1014)
    s$ = item_read$(1014,i%)
    if val(left$(s$,10))=id1%
        sort_off 1014
        item_delete 1014,i%
        sort_on 1014
        return
    end_if
next i%
return

chercher_element:
inex% = 0
s$ = right$(zero$+str$(id1%),10)+","+str$(idr%)
if count(1015)>0
    for i%=1 to count(1015)
        if item_read$(1015,i%)=s$ then return
    next i%
end_if
inex% = 1
return

lister_elements:
inex% = 1
s$ = right$(zero$+str$(id1%),10)+","
if count(1015)>0
    for i%=1 to count(1015)
        if left$(item_read$(1015,i%),11)=s$
            if inex%=1 then item_add 1020,nomx$+" est élément de:"
            inex% = 0
            id% = val(mid$(item_read$(1015,i%),12,10))
            gosub chercher_nom_par_id
            item_add 1020,"  "+nom$
        end_if
    next i%
end_if
return

ajouter_element:
item_add 1015,s$
s$ = item_read$(1014,ic%)
s$ = s$ + "," + str$(id1%)
sort_off 1014
item_delete 1014,ic%
item_insert 1014,ic%,s$
return

chercher_collection:
inex% = 0
if count(1014)>0
    for ic%=1 to count(1014)
        if val(left$(item_read$(1014,ic%),10))=idr% then return
    next ic%
end_if
inex% = 1
return

creer_collection:
item_add 1014,right$(zero$+str$(idr%),10)
ic% = count(1014)
return


affirmer:
nom$ = nom1$
gosub creer_entite
id1% = id%
nom$ = rel$
gosub creer_entite
idr% = id%
nom$ = nom2$
gosub creer_entite
id2% = id%
gosub chercher_triade1
if inex%=1
    item_add 1011,triade$
    item_add 1012,str$(idr%)+","+str$(id2%)+","+str$(id1%)
    item_add 1013,str$(id2%)+","+str$(id1%)+","+str$(idr%)
end_if
return

infirmer:
if count(1002)<3
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
nom$ = text$(5)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom2$ = nom$
id2% = id%
gosub chercher_triade1
if inex%=0
    item_delete 1011,i%
    gosub chercher_triade2
    if inex%=0 then item_delete 1012,i%
    gosub chercher_triade3
    if inex%=0 then item_delete 1013,i%
    j% = message_information_ok("La relation a été annulée.")
else
    j% = message_information_ok(nom1$+" n'est pas "+rel$+" de "+nom2$)
end_if
return

verifier:
if count(1002)<3
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
nom$ = text$(3)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
rel$ = nom$
idr% = id%
nom$ = text$(5)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom2$ = nom$
id2% = id%
gosub chercher_triade1
if inex%=0
    j% = message_information_ok(nom1$+" est bien "+rel$+" de "+nom2$)
else
    j% = message_information_ok(nom1$+" n'est pas "+rel$+" de "+nom2$)
end_if
return

renommer:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(3)
gosub chercher_entite
if inex%=0
    j% = message_error_ok("L'entité "+nom$+" existe déjà.")
    return
end_if
nom2$ = nom$
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
sort_off 1002
item_delete 1002,i%
item_insert 1002,i%,nom2$+","+str$(id1%)
sort_on 1002
item_delete 1001,id1%
item_insert 1001,id1%,right$(zero$+str$(id1%),10)+","+nom2$
return

supprimer:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nom1$ = nom$
id1% = id%
' supprimer l'entité elle-même
item_delete 1002,i%
item_delete 1001,id1%
item_insert 1001,id1%,right$(zero$+str$(id1%),10)+",----------"
' supprimer les informations relationnelles
s1$ = str$(id1%)
for t%=1 to 3
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if (instr(s$,s1$+",")>0) or (instr(s$,","+s1$)>0)
            item_delete 1010+t%,i%
            i% = i% - 1
            if i%=count(1010+t%) then exit_for
        end_if
    next i%
next t%
' supprimer les informations de collection
if count(1014)>0
    k% = count(1014)
    i% = 0
    while i%<k%
        i% = i% + 1
        s$ = item_read$(1014,i%) + ","
        s1$ = ","+str$(id1%)+","
        j% = instr(s$,s1$)
        if j%>0
            s$ = left$(s$,j%) + mid$(s$,j%+len(s1$),len(s$))
            if len(s$)=j%
                sort_off 1014
                item_delete 1014,i%
                sort_on 1014
                i% = i% - 1
                k% = k% - 1
            else
                sort_off 1014
                item_delete 1014,i%
                item_insert 1014,i%,mid$(s$,1,len(s$)-1)
                sort_on 1014
            end_if
        end_if
    end_while
end_if
if count(1015)>0
    j% = count(1015)
    i% = 0
    while i%<j%
        i% = i% + 1
        s$ = item_read$(1015,i%)
        if val(left$(s$,10))=id1%
            sort_off 1015
            item_delete 1015,i%
            sort_on 1015
            i% = i% - 1
            j% = j% - 1
        else
            s$ = mid$(s$,12,len(s$))
            if val(s$)=id1%
                sort_off 1015
                item_delete 1015,i%
                sort_on 1015
                i% = i% - 1
                j% = j% - 1
            end_if
        end_if
    end_while
end_if
return

informer:
if count(1002)<1
    j% = message_error_ok("Il n'y a pas assez d'entités.")
    return
end_if
nom$ = text$(1)
gosub chercher_entite
if inex%=1
    j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
    return
end_if
nomx$ = nom$
idx% = id%
clear 1020
flag_1020% = 0
' lister les informations relationnelles
start_1020% = count(1020)+1
id1% = idx%
nom1$ = nomx$
gosub info_1xx
start_1020% = count(1020)+1
idr% = idx%
rel$ = nomx$
gosub info_xrx
start_1020% = count(1020)+1
id2% = idx%
nom2$ = nomx$
gosub info_xx2
' lister les informations des collections
idr% = idx%
gosub chercher_collection
if inex%=0
    item_add 1020,nomx$+" est collection de:"
    s$ = item_read$(1014,ic%)
    s$ = mid$(s$,12,len(s$))
    repeat
        i% = instr(s$,",")
        if i%>0
            id% = val(left$(s$,i%-1))
            gosub chercher_nom_par_id
            item_add 1020,"  "+nom$
            s$ = mid$(s$,i%+1,len(s$))
        end_if
    until i%=0
    id% = val(s$)
    gosub chercher_nom_par_id
    item_add 1020,"  "+nom$
end_if
gosub lister_elements

return

completer:
flag_1020% = 1
start_1020% = 1
nom1$ = trim$(text$(1))
rel$ = trim$(text$(3))
nom2$ = trim$(text$(5))
if nom1$=""
' [?,x,x] on cherche nom1
    if rel$=""
    ' [?,?,x] on cherche rel
        if nom2$=""
        ' [?,?,?] on cherche nom2
            j% = message_error_ok("La recherche est trop vaste.")
            return
        else
        ' [?,?,$] on a nom2 ==> on cherche nom1 et rel pour nom2
            nom$ = nom2$
            gosub chercher_entite
            id2% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            gosub info_xx2
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
        end_if
    else
    ' [?,$,x] on a rel
        if nom2$=""
        ' [?,$,?] on cherche nom1 et nom2 pour rel
            nom$ = rel$
            gosub chercher_entite
            idr% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            gosub info_xrx
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
        else
        ' [?,$,$] on a nom2 ==> on cherche nom1 pour rel et nom2
            nom$ = rel$
            gosub chercher_entite
            idr% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            nom$ = nom2$
            gosub chercher_entite
            id2% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            triade$ = str$(idr%)+","+str$(id2%)+","
            t% = 2
            gosub chercher_triade_partielle_xR2
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
            for i%=1 to count(1020)
                id% = val(item_read$(1020,i%))
                gosub chercher_nom_par_id
                item_delete 1020,i%
                item_insert 1020,i%,nom$
            next i%
            item_insert 1020,1,rel$ + " de " + nom2$ + ":"
        end_if
    end_if
else
' on a nom1
    if rel$=""
    ' [$,?,x] on cherche rel et nom1
        if nom2$=""
        ' [$,?,?] on cherche nom2 et rel pour nom1
            nom$ = nom1$
            gosub chercher_entite
            id1% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            gosub info_1xx
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
        else
        ' [$,?,$] on a nom2 ==> on cherche rel pour nom1 et nom2
            nom$ = nom1$
            gosub chercher_entite
            id1% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            nom$ = nom2$
            gosub chercher_entite
            id2% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            triade$ = str$(id2%)+","+str$(id1%)+","
            t% = 3
            gosub chercher_triade_partielle_1x2
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
            for i%=1 to count(1020)
                id% = val(item_read$(1020,i%))
                gosub chercher_nom_par_id
                item_delete 1020,i%
                item_insert 1020,i%,nom$
            next i%
            item_insert 1020,1,nom1$ + " est pour " + nom2$ + ":"
        end_if
    else
    ' on a rel
        if nom2$=""
        ' [$,$,?] on cherche nom2 pour nom1 et rel
            nom$ = nom1$
            gosub chercher_entite
            id1% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+nom$+" n'existe pas.")
                return
            end_if
            nom$ = rel$
            gosub chercher_entite
            idr% = id%
            if inex%=1
                j% = message_error_ok("L'entité "+rel$+" n'existe pas.")
                return
            end_if
            triade$ = str$(id1%)+","+str$(idr%)+","
            t% = 1
            gosub chercher_triade_partielle_1Rx
            if inex%=1
                j% = message_error_ok("Recherche vaine.")
                return
            end_if
            for i%=1 to count(1020)
                id% = val(item_read$(1020,i%))
                gosub chercher_nom_par_id
                item_delete 1020,i%
                item_insert 1020,i%,nom$
            next i%
            item_insert 1020,1,nom1$ + " est " + rel$ + " de: "
        else
        ' [$,$,$] on a nom2 ==> on ne cherche rien !
            j% = message_error_ok("Il n'y a rien à compléter.")
            return
        end_if
    end_if
end_if
return

info_1xx:
            triade$ = str$(id1%)+","
            t% = 1
            gosub chercher_triade_partielle_1xx
            if inex%=1 then return
            for i%=start_1020% to count(1020)
                s3$ = item_read$(1020,i%)
                id% = val(left$(s3$,instr(s3$,",")-1))
                gosub chercher_nom_par_id
                sr$ = nom$ + " de "
                id% = val(mid$(s3$,instr(s3$,",")+1,20))
                gosub chercher_nom_par_id
                sr$ = sr$ + nom$
                item_delete 1020,i%
                item_insert 1020,i%,sr$
            next i%
            item_insert 1020,start_1020%,nom1$ + " est: "
return

info_xrx:
            triade$ = str$(idr%)+","
            t% = 2
            gosub chercher_triade_partielle_xRx
            if inex%=1 then return
            for i%=start_1020% to count(1020)
                s3$ = item_read$(1020,i%)
                id% = val(left$(s3$,instr(s3$,",")-1))
                gosub chercher_nom_par_id
                sr$ = " à " + nom$
                id% = val(mid$(s3$,instr(s3$,",")+1,20))
                gosub chercher_nom_par_id
                sr$ = nom$ + sr$
                item_delete 1020,i%
                item_insert 1020,i%,sr$
            next i%
            item_insert 1020,start_1020%,rel$ + " lie:"
return

info_xx2:
            triade$ = str$(id2%)+","
            t% = 3
            gosub chercher_triade_partielle_xx2
            if inex%=1 then return
            for i%=start_1020% to count(1020)
                s3$ = item_read$(1020,i%)
                id% = val(left$(s3$,instr(s3$,",")-1))
                gosub chercher_nom_par_id
                sr$ = nom$ + " est "
                id% = val(mid$(s3$,instr(s3$,",")+1,20))
                gosub chercher_nom_par_id
                sr$ = sr$ + nom$
                item_delete 1020,i%
                item_insert 1020,i%,sr$
            next i%
            item_insert 1020,start_1020%,"Pour "+nom2$+":"
return

creer_entite:
if count(1002)>0
    for i%=1 to count(1002)
        s$ = item_read$(1002,i%)
        if left$(s$,instr(s$,",")-1)=nom$
            id% = val(mid$(s$,instr(s$,",")+1,10 ))
            return
        end_if
    next i%
end_if
    n_entite% = n_entite% + 1
    id% = n_entite%
    item_add 1001,right$(zero$+str$(id%),10)+","+nom$
    item_add 1002,nom$+","+str$(id%)
return

chercher_entite:
if count(1002)>0
    for i%=1 to count(1002)
        s$ = item_read$(1002,i%)
        if left$(s$,instr(s$,",")-1)=nom$
            id% = val(mid$(s$,instr(s$,",")+1,10 ))
            inex% = 0
            return
        end_if
    next i%
end_if
inex% = 1
return

chercher_triade1:
triade$ = str$(id1%)+","+str$(idr%)+","+str$(id2%)
if count(1011)>0
    inex% = 0
    for i%=1 to count(1011)
        if item_read$(1011,i%)=triade$ then return
    next i%
end_if
inex% = 1
return

chercher_triade2:
triade$ = str$(idr%)+","+str$(id2%)+","+str$(id1%)
if count(1012)>0
    inex% = 0
    for i%=1 to count(1012)
        if item_read$(1012,i%)=triade$ then return
    next i%
end_if
inex% = 1
return

chercher_triade3:
triade$ = str$(id2%)+","+str$(id1%)+","+str$(idr%)
if count(1013)>0
    inex% = 0
    for i%=1 to count(1013)
        if item_read$(1013,i%)=triade$ then return
    next i%
end_if
inex% = 1
return

chercher_triade_partielle_1Rx:
inex% = 1
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%) then item_add 1020,mid$(s$,j%+1,20)
    next i%
end_if
if count(1020)>0 then inex% = 0
return

chercher_triade_partielle_1x2:
inex% = 1
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%) then item_add 1020,mid$(s$,j%+1,20)
    next i%
end_if
if count(1020)>0 then inex% = 0
return

chercher_triade_partielle_xR2:
inex% = 1
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%) then item_add 1020,mid$(s$,j%+1,20)
    next i%
end_if
if count(1020)>0 then inex% = 0
return

chercher_triade_partielle_1xx:
inex% = 1
cnt% = 0
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%)
            s$ = mid$(s$,instr(s$,",")+1,20)
            item_add 1020,s$
            cnt% = cnt% + 1
        end_if
    next i%
end_if
if cnt%>0 then inex% = 0
return

chercher_triade_partielle_xx2:
inex% = 1
cnt% = 0
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%)
            s$ = mid$(s$,instr(s$,",")+1,20)
            item_add 1020,s$
            cnt% = cnt% + 1
        end_if
    next i%
end_if
if cnt%>0 then inex% = 0
return

chercher_triade_partielle_xRx:
inex% = 1
cnt% = 0
if flag_1020%=1 then clear 1020
j% = len(triade$)
if count(1010+t%)>0
    for i%=1 to count(1010+t%)
        s$ = item_read$(1010+t%,i%)
        if triade$=left$(s$,j%)
            s$ = mid$(s$,instr(s$,",")+1,20)
            item_add 1020,s$
            cnt% = cnt% + 1
        end_if
    next i%
end_if
if cnt%>0 then inex% = 0
return

chercher_nom_par_id:
s2$ = item_read$(1001,id%)
nom$ = mid$(s2$,instr(s2$,",")+1,len(s2$))
return

sauvegarder:
file$ = file_name$(20)
if left$(file$,1)="_" then return
i% = instr(file$,".")
if i%>0 then file$ = left$(file$,i%-1)
file_open_write 2,file$+".bdr"
file_writeln 2,str$(n_entite%)
file_close 2
file_save 1001,file$+"_01.bdx"
file_save 1002,file$+"_02.bdx"
file_save 1011,file$+"_11.bdx"
file_save 1012,file$+"_12.bdx"
file_save 1013,file$+"_13.bdx"
file_save 1014,file$+"_14.bdx"
file_save 1015,file$+"_15.bdx"
return

restaurer:
file$ = file_name$(21)
if file$<>"_"
    file_open_read 2,file$
    file_readln 2,s$
    file_close 2
    n_entite% = val(s$)
    file$ = left$(file$,instr(file$,".bdr")-1)
    file_load 1001,file$+"_01.bdx"
    file_load 1002,file$+"_02.bdx"
    file_load 1011,file$+"_11.bdx"
    file_load 1012,file$+"_12.bdx"
    file_load 1013,file$+"_13.bdx"
    on_error_goto restaurer_1
    file_load 1014,file$+"_14.bdx"
    file_load 1015,file$+"_15.bdx"
restaurer_1:
    off_error_goto
end_if
return

aide:
show 30
return

aide_general:
hide 52
hide 53
show 51
return

aide_relations:
hide 51
hide 53
show 52
return

aide_collections:
hide 51
hide 52
show 53
return
Very Happy
Revenir en haut Aller en bas
Klaus

Klaus


Nombre de messages : 12274
Age : 74
Localisation : Ile de France
Date d'inscription : 29/12/2009

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptySam 9 Avr 2011 - 19:32

Si tu veux - pas de problème. Je l'avais laissé en grand, car en ligne 25, il y a "debug%=0". Pour la mise au point, je fais "debug%=1", et mes DLIST sont transformés en LIST pour pouvoir visualiser l'effet des commandes.

PS. Je posterai prochainement une base complète de démo, pour voir l'ensemble des fonctionnalités.
Revenir en haut Aller en bas
http://klauspanoramic.comxa.com/index.html
Klaus

Klaus


Nombre de messages : 12274
Age : 74
Localisation : Ile de France
Date d'inscription : 29/12/2009

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptyDim 10 Avr 2011 - 10:37

nouvelle version V1.04. Légère amélioration de la présentation des résultats en "Que sait-on".

Voici un lien vers une base de données complète:
http://www.upshare.me/files/N8XTR91302591809.html
(mis à jour pour la version V1.05)

C'est une base de données concernant des animaux.
L'entité de base est "animaux".
La relation "membre" lie "animaux" à "domestiques" et "sauvages".
La relation "membre" lie "domestiques" à "bétail", "basse-cour" et "compagnie"
La relation "membre" lie bétail à "vache", "cheval", "chèvre","mouton" et "porc"
La relation "membre" lie "basse-cour" à "poule" et "lapin"
La relation "membre" lie "compagnie" à "chat", "chien", "tortue", "poisson rouge" et "canari"
La relation "membre" lie " sauvages" à "sanglier", "canard', "mésange", "aigle", "mouette","phoque", "lieu noir", "lézard", "mouche", "sardine"
La relation "prédateur" lie:
phoque à mouette
aigle à lieu noir
phoque à lieu noir
mésange à mouche
lézard à mouche
mouette à sardine
lieu noir à sardine
Il y a les collections suivantes: "herbivore", "carnivore", "omnivore", "sang chaud" et "sang froid". Les animaux sont éléments de leurs collections respectives; certains sont donc éléments de deux collections: lézard est élément de "sang froid" et élément de "carnivore".

Vous pouvez utiliser "Qe sait-on" sur chaque entité, y compris les relations et les collections, et "lister" sur les collections. Essayez par exemple, "Que sait-on sur" avec l'entité "lieu noir"...

Pour produire de vrais résultats intéressants, on peut par exemple se demander quels sont les aninaux prédateurs à sang froid. Pour cela, on procède par les étapes suivantes:
fonction "copier" premier paramètre: prédateur second paramètre: test
(ceci duplique la collection "prédateur" dans une nouvelle collection "test")
fonction "couper" premier paramètre: " sang froid" second paramètre: 'test'
(ceci affecte à la collection "test" l'intersection des collections "test" et "sang froid'")
fonction "que sait-on" ou "lister" paramètre "test"
(on obtient le résultat, soit "lézard" et "lieu noir")

A vous d'imaginer votre propre application !


Dernière édition par Klaus le Mar 12 Avr 2011 - 9:07, édité 2 fois
Revenir en haut Aller en bas
http://klauspanoramic.comxa.com/index.html
Klaus

Klaus


Nombre de messages : 12274
Age : 74
Localisation : Ile de France
Date d'inscription : 29/12/2009

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptyMar 12 Avr 2011 - 1:04

J'ai mis en ligne la version V1.05.

Nouveauté: 3 nouvelles fonctions permettant de gérer des données pour les entités ! Chaque entité peut avoir des données libres, sous forme d'une chaîne de caractères. La commande "Que sait-on sur" affiche les données de l'entité entre "[...]'. Trois commandes permettent de gérer cela:
"Mémoriser les données" permet de mémoriser une chaîne de caractères pour une entité
"Ajouter les données" ajoute une chaîne de caractères à la fin des données existantes d'une entité
"Oublier les données" supprime toutes les données d'une entité

Une fonction spéciale dans l'aide explique cela.

ATTENTION ! Cette nouvelle fonction implique un changement de format de la base de donnée ! Afin de continuer à travailler avec une base créée avec une version antérieure, faire impérativement:
- bouton "Restaurer" pour charger l'ancienne base
- bouton "Sauvegarder" en choisissant le MEME nom de base
==> le format est adapté automatiquement au moment de la sauvegarde !


Note: la base exemple dans le post précédent a été mise à jour !
Revenir en haut Aller en bas
http://klauspanoramic.comxa.com/index.html
Klaus

Klaus


Nombre de messages : 12274
Age : 74
Localisation : Ile de France
Date d'inscription : 29/12/2009

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptyMer 13 Avr 2011 - 14:16

Version V1.06 du 13/4/2011.
- correction de légers bugs
- nouvelle commande de base: "Créer" - crée une entité seuls, sans contexte relationnel, sans collection, sans données. Elle pourra être utilisée ultérieurement pour tout cela
Revenir en haut Aller en bas
http://klauspanoramic.comxa.com/index.html
Klaus

Klaus


Nombre de messages : 12274
Age : 74
Localisation : Ile de France
Date d'inscription : 29/12/2009

Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic EmptyJeu 14 Avr 2011 - 15:54

Version 1/07 du 14/4/2011

Nouveautés:

1. La base de données animaux.bdr a été modifiée en ajoutant des données aux entités des animaux, avec ine indication de leur nourriture. En outre, le lien vers cette base d'exemple a été placé dans le premier post au début, afin d'avoir un accès plus facile.

2. une commande "Chercher les données" qui permet de rechercher toutes les occurences d'une chaîne de caractères dans les données des entités. On peut ainsi chercher "céréales", et on a la liste des animaux dont céréales fait partie de la nourriture !
Revenir en haut Aller en bas
http://klauspanoramic.comxa.com/index.html
Contenu sponsorisé





Une Base de Données Relationnelle (BDR) en Panoramic Empty
MessageSujet: Re: Une Base de Données Relationnelle (BDR) en Panoramic   Une Base de Données Relationnelle (BDR) en Panoramic Empty

Revenir en haut Aller en bas
 
Une Base de Données Relationnelle (BDR) en Panoramic
Revenir en haut 
Page 1 sur 1
 Sujets similaires
-
» Une base de données relationnelle avec Panoramic
» Base de données relationnelle
» Base de données relationnelle
» Logithèque : une base de données en Panoramic pour Panoramic
» Base de données de type ISAM par Excel sous PANORAMIC

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC :: PANORAMIC :: Vos sources, vos utilitaires à partager-
Sauter vers: