示例#1
0
        private void Create(string relationName, DmColumn[] parentColumns, DmColumn[] childColumns)
        {
            try
            {
                parentKey = new DmKey(parentColumns);
                childKey  = new DmKey(childColumns);

                if (parentColumns.Length != childColumns.Length)
                {
                    throw new Exception("KeyLengthMismatch");
                }

                for (int i = 0; i < parentColumns.Length; i++)
                {
                    if ((parentColumns[i].Table.DmSet == null) || (childColumns[i].Table.DmSet == null))
                    {
                        throw new Exception("Parent Or Child Columns Do Not Have DmSet");
                    }
                }

                CheckState();

                RelationName = relationName ?? "";
            }
            finally
            {
            }
        }
示例#2
0
        void MergeTable(DmTable src, DmTable dst)
        {
            if (src.Rows.Count == 0)
            {
                return;
            }

            DmKey key = default(DmKey);

            try
            {
                foreach (DmRow sourceRow in src.Rows)
                {
                    DmRow targetRow = null;
                    if (dst.Rows.Count > 0 && dst.PrimaryKey != null)
                    {
                        key = GetSrcKey(src, dst);
                        var keyValue = sourceRow.GetKeyValues(key);

                        targetRow = dst.FindByKey(keyValue);
                    }
                    dst.MergeRow(sourceRow, targetRow, preserveChanges);
                }
            }
            finally
            {
            }
        }
示例#3
0
        internal bool Equals(DmKey value)
        {
            //check to see if this.columns && key2's columns are equal...
            DmColumn[] column1 = this.columns;
            DmColumn[] column2 = value.columns;

            if (column1 == column2)
            {
                return(true);
            }
            else if (column1 == null || column2 == null)
            {
                return(false);
            }
            else if (column1.Length != column2.Length)
            {
                return(false);
            }
            else
            {
                for (int i = 0; i < column1.Length; i++)
                {
                    if (!column1[i].Equals(column2[i]))
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
示例#4
0
 internal bool HasKeyChanged(DmKey key, DmRowVersion version1, DmRowVersion version2)
 {
     if (!HasVersion(version1) || !HasVersion(version2))
     {
         return(true);
     }
     return(!key.RecordsEqual(GetRecordFromVersion(version1), GetRecordFromVersion(version2)));
 }
示例#5
0
        internal bool HaveValuesChanged(DmColumn[] rows, DmRowVersion version1, DmRowVersion version2)
        {
            for (int i = 0; i < rows.Length; i++)
            {
                CheckColumn(rows[i]);
            }

            DmKey key = new DmKey(rows); // temporary key, don't copy rows

            return(HasKeyChanged(key, version1, version2));
        }
示例#6
0
        /// <summary>
        /// Gets the parent rows for the given child row across the relation using the version given
        /// </summary>
        internal static DmRow[] GetParentRows(DmKey parentKey, DmKey childKey, DmRow childRow, DmRowVersion version)
        {
            object[] values = childRow.GetKeyValues(childKey, version);
            if (IsKeyNull(values))
            {
                return new DmRow[] { parentKey.Table.NewRow() }
            }
            ;

            return(parentKey.Table.Rows.Where(r => parentKey.ValuesAreEqual(r, values)).ToArray());
        }
示例#7
0
        internal void MergeRows(DmRow[] rows)
        {
            DmTable src = null;
            DmTable dst = null;
            DmKey   key = default(DmKey);

            for (int i = 0; i < rows.Length; i++)
            {
                DmRow row = rows[i];

                if (row == null)
                {
                    throw new ArgumentNullException("rows[" + i + "]");
                }
                if (row.Table == null)
                {
                    throw new ArgumentNullException("rows[" + i + "].Table");
                }

                //somebody is doing an 'automerge'
                if (row.Table.DmSet == dataSet)
                {
                    continue;
                }

                if (src != row.Table)
                {                     // row.Table changed from prev. row.
                    src = row.Table;
                    dst = MergeSchema(row.Table);
                    if (dst.PrimaryKey != null)
                    {
                        key = GetSrcKey(src, dst);
                    }
                }

                if (row.newRecord == -1 && row.oldRecord == -1)
                {
                    continue;
                }

                DmRow targetRow = null;

                dst.MergeRow(row, targetRow, preserveChanges);
            }
        }
示例#8
0
        /// <summary>
        /// For a foreignkey, actually we have only one row
        /// </summary>
        internal static DmRow GetParentRow(DmKey parentKey, DmKey childKey, DmRow childRow, DmRowVersion version)
        {
            if (!childRow.HasVersion((version == DmRowVersion.Original) ? DmRowVersion.Original : DmRowVersion.Current))
            {
                if (childRow.tempRecord == -1)
                {
                    return(null);
                }
            }

            object[] values = childRow.GetKeyValues(childKey, version);
            if (IsKeyNull(values))
            {
                return(null);
            }

            return(parentKey.Table.Rows.FirstOrDefault(r => parentKey.ValuesAreEqual(r, values)));
        }
示例#9
0
        internal void SetKeyValues(DmKey key, object[] keyValues)
        {
            bool fFirstCall = true;
            bool immediate  = (tempRecord == -1);

            for (int i = 0; i < keyValues.Length; i++)
            {
                object value = this[key.Columns[i]];
                if (!value.Equals(keyValues[i]))
                {
                    if (immediate && fFirstCall)
                    {
                        fFirstCall = false;
                        BeginEditInternal();
                    }
                    this[key.Columns[i]] = keyValues[i];
                }
            }
            if (!fFirstCall)
            {
                EndEdit();
            }
        }
示例#10
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);
        }
示例#11
0
 internal bool HasKeyChanged(DmKey key)
 {
     return(HasKeyChanged(key, DmRowVersion.Current, DmRowVersion.Proposed));
 }
示例#12
0
        internal object[] GetKeyValues(DmKey key, DmRowVersion version)
        {
            int record = GetRecordFromVersion(version);

            return(key.GetKeyValues(record));
        }
示例#13
0
        internal object[] GetKeyValues(DmKey key)
        {
            int record = GetRecordId();

            return(key.GetKeyValues(record));
        }
示例#14
0
        internal object[] GetColumnValues(DmColumn[] rows, DmRowVersion version)
        {
            DmKey key = new DmKey(rows); // temporary key, don't copy rows

            return(GetKeyValues(key, version));
        }
示例#15
0
        //internal void CheckState()
        //{
        //    DmTable table = columns[0].Table;

        //    if (table == null)
        //        throw new Exception("ColumnNotInAnyTable");

        //    for (int i = 1; i < columns.Length; i++)
        //    {
        //        if (columns[i].Table == null)
        //            throw new Exception("ColumnNotInAnyTable");

        //        if (columns[i].Table != table)
        //            throw new Exception("KeyTableMismatch");
        //    }
        //}

        //check to see if this.columns && key2's columns are equal regardless of order
        internal bool ColumnsEqual(DmKey key)
        {
            return(ColumnsEqual(this.columns, ((DmKey)key).columns));
        }