private void CreateField() { if (_editor.EditState != esriEditState.esriStateNotEditing) { MessageBox.Show("Stop Editing First", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (cbo_layers.SelectedIndex < 0) { MessageBox.Show("Select A Layer", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } CustomLayer customLayer = (CustomLayer)cbo_layers.SelectedItem; IFeatureClass FeatureClass = customLayer.FeatureClass(); IFields fields = FeatureClass.Fields; int fieldIndex = _utilitiesArcMap.FindField(FeatureClass, FIELD_NAME); if (fieldIndex > -1) { IField field = FeatureClass.Fields.Field[fieldIndex]; if (field.Type != esriFieldType.esriFieldTypeString) { if (MessageBox.Show("Field exists as wrong field type. It needs to be 'Text' Field. Should I delete and re-create?", MB_TITLE, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } FeatureClass.DeleteField(field); } else { if (field.Length < 20) { if (MessageBox.Show("Field exists as wrong size. It needs to be at least 20 in length. Should I delete and re-create?", MB_TITLE, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } FeatureClass.DeleteField(field); } else { return; } } } IFieldEdit2 newField = new FieldClass() as IFieldEdit2; newField.Name_2 = FIELD_NAME; newField.Type_2 = esriFieldType.esriFieldTypeString; newField.Length_2 = 20; newField.DefaultValue_2 = "Unchecked"; ISchemaLock schemaLock = (ISchemaLock)FeatureClass; try { schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock); FeatureClass.AddField(newField); } catch { MessageBox.Show("Cannot Aquire Exclusive Lock. Did Not Add Field", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock); } }
private void WriteToTable() { CustomLayer customLayer = (CustomLayer)cbo_layers.SelectedItem; IFeatureLayer featureLayer = customLayer.FeatureLayer(); IFeatureClass featureClass = customLayer.FeatureClass(); int fieldIndexName = featureClass.FindField(cbo_fieldname.Text); int fieldIndexStatus = featureClass.FindField(FIELD_NAME); ISchemaLock schemaLock = (ISchemaLock)featureClass; try { //schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock); if (rb_all.Checked) { _editor.StartOperation(); IFeatureCursor cursor = featureClass.Search(null, false); IFields fields = cursor.Fields; IFeature feature = cursor.NextFeature(); while (feature != null) { string value = Convert.ToString(feature.get_Value(fieldIndexName)); bool exists = _fileList[value]; feature.set_Value(fieldIndexStatus, exists ? "Exists" : "Missing"); feature.Store(); feature = cursor.NextFeature(); } SaveFileTypeList(GetExtension()); _editor.StopOperation("File Tile Exister Ran"); } if (rb_selected.Checked) { _editor.StartOperation(); IFeatureSelection selection = featureLayer as IFeatureSelection; IEnumIDs IDs = selection.SelectionSet.IDs; IDs.Reset(); int oid = IDs.Next(); while (oid != -1) { IFeature feature = featureClass.GetFeature(oid); if (feature != null) { bool exists = _fileList[Convert.ToString(feature.get_Value(fieldIndexName))]; feature.set_Value(fieldIndexStatus, exists ? "Exists" : "Missing"); feature.Store(); oid = IDs.Next(); } } SaveFileTypeList(GetExtension()); _editor.StopOperation("File Tile Exister Ran"); } } catch (Exception ex) { MessageBox.Show(String.Format("Could Not Get Exclusive Schmea Lock\n{0}", ex.Message)); } finally { //schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock); } }
private bool CheckRequirements() { if (cbo_layers.SelectedIndex < 0) { MessageBox.Show("Choose A Layer", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (cbo_fieldname.SelectedIndex < 0) { MessageBox.Show("Choose A Field Name", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (String.IsNullOrEmpty(cbo_extension.Text) || String.IsNullOrWhiteSpace(cbo_extension.Text)) { MessageBox.Show("Set An Extension", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (string.IsNullOrWhiteSpace(txb_folderpath.Text) || string.IsNullOrWhiteSpace(txb_folderpath.Text)) { MessageBox.Show("Set A Folder Path", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!Directory.Exists(txb_folderpath.Text)) { MessageBox.Show("Folder Path Does Not Exist", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!rb_all.Checked && !rb_selected.Checked) { MessageBox.Show("Choose A Method", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } CustomLayer customLayer = cbo_layers.SelectedItem as CustomLayer; if (customLayer == null) { MessageBox.Show("Error", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } IFeatureClass featureClass = customLayer.FeatureClass(); int fieldIndex = featureClass.FindField(FIELD_NAME); if (fieldIndex < 0) { MessageBox.Show("Please Create Field", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } IField field = featureClass.Fields.Field[fieldIndex]; if (field.Type != esriFieldType.esriFieldTypeString) { MessageBox.Show("Recreate Field, Wrong Type (text)", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (field.Length < 20) { MessageBox.Show("Recreate Field, Wrong Size (>= 20)", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (rb_selected.Checked) { IFeatureSelection selection = customLayer.FeatureLayer() as IFeatureSelection; if (selection.SelectionSet.Count == 0) { MessageBox.Show("Select At Least One Feature", MB_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } if (_editor.EditState != esriEditState.esriStateEditing) { MessageBox.Show("Start and Edit Operation"); return(false); } return(true); }