/// <summary>
 /// Test depends on
 /// </summary>
 /// <param name="legende">summary object</param>
 /// <returns>true or false</returns>
 public bool TestDependsOn(ILegende legende)
 {
     if (legende != null)
     {
         if (legende.DependsOn.valid)
         {
             // cette legende représente un tableau qui dépend d'un champ ou d'une chaîne
             if (String.IsNullOrEmpty(legende.DependsOn.context))
             {
                 // c'est une chaine, vérifier qu'elle existe et qu'elle a la bonne valeur
                 if (this.IsString(legende.DependsOn.name) && legende.DependsOn.value == this.GetString(legende.DependsOn.name))
                 {
                     // c'est une chaîne et elle a la valeur pour ce tableau
                     return(true);
                 }
             }
             else
             {
                 // il y a un context
                 if (this.IsArray(legende.DependsOn.context))
                 {
                     Array  arr    = this.GetArray(legende.DependsOn.context) as Array;
                     Fields fields = arr.Item(1) as Fields;
                     if (fields.Exists(legende.DependsOn.name) && fields.GetString(legende.DependsOn.name) == legende.DependsOn.value)
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
 /// <summary>
 /// Gets a relation with an another name
 /// </summary>
 /// <param name="legende">summary object</param>
 /// <param name="keyTab">tabular name</param>
 /// <param name="index">position in the tabular</param>
 /// <param name="arr">array name</param>
 /// <param name="field">field name</param>
 /// <returns>true if found</returns>
 public bool GetInConnection(ILegende legende, string keyTab, int index, out string arr, out string field)
 {
     if (legende != null)
     {
         if (legende.InConnection.valid)
         {
             if (String.IsNullOrEmpty(legende.InConnection.context))
             {
                 // cette legende indique que cette chaine pointe sur un tableau
                 string value = this.GetString(legende.InConnection.name);
                 if (!String.IsNullOrEmpty(value))
                 {
                     if (this.IsArray(value))
                     {
                         arr   = value;
                         field = legende.InConnection.field;
                         return(true);
                     }
                 }
             }
             else
             {
                 if (String.IsNullOrEmpty(legende.InConnection.name))
                 {
                     // cette legende indique un tableau
                     if (this.IsArray(legende.InConnection.context))
                     {
                         arr   = legende.InConnection.context;
                         field = legende.InConnection.field;
                         return(true);
                     }
                 }
                 else
                 {
                     // cette legende indique un champ du tableau pointant sur un tableau
                     if (legende.InConnection.context == keyTab)
                     {
                         Array relatedArray = this.GetArray(keyTab) as Array;
                         if (index > 0)
                         {
                             Fields relatedFields = relatedArray.Item(index) as Fields;
                             if (relatedFields.Exists(legende.InConnection.name))
                             {
                                 string value = relatedFields.GetString(legende.InConnection.name);
                                 if (!String.IsNullOrEmpty(value))
                                 {
                                     if (this.IsArray(value))
                                     {
                                         arr   = value;
                                         field = legende.InConnection.field;
                                         return(true);
                                     }
                                 }
                             }
                         }
                         else
                         {
                         }
                     }
                 }
             }
         }
     }
     arr   = null;
     field = null;
     return(false);
 }
 /// <summary>
 /// Parse expression to insert into a summary
 /// </summary>
 /// <param name="legende">summary object</param>
 public void ParseExpression(ILegende legende)
 {
     if (legende != null)
     {
         legende.DependsOn    = new depends();
         legende.InConnection = new inconnection();
         legende.PrimaryKey   = new primaryKey();
         legende.Observe      = "";
         Regex reg   = new Regex(@"^observe \(((([^,]+),?)+)\)$|^primary key is (.*)$|^depends on (.*)$|^in connection with (.*)$");
         Match match = reg.Match(legende.Expression);
         if (match.Success)
         {
             if (match.Groups[1].Success)
             {
                 if (!legende.IsArray)
                 {
                     // groupe observe
                     legende.Observe = match.Groups[1].Value;
                 }
             }
             else if (match.Groups[4].Success)
             {
                 // groupe primary key
                 if (legende.IsArray)
                 {
                     legende.PrimaryKey = new primaryKey(match.Groups[4].Value);
                 }
             }
             else if (match.Groups[5].Success)
             {
                 // groupe depends on
                 if (legende.IsArray)
                 {
                     string sub = match.Groups[5].Value;
                     int    next;
                     string context;
                     string depends;
                     if (this.ExtractName(sub, out next, out context, out depends))
                     {
                         Regex nextReg   = new Regex(@" to (.*)$");
                         Match nextMatch = nextReg.Match(sub.Substring(next));
                         if (nextMatch.Success)
                         {
                             legende.DependsOn = new depends(context, depends, nextMatch.Groups[1].Value);
                         }
                     }
                 }
             }
             else if (match.Groups[6].Success)
             {
                 if (!legende.IsArray)
                 {
                     // groupe related to
                     int    next;
                     string context;
                     string related;
                     string sub = match.Groups[6].Value;
                     if (this.ExtractName(sub, out next, out context, out related))
                     {
                         Regex nextReg   = new Regex(@" to (.*)$");
                         Match nextMatch = nextReg.Match(sub.Substring(next));
                         if (nextMatch.Success)
                         {
                             legende.Type         = Legende.TypeNumber;
                             legende.InConnection = new inconnection(context, related, nextMatch.Groups[1].Value);
                         }
                     }
                 }
             }
         }
     }
 }