其实很早前就在论坛里贴过早期的版本,不算新内容
没有做详细的测试,还希望各位朋友指正:)
简单的注释了下:)
DBTransaction.cs
-
- #define AC2008
- using System;
- using System.IO;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using Autodesk..ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- namespace TlsCad
- {
- public class DBTransaction : IDisposable
- {
- private Database m_Database;
- private Transaction m_Transaction;
- private bool m_Commit = false;
- private BlockTableRecord m_BlockTableRecord;
- private BlockTable m_BlockTable;
- private TextStyleTable m_TextStyleTable;
- private LinetypeTable m_LinetypeTable;
- private RegAppTable m_RegAppTable;
- private LayerTable m_LayerTable;
- private UcsTable m_UcsTable;
- private ViewTable m_ViewTable;
- private ViewportTable m_ViewportTable;
- private DrawOrderTable m_DrawOrderTable;
- private DBDictionary m_GroupDictionary;
- //事务相关
- #region Tran
- //事务初始化,并只读方式打开块表
- private void Initialize()
- {
- try
- {
- m_Transaction = m_Database.TransactionManager.StartTransaction();
- m_BlockTable = (BlockTable)m_Transaction.GetObject(m_Database.BlockTableId, OpenMode.ForRead, false);
- }
- catch (Autodesk.AutoCAD.Runtime.Exception ex)
- {
- CadHelper.InfoMessageBox(ex.Message);
- }
- }
- //创建当前活动文档的事务(默认提交)
- public DBTransaction()
- {
- m_Database = HostApplicationServices.WorkingDatabase;
- Initialize();
- }
- //创建当前活动文档的事务
- //commit = true 提交事务
- //commit = false 不提交
- public DBTransaction(bool commit)
- {
- m_Commit = !commit;
- m_Database = HostApplicationServices.WorkingDatabase;
- Initialize();
- }
- //创建指定数据库的事务,一般用于临时数据库(默认提交)
- public DBTransaction(Database database)
- {
- m_Database = database;
- Initialize();
- }
- //创建指定数据库的事务
- //commit = true 提交事务
- //commit = false 不提交
- public DBTransaction(Database database, bool commit)
- {
- m_Commit = !commit;
- m_Database = database;
- Initialize();
- }
- //创建临时数据库的事务,并读入指定的文档(默认提交)
- public DBTransaction(string fileName)
- {
- try
- {
- m_Database = new Database(false, true);
- m_Database.ReadDwgFile(fileName, FileShare.Read, true, null);
- Initialize();
- }
- catch
- { }
- }
- //创建临时数据库的事务,并读入指定的文档
- //commit = true 提交事务
- //commit = false 不提交
- public DBTransaction(string DwgFileName, bool commit)
- {
- m_Commit = !commit;
- try
- {
- m_Database = new Database(false, true);
- m_Database.ReadDwgFile(DwgFileName, FileShare.Read, true, null);
- Initialize();
- }
- catch
- { }
- }
- //
- void IDisposable.Dispose()
- {
- Commit();
- m_Transaction.Dispose();
- }
- //按事务初始化参数决定事物是否提交
- public void Commit()
- {
- if (!m_Commit)
- {
- m_Transaction.Commit();
- m_Commit = true;
- }
- }
- //撤销事务
|