private void simpleButton1_Click(object sender, EventArgs e) { if (Validate(true) == false) { return; } object createLoc; IWorkspace2 workspace2 = null; IObjectDataset dataset = _database.Datasets.FirstOrDefault(c => c.Name == cmbTemplate.SelectedItem.ToString()); if (dataset == null) { return; } IGxDatabase pDataset = txtDB.Tag as IGxDatabase; IWorkspace workspace = ((IGxObject)pDataset).InternalObjectName.Open(); workspace2 = workspace as IWorkspace2; string namePre = txtPreName.Text.Trim(); string nameNext = txtNameNext.Text.Trim(); string aliasPre = txtAliasPre.Text.Trim(); string aliasNext = txtAliasNext.Text.Trim(); if (!chkNamePre.Checked) { namePre = ""; aliasPre = ""; } if (!chkNameNext.Checked) { nameNext = ""; aliasNext = ""; } string dsName = CombineName(dataset.BaseName, namePre, nameNext); if (workspace == null) { return; } if (workspace2.NameExists[esriDatasetType.esriDTFeatureDataset, dsName]) { MessageService.Current.Warn("该名称已经存在,请重新输入!"); return; } ISpatialReference pSpatialReference = _map.SpatialReference; IFeatureDataset pNewDataset = WorkspaceOperator.CreateFeatureDataSet(workspace, dsName, pSpatialReference) as IFeatureDataset; string dsAliasName = CombineName(dataset.AliasName, aliasPre, aliasNext); //(pNewDataset as IClassSchemaEdit).AlterAliasName(dsAliasName); foreach (int selectedItem in chkFeatureClasses.CheckedIndices) { IObjectTemplate template = _templates[selectedItem]; string fcName = CombineName(template.BaseName, namePre, nameNext); string fcAliasName = CombineName(template.AliasName, aliasPre, aliasNext); if (template.FeatureType == esriFeatureType.esriFTAnnotation) { WorkspaceOperator.CreateAnnoFeatureClass(fcName, pNewDataset, 1000); } else { IFieldsEdit pFieldsEdit = new FieldsClass() as IFieldsEdit; IField pField = FieldHelper.CreateOIDField(); if (pFieldsEdit.FindField(pField.Name) < 0) { pFieldsEdit.AddField(pField); } pField = FieldHelper.CreateGeometryField(template.GeometryType, _map.SpatialReference); if (pFieldsEdit.FindField(pField.Name) < 0) { pFieldsEdit.AddField(pField); } string keyName = ""; foreach (YTField ytField in template.Fields) { pField = ytField.CreateField(); if (pFieldsEdit.FindField(pField.Name) < 0) { pFieldsEdit.AddField(pField); } if (ytField.IsKey) { keyName = ytField.Name; } } IFeatureClass pClass = WorkspaceOperator.CreateFeatureClass(pNewDataset, fcName, pSpatialReference, template.FeatureType, template.GeometryType, (IFields)pFieldsEdit, null, null, ""); (pClass as IClassSchemaEdit).AlterAliasName(fcAliasName); if (pClass == null) { MessageService.Current.Info(fcName + "创建失败!"); continue; } } } MapHelper.AddDataset(_map as IBasicMap, pNewDataset, dsAliasName); MessageService.Current.Info("创建成功层!"); DialogResult = DialogResult.OK; }
public static string GetHistoryZDFeatureName(IFeatureClass ifeatureClass_0) { string result; if (ifeatureClass_0 == null) { result = ""; } else { ITable table = null; try { table = AppConfigInfo.OpenTable("ZDInfos"); } catch { } if (table == null) { try { ZDHistoryManage zDHistoryManage = new ZDHistoryManage(); zDHistoryManage.CreateTable(AppConfigInfo.GetWorkspace() as IFeatureWorkspace); table = AppConfigInfo.OpenTable("ZDInfos"); } catch (System.Exception) { } } if (table == null) { result = ""; } else { string workspaceConnectInfo = WorkspaceOperator.GetWorkspaceConnectInfo((ifeatureClass_0 as IDataset).Workspace); IQueryFilter queryFilter = new QueryFilter(); string[] array = (ifeatureClass_0 as IDataset).Name.Split(new char[] { '.' }); queryFilter.WhereClause = string.Format("FeatureClassName='{0}' and GDBConnectInfo='{1}'", array[array.Length - 1], workspaceConnectInfo); using (ComReleaser comReleaser = new ComReleaser()) { ICursor cursor = table.Search(queryFilter, false); comReleaser.ManageLifetime(cursor); IRow row = cursor.NextRow(); if (row != null) { int num = table.FindField("HistoryFeatureClass"); string text = ""; if (num != -1) { text = row.get_Value(num).ToString(); } result = text; return(result); } } result = ""; } } return(result); }
public static bool UnRegister(IFeatureClass ifeatureClass_0) { new ZDRegisterTable(); ITable table = AppConfigInfo.OpenTable("ZDInfos"); bool result; if (table == null) { result = false; } else { IQueryFilter queryFilter = new QueryFilter(); string[] array = (ifeatureClass_0 as IDataset).Name.Split(new char[] { '.' }); string workspaceConnectInfo = WorkspaceOperator.GetWorkspaceConnectInfo((ifeatureClass_0 as IDataset).Workspace); queryFilter.WhereClause = string.Format("FeatureClassName='{0}' and GDBConnectInfo='{1}'", array[array.Length - 1], workspaceConnectInfo); string arg = ""; string name = ""; using (ComReleaser comReleaser = new ComReleaser()) { ICursor cursor = table.Search(queryFilter, false); comReleaser.ManageLifetime(cursor); IRow row = cursor.NextRow(); if (row != null) { int num = table.FindField("HistoryFeatureClass"); if (num != -1) { name = row.get_Value(num).ToString(); } num = table.FindField("Guid"); if (num != -1) { arg = row.get_Value(num).ToString(); } row.Delete(); } } table = AppConfigInfo.OpenTable("ZDHistory"); queryFilter = new QueryFilter(); queryFilter.WhereClause = string.Format("ZDRegisterGuid='{0}'", arg); IWorkspaceEdit workspaceEdit = AppConfigInfo.GetWorkspace() as IWorkspaceEdit; bool flag = false; if (!workspaceEdit.IsBeingEdited()) { flag = true; workspaceEdit.StartEditing(true); } workspaceEdit.StartEditOperation(); table.DeleteSearchedRows(queryFilter); workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); if (!flag) { workspaceEdit.StartEditing(true); } try { IFeatureWorkspace featureWorkspace = (ifeatureClass_0 as IDataset).Workspace as IFeatureWorkspace; IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(name); (featureClass as IDataset).Delete(); } catch (System.Exception) { } result = true; } return(result); }
private void simpleButton1_Click(object sender, EventArgs e) { if (Validate(true) == false) { return; } string locType = label1.Tag != null?label1.Tag.ToString() : ""; if (string.IsNullOrEmpty(locType)) { return; } object createLoc; IWorkspace2 workspace2 = null; IObjectTemplate template = null; if (_isSingle) { template = _template; } else { template = _plugin.TemplateDatabase.Templates.FirstOrDefault(c => c.Name == cmbTemplate.SelectedItem.ToString()); } if (template == null) { return; } if (locType.Contains("Dataset")) { IGxDataset pDataset = txtDB.Tag as IGxDataset; IFeatureDataset fDataset = ((IGxObject)pDataset).InternalObjectName.Open(); workspace2 = fDataset.Workspace as IWorkspace2; createLoc = fDataset; } else { IGxDatabase pDatabase = txtDB.Tag as IGxDatabase; IFeatureWorkspace workspace = ((IGxObject)pDatabase).InternalObjectName.Open(); workspace2 = workspace as IWorkspace2; createLoc = workspace; } if (createLoc == null) { return; } string fcName = txtName.EditValue.ToString().Trim(); IWorkspace2 workSpace2 = createLoc is IFeatureDataset ? ((IFeatureDataset)createLoc).Workspace as IWorkspace2 : createLoc as IWorkspace2; if (workSpace2.NameExists[esriDatasetType.esriDTFeatureClass, fcName]) { MessageService.Current.Warn("该名称已经存在,请重新输入!"); return; } ISpatialReference pSpatialReference = _map.SpatialReference; IFieldsEdit pFieldsEdit = new Fields() as IFieldsEdit; IField pField = FieldHelper.CreateOIDField(); pFieldsEdit.AddField(pField); if (locType.Contains("Dataset")) { IGeoDataset pFDataset = createLoc as IGeoDataset; pField = FieldHelper.CreateGeometryField(template.GeometryType, pFDataset.SpatialReference); pSpatialReference = pFDataset.SpatialReference; pFieldsEdit.AddField(pField); } else { pField = FieldHelper.CreateGeometryField(template.GeometryType, _map.SpatialReference); pFieldsEdit.AddField(pField); } string keyName = ""; foreach (YTField ytField in template.Fields) { pField = ytField.CreateField(); pFieldsEdit.AddField(pField); if (ytField.IsKey) { keyName = ytField.Name; } } IFeatureClass pClass = WorkspaceOperator.CreateFeatureClass(createLoc, txtName.Text, pSpatialReference, template.FeatureType, template.GeometryType, (IFields)pFieldsEdit, null, null, ""); if (pClass == null) { MessageService.Current.Info("创建失败!"); return; } if (pClass != null && chkIndex.Checked == false) { MapHelper.AddFeatureLayer((IBasicMap)_map, pClass); MessageService.Current.Info("创建成功并已经加载图层!"); DialogResult = DialogResult.OK; return; } IEnvelope pEnv = new Envelope() as IEnvelope; pEnv.PutCoords(Convert.ToDouble(txtXMin.Text), Convert.ToDouble(txtYMin.Text), Convert.ToDouble(txtXMax.Text), Convert.ToDouble(txtYMax.Text)); IWorkspaceEdit pWksEdit = ((IDataset)pClass).Workspace as IWorkspaceEdit; pWksEdit.StartEditing(false); pWksEdit.StartEditOperation(); IndexHelper.CreateGridIndex(pClass, pEnv, Convert.ToDouble(txtWidth.Text), Convert.ToDouble(txtHeight.Text), keyName); pWksEdit.StopEditOperation(); pWksEdit.StopEditing(true); MapHelper.AddFeatureLayer((IBasicMap)_map, pClass); MessageService.Current.Info("创建成功并已经加载图层!"); DialogResult = DialogResult.OK; }