ArcFM Engine Developer Guide
DistMainNamer.cs

Resource Center Home

Display Name Objects Developer Sample (C#)

DistMainNamer.cs

 

Copy Code
//-----------------------------------------------------------------------------------
//Telvent, Inc.
//Copyright 2010
//-----------------------------------------------------------------------------------
//Module Name: DistMainNamer
//Description:
//
//Written: 9/20/2010 by Daniel Rouleau
//
//Last Revision:
//
//-----------------------------------------------------------------------------------
using System.Runtime.InteropServices;
using System;
using Miner.Interop;
using Miner.ComCategories;
using Esri.ArcGIS.Geodatabase;
namespace Miner.Samples
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("74DCC5D5-6903-4040-8132-6962B1FC816D")]
    [ComponentCategory(ComCategory.MMDisplayNameObjects)]
    public class DistMainNamer : IMMDisplayNamer
    {
        //Member constants
        private const string _operatingPressureFieldName = "OperatingPressure";
        private const string _diameterFieldName = "NominalDiameter";
        private const string _materialFieldName = "Material";
        private static readonly Resourcer Resourcer = new Resourcer();
        #region IMMDisplayNamer Implementation
        public string DisplayString(IRow pRow)
        {
            IFields fields = pRow.Fields;
            //Get OperatingPressure, Diameter, Material field indices
            int operatingPressureIndex = fields.FindField(_operatingPressureFieldName);
            int diameterIndex = fields.FindField(_diameterFieldName);
            int materialIndex = fields.FindField(_materialFieldName);
            //Assemble individual display strings
            
            //Store OperatingPressure field value
            string operatingPressure = String.Empty;
            if (operatingPressureIndex >= 0)
            {
                double? operatingPressureValue = pRow.get_Value(operatingPressureIndex) as double?;
                operatingPressure = operatingPressureValue == null ? Resourcer.GetString("CustomDisplayNamers.NullValue") : Convert.ToString(operatingPressureValue);
            }
           
            //Store NominalDiameter field value
            string diameter = String.Empty;
            if (diameterIndex >= 0)
            {
                object diameterValue = pRow.get_Value(diameterIndex);
                if (diameterValue == null)
                {
                    diameter = Resourcer.GetString("CustomDisplayNamers.NullValue");
                }
                
                else
                {
                    string diameterCode = Convert.ToString(diameterValue);
                    //Get appropriate Diameter code description from subtype domain
                    //or default domain
                    ICodedValueDomain pCVDomain = CustomNamerUtils.GetCVDomain(pRow, diameterIndex);
                    if (pCVDomain != null)
                    {
                        diameter = CustomNamerUtils.GetCVDescFromCode(pCVDomain, diameterCode);
                    }
                    else
                    {
                        diameter = "Diameter Code: " + diameterCode;
                    }
                }
            }
            //store Material field value
            string material = String.Empty;
            if(materialIndex >= 0)
            {
                object materialValue = pRow.get_Value(materialIndex);
                if (materialValue == null)
                {
                    material = Resourcer.GetString("CustomDisplayNamers.NullValue");
                }
                else
                {
                    int materialSubtypeCode = Convert.ToInt32(materialValue);
                    //Get appropriate Material code description from subtype
                    IObject pObj = pRow as IObject;
                    if (pObj != null)
                    {
                        IObjectClass objectClass = pObj.Class;
                        ISubtypes subtypes = objectClass as ISubtypes;
                        if (subtypes != null)
                        {
                            material = subtypes.get_SubtypeName(materialSubtypeCode);
                            
                            //Get first two character of Material subtype description
                            material = material.Substring(0, 2).ToUpper(); 
                        }
                    }   
                }
            }
            string displayString = operatingPressure + " - " + diameter + " - " + material;
            //Return display string
            return displayString;
        }
        public bool get_Enabled(IDataset pDataset)
        {
            bool result = false;
            //Enable only on "DistributionMain" model name
            IObjectClass objectClass = pDataset as IObjectClass;
            if (objectClass != null)
            {
                if (CustomNamerUtils.GetModelNameMgr.ContainsClassModelName(objectClass, "DistributionMain"))
                {
                    result = true;
                }
            }
            return result;
        }
        public string Name
        {
            get { return "Minerville Distribution Main Display Namer"; }
        }
        #endregion IMMDisplayNamer Implementation
    }
}

 

 

 


Send Comment to ArcFMdocumentation@schneider-electric.com