Ejemplo n.º 1
0
        //执行计算并刷新
        private void btnOK_Click(object sender, EventArgs e)
        {
            string strResult = FieldCal(pFeatureLayer, strField, textBoxCal.Text);

            MessageBox.Show(strResult);
            this.Close();
            RefreshTable refreshtable = new RefreshTable();

            refreshtable.Refresh(dgView, pFeatureLayer);
        }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string strFieldName = txtFieldName.Text;
            string strFieldType = cmbFieldType.Text;

            try
            {
                IFeatureLayer editAttributeLayer = _FeatureLayer;

                //Field collection
                IFieldsEdit pFieldsEdit;
                //获取FeatureLayer
                IFeatureLayer pFeatureLayer = editAttributeLayer;

                //从FeatureLayer获取工作空间
                IDataset   pDataSet   = pFeatureLayer.FeatureClass as IDataset;
                IWorkspace pWorkSpace = pDataSet.Workspace;
                //设置字段属性
                IField     pNewField  = new FieldClass();
                IFieldEdit pFieldEdit = pNewField as IFieldEdit;
                pFieldEdit.AliasName_2 = strFieldName;
                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)
                    {
                        pFeatureLayer.FeatureClass.AddField(pFieldEdit);
                        initField(pFeatureLayer.FeatureClass, strFieldName);
                        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();
            RefreshTable refresh = new RefreshTable();

            refresh.Refresh(_dgv, _FeatureLayer);
        }