Application: TransactionControl
Revit Platform: All
Revit Version: 2011.0
First Released For: 2008.0
Programming Language: C#
Skill Level: Medium
Category: Basics
Type: ExternalCommand

Subject: How to deal with transaction group, transaction and sub transaction.
Summary: 
This sample demonstrates how to use transaction group, transaction and sub transaction.

Classes: 
Autodesk.Revit.Document
Autodesk.Revit.DB.TransactionGroup
Autodesk.Revit.DB.Transaction
Autodesk.Revit.DB.SubTransaction

Project Files: 
Command.cs
It contains the class Command which implements interface IExternalCommand. This is the entry of this external command.

TransactionForm.cs
It contains the class TransactionForm which has options to start, rollback or commit transaction groups and transactions. The form also let user to create, move or delete walls inside transaction. The tree view is used to display all operations and transactions/transaction groups above and their relationship.

CreateWallForm.cs
It contains the class CreateWallForm which is used to create a wall. There is a combo box and several text boxes in this form to set parameters used to create wall.

Description: 
Functionalities:
-	Three buttons in group box of transaction group provide following operations: begin a transaction group, rollback a transaction group, commit a transaction group. 
-	Three buttons in group box of transaction provide following operations: begin a transaction, rollback a transaction, commit a transaction. 
-	Three buttons in another operations group box provide following operations: create a wall, move a wall, delete a wall. 
-	Provide a tree view to display transaction groups, transactions, operations and the relationship between them. 
-	Allow user to use nested transaction groups to manage their transaction groups and transactions. Transactions cannot be nested and can be created inside or outside a transaction group. Sub transactions must be created inside a transaction. User can do one or more of the operations listed above inside a transaction or sub transaction.
-	When user clicks “Ok”/”Cancel” and there are some transaction groups or transactions which are not finished, show a message box to ask user whether to end all transactions.

Implements:
-	Transaction Group can be started/rolled back/committed via class TransactionGroup’s Start/Rollback/Commit methods.
-	Transaction can be started/rolledback/committed via class Transaction’s Start/Rollback/Commit methods.
-	Wall can be created via Autodesk.Revit.Creation.Document’s NewWall Method and can be moved/deleted via Autodesk.Revit.Document’s Move/Delete methods
-	Tree node’s ForeColor represents different status, e.g. green means that a transaction or transaction group has been started, black means that a transaction or transaction group has been committed and gray means that a transaction or transaction group has been rolled back.

Instructions: 
1.	Run this external command.
2.	A dialog will be shown. Do some operations such as start a transaction or transaction group or create a wall, and then the tree view adds corresponding nodes to describe these operations and their relationship.
3.	When closing this dialog, if some transaction groups or transactions are not finished, a message box is shown to ask whether to end all transactions.