Описание
(Нет описания для триггера SILAGEPACKS_SetWeight)
Определение
CREATE TRIGGER "SILAGEPACKS_SetWeight" FOR SILAGEPACKS
ACTIVE BEFORE UPDATE POSITION 1
as
declare variable SQUALITYCOUNT integer;
declare variable MIXINGCLASSES integer;
begin
if (new.WEIGHT is null) then begin
new.SILAGEQUALITYID = null;
new.RECIPEID = null;
new.QUALITYID = null;
new.COVERDATE = null;
new.EMPTYDATE = current_timestamp;
new.STATE = 1;
update SILAGE
set WEIGHT = null
where (SILAGE.SILAGEPACKID = old.SILAGEPACKID);
end
else
if ((old.WEIGHT is null) and (new.WEIGHT is not null) and (new.COVERDATE is null)) then
new.COVERDATE = current_timestamp;
-- Изменение веса в SILAGEQUALITY при изменеии веса силоса и наличии одного класа в оном
if ((new.WEIGHT is not null) and (new.SILAGEQUALITYID is not null)
and (old.WEIGHT is not null) and (old.WEIGHT <> new.WEIGHT)
) then begin
select count(SILAGEQUALITY.SILAGEQUALITYID)
from SILAGEQUALITY
where (SILAGEQUALITY.SILAGEQUALITYID = new.SILAGEQUALITYID)
into SQUALITYCOUNT;
select STORAGE.MIXINGCLASSES
from STORAGE
where (STORAGE.STORAGEID = 1)
into :MIXINGCLASSES;
if (:MIXINGCLASSES <> 1) then begin
if (SQUALITYCOUNT = 1) then begin
update SILAGEQUALITY
set WEIGHT = new.WEIGHT
where (SILAGEQUALITY.SILAGEQUALITYID = new.SILAGEQUALITYID);
end
end
-- если 2 и больше - считается в другом тригере
end
end