ArcFM Engine Developer Guide
ClassicDesigner.cs

Resource Center Home

Display Name Objects Developer Sample (C#)

ClassicDesigner.cs

 

Copy Code
//-----------------------------------------------------------------------------------
//Telvent, Inc.
//Copyright 2010
//-----------------------------------------------------------------------------------
//Module Name: ClassicDesigner
//Description: This Custom Namer Object replicates the pre 832 Designer Names,
//             IF the Design, WorkLocation or WorkRequest are stored in the DB.
//             Clients will now be able to customize their own to replace this
//             one if they wish.
//
//Written: 09/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("A2F4E660-0059-44e1-926D-E9EC272FD575")]
    [ComponentCategory(ComCategory.MMDisplayNameObjects)]
    public class ClassicDesigner : IMMDisplayNamer
    {
        //Class Model Names
        private const string _designClassModelName = "DESIGN";
        private const string _workLocationClassModelName = "WORKLOCATION";
        private const string _workRequestClassModelName = "WORKREQUEST";
        //Field Model Names
        private const string _descriptionFieldModelName = "DESCRIPTION";
        private const string _designIdFieldModelName = "DESIGNID";
        private const string _workLocationIdFieldModelName = "WORKLOCATIONID";
        private const string _workRequestIdFieldModelName = "WORKREQUESTID";
        private static readonly Resourcer Resourcer = new Resourcer();
        private string _name;
        #region IMMDisplayNamer Implementation
        public string DisplayString(IRow pRow)
        {
            string displayName = String.Empty;
            ITable table = pRow.Table;
            IObjectClass objectClass = table as IObjectClass;
            if (objectClass != null)
            {
                if (CustomNamerUtils.GetModelNameMgr.ContainsClassModelName(objectClass, _designClassModelName))
                {
                    displayName = GetDesignDisplay(objectClass, pRow);
                }
                else if (CustomNamerUtils.GetModelNameMgr.ContainsClassModelName(objectClass, _workLocationClassModelName))
                {
                    displayName = GetWorkLocationDisplay(objectClass, pRow);
                }
                else if (CustomNamerUtils.GetModelNameMgr.ContainsClassModelName(objectClass, _workRequestClassModelName))
                {
                    displayName = GetWorkRequestDisplay(objectClass, pRow);
                }
            }
            return displayName;
        }
        public bool get_Enabled(IDataset pDataset)
        {
            bool result = false;
            IObjectClass objectClass = pDataset as IObjectClass;
            if (objectClass != null)
            {
                result = CustomNamerUtils.GetModelNameMgr.ContainsClassModelName(objectClass, _workRequestClassModelName) ||
                    CustomNamerUtils.GetModelNameMgr.ContainsClassModelName(objectClass, _workLocationClassModelName) ||
                    CustomNamerUtils.GetModelNameMgr.ContainsClassModelName(objectClass, _designClassModelName);
            }
            return result;
        }
        public string Name
        {
            get { return _name ?? (_name = Resourcer.GetBrandedString("CustomDisplayNamers.ClassicDesignNamer")); }
        }
        #endregion IMMDisplayNamer Implementation
        #region Private Methods
        /// <summary>
        /// Format the 'Classic' Designer display string like this:
        /// "DSN " + DesignID + [space + Description [+ " : " + ErrorMessage]]
        /// </summary>
        private static string GetDesignDisplay(IObjectClass objectClass, IRow row)
        {
            // Get the DesignID (String.Empty will be returned if field is not found)
            string sDesignID = GetDesignID(objectClass, row);
            // Get the Description (String.Empty will be returned if field is not found)
            string sDesc = GetDescription(objectClass, row);
            return sDesignID + sDesc;
        } 
        /// <summary>
        /// Format the 'Classic' WorkLocation display string like this:
        /// "WL " + WorkLocationID + [space + Description [+ " : " + ErrorMessage]]
        /// ErrorMessage will be added on in CoreObjects\D8WorkLocation.cpp->get_DisplayName IF it exists. 
        /// </summary>
        private static string GetWorkLocationDisplay(IObjectClass objectClass, IRow row)
        {
            // Get the WorkLocationID (String.Empty will be returned if field is not found)
            string sWorkLocationID = GetWorkLocationID(objectClass, row);
            // Get the Description (String.Empty will be returned if field is not found)
            string sDesc = GetDescription(objectClass, row);
            return sWorkLocationID + sDesc;
        }
        /// <summary>
        /// Format the 'Classic' WorkRequest display string like this:
        /// "WR " + WorkRequestID + [space + Description [+ " : " + ErrorMessage]]
        /// ErrorMessage will be added on in CoreObjects\D8WorkRequest.cpp->get_DisplayName IF it exists.
        /// </summary>
        private static string GetWorkRequestDisplay(IObjectClass objectClass, IRow row)
        {
            if (objectClass == null) throw new ArgumentNullException("objectClass");
            // Get the WorkRequestID (String.Empty will be returned if field is not found)
            string sWorkRequestID = GetWorkRequestID(objectClass, row);
            // Get the Description (String.Empty will be returned if field is not found)
            string sDesc = GetDescription(objectClass, row);
            return sWorkRequestID + sDesc;
        }
        /// <summary>
        /// Generic implementation to find the Description field by modelname
        /// and format it into a string for display purposes.
        /// </summary>
        private static string GetDescription(IObjectClass objectClass, IRow row)
        {
            string result = String.Empty;
            string value = CustomNamerUtils.GetRowValueFromFieldModelName(objectClass, row, _descriptionFieldModelName);
            //If Description is set, prefix with a space and return
            if(!string.IsNullOrEmpty(value))
            {
                result = " " + value;
            }
            return result;
        }
        /// <summary>
        /// Generic implementation to find the Design field by modelname
        /// and format its value into a string for display purposes.
        /// </summary>
        private static string GetDesignID(IObjectClass objectClass, IRow row)
        {
            string result = String.Empty;
            string value = CustomNamerUtils.GetRowValueFromFieldModelName(objectClass, row, _designIdFieldModelName);
            if (!string.IsNullOrEmpty(value))
            {
                //DesignID is set, prefix with localized "DSN" and return
                string prefix = Resourcer.GetString("CustomDisplayNamers.DesignPrefix");
                result = prefix + " " + value;
            }
            return result;
        }
        /// <summary>
        /// Generic implementation to find the WorkLocation field by modelname
        /// and format its value into a string for display purposes.
        /// </summary>
        private static string GetWorkLocationID(IObjectClass objectClass, IRow row)
        {
            // Get the value from the field with the WorkLocationID model name
            string value = CustomNamerUtils.GetRowValueFromFieldModelName(objectClass, row, _workLocationIdFieldModelName);
            //IF the Worklocation is not set, say so.
            if (string.IsNullOrEmpty(value))
            {
                value = Resourcer.GetString("CustomDisplayNamers.NotSet");
            }
            string prefix = Resourcer.GetString("CustomDisplayNamers.WorkLocationPrefix");
            return (prefix + " " + value);
        }
        /// <summary>
        /// Generic implementation to find the WorkRequest field by modelname
        /// and format its value into a string for display purposes.
        /// </summary>
        private static string GetWorkRequestID(IObjectClass objectClass, IRow row)
        {
            string result = String.Empty;
            string value = CustomNamerUtils.GetRowValueFromFieldModelName(objectClass, row, _workRequestIdFieldModelName);
            if (!string.IsNullOrEmpty(value))
            {
                //WorkRequestID is set, prefix with localized "WR" and return
                string prefix = Resourcer.GetString("CustomDisplayNamers.WorkRequestPrefix");
                result = prefix + " " + value;
            }
            return result;
        }
        #endregion Private Methods
    }
}

 

 

 


Send Comment to ArcFMdocumentation@schneider-electric.com