Ejemplo n.º 1
0
 //删除选中的要素
 private void button4_Click(object sender, EventArgs e)
 {
     row_index = dataGridView1.CurrentRow.Index;
     if (((MessageBox.Show("确定要删除吗", "警告", MessageBoxButtons.YesNo)) == DialogResult.Yes))
     {
         ILayer        pLayer        = currentLayer;
         IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
         ITable        pTable        = pFeatureLayer as ITable;
         IRow          pRow          = pTable.GetRow(row_index);
         pRow.Delete();
         TableShow();
         MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK);
         _MapControl.ActiveView.Refresh();
         RefreshTable refresh = new RefreshTable();
         refresh.Refresh(dataGridView1, pFeatureLayer);
     }
 }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string strFieldName      = txtFieldName.Text;
            string strFieldNameAlias = txtFieldAliasName.Text;
            string strFieldType      = cmbFieldType.Text;

            try
            {
                IFeatureLayer editAttributeLayer = _FeatureLayer;
                //获取FeatureLayer
                IFeatureLayer pFeatureLayer = editAttributeLayer;

                //从FeatureLayer获取工作空间
                IDataset   pDataSet   = pFeatureLayer.FeatureClass as IDataset;
                IWorkspace pWorkSpace = pDataSet.Workspace;
                //设置字段属性
                IField     pNewField  = new FieldClass();
                IClass     pClass     = pFeatureLayer as IClass;
                IFieldEdit pFieldEdit = pNewField as IFieldEdit;
                pFieldEdit.AliasName_2 = strFieldNameAlias;
                pFieldEdit.Name_2      = strFieldName;
                switch (strFieldType)
                {
                case "长整型":
                {
                    pFieldEdit.Type_2      = esriFieldType.esriFieldTypeInteger;
                    pFieldEdit.Precision_2 = int.Parse(txtPrecision.Text);
                    break;
                }

                case "短整型":
                {
                    pFieldEdit.Type_2      = esriFieldType.esriFieldTypeSmallInteger;
                    pFieldEdit.Precision_2 = int.Parse(txtPrecision.Text);
                    break;
                }

                case "浮点型":
                {
                    pFieldEdit.Type_2      = esriFieldType.esriFieldTypeSingle;
                    pFieldEdit.Precision_2 = int.Parse(txtPrecision.Text);
                    pFieldEdit.Scale_2     = int.Parse(txtScale.Text);
                    break;
                }

                case "双精度":
                {
                    pFieldEdit.Type_2      = esriFieldType.esriFieldTypeDouble;
                    pFieldEdit.Precision_2 = int.Parse(txtPrecision.Text);
                    pFieldEdit.Scale_2     = int.Parse(txtScale.Text);
                    break;
                }

                case "文本型":
                {
                    pFieldEdit.Type_2   = esriFieldType.esriFieldTypeString;
                    pFieldEdit.Length_2 = int.Parse(txtPrecision.Text);
                    break;
                }

                default:    //日期型0
                {
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate;
                    break;
                }
                }
                //添加字段
                try
                {
                    int theField = pFeatureLayer.FeatureClass.Fields.FindField(strFieldName);
                    if (theField == -1)
                    {
                        pClass.AddField(pFieldEdit);
                        //pFeatureLayer.FeatureClass.AddField(pFieldEdit);
                        MessageBox.Show("字段添加成功!");
                    }
                    else
                    {
                        MessageBox.Show("字段已经存在!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Field " + pFieldEdit.Name + " was not added due to an error (" + ex.Message + " )");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.Close();
            _dgv.Update();
            RefreshTable refresh = new RefreshTable();

            refresh.Refresh(_dgv, _FeatureLayer);
        }