When you are finished renamed the Item number, you must record original Item number, related configure and so on!
static void Jimmy_ItemRenamedAfterUpdate(Args _args)
{
InventTableCompany ITCompany,delITCompany;
InventTable IT,ITUpdateOrg;
ConfigTable ConfigTable;
InventDimCombination Combination;
Dialog dlg = new Dialog("updated to comoany Items infomation");
DialogField dlgItem = dlg.addField(types::String,'after rename Items:',"Format such as :Items + ',' + Items + ',' + items");
ListEnumerator le;
ItemId ItemConfig;
InventTrans InventTrans;
int ITCompanys,Combinations,NoConfig;
SysDataBaseLog SysDataBaseLog;
Container Con;
fieldId fieldId;
List datalist;
ListEnumerator enumerator;
;
dlgItem.displayHeight(20);
dlgItem.displayLength(50);
dlg.doInit();
if(!dlg.run())
return ;
le = global::strSplit(dlgItem.value(),',').getEnumerator();
while (le.moveNext())
{
ttsbegin;
ITUpdateOrg = InventTable::find(le.current(),true);
if(ITUpdateOrg)
{
select firstonly SysDataBaseLog
where SysDataBaseLog.table == tablenum(InventTable)
&& SysDataBaseLog.LogType == DatabaseLogType::RenameKey
&& SysDataBaseLog.Description like ITUpdateOrg.ItemId + '*';
if(SysDataBaseLog)
{
datalist = SysDataBaseLog.getDataAslist();
enumerator = datalist.getEnumerator();
while (enumerator.moveNext())
{
Con = enumerator.current();
fieldId = conpeek(Con, 1);
ITUpdateOrg.OrgItemId = sysdatabaselog.contents2Str(conpeek(Con, 3), fieldId);
break;
}
}
if(!ITUpdateOrg.OrgItemId)
ITUpdateOrg.OrgItemId = ITUpdateOrg.ItemId;
ITUpdateOrg.Update();
}
ttscommit;
select firstonly forupdate IT where IT.ItemId == le.current();
if(IT)
{
/*
select firstonly InventTrans where InventTrans.ItemId == le.current();
if(InventTrans)
throw Error(StrFmt("The ItemId %1 Exists InventTrans,do not rename of Items!",le.current()));
*/
select firstonly ConfigTable where ConfigTable.ItemId == IT.ItemId;
//Have Configuration
ItemConfig = '';
if(ConfigTable)
{
ConfigTable.clear();
while select ConfigTable where ConfigTable.ItemId == IT.ItemId
{
ItemConfig = IT.ItemId + '_' + ConfigTable.ConfigId;
ttsbegin;
select firstonly forupdate ITCompany where ITCompany.ItemId == ItemConfig;
if(!ITCompany)
{
ITCompany.initValue();
ITCompany.ItemId = ItemConfig;
ITCompany.Name = IT.itemName;
ITCompany.OrgItemId = IT.OrgItemId;
ITCompany.NormalItemId = IT.ItemId;
ITCompany.insert();
ITCompanys++;
}
else
{
ITCompany.ItemId = ItemConfig;
ITCompany.Name = IT.itemName;
ITCompany.OrgItemId = IT.OrgItemId;
ITCompany.NormalItemId = IT.ItemId;
ITCompany.update();
}
ttscommit;
ttsbegin;
delete_from delITCompany where delITCompany.ItemId == IT.OrgItemId + '_' + ConfigTable.ConfigId
&& delITCompany.OrgItemId == '' && delITCompany.NormalItemId == '';
ttscommit;
ttsbegin;
select firstonly forupdate Combination
where Combination.ItemId == ConfigTable.ItemId
&& Combination.ConfigId == ConfigTable.ConfigId;
if(Combination)
{
Combination.ItemIdCompany = ItemConfig;
Combination.update();
Combinations++;
}
ttscommit;
}
}
else //Have not Configuration
{
ttsbegin;
select firstonly forupdate ITCompany where ITCompany.ItemId == IT.ItemId;
if(!ITCompany)
{
ITCompany.initValue();
ITCompany.ItemId = IT.ItemId;
ITCompany.Name = IT.itemName;
ITCompany.OrgItemId = IT.OrgItemId;
ITCompany.NormalItemId = IT.ItemId;
ITCompany.insert();
}
else
{
ITCompany.ItemId = IT.ItemId;
ITCompany.Name = IT.itemName;
ITCompany.OrgItemId = IT.OrgItemId;
ITCompany.NormalItemId = IT.ItemId;
ITCompany.update();
}
ttscommit;
ttsbegin;
IT.ItemIdCompany = it.ItemId;
IT.update();
ttscommit;
NoConfig ++;
info(IT.ItemId);
}
}
ELSE
info("Not exists Item detail " + le.current());
}
info(strfmt("NoConfig : %1,Combinations : %2,ITCompanys : %3",NoConfig,Combinations,ITCompanys));
}