Ejemplo n.º 1
0
        /// <summary>
        /// Creates vessel type coded domain.
        /// </summary>
        /// <param name="pWorkspace">FileGeodatabase workspace.</param>
        private void CreateTypeDomain(IWorkspace pWorkspace)
        {
            try
            {
                if (!(IsArcInfoLicense()))
                {
                    return;
                }

                IFeatureWorkspace pFWS   = (IFeatureWorkspace)pWorkspace;
                ITable            pTable = pFWS.OpenTable("Vessel");

                IWorkspaceDomains pWSD             = (IWorkspaceDomains)pWorkspace;
                ICodedValueDomain codedValueDomain = new CodedValueDomainClass();
                int i;

                //VESSEL TYPE DOMAIN
                // Value and name pairs.
                for (i = 0; i <= 9; i++)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }
                for (i = 10; i <= 19; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }
                for (i = 20; i <= 29; i++)
                {
                    codedValueDomain.AddCode(i, "WIG");
                }
                codedValueDomain.AddCode(30, "Fishing");
                codedValueDomain.AddCode(31, "Towing");
                codedValueDomain.AddCode(32, "Towing and length of the tow exceeds 200 m or breadth exceeds 25 m");
                codedValueDomain.AddCode(33, "Engaged in dredging or underwater operations");
                codedValueDomain.AddCode(34, "Engaged in diving operations");
                codedValueDomain.AddCode(35, "Engaged in military operations");
                codedValueDomain.AddCode(36, "Sailing");
                codedValueDomain.AddCode(37, "Pleasure craft");
                codedValueDomain.AddCode(38, "Reserved for future use");
                codedValueDomain.AddCode(39, "Reserved for future use");
                for (i = 40; i <= 49; i++)
                {
                    codedValueDomain.AddCode(i, "HSC");
                }
                codedValueDomain.AddCode(50, "Pilot vessel");
                codedValueDomain.AddCode(51, "Search and rescue vessels");
                codedValueDomain.AddCode(52, "Tugs");
                codedValueDomain.AddCode(53, "Port tenders");
                codedValueDomain.AddCode(54, "Vessels with anti-pollution facilities or equipment");
                codedValueDomain.AddCode(55, "Law enforcement vessels");
                codedValueDomain.AddCode(56, "Spare - for assignments to local vessels");
                codedValueDomain.AddCode(57, "Spare - for assignments to local vessels");
                codedValueDomain.AddCode(58, "Medical transports (as defined in the 1949 Geneva Conventions and Additional Protocols)");
                codedValueDomain.AddCode(59, "Ships according to RR Resolution No. 18 (Mob-83)");
                for (i = 60; i <= 69; i++)
                {
                    codedValueDomain.AddCode(i, "Passenger ships");
                }
                for (i = 70; i <= 79; i++)
                {
                    codedValueDomain.AddCode(i, "Cargo ships");
                }
                for (i = 80; i <= 89; i++)
                {
                    codedValueDomain.AddCode(i, "Tanker(s)");
                }
                for (i = 90; i <= 99; i++)
                {
                    codedValueDomain.AddCode(i, "Other types of ship");
                }
                for (i = 100; i <= 199; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved, for regional use");
                }
                for (i = 200; i <= 255; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved, for future use");
                }

                // The code to set the common properties for the new coded value domain.
                IDomain domain = (IDomain)codedValueDomain;
                domain.Name        = "VesselType";
                domain.FieldType   = esriFieldType.esriFieldTypeInteger;
                domain.SplitPolicy = esriSplitPolicyType.esriSPTDefaultValue;
                domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;

                // Add the new domain to the workspace.
                pWSD.AddDomain(domain);

                //assign the domain to the vessel table VesselType field
                IFields pFields     = pTable.Fields;
                int     iFieldIndex = pTable.FindField("VesselType");
                IField  pField      = pFields.get_Field(iFieldIndex);

                // Check that the field and domain have the same field type.
                if (pField.Type == domain.FieldType)
                {
                    // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                    ISchemaLock      schemaLock      = (ISchemaLock)pTable;
                    IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pTable;

                    // Attempt to get an exclusive schema lock.
                    try
                    {
                        // Lock the class and alter the domain.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        classSchemaEdit.AlterDomain("VesselType", domain);
                    }
                    catch (Exception exc)
                    {
                        // Handle the exception in a way appropriate for the application.
                        MessageBox.Show(exc.Message);
                    }
                    finally
                    {
                        // Set the schema lock to be a shared lock.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "AIS_DataModel:CodedDomain:CreateTypeDomain");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates Cargo type Voyage workspace.
        /// </summary>
        /// <param name="pWorkspace">FileGeodatabase workspace.</param>
        private void CreateCargoDomain(IWorkspace pWorkspace)
        {
            try
            {
                if (!(IsArcInfoLicense()))
                {
                    return;
                }

                IFeatureWorkspace pFWS   = (IFeatureWorkspace)pWorkspace;
                ITable            pTable = pFWS.OpenTable("Voyage");

                IWorkspaceDomains pWSD             = (IWorkspaceDomains)pWorkspace;
                ICodedValueDomain codedValueDomain = new CodedValueDomainClass();
                int i;

                //VESSEL CARGO DOMAIN
                // Value and name pairs.

                for (i = 0; i <= 9; i++)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }
                for (i = 10; i <= 19; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 20; i <= 90; i += 10)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }

                for (i = 21; i <= 81; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category A");
                }
                for (i = 22; i <= 82; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category B");
                }
                for (i = 23; i <= 83; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category C");
                }
                for (i = 24; i <= 84; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category D");
                }
                for (i = 29; i <= 89; i += 20)
                {
                    codedValueDomain.AddCode(i, "No additional information");
                }

                for (i = 25; i <= 28; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 31; i <= 39; i++)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }

                for (i = 45; i <= 48; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 51; i <= 59; i++)
                {
                    codedValueDomain.AddCode(i, "Not Available");
                }

                for (i = 65; i <= 68; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 71; i <= 91; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category A");
                }
                for (i = 72; i <= 92; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category B");
                }
                for (i = 73; i <= 93; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category C");
                }
                for (i = 74; i <= 94; i += 20)
                {
                    codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category D");
                }
                for (i = 79; i <= 99; i += 20)
                {
                    codedValueDomain.AddCode(i, "No additional information");
                }

                for (i = 75; i <= 78; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 85; i <= 88; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 95; i <= 98; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved for future use");
                }

                for (i = 100; i <= 199; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved, for regional use");
                }
                for (i = 200; i <= 255; i++)
                {
                    codedValueDomain.AddCode(i, "Reserved, for future use");
                }

                // The code to set the common properties for the new coded value domain.
                IDomain domain = (IDomain)codedValueDomain;
                domain.Name        = "Cargo";
                domain.FieldType   = esriFieldType.esriFieldTypeInteger;
                domain.SplitPolicy = esriSplitPolicyType.esriSPTDefaultValue;
                domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;

                // Add the new domain to the workspace.
                pWSD.AddDomain(domain);

                //assign the domain to the voyage table cargo field
                IFields pFields     = pTable.Fields;
                int     iFieldIndex = pTable.FindField("Cargo");
                IField  pField      = pFields.get_Field(iFieldIndex);

                // Check that the field and domain have the same field type.
                if (pField.Type == domain.FieldType)
                {
                    // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                    ISchemaLock      schemaLock      = (ISchemaLock)pTable;
                    IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pTable;

                    // Attempt to get an exclusive schema lock.
                    try
                    {
                        // Lock the class and alter the domain.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        classSchemaEdit.AlterDomain("Cargo", domain);
                    }
                    catch (Exception exc)
                    {
                        // Handle the exception in a way appropriate for the application.
                        MessageBox.Show(exc.Message);
                    }
                    finally
                    {
                        // Set the schema lock to be a shared lock.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "AIS_DataModel:CodedDomain:CreateCargoDomain");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates Broadcast feature class Status coded domain.
        /// </summary>
        /// <param name="pWorkspace">FileGeodatabase workspace.</param>
        private void CreateStatusDomain(IWorkspace pWorkspace)
        {
            try
            {
                if (!(IsArcInfoLicense()))
                {
                    return;
                }

                IFeatureWorkspace pFWS = (IFeatureWorkspace)pWorkspace;
                IFeatureClass     pFC  = pFWS.OpenFeatureClass("Broadcast");

                IWorkspaceDomains pWSD             = (IWorkspaceDomains)pWorkspace;
                ICodedValueDomain codedValueDomain = new CodedValueDomainClass();

                //VESSEL STATUS DOMAIN
                // Value and name pairs.
                codedValueDomain.AddCode(0, "Under way using engine");
                codedValueDomain.AddCode(1, "At anchor");
                codedValueDomain.AddCode(2, "Not under command");
                codedValueDomain.AddCode(3, "Restricted maneuverability");
                codedValueDomain.AddCode(4, "Constrained by her draught");
                codedValueDomain.AddCode(5, "Moored");
                codedValueDomain.AddCode(6, "Aground");
                codedValueDomain.AddCode(7, "Fishing");
                codedValueDomain.AddCode(8, "Under way sailing");
                codedValueDomain.AddCode(9, "Reserved for future amendment of navigational status for ships carrying DG, HS, or MP, or IMO hazard or pollutant category C, high speed craft (HSC)");
                codedValueDomain.AddCode(10, "Reserved for future amendment of navigational status for ships carrying dangerous goods (DG), harmful substances (HS) or marine pollutants (MP), or IMO hazard or pollutant category A, wing in grand (WIG)");
                codedValueDomain.AddCode(11, "Reserved for future use");
                codedValueDomain.AddCode(12, "Reserved for future use");
                codedValueDomain.AddCode(13, "Reserved for future use");
                codedValueDomain.AddCode(14, "AIS-START (active)");
                codedValueDomain.AddCode(15, "Not-Defined");


                // The code to set the common properties for the new coded value domain.
                IDomain domain = (IDomain)codedValueDomain;
                domain.Name        = "Status";
                domain.FieldType   = esriFieldType.esriFieldTypeInteger;
                domain.SplitPolicy = esriSplitPolicyType.esriSPTDefaultValue;
                domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;

                // Add the new domain to the workspace.
                pWSD.AddDomain(domain);

                //assign the domain to the broadcast feature class status field
                IFields pFields     = pFC.Fields;
                int     iFieldIndex = pFC.FindField("Status");
                IField  pField      = pFields.get_Field(iFieldIndex);

                // Check that the field and domain have the same field type.
                if (pField.Type == domain.FieldType)
                {
                    // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                    ISchemaLock      schemaLock      = (ISchemaLock)pFC;
                    IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pFC;

                    // Attempt to get an exclusive schema lock.
                    try
                    {
                        // Lock the class and alter the domain.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        classSchemaEdit.AlterDomain("Status", domain);
                    }
                    catch (Exception exc)
                    {
                        // Handle the exception in a way appropriate for the application.
                        MessageBox.Show(exc.Message);
                    }
                    finally
                    {
                        // Set the schema lock to be a shared lock.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "AIS_DataModel:CodedDomain:CreateStatusDomain");
            }
        }
Ejemplo n.º 4
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            if (txtBoxExcelPath.Text == "")
            {
                MessageBox.Show("请选择导入的外业调查表!");
                return;
            }
            string strExcelPath = this.txtBoxExcelPath.Text;

            ExcelHelper elh = new ExcelHelper(strExcelPath);

            Microsoft.Office.Interop.Excel.Worksheet sheet = elh.excelApp.Worksheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
            sheet.Columns.EntireColumn.AutoFit();   //自动调整列宽  added by chulili 2012-11-29


            IFeatureClass pFeatureClass = m_pCurFeaCls;
            IWorkspace    pws           = (pFeatureClass as IDataset).Workspace;

            string strKeyChineseName = cmbKeyField.Text;
            string strKeyFieldName   = "";
            int    indexKeyField     = -1;

            if (_DicFieds.ContainsKey(strKeyChineseName))
            {
                indexKeyField   = _DicFieds[strKeyChineseName];
                strKeyFieldName = m_pCurFeaCls.Fields.get_Field(indexKeyField).Name;
            }

            IField pKeyField = pFeatureClass.Fields.get_Field(indexKeyField);

            IWorkspaceDomains pWorkSpaceDomains = pws as IWorkspaceDomains;
            ICodedValueDomain pCodedDomain      = new CodedValueDomainClass();
            int iNullRowCnt = 0;
            int iNullCnt    = 0;

            for (int i = 2; i <= sheet.UsedRange.Rows.Count; i++)
            {
                Exception er = null;

                string sql = "";
                iNullCnt = 0;

                object objcode  = ((Microsoft.Office.Interop.Excel.Range)sheet.UsedRange.Cells[i, 1]).Text; //对应行的该列的值
                string strcode  = objcode.ToString();
                object objvalue = ((Microsoft.Office.Interop.Excel.Range)sheet.UsedRange.Cells[i, 2]).Text; //对应行的该列的值
                string strvalue = objvalue.ToString();
                if (strcode == "")
                {
                    iNullRowCnt++;
                    if (iNullRowCnt > 10)
                    {
                        break;
                    }
                }
                else
                {
                    iNullRowCnt = 0;
                }
                pCodedDomain.AddCode(strcode, strvalue);
            }
            //pCodedDomain.AddCode("111", "纯林");
            //pCodedDomain.AddCode("112", "混交林");
            IDomain pDomain = pCodedDomain as IDomain;

            pDomain.Name        = pKeyField.Name + "domain2";
            pDomain.FieldType   = pKeyField.Type;
            pDomain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate;
            pDomain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;


            pWorkSpaceDomains.AddDomain(pDomain);

            ISchemaLock      schemaLock      = (ISchemaLock)pFeatureClass;
            IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pFeatureClass;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                classSchemaEdit.AlterDomain(pKeyField.Name, pDomain);
            }
            catch (Exception exc)
            {
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }

            sheet = null;
            elh.Close();
        }
Ejemplo n.º 5
0
        public bool Apply()
        {
            int num;

            if (this.itable_0 != null)
            {
                Exception exception;
                try
                {
                    try
                    {
                        IField field;
                        for (num = 0; num < this.ifieldsEdit_1.FieldCount; num++)
                        {
                            IFields fields = this.itable_0.Fields;
                            field = this.ifieldsEdit_1.get_Field(num);
                            int index = this.itable_0.FindField(field.Name);
                            if (index != -1)
                            {
                                this.itable_0.DeleteField(fields.get_Field(index));
                            }
                        }
                        for (num = 0; num < this.ifieldsEdit_0.FieldCount; num++)
                        {
                            this.itable_0.AddField(this.ifieldsEdit_0.get_Field(num));
                        }
                        if (!ObjectClassShareData.m_IsShapeFile)
                        {
                            IClassSchemaEdit edit = this.itable_0 as IClassSchemaEdit;
                            num = 0;
                            while (num < this.ifields_0.FieldCount)
                            {
                                field = this.ifields_0.get_Field(num);
                                edit.AlterFieldAliasName(field.Name, field.AliasName);
                                if (((field.Name != "SHAPE.area") && !(field.Name == "SHAPE.len")) &&
                                    (((((field.Type == esriFieldType.esriFieldTypeDouble) ||
                                        (field.Type == esriFieldType.esriFieldTypeInteger)) ||
                                       ((field.Type == esriFieldType.esriFieldTypeSingle) ||
                                        (field.Type == esriFieldType.esriFieldTypeSmallInteger))) ||
                                      (field.Type == esriFieldType.esriFieldTypeDate)) ||
                                     (field.Type == esriFieldType.esriFieldTypeString)))
                                {
                                    edit.AlterDomain(field.Name, field.Domain);
                                }
                                num++;
                            }
                        }
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                        Logger.Current.Error("", exception, "");
                    }
                    this.ifieldsEdit_1.DeleteAllFields();
                    this.ifieldsEdit_0.DeleteAllFields();
                    this.ifields_0 = (this.itable_0.Fields as IClone).Clone() as IFields;
                    this.method_0(this.listView2, this.ifields_0);
                    this.listView2.LockRowCount = this.ifields_0.FieldCount;
                    goto Label_023C;
                }
                catch (Exception exception2)
                {
                    exception = exception2;
                    Logger.Current.Error("", exception, "");
                    MessageBox.Show(exception.Message);
                    return(false);
                }
            }
            if (this.ifields_0 != null)
            {
                for (num = 0; num < this.ifieldsEdit_0.FieldCount; num++)
                {
                    (this.ifields_0 as IFieldsEdit).AddField(this.ifieldsEdit_0.get_Field(num));
                }
            }
Label_023C:
            return(true);
        }
Ejemplo n.º 6
0
        protected override void OnClick()
        {
            m_pApp = (IApplication)ArcMap.Application;
            if (m_pApp == null)
            {
                //if the app is null then could be running from ArcCatalog
                m_pApp = (IApplication)ArcCatalog.Application;
            }

            if (m_pApp == null)
            {
                MessageBox.Show("Could not access the application.", "No Application found");
                return;
            }
            IGxApplication pGXApp = (IGxApplication)m_pApp;

            stdole.IUnknown pUnk = null;
            try
            {
                pUnk = (stdole.IUnknown)pGXApp.SelectedObject.InternalObjectName.Open();
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode == (int)fdoError.FDO_E_DATASET_TYPE_NOT_SUPPORTED_IN_RELEASE ||
                    ex.ErrorCode == -2147220944)
                {
                    MessageBox.Show("The dataset is not supported in this release.", "Could not open the dataset");
                }
                else
                {
                    MessageBox.Show(ex.ErrorCode.ToString(), "Could not open the dataset");
                }
                return;
            }

            if (pUnk is ICadastralFabric)
            {
                m_pCadaFab = (ICadastralFabric)pUnk;
            }
            else
            {
                MessageBox.Show("Please select a parcel fabric and try again.", "Not a parcel fabric");
                return;
            }


            Utils FabricUTILS = new Utils();

            ITable     pTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans);
            IDataset   pDS    = (IDataset)pTable;
            IWorkspace pWS    = pDS.Workspace;

            //Do a Start and Stop editing to make sure we're not running in an edit session
            if (!FabricUTILS.StartEditing(pWS, true))
            {//if start editing fails then bail
                if (pUnk != null)
                {
                    Marshal.ReleaseComObject(pUnk);
                }
                Cleanup(pTable, pWS);
                FabricUTILS = null;
                return;
            }
            FabricUTILS.StopEditing(pWS);

            bool bAddedField = false;

            if (FabricUTILS.GetFabricVersion((ICadastralFabric2)m_pCadaFab) < 2)
            {
                bAddedField = FabricUTILS.CadastralTableAddFieldV1(m_pCadaFab, esriCadastralFabricTable.esriCFTPlans, esriFieldType.esriFieldTypeInteger,
                                                                   "KeepOnMerge", "KeepOnMerge", 1);
            }
            else
            {
                bAddedField = FabricUTILS.CadastralTableAddField(m_pCadaFab, esriCadastralFabricTable.esriCFTPlans, esriFieldType.esriFieldTypeInteger,
                                                                 "KeepOnMerge", "KeepOnMerge", 1);
            }

            if (bAddedField)
            {
                MessageBox.Show("Plan-merge helper field 'KeepOnMerge' added.", "Add Field");
            }
            else
            {
                MessageBox.Show("Field 'KeepOnMerge' could not be added." + Environment.NewLine + "The field may already exist.",
                                "Add Field");
            }

            if (bAddedField)
            {
                //if the field was added succesfully, add the Yes/No domain
                IDomain pDom = new CodedValueDomainClass();
                try
                {
                    IWorkspaceDomains2 pWSDoms = (IWorkspaceDomains2)pWS;
                    pDom.FieldType   = esriFieldType.esriFieldTypeInteger;
                    pDom.Name        = "Flag for Keep on Plan Merge";
                    pDom.Description = "Flag for Keep on Plan Merge";
                    ICodedValueDomain pCVDom = (ICodedValueDomain)pDom;
                    //pCVDom.AddCode(0, "No");
                    pCVDom.AddCode(1, "Keep On Merge");
                    pWSDoms.AddDomain(pDom);
                }
                catch (COMException ex)
                {
                    MessageBox.Show(ex.ErrorCode.ToString());
                }

                //Get the field
                int iFld = pTable.FindField("KeepOnMerge");
                if (iFld >= 0)
                {
                    IField pFld = pTable.Fields.get_Field(iFld);
                    // Check that the field and domain have the same field type.
                    if (pFld.Type == pDom.FieldType)
                    {
                        // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                        ISchemaLock      schemaLock      = (ISchemaLock)pTable;
                        IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pTable;

                        // Attempt to get an exclusive schema lock.
                        try
                        {
                            // Lock the class and alter the domain.
                            schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                            classSchemaEdit.AlterDomain("KeepOnMerge", pDom);
                            Console.WriteLine("The domain was successfully assigned.");
                        }
                        catch (COMException exc)
                        {
                            // Handle the exception in a way appropriate for the application.
                            Console.WriteLine(exc.Message);
                        }
                        finally
                        {
                            // Set the schema lock to be a shared lock.
                            schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                        }
                    }
                }

                if (pDom != null)
                {
                    Marshal.ReleaseComObject(pDom);
                }
            }
            Cleanup(pTable, pWS);
            FabricUTILS = null;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds coded domain values to the Voyage Tracks feature class.
        /// </summary>
        /// <param name="sWorkspace"></param>
        /// <param name="sLayerName"></param>
        private void AddCodedDomain(string sWorkspace, string sLayerName)
        {
            try
            {
                IWorkspace    pWorkspace = clsStatic.OpenWorkspace(sWorkspace);
                IFeatureLayer pFL        = clsStatic.GetFeatureLayer(pWorkspace, sLayerName); // pFWS.OpenTable("Voyage");
                ITable        pTable     = (ITable)pFL.FeatureClass;

                IWorkspaceDomains pWSD             = (IWorkspaceDomains)pWorkspace;
                ICodedValueDomain codedValueDomain = new CodedValueDomainClass();
                IEnumDomain       pDomains         = pWSD.Domains;
                pDomains.Reset();
                IDomain pDomain = pDomains.Next();
                while (pDomain != null)
                {
                    if (pDomain.Name == "Cargo")
                    {
                        break;
                    }
                }
                if (pDomain == null)
                {
                    if (clsStatic.GetArcLicense())
                    {
                        //VESSEL CARGO DOMAIN
                        // Value and name pairs.
                        for (int i = 0; i <= 9; i++)
                        {
                            codedValueDomain.AddCode(i, "Not Available");
                        }
                        for (int i = 10; i <= 19; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 20; i <= 90; i += 10)
                        {
                            codedValueDomain.AddCode(i, "Not Available");
                        }

                        for (int i = 21; i <= 81; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category A");
                        }
                        for (int i = 22; i <= 82; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category B");
                        }
                        for (int i = 23; i <= 83; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category C");
                        }
                        for (int i = 24; i <= 84; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category D");
                        }
                        for (int i = 29; i <= 89; i += 20)
                        {
                            codedValueDomain.AddCode(i, "No additional information");
                        }

                        for (int i = 25; i <= 28; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 31; i <= 39; i++)
                        {
                            codedValueDomain.AddCode(i, "Not Available");
                        }

                        for (int i = 45; i <= 48; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 51; i <= 59; i++)
                        {
                            codedValueDomain.AddCode(i, "Not Available");
                        }

                        for (int i = 65; i <= 68; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 71; i <= 91; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category A");
                        }
                        for (int i = 72; i <= 92; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category B");
                        }
                        for (int i = 73; i <= 93; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category C");
                        }
                        for (int i = 74; i <= 94; i += 20)
                        {
                            codedValueDomain.AddCode(i, "Carrying DG, HS, or MP, IMO hazard or pollutant category D");
                        }
                        for (int i = 79; i <= 99; i += 20)
                        {
                            codedValueDomain.AddCode(i, "No additional information");
                        }

                        for (int i = 75; i <= 78; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 85; i <= 88; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 95; i <= 98; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved for future use");
                        }

                        for (int i = 100; i <= 199; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved, for regional use");
                        }
                        for (int i = 200; i <= 255; i++)
                        {
                            codedValueDomain.AddCode(i, "Reserved, for future use");
                        }

                        // The code to set the common properties for the new coded value domain.
                        pDomain             = (IDomain)codedValueDomain;
                        pDomain.Name        = "Cargo";
                        pDomain.FieldType   = esriFieldType.esriFieldTypeInteger;
                        pDomain.SplitPolicy = esriSplitPolicyType.esriSPTDefaultValue;
                        pDomain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;
                        // Add the new domain to the workspace.
                        pWSD.AddDomain(pDomain);
                    }
                }
                //assign the domain to the voyage table cargo field
                IFields pFields     = pTable.Fields;
                int     iFieldIndex = pTable.FindField("Cargo");
                IField  pField      = pFields.get_Field(iFieldIndex);

                // Check that the field and domain have the same field type.
                if (pField.Type == pDomain.FieldType)
                {
                    // Cast the feature class to the ISchemaLock and IClassSchemaEdit interfaces.
                    ISchemaLock      schemaLock      = (ISchemaLock)pTable;
                    IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)pTable;

                    // Attempt to get an exclusive schema lock.
                    try
                    {
                        // Lock the class and alter the domain.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        classSchemaEdit.AlterDomain("Cargo", pDomain);
                    }
                    catch (Exception ex)
                    {
                        // Handle the exception in a way appropriate for the application.
                        clsStatic.ShowErrorMessage(ex.ToString());
                    }
                    finally
                    {
                        // Set the schema lock to be a shared lock.
                        schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                }
            }
            catch (Exception ex)
            {
                clsStatic.ShowErrorMessage(ex.ToString());
            }
        }
Ejemplo n.º 8
0
        public bool Apply()
        {
            int num;

            if (!(!this.bool_2 || this.bool_3))
            {
                return(true);
            }
            this.bool_3 = false;
            if (NewObjectClassHelper.m_pObjectClassHelper.ObjectClass != null)
            {
                COMException exception;
                Exception    exception2;
                this.itable_0 = NewObjectClassHelper.m_pObjectClassHelper.ObjectClass as ITable;
                string name = (this.itable_0 as IDataset).Name;
                try
                {
                    IField       field;
                    CodeDomainEx ex;
                    try
                    {
                        for (num = 0; num < this.ifieldsEdit_1.FieldCount; num++)
                        {
                            IFields fields = this.itable_0.Fields;
                            field = this.ifieldsEdit_1.get_Field(num);
                            int index = this.itable_0.FindField(field.Name);
                            if (index != -1)
                            {
                                this.itable_0.DeleteField(fields.get_Field(index));
                                if ((NewObjectClassHelper.m_pObjectClassHelper != null) &&
                                    NewObjectClassHelper.m_pObjectClassHelper.FieldDomains.ContainsKey(field))
                                {
                                    ex = NewObjectClassHelper.m_pObjectClassHelper.FieldDomains[field];
                                    if (ex != null)
                                    {
                                        CodeDomainManage.DeleteCodeDoaminMap(name, field.Name);
                                    }
                                }
                            }
                        }
                    }
                    catch (COMException exception1)
                    {
                        exception = exception1;
                        Logger.Current.Error("", exception, "");
                        MessageBox.Show(exception.Message);
                        return(false);
                    }
                    catch (Exception exception3)
                    {
                        exception2 = exception3;
                        Logger.Current.Error("", exception2, "");
                    }
                    try
                    {
                        for (num = 0; num < this.ifieldsEdit_0.FieldCount; num++)
                        {
                            IField key = this.ifieldsEdit_0.get_Field(num);
                            this.itable_0.AddField(this.ifieldsEdit_0.get_Field(num));
                            if ((NewObjectClassHelper.m_pObjectClassHelper != null) &&
                                NewObjectClassHelper.m_pObjectClassHelper.FieldDomains.ContainsKey(key))
                            {
                                ex = NewObjectClassHelper.m_pObjectClassHelper.FieldDomains[key];
                                if (ex != null)
                                {
                                    CodeDomainManage.AddFieldCodeDoaminMap(name, key.Name, ex.DomainID);
                                }
                            }
                        }
                    }
                    catch (COMException exception4)
                    {
                        exception = exception4;
                        if (exception.ErrorCode == -2147220969)
                        {
                            MessageBox.Show("不是对象的所有者,无法修改对象!");
                        }
                        else if (exception.ErrorCode == -2147219887)
                        {
                            MessageBox.Show("无法添加字段!");
                        }
                        else
                        {
                            Logger.Current.Error("", exception, "");
                            MessageBox.Show(exception.Message);
                        }
                    }
                    catch (Exception exception5)
                    {
                        exception2 = exception5;
                        Logger.Current.Error("", exception2, "");
                    }
                    if (!ObjectClassShareData.m_IsShapeFile)
                    {
                        IClassSchemaEdit edit = this.itable_0 as IClassSchemaEdit;
                        num = 0;
                        while (num < this.ilist_0.Count)
                        {
                            field = this.ilist_0[num];
                            try
                            {
                                if (((FieldChangeType)this.ilist_1[num]) == FieldChangeType.FCTAlias)
                                {
                                    edit.AlterFieldAliasName(field.Name, field.AliasName);
                                }
                                else if (((FieldChangeType)this.ilist_1[num]) == FieldChangeType.FCTDomain)
                                {
                                    edit.AlterDomain(field.Name, field.Domain);
                                    if ((NewObjectClassHelper.m_pObjectClassHelper != null) &&
                                        NewObjectClassHelper.m_pObjectClassHelper.FieldDomains.ContainsKey(field))
                                    {
                                        ex = NewObjectClassHelper.m_pObjectClassHelper.FieldDomains[field];
                                        if (ex != null)
                                        {
                                            CodeDomainManage.AddFieldCodeDoaminMap(name, field.Name, ex.DomainID);
                                        }
                                        else
                                        {
                                            CodeDomainManage.DeleteCodeDoaminMap(name, field.Name);
                                        }
                                    }
                                }
                            }
                            catch (COMException exception6)
                            {
                                exception = exception6;
                                (field as IFieldEdit).AliasName_2 = field.Name;
                                if (exception.ErrorCode == -2147220969)
                                {
                                    MessageBox.Show("不是对象的所有者,无法修改字段[" + field.Name + "]!");
                                }
                                else if (exception.ErrorCode == -2147219887)
                                {
                                    MessageBox.Show("无法修改字段[" + field.Name + "]!");
                                }
                                else
                                {
                                    Logger.Current.Error("", exception, "");
                                    MessageBox.Show(exception.Message);
                                }
                                return(false);
                            }
                            catch (Exception exception7)
                            {
                                exception2 = exception7;
                                Logger.Current.Error("", exception2, "");
                            }
                            num++;
                        }
                    }
                    if (!ObjectClassShareData.m_IsShapeFile)
                    {
                        (this.itable_0 as ISchemaLock).ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                    this.ifieldsEdit_1.DeleteAllFields();
                    this.ifieldsEdit_0.DeleteAllFields();
                    this.ilist_0.Clear();
                    this.ilist_1.Clear();
                    this.ifields_0 = (this.itable_0.Fields as IClone).Clone() as IFields;
                    this.method_2(this.listView2, this.ifields_0);
                    this.listView2.LockRowCount = this.ifields_0.FieldCount;
                    goto Label_0512;
                }
                catch (COMException exception8)
                {
                    exception = exception8;
                    if (exception.ErrorCode == -2147220969)
                    {
                        MessageBox.Show("不是对象的所有者,无法修改对象!");
                    }
                    else
                    {
                        Logger.Current.Error("", exception, "");
                        MessageBox.Show(exception.Message);
                    }
                    return(false);
                }
                catch (Exception exception9)
                {
                    exception2 = exception9;
                    Logger.Current.Error("", exception2, "");
                    MessageBox.Show(exception2.Message);
                    return(false);
                }
            }
            if (this.ifields_0 != null)
            {
                for (num = 0; num < this.ifieldsEdit_0.FieldCount; num++)
                {
                    (this.ifields_0 as IFieldsEdit).AddField(this.ifieldsEdit_0.get_Field(num));
                }
            }
Label_0512:
            return(true);
        }