Exemplo n.º 1
0
        //-------------------------------------------
        public override bool  Equals(object obj)
        {
            CIdentifiantElement id = obj as CIdentifiantElement;

            if (id != null)
            {
                return(id.TableName == TableName && id.IdElement == IdElement);
            }
            return(false);
        }
Exemplo n.º 2
0
        //-----------------------------------------------------------------------
        private CResultAErreur AjouteNouveauxFromSecondaire(CContexteDonnee ctxDonnee)
        {
            CUtilSynchronisation utilSync        = new CUtilSynchronisation(IdSession);
            int            nIdSyncSessionEnCours = utilSync.IdSyncSession;
            CResultAErreur result = CResultAErreur.True;
            DataTable      tableLogsSynchroFromSecondaire = ctxDonnee.Tables[CEntreeLogSynchronisation.c_nomTable];

            if (tableLogsSynchroFromSecondaire == null)
            {
                result.EmpileErreur(I.T("Synchro table missing|20003"));
                return(result);
            }

            Dictionary <CIdentifiantElement, int> dicNewIds = new Dictionary <CIdentifiantElement, int>();

            ArrayList lstTables = ctxDonnee.GetTablesOrderInsert();

            foreach (DataTable tableSource in lstTables)
            {
                if (tableSource.PrimaryKey.Length == 1 && m_mappeurTablesToClass.IsSynchronisable(tableSource.TableName))
                {
                    DataTable tableDest  = GetTableSafe(tableSource.TableName);
                    string    strPrimKey = tableDest.PrimaryKey[0].ColumnName;
                    //Identifie tous les ajouts
                    DataRow[] rowsLogAjout = tableLogsSynchroFromSecondaire.Select(
                        CEntreeLogSynchronisation.c_champTable + "='" + tableSource.TableName + "' and " +
                        CEntreeLogSynchronisation.c_champType + "=" + (int)CEntreeLogSynchronisation.TypeModifLogSynchro.tAdd);
                    foreach (DataRow rowLogAjout in rowsLogAjout)
                    {
                        //Cherche la DataRow dans la table source
                        DataRow rowSource = tableSource.Rows.Find(rowLogAjout[CEntreeLogSynchronisation.c_champIdElement]);
                        if (rowSource != null)
                        {
                            //Création d'une nouvelle ligne
                            DataRow rowDest = tableDest.NewRow();
                            //copie de la ligne
                            foreach (DataColumn col in tableSource.Columns)
                            {
                                if (rowDest.Table.Columns.Contains(col.ColumnName) &&
                                    col.ColumnName != strPrimKey)
                                {
                                    rowDest[col.ColumnName] = rowSource[col.ColumnName];
                                }
                            }
                            rowDest[CSc2iDataConst.c_champIdSynchro] = nIdSyncSessionEnCours;
                            tableDest.Rows.Add(rowDest);
                            m_mapRowsFromSecondaireToMain[rowSource] = rowDest;
                            m_mapOldRowToOldId[rowSource]            = (int)rowSource[strPrimKey];


                            dicNewIds[new CIdentifiantElement(tableDest.TableName, (int)rowSource[strPrimKey])] = (int)rowDest[strPrimKey];
                            //Change l'id dans la rowSource pour qu'il soit
                            //répercuté sur les dépendances
                            rowSource[strPrimKey] = rowDest[strPrimKey];
                        }
                    }
                }
            }

            //change tous les anciens identifiants par les nouveaux
            foreach (KeyValuePair <CIdentifiantElement, int> kv in dicNewIds)
            {
                CIdentifiantElement ident = kv.Key;
                int nNewId = kv.Value;
                foreach (CInfoRelation relation in CContexteDonnee.GetListeRelationsTable(ident.TableName))
                {
                    if (relation.TableParente == ident.TableName)
                    {
                        DataTable tableThis = Tables[relation.TableFille];
                        if (tableThis != null)
                        {
                            DataRow[] rows = tableThis.Select(relation.ChampsFille[0] + "=" + ident.IdElement);
                            foreach (DataRow row in rows)
                            {
                                row[relation.ChampsFille[0]] = nNewId;
                            }
                        }
                        DataTable tableSource = ctxDonnee.Tables[relation.TableFille];
                        if (tableSource != null)
                        {
                            DataRow[] rows = tableSource.Select(relation.ChampsFille[0] + "=" + ident.IdElement);
                            foreach (DataRow row in rows)
                            {
                                row[relation.ChampsFille[0]] = nNewId;
                            }
                        }
                    }
                }
                Type tp = CContexteDonnee.GetTypeForTable(ident.TableName);
                //Change les ids des relation typeid
                foreach (RelationTypeIdAttribute rel in RelationsTypeIds)
                {
                    DataTable tableThis = Tables[rel.TableFille];
                    if (tableThis != null)
                    {
                        DataRow[] rows = tableThis.Select(rel.ChampId + "=" + ident.IdElement + " and " +
                                                          rel.ChampType + "='" + tp.ToString() + "'");
                        foreach (DataRow row in rows)
                        {
                            row[rel.ChampId] = nNewId;
                        }
                    }
                    DataTable tableSource = ctxDonnee.Tables[rel.TableFille];
                    if (tableSource != null)
                    {
                        DataRow[] rows = tableSource.Select(rel.ChampId + "=" + ident.IdElement + " and " +
                                                            rel.ChampType + "='" + tp.ToString() + "'");
                        foreach (DataRow row in rows)
                        {
                            row[rel.ChampId] = nNewId;
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        //-------------------------------------------
        public void SetNewIdForElement(string strNomTable, int nOldId, int nNewId)
        {
            CIdentifiantElement id = new CIdentifiantElement(strNomTable, nOldId);

            m_mapElementToNewId[id] = nNewId;
        }