Using X++ Modify Table and class name From AOT Project
Wrote by Jimmy on DEC.2th 2010
1) create to a Customized table(class),table(class) name need to add the short for company Name referred to as the prefix;
then table field/method name is not necessary add short for company name;
2) add the table field/method name need to add the short for company name referred to as a prefix on a system table or class
using x++ code modify tableName and fieldName or className and classmethod name for define customization
such as table name prefix "QVS_" as our short name for company from AOT Private Project (Project1)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
static void Jimmy_ModifyTableAndClassFromProject(Args _args)
{
/***
Wrote by Jimmy on DEC.2th 2010
1) create to a Customized table(class),table(class) name need to add the short for company Name referred to as the prefix;
then table field/method name is not necessary add short for company name;
2) add the table field/method name need to add the short for company name referred to as a prefix on a system table or class
using x++ code modify tableName and fieldName or className and classmethod name for define customization
such as table name prefix "QVS_" as our short name for company from AOT Private Project (Project1)
*/
#TreeNodeSysNodeType
#define.prefix("QVS_")
#define.ProjectName("Project1")
ProjectGroupNode pNode;
TreeNodeIterator projectIt;
TreeNode projectListNode = SysTreeNode::getPrivateProject();
ProjectNode projectNode = projectListNode.AOTfindChild(#ProjectName);
//Only has current Layers?
Boolean onlyCurrentLayer(TreeNode _treeNode)
{
int layers = _treeNode.applObjectLayerMask();
UtilEntryLevel level;
UtilEntryLevel currentLevel;
int i,j=0;
;
for(i=0;i<enumcnt(UtilEntryLevel);i++)
{
if (layers & (1 << i))
{
currentLevel = i;
j++;
}
}
if(j == 1 && currentLevel == infolog.currentAOLayer())
return true;
return false;
}
//Modify Classes and Tables
void modify(TreeNode _treeNode)
{
str property;
TreeNode childTreeNode;
SysDictClass SysDictClass;
name tableName,fieldName;
name className,classMethodName;
int i;
;
switch(_treeNode.sysNodeType())
{
case #NT_DBTABLE:
{
//Modify TableName
if(onlyCurrentLayer(_treeNode))
{
tableName = tableId2Name(_treeNode.applObjectId());
if(substr(tableName,1,4) != #prefix)
_treeNode.AOTsetProperty("Name",#Prefix + tableName);
}
//Modify field Name
childTreeNode = _treeNode.AOTfirstChild().AOTfirstChild();
while(childTreeNode)
{
if(!onlyCurrentLayer(_treeNode) && onlyCurrentLayer(childTreeNode))
{
fieldName = fieldId2Name(_treeNode.applObjectId(),childTreeNode.applObjectId());
if(substr(fieldName,1,4) != #prefix)
{
childTreeNode.AOTsetProperty("Name",#Prefix + fieldName);
childTreeNode.AOTcompile(1);
childTreeNode.AOTsave();
}
}
childTreeNode = childTreeNode.AOTnextSibling();
}
//Save
_treeNode.AOTcompile(1);
_treeNode.AOTsave();
//Synchronize Table
appl.dbSynchronize(SysDictTable::newTreeNode(_treeNode).id());
break;
}
case #NT_CLASS :
{
//Modify className
if(onlyCurrentLayer(_treeNode))
{
className = ClassId2Name(_treeNode.applObjectId());
if(substr(className,1,4) != #prefix)
_treeNode.AOTsetProperty("Name",#Prefix + className);
}
//Modify method Name on this class
childTreeNode = _treeNode.AOTfirstChild();
SysDictClass = new SysDictClass(_treeNode.applObjectId());
i = 0;
while(childTreeNode)
{
if(!onlyCurrentLayer(_treeNode) && onlyCurrentLayer(childTreeNode))
{
info(int2str(_treeNode.applObjectId()));
classMethodName = SysDictClass.objectMethodObject(i).name();
info(classMethodName);
if(classMethodName && substr(classMethodName,1,4) != #prefix)
{
childTreeNode.AOTsetProperty("Name",#Prefix + classMethodName);
childTreeNode.AOTcompile(1);//It look like throw waring....?????
childTreeNode.AOTsave();
}
}
childTreeNode = childTreeNode.AOTnextSibling();
i++;
}
//Save
_treeNode.AOTcompile(1);
_treeNode.AOTsave();
break;
}
default : break;
}
}
//Get the classes and tables to be modify
void getElementsToBeModified(TreeNode _treeNode)
{
TreeNodeIterator projectGroupIt;
TreeNode projectSuperNode,projectGroupNode;
;
if(!_treeNode)
return;
//Project Group
if(_treeNode.sysNodeType() == #NT_PROJECT_GROUP)
{
projectGroupIt = _treeNode.AOTiterator();
projectGroupNode = projectGroupIt.next();
while(projectGroupNode != null)
{
getElementsToBeModified(projectGroupNode);
projectGroupNode = projectGroupIt.next();
}
}
else
info(strfmt("Modify object : %1", _treeNode.toString()));
modify(_treeNode);
}
;
projectNode = projectNode.getRunNode();
projectIt = projectNode.AOTiterator();
pNode = projectIt.next();
while(pNode)
{
getElementsToBeModified(pNode);
pNode = projectIt.next();
}
}