Ejemplo n.º 1
0
        /// <summary>
        /// Applies all given transactions
        /// </summary>
        /// <param name="ops">Operation list</param>
        private void ApplyTransaction(List <UndoRedoOperationBase> ops)
        {
            int i = 0;

            while (i < ops.Count)
            {
                UndoRedoOperationBase r = ops[i];
                DataRow row             = r.Row;

                switch (r.OperationType)
                {
                case UndoRedoOperationBaseType.NewRow:
                    UndoRedoRowOperation rowOp       = (UndoRedoRowOperation)r;
                    DataTable            sourceTable = rowOp.Table;
                    DataRow newRow = sourceTable.NewRow();

                    if (rowOp.WasDeleted)
                    {
                        RestoreRowFields(rowOp, newRow);
                    }
                    bool flag = true;
                    int  j    = i + 1;
                    while (flag & j < ops.Count)
                    {
                        if (ops[j].OperationType == UndoRedoOperationBaseType.ChangeField)
                        {
                            UndoRedoFieldOperation f = (UndoRedoFieldOperation)ops[j];
                            newRow[f.ColumnName] = f.NewValue;
                            i = j - 1;
                        }
                        else
                        {
                            flag = false;
                        }
                        j++;
                    }
                    sourceTable.Rows.Add(newRow);

                    for (int n = r.ID; n < m_operations.Count; ++n)
                    {
                        if (m_operations[n].Row == row)
                        {
                            m_operations[n].Row = newRow;
                        }
                    }
                    break;

                case UndoRedoOperationBaseType.DeleteRow:
                    //((UndoRedoRowOperation)r).Table.Rows.Remove(row);
                    ((UndoRedoRowOperation)r).Row.Delete();
                    break;

                case UndoRedoOperationBaseType.ChangeField:
                    UndoRedoFieldOperation fieldOp = (UndoRedoFieldOperation)r;
                    row[fieldOp.ColumnName] = fieldOp.NewValue;
                    break;
                }
                i++;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new <see cref="UndoRedoEventArgs"/> object.
 /// </summary>
 /// <param name="record">The transaction record.</param>
 public UndoRedoEventArgs(UndoRedoOperationBase record)
 {
     this.record = record;
 }