Example Naming Rule Script: Stockpiles

When naming an object, ensure that you set the Alias1 value if required. The out parameter scriptResult must be set in the event to indicate whether the naming was successful.

Copy
using System;
using Mincom.MineMarket.DAL;
using Mincom.MineMarket;
using Mincom.MineMarket.Server;

/// <summary>
/// This is an example or template class and should not be used as is.
/// </summary>

public class StockpileNamingExample : INameGenerator
{
    public StockpileNamingExample() { }

    public string[] GetParameterMap()
    {
        return new string[2] { "Location Name", "Product Name" };
    }

    public string GetName(string[] paramList)
    {
        return paramList[0] + " Pile - " + paramList[1].Substring(0, 3)
            + " - " + ClientManager.ClientManagerProxy.SequenceGenerator
            .NextNumber(paramList[0], "StockpileName", true);
    }

    public string GetName(BTNamedBusinessObject obj, ValidationInfo info, out 
        ScriptResult scriptResult)
    {
        if (obj is BaseStockpile)
        {
            BaseStockpile stockpile = (BaseStockpile)obj;
            if (stockpile.Location == null)
            {
                if (info != null)
                {
                    info.AddError(obj, "The stockpile location is required before the name can be generated.");
                }
                scriptResult = ScriptResult.NameNotGenerated;
                return null;
            }
            else
            {
                scriptResult = ScriptResult.NameGenerated;
                return stockpile.Location.Name + " Stockpile/" +
                    ClientManager.ClientManagerProxy.SequenceGenerator
                    .NextNumber(1, stockpile.Location.ID.ToString(), 
                    "StockpileName", false);
            }
        }
        scriptResult = ScriptResult.NameNotGenerated;
        return null;
    }
}