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));
}

相关文章:

  • 2021-05-29
  • 2021-12-05
  • 2021-08-28
  • 2021-09-18
  • 2022-12-23
  • 2022-01-13
  • 2021-11-11
  • 2021-09-16
猜你喜欢
  • 2021-08-11
  • 2022-12-23
  • 2021-11-21
  • 2021-09-12
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案