private bool UpdateFacClassReg(FacClassReg reg) { IFdeCursor cursor = null; IRowBuffer row = null; try { IFeatureDataSet fds = this._dsPipe.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(false); } IObjectClass oc = fds.OpenObjectClass("OC_FacilityClass"); if (oc == null) { return(false); } IQueryFilter filter = new QueryFilter() { WhereClause = string.Format("FacClassCode = '{0}'", reg.FacClassCode), SubFields = "oid,LocationType,TurnerStyle,FacilityType,Comment" }; cursor = oc.Update(filter); row = cursor.NextRow(); if (row != null) { row.SetValue(1, reg.LocationType.ToString()); row.SetValue(2, reg.TurnerStyle.ToString()); row.SetValue(3, reg.FacilityType.Name); row.SetValue(4, reg.Comment); cursor.UpdateRow(row); return(true); } else { return(false); } } 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; } } }
public override void Run(object sender, System.EventArgs e) { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } try { Map3DCommandManager.Push(this); RenderControlEditServices.Instance().StopGeometryEdit(true); app.Current3DMapControl.PauseRendering(false); System.Collections.Generic.IList <System.Collections.Generic.KeyValuePair <int, string> > list = new System.Collections.Generic.List <System.Collections.Generic.KeyValuePair <int, string> >(); HashMap featureClassInfoMap = SelectCollection.Instance().FeatureClassInfoMap; DF3DFeatureClass featureClassInfo = null; System.Collections.Generic.IList <int> list2 = new System.Collections.Generic.List <int>(); System.Collections.IEnumerator enumerator = featureClassInfoMap.Keys.GetEnumerator(); try { if (enumerator.MoveNext()) { DF3DFeatureClass featureClassInfo2 = (DF3DFeatureClass)enumerator.Current; featureClassInfo = featureClassInfo2; ResultSetInfo resultSetInfo = featureClassInfoMap[featureClassInfo2] as ResultSetInfo; foreach (DataRow dataRow in resultSetInfo.ResultSetTable.Rows) { int num = int.Parse(dataRow[featureClassInfo.GetFeatureClass().FidFieldName].ToString()); string value = num.ToString(); System.Collections.Generic.KeyValuePair <int, string> item = new System.Collections.Generic.KeyValuePair <int, string>(num, value); list.Add(item); list2.Add(num); } } } finally { System.IDisposable disposable = enumerator as System.IDisposable; if (disposable != null) { disposable.Dispose(); } } if (featureClassInfo != null) { using (MergeDlg mergeDlg = new MergeDlg(list)) { if (mergeDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (System.Windows.Forms.DialogResult.No != XtraMessageBox.Show("模型合并不支持撤销操作,是否继续?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation)) { int fid = mergeDlg.Fid; using (new WaitDialogForm("", "正在进行模型合并,请稍后...")) { IFeatureClass featureClass = featureClassInfo.GetFeatureClass(); string geometryFieldName = featureClassInfo.GetFeatureLayer().GeometryFieldName; IModelPoint model = this.GetModel(featureClass, geometryFieldName, fid); IResourceManager resourceManager = CommonUtils.Instance().GetCurrentFeatureDataset() as IResourceManager; if (resourceManager != null) { if (!this.MergeModels(featureClass, geometryFieldName, list2.ToArray <int>(), resourceManager, ref model)) { XtraMessageBox.Show("模型合并失败!"); } else { if (list2.Remove(fid)) { featureClass.Delete(new QueryFilterClass { IdsFilter = list2.ToArray <int>() }); CommonUtils.Instance().Delete(featureClassInfo, list2.ToArray <int>()); app.Current3DMapControl.FeatureManager.DeleteFeatures(featureClass, list2.ToArray <int>()); } app.Current3DMapControl.RefreshModel(CommonUtils.Instance().GetCurrentFeatureDataset(), model.ModelName); IFdeCursor fdeCursor = featureClass.Update(new QueryFilterClass { IdsFilter = new int[] { fid } }); IRowBuffer rowBuffer = fdeCursor.NextRow(); if (rowBuffer != null) { int num2 = rowBuffer.FieldIndex(geometryFieldName); if (num2 != -1) { rowBuffer.SetValue(num2, model); } fdeCursor.UpdateRow(rowBuffer); System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); app.Current3DMapControl.FeatureManager.EditFeature(featureClass, rowBuffer); } //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); } } } } } } } } catch (System.Runtime.InteropServices.COMException ex) { XtraMessageBox.Show(ex.Message); } catch (System.UnauthorizedAccessException var_23_389) { XtraMessageBox.Show("拒绝访问"); } catch (System.Exception ex2) { XtraMessageBox.Show(ex2.Message); } finally { app.Current3DMapControl.ResumeRendering(); } }
private bool UpdateFacStyleClass(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); } IQueryFilter filter = new QueryFilter() { WhereClause = string.Format("ObjectId = '{0}'", style.ObjectId) }; cursor = oc.Update(filter); row = cursor.NextRow(); if (row != null) { 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.UpdateRow(row); return(true); } else { return(false); } } 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 UpdateColor() { 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); } IQueryFilter filter = new QueryFilter() { WhereClause = string.Format("ObjectId = '{0}'", this._color.ObjectId) }; cursor = oc.Update(filter); row = cursor.NextRow(); if (row != null) { row.SetValue(row.FieldIndex("Name"), this._color.Name); row.SetValue(row.FieldIndex("GroupId"), this._color.Group); row.SetValue(row.FieldIndex("Code"), this._color.Code); row.SetValue(row.FieldIndex("Type"), this._color.Type); row.SetValue(row.FieldIndex("Comment"), this._color.Comment); if (this._color.Thumbnail != null) { try { IBinaryBuffer newVal = new BinaryBufferClass(); MemoryStream stream = new MemoryStream(); this._color.Thumbnail.Save(stream, ImageFormat.Png); newVal.FromByteArray(stream.ToArray()); row.SetValue(2, newVal); } catch (Exception ex) { } } cursor.UpdateRow(row); return(true); } else { return(false); } } 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; } } }
static void Main(string[] args) { //创建要素类要先定义属性字段 IFieldInfoCollection fields = new FieldInfoCollection(); { //名称列 IFieldInfo field = new FieldInfo(); field.Name = "Name"; field.FieldType = gviFieldType.gviFieldString; field.Length = 255; fields.Add(field); //空间列 field = new FieldInfo(); field.Name = "Geometry"; field.FieldType = gviFieldType.gviFieldGeometry; //列类型为空间类型 field.GeometryDef = new GeometryDef(); //需要实例化一个几何定义对象,里面有大量与空间有关的内容,比如: field.GeometryDef.HasZ = true; //是否在Z值,默认为false,只能存XY field.GeometryDef.GeometryColumnType = gviGeometryColumnType.gviGeometryColumnPoint; //空间列的几何类型 field.RegisteredRenderIndex = true; //注册渲染索引,允许在renderControl中显示 fields.Add(field); //多空间列 field = new FieldInfo(); field.Name = "Model"; field.FieldType = gviFieldType.gviFieldGeometry; //列类型为空间类型 field.GeometryDef = new GeometryDef(); //需要实例化一个几何定义对象,里面有大量与空间有关的内容,比如: field.GeometryDef.HasZ = true; //是否在Z值,默认为false,只能存XY field.GeometryDef.GeometryColumnType = gviGeometryColumnType.gviGeometryColumnModelPoint; //空间列的几何类型 field.RegisteredRenderIndex = true; //注册渲染索引,允许在renderControl中显示 fields.Add(field); //... 其它列 } //创建要素类 IFeatureClass FC = FDS.CreateFeatureClass("FC", fields); int nameID = FC.GetFields().IndexOf("Name"); //获取对应列的索引, int geomID = FC.GetFields().IndexOf("Geometry"); int fidIndex = FC.GetFields().IndexOf(FC.FidFieldName); //增加单条数据,并同步到FeatureLayer IFdeCursor fcu = FC.Insert(); //通过FC创建一个插入游标,用来操作rowBuffer IRowBuffer rb = FC.CreateRowBuffer(); //通过FC创建一条空要素实例,用来设置数据,设置完成后将其塞入FC IPoint p = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); // 将要塞入空间列的几何对象,类型要对应 FC的field.GeometryDef.GeometryColumnType ,否则塞不进 rb.SetValue(nameID, "testPointA"); //塞名称 rb.SetValue(geomID, p); //塞几何 fcu.InsertRow(rb); //塞进FC int fid = fcu.LastInsertId; //成功后反回这条buffer的主键ID rb.SetValue(fidIndex, fid); //Cursor(FC)增加数据后会产生一个对应的FID,要把这个FID赋值给row才能在FLayer中显示 ax.FeatureManager.CreateFeature(FC, rb); //同步到renderControl //增加很大量数据时,参考以下方法 IFdeCursor cu = FC.Insert(); IRowBufferCollection rows = new RowBufferCollection(); for (int i = 0; i < 100000; i++) { IRowBuffer row = FC.CreateRowBuffer(); // do something ... row.SetValue(geomID, p); cu.InsertRow(row); row.SetValue(fidIndex, cu.LastInsertId); rows.Add(row); } ax.FeatureManager.CreateFeatures(FC, rows); //或直接整体更新 ax.FeatureManager.RefreshFeatureClass(FC); //查 string tagStr = "tagName"; IQueryFilter qf = new QueryFilter(); //过滤器 qf.WhereClause = $"Name = '{tagStr}'"; IFdeCursor res = FC.Search(qf, true); //条件查 IRowBuffer aBuffer = res.NextRow(); //遍历查询结果 //改 IFdeCursor upCu = FC.Update(qf); IRowBuffer upBuffer = upCu.NextRow(); upCu.UpdateRow(upBuffer); //删 FC.Delete(qf); FC.DeleteRow(0); FC.Truncate(); //保留表结构,清空表 }
private void btn_ok_Click(object sender, EventArgs e) { try { if (this._dt.Rows.Count == 0) { return; } if (!this.ceConnectMajorClass.Checked && !this.ceConnectFacility.Checked) { return; } WaitForm.Start("三维数据关联设置启动...", "请稍后", new Size(400, 50)); CheckRowGroup(); WaitForm.SetCaption("设施类关联设置进行中..."); // 设置设施类 HashSet <FacilityClass> listFac = _checkFacCList; if (listFac != null && this.ceConnectFacility.Checked) { foreach (FacilityClass fac in listFac) { string strTemp = ""; foreach (DataRow dr in this._dt.Rows) { if (!(bool)dr["CheckState"]) { continue; } IFeatureClass featureClass = dr["FeatureClass"] as IFeatureClass; if (featureClass == null) { continue; } FacilityClass fcc = dr["FacilityClass"] as FacilityClass; if (fcc == fac) { strTemp += featureClass.GuidString + ";"; } } if (this._facDoc != null) { XmlNode node = this._facDoc.SelectSingleNode(".//FacilityClass[@name=\"" + fac.Name + "\"]"); if (node != null) { if (node.Attributes["fc3D"] == null) { XmlAttribute attr = this._facDoc.CreateAttribute("fc3D"); node.Attributes.Append(attr); } node.Attributes["fc3D"].Value = strTemp; } this._facDoc.Save(this._xmlFacFilePath); } } } //设施大类所属 WaitForm.SetCaption("所属大类关联设置进行中..."); HashSet <MajorClass> listMC = _checkMCList; if (listMC != null && this.ceConnectMajorClass.Checked) { foreach (MajorClass mc in listMC) { string strTemp = ""; List <IFeatureClass> listFc = new List <IFeatureClass>(); foreach (DataRow dr in this._dt.Rows) { if (!(bool)dr["CheckState"]) { continue; } IFeatureClass featureClass = dr["FeatureClass"] as IFeatureClass; if (featureClass == null) { continue; } MajorClass mcc = dr["MajorClass"] as MajorClass; if (mcc == mc) { strTemp += featureClass.GuidString + ";"; listFc.Add(featureClass); } } if (this._logicDoc != null) { XmlNode node = this._logicDoc.SelectSingleNode(".//MajorClass[@name=\"" + mc.Name + "\"]"); if (node != null) { if (node.Attributes["fc3D"] == null) { XmlAttribute attr = this._logicDoc.CreateAttribute("fc3D"); node.Attributes.Append(attr); } node.Attributes["fc3D"].Value = strTemp; } for (int i = node.ChildNodes.Count - 1; i >= 0; i--) { XmlNode childNode = node.ChildNodes[i]; node.RemoveChild(childNode); } //foreach (XmlNode childNode in node.ChildNodes) //{ // node.RemoveChild(childNode); //} // 二级分组 WaitForm.SetCaption("小类分组中..."); IQueryFilter filter = null; IFdeCursor cursor = null; IRowBuffer row = null; HashSet <string> hsValues = new HashSet <string>(); try { foreach (IFeatureClass fc in listFc) { WaitForm.SetCaption("要素类【" + (string.IsNullOrEmpty(fc.AliasName) ? fc.Name : fc.AliasName) + "】分组中..."); if (fc.GetFields().IndexOf(mc.ClassifyField) == -1) { continue; } if (fc.GetFields().IndexOf("GroupId") == -1) { continue; } filter = new QueryFilter(); filter.SubFields = mc.ClassifyField; cursor = fc.Search(filter, true); while ((row = cursor.NextRow()) != null) { if (!row.IsNull(0)) { hsValues.Add(row.GetValue(0).ToString()); } } if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } fc.SubTypeFieldName = ""; fc.SubTypeFieldName = "GroupId"; } // 重设groupid WaitForm.SetCaption("启动重置GroupId..."); foreach (IFeatureClass fc in listFc) { string strfcname = (string.IsNullOrEmpty(fc.AliasName) ? fc.Name : fc.AliasName); WaitForm.SetCaption("要素类【" + strfcname + "】重置GroupId中..."); if (fc.GetFields().IndexOf(mc.ClassifyField) == -1) { continue; } if (fc.GetFields().IndexOf("GroupId") == -1) { continue; } filter = new QueryFilter(); filter.SubFields = "GroupId,oid"; int groupid = -1; foreach (string str in hsValues) { groupid++; filter.WhereClause = mc.ClassifyField + " = '" + str + "'"; int fccount = fc.GetCount(filter); if (fccount == 0) { continue; } int counttemp = 0; cursor = fc.Update(filter); while ((row = cursor.NextRow()) != null) { row.SetValue(0, groupid); cursor.UpdateRow(row); counttemp++; WaitForm.SetCaption("要素类【" + strfcname + "】子类【" + str + "】(" + counttemp + "/" + fccount + ")重置GroupId中..."); } if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } } } catch (Exception ex) { throw ex; } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } if (filter != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(filter); row = null; } } WaitForm.SetCaption("分组信息写入配置文件中..."); int index = -1; foreach (string str in hsValues) { index++; XmlElement ele = this._logicDoc.CreateElement("SubClass"); ele.SetAttribute("name", str); ele.SetAttribute("groupid", index.ToString()); node.AppendChild(ele); foreach (IFeatureClass fc in listFc) { if (fc.GetFields().IndexOf(mc.ClassifyField) == -1) { continue; } if (fc.GetFields().IndexOf("GroupId") == -1) { continue; } SubTypeInfo sti = new SubTypeInfo(); sti.Code = index; sti.Name = str; fc.AddSubType(sti); } } //XmlElement ele1 = this._logicDoc.CreateElement("SubClass"); //ele1.SetAttribute("name", "其他"); //ele1.SetAttribute("groupid", index.ToString()); //node.AppendChild(ele1); this._logicDoc.Save(this._xmlLogicFilePath); } } } WaitForm.Stop(); XtraMessageBox.Show("设置成功!", "提示"); } catch (Exception ex) { WaitForm.Stop(); XtraMessageBox.Show("设置失败!", "提示"); } }
private void UpdateAttribute(object param) { IFeatureClass featureClass = null; try { EditParameters editParameters = (EditParameters)param; if (editParameters != null) { DF3DFeatureClass featureClassInfo = DF3DFeatureClassManager.Instance.GetFeatureClassByID(editParameters.featureClassGuid); IDataSource dataSource = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSourceByString(editParameters.connectionInfo); IFeatureDataSet featureDataSet = dataSource.OpenFeatureDataset(editParameters.datasetName); featureClass = featureDataSet.OpenFeatureClass(editParameters.fcName); int nTotalCount = editParameters.nTotalCount; int num = 0; if (featureClass.HasTemporal() && CommonUtils.Instance().EnableTemproalEdit) { ITemporalManager temporalManager = featureClass.TemporalManager; ITemporalCursor temporalCursor = temporalManager.Search(new TemporalFilterClass { IdsFilter = editParameters.fidList }); while (temporalCursor.MoveNext()) { this._manualResult.WaitOne(); num++; string userState = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount); int percentProgress = num * 100 / nTotalCount; this._bgWorker.ReportProgress(percentProgress, userState); bool flag = false; int currentId = temporalCursor.CurrentId; IRowBuffer row = featureClass.GetRow(currentId); base.UpdateRowBuffer(ref row, editParameters.colName, editParameters.regexDataList); ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false); TemporalInstance temporalInstance; while ((temporalInstance = temporalInstances.NextInstance()) != null) { if (temporalInstance.StartDatetime == editParameters.TemproalTime) { flag = true; temporalInstances.Update(row); break; } } System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances); if (!flag) { temporalCursor.Insert(editParameters.TemproalTime, row); } } System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager); } else { featureClass.FeatureDataSet.DataSource.StartEditing(); IFdeCursor fdeCursor = featureClass.Update(new QueryFilterClass { IdsFilter = editParameters.fidList }); IRowBuffer rowBuffer = null; System.Collections.Generic.Dictionary <int, string> dictionary = new System.Collections.Generic.Dictionary <int, string>(); while ((rowBuffer = fdeCursor.NextRow()) != null && !this._bgWorker.CancellationPending) { int position = rowBuffer.FieldIndex(featureClass.FidFieldName); int key = int.Parse(rowBuffer.GetValue(position).ToString()); string value = base.UpdateRowBuffer(ref rowBuffer, editParameters.colName, editParameters.regexDataList); fdeCursor.UpdateRow(rowBuffer); num++; dictionary[key] = value; string userState2 = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount); int percentProgress2 = num * 100 / nTotalCount; this._bgWorker.ReportProgress(percentProgress2, userState2); } System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); featureClass.FeatureDataSet.DataSource.StopEditing(true); object[] args = new object[] { featureClassInfo, editParameters.colName, dictionary }; //System.IAsyncResult asyncResult = MainFrmService.ResultSetPanel.BeginInvoke(this._updateSelection, args); //MainFrmService.ResultSetPanel.EndInvoke(asyncResult); } //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet); System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource); } } catch (System.Exception) { if (featureClass != null) { featureClass.FeatureDataSet.DataSource.StopEditing(true); } } }