Exemple #1
0
 /// /////////////////////////////////////////////
 private void RAZDataTable()
 {
     if (TypeTable != null)
     {
         DataTableObject = TypeTable.GetNewDataTable(Libelle);
         return;
     }
     DataTableObject = new DataTable(Libelle);
 }
Exemple #2
0
        /// /////////////////////////////////////////////
        public CResultAErreur ImportTable(
            DataTable tableSource,
            Dictionary <DataColumn, CColonneTableParametrable> mapColonnes,
            CImportTableParametrableMode mode)
        {
            CResultAErreur result = CResultAErreur.True;

            if (mode == null)
            {
                result.EmpileErreur(I.T("A mapping mode is mandatory|518"));
                return(result);
            }
            DataTable tableDest = null;

            if (mode.Code == EImportTableParametrableMode.RAZ_Puis_Import)
            {
                tableDest = TypeTable.GetNewDataTable(Libelle);
            }
            else
            {
                tableDest = DataTableObject;
            }

            //Map de colonne source sur colonne dest
            Hashtable tableColSourceToColDest = new Hashtable();

            foreach (KeyValuePair <DataColumn, CColonneTableParametrable> map in mapColonnes)
            {
                if (tableDest.Columns.Contains(map.Value.Libelle))
                {
                    tableColSourceToColDest[map.Key] = tableDest.Columns[map.Value.Libelle];
                }
            }

            //Vérification de la compatibilité des types de données source et destination
            foreach (DataColumn colTable in tableSource.Columns)
            {
                DataColumn colDest = (DataColumn)tableColSourceToColDest[colTable];
                if (colDest != null && !colDest.DataType.IsAssignableFrom(colTable.DataType))
                {
                    result.EmpileErreur(I.T("The source column @1 is not compatible with the destination column @2|513",
                                            colTable.ColumnName,
                                            colDest.ColumnName));
                    return(result);
                }
            }

            result = VerifMappingPk(mode, mapColonnes);
            if (!result)
            {
                return(result);
            }

            //Import des données
            foreach (DataRow row in tableSource.Rows)
            {
                if (mode == EImportTableParametrableMode.Delete)
                {
                    result = DeleteRows(row, tableDest, tableColSourceToColDest);
                }
                else
                {
                    result = UpdateOrCreateRow(row, tableDest, tableColSourceToColDest);
                }

                if (!result)
                {
                    return(result);
                }
            }
            DataTableObject = tableDest;
            return(result);
        }