public void InsertFeatures(IObjectClass oc, IRowBufferCollection rows) { if (oc == null || rows == null || rows.Count == 0) { return; } IFdeCursor cursor = null; try { oc.FeatureDataSet.DataSource.StartEditing(); cursor = oc.Insert(); for (int i = 0; i < rows.Count; ++i) { IRowBuffer row = rows.Get(i); cursor.InsertRow(row); int oid = cursor.LastInsertId; row.SetValue(0, oid); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (cursor != null) { //Marshal.ReleaseComObject(cursor); oc.FeatureDataSet.DataSource.StopEditing(true); } //Marshal.ReleaseComObject(cursor); } }
private bool InsertFacStyleClass(FacStyleClass style) { IFdeCursor cursor = null; IRowBuffer row = null; try { IFeatureDataSet fds = this._ds.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(false); } IObjectClass oc = fds.OpenObjectClass("OC_FacilityStyle"); if (oc == null) { return(false); } row = oc.CreateRowBuffer(); cursor = oc.Insert(); row.SetValue(row.FieldIndex("Name"), style.Name); row.SetValue(row.FieldIndex("FacClassCode"), style.FacClassCode); row.SetValue(row.FieldIndex("ObjectId"), style.ObjectId); row.SetValue(row.FieldIndex("StyleType"), style.Type.ToString()); row.SetValue(row.FieldIndex("StyleInfo"), style.ObjectToJson()); if (style.Thumbnail != null) { try { IBinaryBuffer bb = new BinaryBufferClass(); MemoryStream stream = new MemoryStream(); style.Thumbnail.Save(stream, ImageFormat.Png); bb.FromByteArray(stream.ToArray()); row.SetValue(row.FieldIndex("Thumbnail"), bb); } catch (Exception exception) { } } cursor.InsertRow(row); style.Id = cursor.LastInsertId; return(true); } catch (Exception ex) { return(false); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
private bool CreateFacClassReg(FacClass fc) { if (fc == null || fc.FacilityType == null) { return(false); } IFdeCursor cursor = null; IRowBuffer row = null; try { IFeatureDataSet fds = this._dsPipe.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(false); } IFeatureDataSet fdsActuality = this._dsPipe.OpenFeatureDataset("DataSet_GEO_Actuality"); if (fdsActuality == null) { return(false); } IObjectClass oc = fds.OpenObjectClass("OC_FacilityClass"); if (oc == null) { return(false); } row = oc.CreateRowBuffer(); cursor = oc.Insert(); if (row != null) { row.SetValue(row.FieldIndex("FacClassCode"), fc.Code); row.SetValue(row.FieldIndex("Name"), fc.Name); row.SetValue(row.FieldIndex("FacilityType"), fc.FacilityType.Name); row.SetValue(row.FieldIndex("LocationType"), fc.LocationType.ToString()); row.SetValue(row.FieldIndex("TurnerStyle"), fc.TurnerStyle.ToString()); row.SetValue(row.FieldIndex("Comment"), fc.Comment); string fcName = string.Format("FC_{0}_{1}", (int)DataLifeCyle.Actuality, fc.Code); List <CMFieldConfig> fieldConfig = GetFieldsConfig(fc.Code); IFieldInfoCollection fielInfoCol = CreateFieldInfoCollection(fieldConfig, fc.FacilityType.Name); IFeatureClass featureClass = fdsActuality.CreateFeatureClass(fcName, fielInfoCol); if (featureClass == null) { return(false); } featureClass.AliasName = fc.Name; featureClass.LockType = gviLockType.gviLockExclusiveSchema; IGridIndexInfo indexInfo = new GridIndexInfoClass { L1 = 500.0, L2 = 2000.0, L3 = 10000.0, GeoColumnName = "Geometry" }; featureClass.AddSpatialIndex(indexInfo); indexInfo.GeoColumnName = "Shape"; featureClass.AddSpatialIndex(indexInfo); indexInfo.GeoColumnName = "FootPrint"; featureClass.AddSpatialIndex(indexInfo); IRenderIndexInfo info2 = new RenderIndexInfoClass { L1 = 500.0, GeoColumnName = "Geometry" }; featureClass.AddRenderIndex(info2); info2.GeoColumnName = "Shape"; featureClass.AddRenderIndex(info2); info2.GeoColumnName = "FootPrint"; featureClass.AddRenderIndex(info2); featureClass.LockType = gviLockType.gviLockSharedSchema; row.SetValue(row.FieldIndex("FeatureClassId"), featureClass.Guid.ToString()); row.SetValue(row.FieldIndex("DataSetName"), "DataSet_GEO_Actuality"); row.SetValue(row.FieldIndex("FcName"), featureClass.Name); row.SetValue(row.FieldIndex("DataType"), DataLifeCyle.Actuality.ToString()); cursor.InsertRow(row); return(true); } else { return(false); } } catch (Exception ex) { WaitForm.SetCaption("创建管线库中的设施要素类【" + fc.Name + "】失败!"); return(false); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
private bool InsertColor() { IFdeCursor cursor = null; IRowBuffer row = null; try { IFeatureDataSet fds = this._ds.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(false); } IObjectClass oc = fds.OpenObjectClass("OC_ColorInfo"); if (oc == null) { return(false); } row = oc.CreateRowBuffer(); cursor = oc.Insert(); row.SetValue(row.FieldIndex("Name"), this._color.Name); row.SetValue(row.FieldIndex("ObjectId"), this._color.ObjectId); row.SetValue(row.FieldIndex("GroupId"), this._color.Group); row.SetValue(row.FieldIndex("Code"), this._color.Code); row.SetValue(row.FieldIndex("Type"), this._color.Type); if (this._color.Thumbnail != null) { try { IBinaryBuffer bb = new BinaryBufferClass(); MemoryStream stream = new MemoryStream(); this._color.Thumbnail.Save(stream, ImageFormat.Png); bb.FromByteArray(stream.ToArray()); row.SetValue(row.FieldIndex("Thumbnail"), bb); } catch (Exception exception) { } } row.SetValue(row.FieldIndex("Comment"), this._color.Comment); cursor.InsertRow(row); this._color.Id = cursor.LastInsertId; return(true); } catch (Exception ex) { return(false); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }