예제 #1
0
        internal DmRelation Clone(DmSet destination)
        {
            DmTable parent    = destination.Tables[ParentTable.TableName];
            DmTable child     = destination.Tables[ChildTable.TableName];
            int     keyLength = parentKey.Columns.Length;

            DmColumn[] parentColumns = new DmColumn[keyLength];
            DmColumn[] childColumns  = new DmColumn[keyLength];

            for (int i = 0; i < keyLength; i++)
            {
                parentColumns[i] = parent.Columns[ParentKey.Columns[i].ColumnName];
                childColumns[i]  = child.Columns[ChildKey.Columns[i].ColumnName];
            }

            DmRelation clone = new DmRelation(RelationName, parentColumns, childColumns);

            return(clone);
        }
예제 #2
0
        /// <summary>
        /// Create a clone of the current DmTable
        /// </summary>
        public DmTable Clone()
        {
            DmTable clone = new DmTable
            {
                // Set All properties
                TableName              = tableName,
                Schema                 = schema,
                Culture                = culture,
                CaseSensitive          = caseSensitive,
                OriginalProvider       = OriginalProvider,
                SyncDirection          = SyncDirection,
                TrackingTablesPrefix   = TrackingTablesPrefix,
                TrackingTablesSuffix   = TrackingTablesSuffix,
                StoredProceduresPrefix = StoredProceduresPrefix,
                StoredProceduresSuffix = StoredProceduresSuffix,
                TriggersPrefix         = TriggersPrefix,
                TriggersSuffix         = TriggersSuffix
            };

            // add all columns
            var clmns = this.Columns;

            for (int i = 0; i < clmns.Count; i++)
            {
                clone.Columns.Add(clmns[i].Clone());
            }

            // Create PrimaryKey
            DmColumn[] pkey = PrimaryKey.Columns;
            if (pkey != null && pkey.Length > 0)
            {
                DmColumn[] key = new DmColumn[pkey.Length];

                for (int i = 0; i < pkey.Length; i++)
                {
                    key[i] = clone.Columns[pkey[i].Ordinal];
                }

                clone.PrimaryKey = new DmKey(key);
            }

            return(clone);
        }
예제 #3
0
        /// <summary>
        /// Copy a record, whatever the state (Added, Modified, Deleted etc...)
        /// </summary>
        internal void CopyRecords(DmTable src, int srcRecord, int newRecord)
        {
            // Parcours de toutes les colonnes de destination
            for (int i = 0; i < this.Columns.Count; ++i)
            {
                // colonne de destination
                DmColumn dstColumn = this.Columns[i];
                // colonne à copier
                DmColumn srcColumn = src.Columns.FirstOrDefault(c => this.IsEqual(c.ColumnName, dstColumn.ColumnName));

                if (srcColumn == null)
                {
                    dstColumn.Init(newRecord);
                    continue;
                }

                if (dstColumn.IsValueType)
                {
                    dstColumn[newRecord] = srcColumn[srcRecord];
                    continue;
                }

                if (dstColumn.DataType == typeof(byte[]))
                {
                    byte[] srcArray  = (byte[])srcColumn[srcRecord];
                    byte[] destArray = (byte[])dstColumn[newRecord];

                    Buffer.BlockCopy(srcArray, 0, destArray, 0, srcArray.Length);
                    continue;
                }
                if (dstColumn.DataType == typeof(char[]))
                {
                    char[] srcArray  = (char[])srcColumn[srcRecord];
                    char[] destArray = (char[])dstColumn[newRecord];

                    Buffer.BlockCopy(srcArray, 0, destArray, 0, srcArray.Length);
                    continue;
                }

                dstColumn[newRecord] = srcColumn[srcRecord];
            }
        }
예제 #4
0
        /// <summary>
        /// Get Changes from the DmTable, with a DmRowState value
        /// </summary>
        public DmTable GetChanges(DmRowState rowStates)
        {
            DmTable dtChanges = this.Clone();
            DmRow   row       = null;

            for (int i = 0; i < Rows.Count; i++)
            {
                row = Rows[i];
                if ((row.RowState & rowStates) == row.RowState)
                {
                    dtChanges.ImportRow(row);
                }
            }

            if (dtChanges.Rows.Count == 0)
            {
                return(null);
            }

            return(dtChanges);
        }
예제 #5
0
        /// <summary>
        /// Get Changes from the DmTable
        /// </summary>
        public DmTable GetChanges()
        {
            DmTable dtChanges = this.Clone();
            DmRow   row       = null;

            for (int i = 0; i < Rows.Count; i++)
            {
                row = Rows[i];
                if (row.oldRecord != row.newRecord)
                {
                    dtChanges.ImportRow(row);
                }
            }

            if (dtChanges.Rows.Count == 0)
            {
                return(null);
            }

            return(dtChanges);
        }
예제 #6
0
        DmKey GetSrcKey(DmTable src, DmTable dst)
        {
            if (src.PrimaryKey != null)
            {
                return(src.PrimaryKey);
            }

            DmKey key = default(DmKey);

            if (dst.PrimaryKey != null)
            {
                DmColumn[] dstColumns = dst.PrimaryKey.Columns;
                DmColumn[] srcColumns = new DmColumn[dstColumns.Length];
                for (int j = 0; j < dstColumns.Length; j++)
                {
                    srcColumns[j] = src.Columns[dstColumns[j].ColumnName];
                }

                key = new DmKey(srcColumns); // DmKey will take ownership of srcColumns
            }

            return(key);
        }
예제 #7
0
        /// <summary>
        /// Create a clone of the current DmTable
        /// </summary>
        public DmTable Clone()
        {
            DmTable clone = new DmTable();

            // Set All properties
            clone.TableName        = tableName;
            clone.Schema           = schema;
            clone.Culture          = culture;
            clone.CaseSensitive    = caseSensitive;
            clone.OriginalProvider = OriginalProvider;
            clone.SyncDirection    = SyncDirection;

            // add all columns
            var clmns = this.Columns;

            for (int i = 0; i < clmns.Count; i++)
            {
                clone.Columns.Add(clmns[i].Clone());
            }

            // Create PrimaryKey
            DmColumn[] pkey = PrimaryKey.Columns;
            if (pkey.Length > 0)
            {
                DmColumn[] key = new DmColumn[pkey.Length];

                for (int i = 0; i < pkey.Length; i++)
                {
                    key[i] = clone.Columns[pkey[i].Ordinal];
                }

                clone.PrimaryKey = new DmKey(key);
            }

            return(clone);
        }
예제 #8
0
        public virtual DmSet Clone()
        {
            DmSet ds = new DmSet();

            ds.DmSetName     = this.DmSetName;
            ds.CaseSensitive = this.CaseSensitive;
            ds.Culture       = this.Culture;

            for (int i = 0; i < Tables.Count; i++)
            {
                DmTable dt = Tables[i].Clone();
                ds.Tables.Add(dt);
            }

            List <DmRelation> rels = Relations;

            for (int i = 0; i < rels.Count; i++)
            {
                DmRelation rel = rels[i].Clone(ds);
                ds.Relations.Add(rel);
            }

            return(ds);
        }
예제 #9
0
 internal DmRowCollection(DmTable dt)
 {
     this.table = dt;
 }
예제 #10
0
 public void Dispose()
 {
     internalRows.Clear();
     internalRows = null;
     this.Table   = null;
 }
예제 #11
0
 internal abstract void SetTable(DmTable table);
예제 #12
0
 /// <summary>
 /// Merge a dmTable in this dmTable without perserving changes
 /// </summary>
 public void Merge(DmTable table)
 {
     Merge(table, false);
 }
예제 #13
0
 internal DmMerger(DmTable dataTable, bool preserveChanges)
 {
     this.dataTable       = dataTable;
     this.preserveChanges = preserveChanges;
 }
예제 #14
0
        DmTable MergeSchema(DmTable table)
        {
            if (dataTable == null)
            {
                dataTable = table.Clone();

                if (dataTable.DmSet != null)
                {
                    dataTable.DmSet.Tables.Add(dataTable);
                }
            }
            else
            {
                // Do the columns
                int oldCount = dataTable.Columns.Count;
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    DmColumn src  = table.Columns[i];
                    DmColumn dest = (dataTable.Columns.Contains(src.ColumnName, true)) ? dataTable.Columns[src.ColumnName] : null;

                    // If columns doesn't exist, create it
                    if (dest == null)
                    {
                        dest = src.Clone();
                        dataTable.Columns.Add(dest);
                    }
                }

                // check the PrimaryKey
                DmColumn[] targetPKey = dataTable.PrimaryKey.Columns;
                DmColumn[] tablePKey  = table.PrimaryKey.Columns;
                if (targetPKey.Length != tablePKey.Length)
                {
                    if (tablePKey.Length != 0)
                    {
                        throw new Exception("Merge Failed, keys are differents");
                    }

                    // special case when the target table does not have the PrimaryKey
                    if (targetPKey.Length == 0)
                    {
                        DmColumn[] key = new DmColumn[tablePKey.Length];
                        for (int i = 0; i < tablePKey.Length; i++)
                        {
                            key[i] = dataTable.Columns[tablePKey[i].ColumnName];
                        }

                        dataTable.PrimaryKey = new DmKey(key);
                    }
                }
                else
                {
                    // Check the keys are same
                    for (int i = 0; i < targetPKey.Length; i++)
                    {
                        if (!table.IsEqual(targetPKey[i].ColumnName, tablePKey[i].ColumnName))
                        {
                            throw new Exception("Merge Failed, keys are differents");
                        }
                    }
                }
            }

            return(dataTable);
        }
예제 #15
0
 public DmColumnCollection(DmTable dt)
 {
     this.table = dt;
 }