ValveNamer.cs
Copy Code
|
|
---|---|
//----------------------------------------------------------------------------------- //Schneider Electric //Copyright 2010 //----------------------------------------------------------------------------------- //Module Name: ValveNamer //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("00697312-4335-40d7-BD8A-C5E5C3A76749")] [ComponentCategory(ComCategory.MMDisplayNameObjects)] public class ValveNamer : IMMDisplayNamer { //Member constants private const string _facilityIdFieldName = "FacilityID"; private const string _valveDiameterFieldName = "ValveDiameter"; private const string _materialFieldName = "Material"; private static readonly Resourcer Resourcer = new Resourcer(); #region IMMDisplayNamer Implementation public string DisplayString(IRow pRow) { IFields fields = pRow.Fields; ICodedValueDomain codedValueDomain; //Assemble individual display strings //Store FacilityID field value int facilityIDIndex = fields.FindField(_facilityIdFieldName); string facilityID = pRow.get_Value(facilityIDIndex) as string; if (facilityIDIndex >= 0) { if (facilityID == null) { if (pRow.HasOID) { facilityID = "(" + Convert.ToString(pRow.OID) + ")"; } } } //Store ValveSize field value int valveSizeIndex = fields.FindField(_valveDiameterFieldName); string valveSize = string.Empty; if (valveSizeIndex >= 0) { string valveSizeValue = pRow.get_Value(valveSizeIndex) as string; if (valveSizeValue == null) { valveSize = Resourcer.GetString("CustomDisplayNamers.NullValue"); } else { //Get appropriate ValveSize code description from subtype domain //or default domain codedValueDomain = CustomNamerUtils.GetCVDomain(pRow, valveSizeIndex); valveSize = codedValueDomain != null ? CustomNamerUtils.GetCVDescFromCode(codedValueDomain, valveSizeValue) : valveSizeValue; } } //Store Material field value int materialIndex = fields.FindField(_materialFieldName); string material = string.Empty; if (materialIndex >= 0) { string materialValue = pRow.get_Value(materialIndex) as string; if (materialValue == null) { material = Resourcer.GetString("CustomDisplayNamers.NullValue"); } else { //Get appropriate material code description from subtype domain //or default domain codedValueDomain = CustomNamerUtils.GetCVDomain(pRow, materialIndex); if (codedValueDomain != null) { material = CustomNamerUtils.GetCVDescFromCode(codedValueDomain, materialValue); //Get first two character of material domain description material = material.Substring(0, 2).ToUpper(); } else { material = "Material Code:" + materialValue; } } } //Assemble display string string sDisplayString = facilityID + " - " + valveSize + " - " + material; //return display string return sDisplayString; } public bool get_Enabled(IDataset pDataset) { bool result = false; //Enable only on "GasValve" model name IObjectClass objectClass = pDataset as IObjectClass; if (objectClass != null) { if (CustomNamerUtils.GetModelNameMgr.ContainsClassModelName(objectClass, "Valve")) { result = true; } } return result; } public string Name { get { return "Minerville Valve Display Namer"; } } #endregion IMMDisplayNamer Implementation } } |