Esempio n. 1
0
 //复制工作空间坐标空间域
 private void CreateWorkspaceDomains(IWorkspace pWs1, IWorkspace pWs2)
 {
     try
     {
         WaitForm.SetCaption("正在复制工作空间域,请稍后...");
         IWorkspaceDomains pWsD1       = pWs1 as IWorkspaceDomains;
         IWorkspaceDomains pWsD2       = pWs2 as IWorkspaceDomains;
         IEnumDomain       pEnumDomain = pWsD1.Domains;
         IDomain           pDomain1    = null;
         IDomain           pDomain2    = null;
         if (pEnumDomain == null)
         {
             return;
         }
         while ((pDomain1 = pEnumDomain.Next()) != null)
         {
             if (pDomain1.Type == esriDomainType.esriDTCodedValue)//编码域
             {
                 ICodedValueDomain tempDomain1 = pDomain1 as ICodedValueDomain;
                 ICodedValueDomain tempDomain2 = new CodedValueDomainClass();
                 for (int i = 0; i < tempDomain1.CodeCount; i++)
                 {
                     tempDomain2.AddCode(tempDomain1.get_Value(i), tempDomain1.get_Name(i));
                 }
                 pDomain2             = tempDomain2 as IDomain;
                 pDomain2.Description = pDomain1.Description;
                 pDomain2.FieldType   = pDomain1.FieldType;
                 pDomain2.DomainID    = pDomain1.DomainID;
                 pDomain2.MergePolicy = pDomain1.MergePolicy;
                 pDomain2.Name        = pDomain1.Name;
                 pDomain2.Owner       = pDomain1.Owner;
                 pDomain2.SplitPolicy = pDomain1.SplitPolicy;
                 pWsD2.AddDomain(pDomain2);
             }
             else//范围域
             {
                 IRangeDomain tempDomain1 = pDomain1 as IRangeDomain;
                 IRangeDomain tempDomain2 = new RangeDomainClass();
                 tempDomain2.MaxValue = tempDomain1.MaxValue;
                 tempDomain2.MinValue = tempDomain1.MinValue;
                 pDomain2             = tempDomain2 as IDomain;
                 pWsD2.AddDomain(pDomain2);
             }
         }
     }
     catch (System.Exception ex)
     {
         return;
     }
 }
Esempio n. 2
0
 public void Apply(IWorkspaceDomains iworkspaceDomains_0)
 {
     try
     {
         if (this.bool_1)
         {
             if (!this.bool_0)
             {
                 iworkspaceDomains_0.DeleteDomain(this.string_0);
             }
         }
         else if (this.bool_0)
         {
             iworkspaceDomains_0.AddDomain(this.idomain_1);
         }
         else if (this.bool_2)
         {
             if (this.idomain_0 != null)
             {
                 iworkspaceDomains_0.DeleteDomain(this.idomain_0.Name);
                 (iworkspaceDomains_0 as IWorkspaceDomains2).AddDomain(this.idomain_1);
             }
             else
             {
                 (iworkspaceDomains_0 as IWorkspaceDomains2).AlterDomain(this.idomain_1);
             }
         }
     }
     catch (COMException exception)
     {
         if (exception.ErrorCode == -2147220969)
         {
             MessageBox.Show("非数据库所有者,无法修改域值!");
         }
         else
         {
             Logger.Current.Error("", exception, "");
         }
     }
     catch (Exception exception2)
     {
         Logger.Current.Error("", exception2, "");
     }
     this.bool_0 = false;
     this.bool_1 = false;
     this.bool_2 = false;
 }
Esempio n. 3
0
        public static IDomain AddDomain(IWorkspace workspace, IDomain domain)
        {
            if (domain == null)
            {
                return(null);
            }
            IWorkspaceDomains pWorkspaceDomains = workspace as IWorkspaceDomains;

            if (pWorkspaceDomains == null)
            {
                return(null);
            }
            IDomain pDomain = pWorkspaceDomains.DomainByName[domain.Name];

            if (pDomain != null)
            {
                return(pDomain);
            }
            if (domain.Type == esriDomainType.esriDTCodedValue)
            {
                ICodedValueDomain pCodedValueDomain       = new CodedValueDomainClass();
                ICodedValueDomain pOriginCodedValueDomain = domain as ICodedValueDomain;
                for (int i = 0; i < pOriginCodedValueDomain.CodeCount; i++)
                {
                    pCodedValueDomain.AddCode(pOriginCodedValueDomain.Value[i], pOriginCodedValueDomain.Name[i]);
                }
                pDomain = pCodedValueDomain as IDomain;
            }
            else
            {
                IRangeDomain pRangeDomain       = new RangeDomainClass();
                IRangeDomain pOriginRangeDomain = domain as IRangeDomain;
                pRangeDomain.MinValue = pOriginRangeDomain.MinValue;
                pRangeDomain.MaxValue = pOriginRangeDomain.MaxValue;
                pDomain = pRangeDomain as IDomain;
            }
            pDomain.Name        = domain.Name;
            pDomain.FieldType   = domain.FieldType;
            pDomain.Description = domain.Description;
            pDomain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate;
            pDomain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;
            pWorkspaceDomains.AddDomain(pDomain);
            return(pDomain);
        }
Esempio n. 4
0
        /// <summary>
        /// 创建属性域
        /// </summary>
        /// <param name="workspace">工作空间</param>
        /// <param name="strDomainName">属性域名称</param>
        /// <param name="dicDomainItems">属性域的项</param>
        public static void CreateDomain(this IWorkspace workspace, string strDomainName, Dictionary <string, string> dicDomainItems)
        {
            IWorkspaceDomains wsDomains       = (IWorkspaceDomains)workspace;
            ICodedValueDomain codeValueDomain = new CodedValueDomainClass();

            foreach (KeyValuePair <string, string> domainItem in dicDomainItems)
            {
                codeValueDomain.AddCode(domainItem.Key, domainItem.Value);
            }

            IDomain domain = (IDomain)codeValueDomain;

            domain.Name        = strDomainName;
            domain.FieldType   = esriFieldType.esriFieldTypeString;
            domain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate;
            domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;

            wsDomains.AddDomain(domain);
        }
Esempio n. 5
0
        private static IDomain GetOrCreateDomain(IWorkspace ws)
        {
            IWorkspaceDomains wsd    = ws as IWorkspaceDomains;
            IDomain           domain = wsd.get_DomainByName(DOMAIN_NAME);

            if (domain == null)
            {
                ICodedValueDomain2 cvd = new CodedValueDomain() as ICodedValueDomain2;
                cvd.AddCode(1, "New Feature");
                cvd.AddCode(2, "Modified Feature");
                cvd.AddCode(3, "Modified Feature (After)");
                cvd.AddCode(6, "Modified Feature (Before)");
                cvd.AddCode(4, "Deleted Feature");
                domain             = cvd as IDomain;
                domain.FieldType   = esriFieldType.esriFieldTypeInteger;
                domain.Name        = DOMAIN_NAME;
                domain.SplitPolicy = esriSplitPolicyType.esriSPTDuplicate;
                domain.MergePolicy = esriMergePolicyType.esriMPTDefaultValue;
                int i = wsd.AddDomain(domain);
            }
            return(domain);
        }
Esempio n. 6
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");
            }
        }
Esempio n. 7
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");
            }
        }
Esempio n. 8
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");
            }
        }
Esempio n. 9
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();
        }
Esempio n. 10
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());
            }
        }