Drawing3d documented Class Library

TaskCtrl.Commit Method

Set up an rolluppoint and calls Commit with object = null. For the use of this method you have to override the method GetUndoData.

Overload List

Set up an rolluppoint and calls Commit with object = null. For the use of this method you have to override the method GetUndoData.

public void Commit(int,string)

The handling of the undo- redo-theme seems to be easier with this method than with Commit. You specify the rollbackdata in the object UndoData. This object you get back in the UnDo method or in the event OnUndo.
The id is a tag, which you have to choice for every rollback situation. For example if you want to rollback "Insert" "Delete" and "Update" you define

const int UD_Insert = 1;
const int UD_Delete = 2;
const int UD_Update = 3;
and call
 Commit(UD_Insert,"Insert an object",UDData);
 ....
 and 
 ....
 public override void UnDo(int id, object Data)
 {
   UndoData UD = (Data as UndoData);

    switch (id)
    {
    case  UD_Insert: RemoveCustomerAt(UD.Id);
                    break;
    case  UD_Delete: InsertCustomer(UD.Id, UD.Name, UD.Street, UD.Country);
                 break;
    case  UD_Update: UpdateCustomerAt(UD.Id, UD.Name, UD.Street, UD.Country);
                 break;
                 
 
 
    }
 }
 ...
 where
 ...
 public void RemoveCustomerAt(int Id)
  {
 
    Commit(UD_Delete, "Delete Customer", new UndoData(Id, Form1.CustomerContainer[Id]));
    CustomerContainer.RemoveAt(Id);
  }
  ...
  public  Customer InsertCustomer(int id,string Name, string Street, string Country)
  {
    Customer Result = new Customer(Name, Street, Country);
    Commit(UD_Insert, "Add Customer", new UndoData(id,Result));
    CustomerContainer.Insert(id,Result);
    return Result;
  }
  ...
  and
  ...
   public void UpdateCustomerAt(int Id, string Name, string Street, string Country)
{
    Customer C = CustomerContainer[Id];
    Commit(UD_Update, "Update Customer", new UndoData(Id,C));
    C.Name = Name;
    C.Street = Street;
    C.Country = Country;
}
 
To start Undo you call for example in a click event UnDo resp. ReDoCommit

public void Commit(int,string,object)

See Also

TaskCtrl Class | Drawing3d Namespace | Commit