public void Dispose() { if (dbo != null && !dbo.IsDisposed) { dbo.Dispose(); } }
// the same as Editor.ActiveViewportId if ApplicationServices are available private void zoom_extents_handler(object sender, EventArgs e) { using (DBObject pVpObj = Aux.active_viewport_id(database).GetObject(OpenMode.ForWrite)) { // using protocol extensions we handle PS and MS viewports in the same manner AbstractViewportData pAVD = new AbstractViewportData(pVpObj); Teigha.GraphicsSystem.View pView = pAVD.GsView; // do actual zooming - change GS view zoom_extents(pView, pVpObj); // save changes to database pAVD.SetView(pView); pAVD.Dispose(); pVpObj.Dispose(); Invalidate(); } }
public static System.Data.DataTable GetAllPolylineNums() { System.Data.DataTable table = new System.Data.DataTable("编码"); table.Columns.Add(new System.Data.DataColumn(("多段线id"), typeof(string))); table.Columns.Add(new System.Data.DataColumn(("个体编码"), typeof(string))); table.Columns.Add(new System.Data.DataColumn(("个体要素"), typeof(string))); table.Columns.Add(new System.Data.DataColumn(("个体名称"), typeof(string))); table.Columns.Add(new System.Data.DataColumn(("数量"), typeof(string))); table.Columns.Add(new System.Data.DataColumn(("个体阶段"), typeof(string))); System.Data.DataColumn column; System.Data.DataRow row; Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; DocumentLock m_DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument(); try { using (Transaction tr = db.TransactionManager.StartTransaction()) { foreach (ObjectId layerId in LayersToList(db)) { LayerTableRecord layer = tr.GetObject(layerId, OpenMode.ForRead) as LayerTableRecord; TypedValue[] filList = new TypedValue[1] { new TypedValue((int)DxfCode.LayerName, layer.Name) }; SelectionFilter sfilter = new SelectionFilter(filList); PromptSelectionResult result = ed.SelectAll(sfilter); if (result.Status == PromptStatus.OK) { SelectionSet acSSet = result.Value; foreach (ObjectId id in acSSet.GetObjectIds()) { DBObject obj = id.GetObject(OpenMode.ForRead); //以读的方式打开对象 ObjectId dictId = obj.ExtensionDictionary; //获取对象的扩展字典的id Entity ent1 = tr.GetObject(id, OpenMode.ForRead) as Entity; if (ent1 is Polyline && !dictId.IsNull) { DBDictionary dict = dictId.GetObject(OpenMode.ForRead) as DBDictionary;//获取对象的扩展字典 if (!dict.Contains("polylineNumber")) { continue;//如果扩展字典中没有包含指定关键 字的扩展记录,则返回null; } //先要获取对象的扩展字典或图形中的有名对象字典,然后才能在字典中获取要查询的扩展记录 ObjectId xrecordId = dict.GetAt("polylineNumber"); //获取扩展记录对象的id Xrecord xrecord = xrecordId.GetObject(OpenMode.ForRead) as Xrecord; //根据id获取扩展记录对象 ResultBuffer resBuf = xrecord.Data; ResultBufferEnumerator rator = resBuf.GetEnumerator(); int i = 0; List <string> values = new List <string>(); while (rator.MoveNext()) { TypedValue re = rator.Current; values.Add((string)re.Value); } bool hasData = false; foreach (System.Data.DataRow item in table.Rows) { if ((string)item["个体编码"] == values[0] && (string)item["个体要素"] == values[1] && (string)item["个体名称"] == values[2] && (string)item["个体阶段"] == values[3]) { item["多段线id"] += id.Handle.Value.ToString() + ","; int count = 0; int.TryParse((string)item["数量"], out count); item["数量"] = count + 1; hasData = true; break; } } if (!hasData) { row = table.NewRow(); row["多段线id"] = id.Handle.Value.ToString() + ","; row["数量"] = 1; while (rator.MoveNext()) { TypedValue re = rator.Current; if (i == 0) { row["个体编码"] = re.Value; } if (i == 1) { row["个体要素"] = re.Value; } if (i == 2) { row["个体名称"] = re.Value; } if (i == 3) { row["个体阶段"] = re.Value; } i++; } table.Rows.Add(row); } resBuf.Dispose(); xrecord.Dispose(); dict.Dispose(); } ent1.Dispose(); obj.Dispose(); } } layer.Dispose(); } tr.Commit(); } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); } finally { m_DocumentLock.Dispose(); } return(table); }