ArcFM Engine Developer Guide
XFRNamer.cs

Resource Center Home

Display Name Objects Developer Sample (C#)

XFRNamer.cs

 


Copy Code
//-----------------------------------------------------------------------------------
//Schneider Electric
//Copyright 2010
//-----------------------------------------------------------------------------------
//Module Name: XFRNamer
//Description:
//
//Written: 9/20/2010 by Daniel Rouleau
//
//Last Revision:
//
//-----------------------------------------------------------------------------------
using System.Runtime.InteropServices;
using Miner.Interop;
using Miner.ComCategories;
using Esri.ArcGIS.Geodatabase;
namespace Miner.Samples
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("AA356F9F-0B2A-452b-B024-4FCCD1C740C3")]
    [ComponentCategory(ComCategory.MMDisplayNameObjects)]
    public class XFRNamer : IMMDisplayNamer
    {
        //Member constants
        private const string _facilityIdFieldName = "FacilityID";
        private const string _ratedKvaFieldName = "RatedKVA";
        private const string _phaseDesignationFieldName = "PhaseDesignation";
        private static readonly Resourcer Resourcer = new Resourcer();
        #region IMMDisplayNamer Implementation
        public string DisplayString(IRow pRow)
        {
            IFields fields = pRow.Fields;
            //Assemble individual display strings
            //Store FacilityID value
            int facilityIDIndex = fields.FindField(_facilityIdFieldName);
            string facilityID = pRow.get_Value(facilityIDIndex) as string ?? ("(" + pRow.OID + ")");
            //Store RatedKVA field value
           
            int ratedKVAIndex = fields.FindField(_ratedKvaFieldName);
            string ratedKVA;
            double? fieldValue = pRow.get_Value(ratedKVAIndex) as double?;
            if (fieldValue == null)
            {
                ratedKVA = Resourcer.GetString("CustomDisplayNamers.NullValue");
            }
            else
            {
                ratedKVA = fieldValue + " KVA";
            }
            //Store PhaseDesignation field value
            int phaseDesigIndex = fields.FindField(_phaseDesignationFieldName);
            string phaseDesignation;
            int? phaseValue = pRow.get_Value(phaseDesigIndex) as int?;
            if (phaseValue == null)
            {
                phaseDesignation = Resourcer.GetString("CustomDisplayNamers.NullValue");
            }
            else
            {
                //Get appropriate PhaseDesignation code description from subtype domain
                //or default domain
                ICodedValueDomain codedValueDomain = CustomNamerUtils.GetCVDomain(pRow, phaseDesigIndex);
                if (codedValueDomain != null)
                {
                    phaseDesignation = CustomNamerUtils.GetCVDescFromCode(codedValueDomain, phaseValue.ToString());
                }
                else
                {
                    phaseDesignation = "Phase Code: " + phaseValue;
                }
            }
            string displayString = facilityID + " - " + ratedKVA + " - " + phaseDesignation;
            //Return display string
            return displayString;
        }
        public bool get_Enabled(IDataset pDataset)
        {
            bool result = false;
            //Enable only on "Transformer" model name
            IObjectClass objectClass = pDataset as IObjectClass;
            if (objectClass != null)
            {
                if (CustomNamerUtils.GetModelNameMgr.ContainsClassModelName(objectClass, "Transformer"))
                {
                    result = true;
                }
            }
            return result;
        }
        public string Name
        {
            get
            {
                return "Minerville Transformer Display Namer";
            }
        }
        #endregion IMMDisplayNamer Implementation
    }
}

 

 


Send Comment to ArcFMdocumentation@schneider-electric.com