Exemple #1
0
 private NavisionDBRelation.ResultJoin[] HacerInner_Join(NavisionDBRelation.ResultJoin[] ResJoinAux, NavisionDBRelation.Relation relacion, DataTable t_padreAux, int indexPadreResultJoin, DataTable t_hijaAux, int indexHijoResultJoin)
 {
     string[] strArray = new string[relacion.RelationCol.Length];
     string[] strArray2 = new string[relacion.RelationCol.Length];
     DataTable table = new DataTable();
     if (t_padreAux == null)
     {
         throw new Exception("Parent table must not be null");
     }
     for (int i = 0; i < relacion.RelationCol.Length; i++)
     {
         strArray[i] = relacion.Parent_T + "." + relacion.RelationCol[i].PColumn;
         strArray2[i] = relacion.RelationCol[i].ChColumn;
     }
     if (t_hijaAux != null)
     {
         for (int j = 0; j < t_hijaAux.Columns.Count; j++)
         {
             t_padreAux.Columns.Add(t_hijaAux.Columns[j].ColumnName, t_hijaAux.Columns[j].DataType);
         }
         table = t_padreAux.Clone();
         table.AcceptChanges();
         for (int k = 0; k < t_padreAux.Rows.Count; k++)
         {
             if (t_hijaAux.Rows.Count > 0)
             {
                 for (int m = 0; m < t_hijaAux.Rows.Count; m++)
                 {
                     string columnName;
                     bool flag = true;
                     for (int n = 0; n < relacion.RelationCol.Length; n++)
                     {
                         string str3 = relacion.Parent_T + "." + relacion.RelationCol[n].PColumn;
                         columnName = relacion.Child_T + "." + relacion.RelationCol[n].ChColumn;
                         if (t_padreAux.Rows[k][str3].ToString() != t_hijaAux.Rows[m][columnName].ToString())
                         {
                             flag = false;
                         }
                     }
                     if (flag)
                     {
                         table.ImportRow(t_padreAux.Rows[k]);
                         for (int num13 = 0; num13 < t_hijaAux.Columns.Count; num13++)
                         {
                             columnName = t_hijaAux.Columns[num13].ColumnName;
                             table.Rows[table.Rows.Count - 1][columnName] = t_hijaAux.Rows[m][columnName];
                         }
                         if (relacion.distinct)
                         {
                             break;
                         }
                     }
                 }
             }
         }
     }
     else
     {
         int index = -1;
         for (int num3 = 0; num3 < this.Tablas.Length; num3++)
         {
             if (this.Tablas[num3].TableName == relacion.Child_T)
             {
                 index = num3;
                 break;
             }
         }
         if (index == -1)
         {
             throw new Exception("Child table must be add to the adapter.");
         }
         NavisionDBTable table2 = new NavisionDBTable(this.Tablas[index].ConnectionDB, this.Tablas[index].User);
         try
         {
             for (int num4 = 0; num4 < this.Tablas[index].ColumnsName.Length; num4++)
             {
                 Type type = this.Tablas[index].ColumnType(this.Tablas[index].Columns[num4]);
                 t_padreAux.Columns.Add(relacion.Child_T + "." + this.Tablas[index].ColumnsName[num4], type);
             }
         }
         catch (Exception exception)
         {
             throw exception;
         }
         table = t_padreAux.Clone();
         table.TableName = relacion.Parent_T;
         table.AcceptChanges();
         for (int num5 = 0; num5 < t_padreAux.Rows.Count; num5++)
         {
             table2.Reset();
             this.CopiarDBTable(this.Tablas[index], ref table2);
             for (int num6 = 0; num6 < relacion.RelationCol.Length; num6++)
             {
                 object obj2 = t_padreAux.Rows[num5][strArray[num6]];
                 if (obj2 is DBNull)
                 {
                     obj2 = " ";
                 }
                 table2.AddFilter(strArray2[num6], (string) obj2);
             }
             DataTable myDataTable = new DataTable();
             this.RellenarTablaGeneral(ref myDataTable, table2, relacion.distinct);
             if (myDataTable.Rows.Count > 0)
             {
                 for (int num7 = 0; num7 < myDataTable.Rows.Count; num7++)
                 {
                     table.ImportRow(t_padreAux.Rows[num5]);
                     string str = "";
                     string str2 = "";
                     for (int num8 = 0; num8 < myDataTable.Columns.Count; num8++)
                     {
                         str = myDataTable.Columns[num8].ColumnName;
                         str2 = relacion.Child_T + "." + str;
                         table.Rows[table.Rows.Count - 1][str2] = myDataTable.Rows[num7][str];
                     }
                 }
             }
             table.AcceptChanges();
         }
     }
     this.ActualizaResultJoin(ref ResJoinAux, ref indexPadreResultJoin, ref indexHijoResultJoin, relacion.Parent_T, relacion.Child_T);
     if (indexPadreResultJoin != -1)
     {
         ResJoinAux[indexPadreResultJoin].resJoin = table;
     }
     if (indexHijoResultJoin != -1)
     {
         ResJoinAux[indexHijoResultJoin].resJoin = table;
     }
     return ResJoinAux;
 }
Exemple #2
0
 private void ActualizaResultJoin(ref NavisionDBRelation.ResultJoin[] resJoin, ref int indexP, ref int indexH, string TPadre, string THijo)
 {
     if (indexH != -1)
     {
         resJoin[indexH].AniadeTablaJoin(TPadre);
     }
     if (indexP != -1)
     {
         resJoin[indexP].AniadeTablaJoin(THijo);
     }
     if ((indexH == -1) && (indexP == -1))
     {
         if (resJoin == null)
         {
             resJoin = new NavisionDBRelation.ResultJoin[1];
             resJoin[0].tNames = new string[] { TPadre, THijo };
             indexP = 0;
             indexH = 0;
         }
         else
         {
             NavisionDBRelation.ResultJoin[] joinArray = new NavisionDBRelation.ResultJoin[resJoin.Length + 1];
             for (int i = 0; i < resJoin.Length; i++)
             {
                 joinArray[i] = resJoin[i];
                 joinArray[i].tNames = new string[resJoin[i].tNames.Length];
                 for (int j = 0; j < joinArray[i].tNames.Length; j++)
                 {
                     joinArray[i].tNames[j] = resJoin[i].tNames[j];
                 }
             }
             joinArray[joinArray.Length - 1].tNames = new string[] { TPadre, THijo };
             resJoin = joinArray;
             indexP = joinArray.Length - 1;
             indexH = indexP;
         }
     }
 }
Exemple #3
0
 private DataTable ObtenerPadreRelac(NavisionDBRelation.ResultJoin[] ResJoinAux, string nombreTabla, ref int indexRelPadre)
 {
     DataTable myDataTable = new DataTable(nombreTabla);
     indexRelPadre = -1;
     if (ResJoinAux == null)
     {
         for (int k = 0; k < this.Tablas.Length; k++)
         {
             if (nombreTabla == this.Tablas[k].TableName)
             {
                 this.RellenarTabla(ref myDataTable, k);
                 for (int m = 0; m < myDataTable.Columns.Count; m++)
                 {
                     myDataTable.Columns[m].ColumnName = myDataTable.TableName + "." + myDataTable.Columns[m].ColumnName;
                 }
                 myDataTable.AcceptChanges();
                 return myDataTable;
             }
         }
         return myDataTable;
     }
     for (int i = 0; i < ResJoinAux.Length; i++)
     {
         for (int n = 0; n < ResJoinAux[i].tNames.Length; n++)
         {
             if (ResJoinAux[i].tNames[n] == nombreTabla)
             {
                 indexRelPadre = i;
                 return ResJoinAux[i].resJoin;
             }
         }
     }
     for (int j = 0; j < this.Tablas.Length; j++)
     {
         if (nombreTabla == this.Tablas[j].TableName)
         {
             this.RellenarTabla(ref myDataTable, j);
             for (int num6 = 0; num6 < myDataTable.Columns.Count; num6++)
             {
                 myDataTable.Columns[num6].ColumnName = myDataTable.TableName + "." + myDataTable.Columns[num6].ColumnName;
             }
             myDataTable.AcceptChanges();
             return myDataTable;
         }
     }
     return myDataTable;
 }
Exemple #4
0
 private DataTable ObtenerHijaRelac(NavisionDBRelation.ResultJoin[] ResJoinAux, string nombreTabla, ref int indexRelHijo)
 {
     indexRelHijo = -1;
     new DataTable();
     if (ResJoinAux != null)
     {
         for (int i = 0; i < ResJoinAux.Length; i++)
         {
             for (int j = 0; j < ResJoinAux[i].tNames.Length; j++)
             {
                 if (ResJoinAux[i].tNames[j] == nombreTabla)
                 {
                     indexRelHijo = i;
                     return ResJoinAux[i].resJoin;
                 }
             }
         }
     }
     return null;
 }
Exemple #5
0
 private NavisionDBRelation.ResultJoin[] Hacer_TipoJoin(NavisionDBRelation.ResultJoin[] ResJoinAux, NavisionDBRelation.Relation relacion, DataTable t_padreAux, int indexPadreResultJoin, DataTable t_hijaAux, int indexHijoResultJoin)
 {
     string[] strArray = new string[relacion.RelationCol.Length];
     string[] strArray2 = new string[relacion.RelationCol.Length];
     DataTable table = new DataTable();
     if (t_padreAux == null)
     {
         throw new Exception("Parent table must not be null in Join.");
     }
     if (t_hijaAux == null)
     {
         throw new Exception("Child table must not be null in Join");
     }
     for (int i = 0; i < relacion.RelationCol.Length; i++)
     {
         strArray[i] = relacion.Parent_T + "." + relacion.RelationCol[i].PColumn;
         strArray2[i] = relacion.RelationCol[i].ChColumn;
     }
     for (int j = 0; j < t_hijaAux.Columns.Count; j++)
     {
         t_padreAux.Columns.Add(t_hijaAux.Columns[j].ColumnName, t_hijaAux.Columns[j].DataType);
     }
     table = t_padreAux.Clone();
     table.AcceptChanges();
     t_hijaAux.Columns.Add("Aniadida", Type.GetType("System.Boolean"));
     t_hijaAux.AcceptChanges();
     for (int k = 0; k < t_padreAux.Rows.Count; k++)
     {
         bool flag = false;
         if (t_hijaAux.Rows.Count > 0)
         {
             for (int n = 0; n < t_hijaAux.Rows.Count; n++)
             {
                 string columnName;
                 bool flag2 = true;
                 for (int num5 = 0; num5 < relacion.RelationCol.Length; num5++)
                 {
                     string str = relacion.Parent_T + "." + relacion.RelationCol[num5].PColumn;
                     columnName = relacion.Child_T + "." + relacion.RelationCol[num5].ChColumn;
                     if (t_padreAux.Rows[k][str].ToString() != t_hijaAux.Rows[n][columnName].ToString())
                     {
                         flag2 = false;
                     }
                 }
                 if (flag2)
                 {
                     table.ImportRow(t_padreAux.Rows[k]);
                     flag = true;
                     for (int num6 = 0; num6 < t_hijaAux.Columns.Count; num6++)
                     {
                         columnName = t_hijaAux.Columns[num6].ColumnName;
                         if (columnName != "Aniadida")
                         {
                             table.Rows[table.Rows.Count - 1][columnName] = t_hijaAux.Rows[n][columnName];
                         }
                     }
                     t_hijaAux.Rows[n]["Aniadida"] = true;
                     if (!relacion.distinct)
                     {
                         continue;
                     }
                     break;
                 }
                 if ((n == (t_hijaAux.Rows.Count - 1)) && !flag)
                 {
                     table.ImportRow(t_padreAux.Rows[k]);
                 }
             }
         }
         else
         {
             table.ImportRow(t_padreAux.Rows[k]);
         }
     }
     for (int m = 0; m < t_hijaAux.Rows.Count; m++)
     {
         if (t_hijaAux.Rows[m]["Aniadida"] != DBNull.Value)
         {
             continue;
         }
         for (int num8 = 0; num8 < table.Rows.Count; num8++)
         {
             bool flag3 = true;
             for (int num9 = 0; num9 < relacion.RelationCol.Length; num9++)
             {
                 string str3 = relacion.Parent_T + "." + relacion.RelationCol[num9].PColumn;
                 string str4 = relacion.Child_T + "." + relacion.RelationCol[num9].ChColumn;
                 if (table.Rows[num8][str3].ToString() != t_hijaAux.Rows[m][str4].ToString())
                 {
                     flag3 = false;
                 }
             }
             if (flag3)
             {
                 t_hijaAux.Rows[m]["Aniadida"] = true;
                 break;
             }
         }
         if (t_hijaAux.Rows[m]["Aniadida"] == DBNull.Value)
         {
             DataRow row = table.NewRow();
             string str5 = "";
             for (int num10 = 0; num10 < t_hijaAux.Columns.Count; num10++)
             {
                 str5 = t_hijaAux.Columns[num10].ColumnName;
                 if (str5 != "Aniadida")
                 {
                     row[str5] = t_hijaAux.Rows[m][str5];
                 }
             }
             table.Rows.Add(row);
         }
     }
     table.AcceptChanges();
     this.ActualizaResultJoin(ref ResJoinAux, ref indexPadreResultJoin, ref indexHijoResultJoin, relacion.Parent_T, relacion.Child_T);
     if (indexPadreResultJoin != -1)
     {
         ResJoinAux[indexPadreResultJoin].resJoin = table;
     }
     if (indexHijoResultJoin != -1)
     {
         ResJoinAux[indexHijoResultJoin].resJoin = table;
     }
     return ResJoinAux;
 }
Exemple #6
0
 private DataRelation Hacer_DataSetRelation(ref int index, ref DataTable[] myDataTables, NavisionDBRelation.Relation relacion)
 {
     bool flag = false;
     bool flag2 = false;
     if (index > 0)
     {
         for (int j = 0; j < index; j++)
         {
             if (relacion.Parent_T == myDataTables[j].TableName)
             {
                 flag = true;
                 break;
             }
         }
         for (int k = 0; k < index; k++)
         {
             if (relacion.Parent_T == myDataTables[k].TableName)
             {
                 flag2 = true;
                 break;
             }
         }
     }
     if (!flag)
     {
         for (int m = 0; m < this.Tables.Length; m++)
         {
             if (relacion.Parent_T == this.Tables[m].TableName)
             {
                 myDataTables[index] = new DataTable(this.Tablas[m].TableName + "DR");
                 this.RellenarTabla(ref myDataTables[index], m);
                 index++;
             }
         }
     }
     if (!flag2)
     {
         for (int n = 0; n < this.Tables.Length; n++)
         {
             if (relacion.Child_T == this.Tables[n].TableName)
             {
                 myDataTables[index] = new DataTable(this.Tablas[n].TableName + "DR");
                 this.RellenarTabla(ref myDataTables[index], n);
                 index++;
             }
         }
     }
     string[] parentColumnNames = new string[relacion.RelationCol.Length];
     string[] childColumnNames = new string[relacion.RelationCol.Length];
     for (int i = 0; i < relacion.RelationCol.Length; i++)
     {
         parentColumnNames[i] = relacion.RelationCol[i].PColumn;
         childColumnNames[i] = relacion.RelationCol[i].ChColumn;
     }
     return new DataRelation(relacion.Parent_T + "DR." + relacion.Child_T + "DR", relacion.Parent_T + "DR", relacion.Child_T + "DR", parentColumnNames, childColumnNames, false);
 }