Показать сообщение отдельно
Старый 19.07.2021, 20:14   #1  
Blog bot is offline
Blog bot
Участник
 
24,408 / 822 (76) +++++++
Регистрация: 28.10.2006
a33ik: InventSum update event handler
Источник: http://daxonline.org/1720-inventsum-...t-handler.html
==============

Usual update/insert InventSum event handlers to handle simple cases
/// /// Event handlers for InventSum table/// class VKInventSumEventHandler{ /// /// pre insert event handler /// /// PrePost event handler arguments [PreHandlerFor(tableStr(InventSum), tableMethodStr(InventSum, insert))] public static void InventSum_Pre_insert(XppPrePostArgs args) { InventSum inventSum = args.getThis(); InventItemBarcode inventItemBarcode = InventItemBarcode::findItem( inventSum.ItemId, VKUpdateBarcodesService::getProductDimensionsOnly(inventSum.ItemId, inventSum.inventDim()), false, false); inventSum.VKItemBarcode = inventItemBarcode.itemBarCode; } /// /// pre update event handler /// /// PrePost event handler arguments [PreHandlerFor(tableStr(InventSum), tableMethodStr(InventSum, update))] public static void InventSum_Pre_update(XppPrePostArgs args) { InventSum inventSum = args.getThis(); InventItemBarcode inventItemBarcode = InventItemBarcode::findItem( inventSum.ItemId, VKUpdateBarcodesService::getProductDimensionsOnly(inventSum.ItemId, inventSum.inventDim()), false, false); inventSum.VKItemBarcode = inventItemBarcode.itemBarCode; }}Update inventSum advanced case (InventUpdateOnhand.updateInventSum())
/// /// An extension class for InventUpdateOnhand class/// [ExtensionOf(classstr(InventUpdateOnhand))]public final class VKInventUpdateOnhand_Extension{ protected str sqlUpdateInventSumStr() { str sqlSet = ' SET ', sqlFrom = ' FROM INVENTSUMDELTA ', sqlGroupBy = ' GROUP BY ', sqlStr, sqlStrFirst, sqlStrLast, sqlStrInject, newSqlStr; int injectCount = 0; str 256 inventSumName = new SysDictTable(tableNum(InventSum)).name(DbBackend::Sql); str 256 inventSumDeltaName = new SysDictTable(tableNum(InventSumDelta)).name(DbBackend::Sql); str 256 inventSumVKItemBarcodeName = new SysDictField(tableNum(InventSum),fieldNum(InventSum,VKItemBarcode)).name(DbBackend::Sql,0,FieldNameGenerationMode::FieldList); str 256 inventSumDeltaVKItemBarcodeName = new SysDictField(tableNum(InventSumDelta),fieldNum(InventSumDelta,VKItemBarcode)).name(DbBackend::Sql,0,FieldNameGenerationMode::FieldList); // see query structure at header comments of original sqlUpdateInventSumStr method sqlStr = next sqlUpdateInventSumStr(); newSqlStr = sqlStr; // modify SET section to insert our new field update int pos = strScan(newSqlStr, sqlSet, 0, strLen(newSqlStr)); if (pos > 0) { sqlStrInject = strFmt(' %1.%2 = %3.%4, ', inventSumName, inventSumVKItemBarcodeName, inventSumDeltaName, inventSumDeltaVKItemBarcodeName); newSqlStr = this.injectStr(newSqlStr, pos + strLen(sqlSet) - 1, sqlStrInject); injectCount++; } // modify SELECT ... FROM section to select new field from InventSumDelta pos = strScan(newSqlStr, sqlFrom, 0, strLen(newSqlStr)); if (pos > 0) { sqlStrInject = strFmt(', %1.%2 ', inventSumDeltaName, inventSumDeltaVKItemBarcodeName); newSqlStr = this.injectStr(newSqlStr, pos - 1, sqlStrInject); injectCount++; } // modify GROUP BY section to add out field and let it appear in selection pos = strScan(newSqlStr, sqlGroupBy, pos, strLen(newSqlStr)); if (pos > 0) { sqlStrInject = strFmt('%1.%2, ', inventSumDeltaName, inventSumDeltaVKItemBarcodeName); newSqlStr = this.injectStr(newSqlStr, pos + strLen(sqlGroupBy) - 1, sqlStrInject); injectCount++; } if (3 == injectCount) { sqlStr = newSqlStr; } return sqlStr; } public void addInventSumDelta( InventSumDelta _inventSumDelta, InventTrans _inventTrans, InventTable _inventTable) { InventItemBarcode inventItemBarcode = InventItemBarcode::findItem( _inventSumDelta.ItemId, VKUpdateBarcodesService::getProductDimensionsOnly(_inventSumDelta.ItemId, InventDim::find(_inventSumDelta.inventDimId)), false, false); // Calculate/update required field here. InventSumDelta table should also have the same field added to InventSum _inventSumDelta.VKItemBarcode = inventItemBarcode.itemBarCode; next addInventSumDelta(_inventSumDelta, _inventTrans, _inventTable); } protected str injectStr(str _baseStr, int _pos, str _inStr) { str newStr, sqlStrFirst, sqlStrLast; sqlStrFirst = subStr(_baseStr, 0, _pos); sqlStrLast = subStr(_baseStr, _pos+1, strLen(_baseStr)); newStr = sqlStrFirst + _inStr + sqlStrLast; return newStr; }}



Источник: http://daxonline.org/1720-inventsum-...t-handler.html