ALTER TABLE TBCASO_PAINEL_CONF
    ADD STEP2 NUMERIC(15,4) DEFAULT 1;

COMMENT ON COLUMN TBCASO_PAINEL_CONF.STEP2 IS
'pasos para numeros';


UPDATE TBCASO_PAINEL_CONF
	SET STEP2 = STEP;
	
/********************************************/
/********************************************/

SET TERM ^ ;

CREATE OR ALTER trigger ttbcaso_painel_conf_b01u for tbcaso_painel_conf
active after update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

HISTORICO = '';

    IF(OLD.ORDEM <> NEW.ORDEM)THEN
    BEGIN
       HISTORICO = HISTORICO||' ORDEM:'||OLD.ORDEM||'->'||NEW.ORDEM;
    END

    IF(OLD.DESCRICAO <> NEW.DESCRICAO)THEN
    BEGIN
       HISTORICO = HISTORICO||' DESC:'||OLD.DESCRICAO||'->'||NEW.DESCRICAO;
    END

    IF(OLD.TIPO <> NEW.TIPO)THEN
    BEGIN
       HISTORICO = HISTORICO||' TIPO:'||OLD.TIPO||'->'||NEW.TIPO;
    END

    IF(OLD.STATUS <> NEW.STATUS)THEN
    BEGIN
       HISTORICO = HISTORICO||' STATUS:'||OLD.STATUS||'->'||NEW.STATUS;
    END

    IF(OLD."DEFAULT" <> NEW."DEFAULT")THEN
    BEGIN
       HISTORICO = HISTORICO||' DEFAULT:'||OLD."DEFAULT"||'->'||NEW."DEFAULT";
    END

    IF(OLD."MIN" <> NEW."MIN")THEN
    BEGIN
       HISTORICO = HISTORICO||' MIN:'||OLD."MIN"||'->'||NEW."MIN";
    END

    IF(OLD."MAX" <> NEW."MAX")THEN
    BEGIN
       HISTORICO = HISTORICO||' MAX:'||OLD."MAX"||'->'||NEW."MAX";
    END

    IF(OLD.TAMANHO <> NEW.TAMANHO)THEN
    BEGIN
       HISTORICO = HISTORICO||' TAMANHO:'||OLD.TAMANHO||'->'||NEW.TAMANHO;
    END

    IF(OLD.TAM_PX_CAMPO <> NEW.TAM_PX_CAMPO)THEN
    BEGIN
       HISTORICO = HISTORICO||' TAM PX:'||OLD.TAM_PX_CAMPO||'->'||NEW.TAM_PX_CAMPO;
    END

    IF(OLD.REQUERED <> NEW.REQUERED)THEN
    BEGIN
       HISTORICO = HISTORICO||' REQ:'||OLD.REQUERED||'->'||NEW.REQUERED;
    END

    IF(OLD.VINCULO <> NEW.VINCULO)THEN
    BEGIN
       HISTORICO = HISTORICO||' VINCULO:'||OLD.VINCULO||'->'||NEW.VINCULO;
    END

    IF(OLD.STEP2 <> NEW.STEP2)THEN
    BEGIN
       HISTORICO = HISTORICO||' STEP:'||OLD.STEP2||'->'||NEW.STEP2;
    END

    IF(OLD.GRUPO_ID <> NEW.GRUPO_ID)THEN
    BEGIN
       HISTORICO = HISTORICO||' AGRUP:'||OLD.GRUPO_ID||'->'||NEW.GRUPO_ID;
    END

    IF(OLD.VAR_NOME <> NEW.VAR_NOME)THEN
    BEGIN
       HISTORICO = HISTORICO||' VARIAVEL:'||OLD.VAR_NOME||'->'||NEW.VAR_NOME;
    END

    IF(OLD.CAMPO_GRAVAR <> NEW.CAMPO_GRAVAR)THEN
    BEGIN
       HISTORICO = HISTORICO||' GRAVAR:'||OLD.CAMPO_GRAVAR||'->'||NEW.CAMPO_GRAVAR;
    END

    IF(OLD.CAMPO_VISUALIZAR <> NEW.CAMPO_VISUALIZAR)THEN
    BEGIN
       HISTORICO = HISTORICO||' VISUALIZAR:'||OLD.CAMPO_VISUALIZAR||'->'||NEW.CAMPO_VISUALIZAR;
    END

    IF(OLD.AUTOLOAD <> NEW.AUTOLOAD)THEN
    BEGIN
       HISTORICO = HISTORICO||' AUTOLOAD:'||OLD.AUTOLOAD||'->'||NEW.AUTOLOAD;
    END

    IF(OLD.PARAM_EXEC <> NEW.PARAM_EXEC)THEN
    BEGIN
       HISTORICO = HISTORICO||' CAMPO PARAM:'||OLD.PARAM_EXEC||'->'||NEW.PARAM_EXEC;
    END

    IF(OLD.PARAM_UTL <> NEW.PARAM_UTL)THEN
    BEGIN
       HISTORICO = HISTORICO||' PARAM.PREENCHIMENTO:'||OLD.PARAM_UTL||'->'||NEW.PARAM_UTL;
    END

IF(HISTORICO <> '') THEN
   BEGIN
     HISTORICO = 'PAINEL:'|| FN_LPAD(NEW.ID,4,0)||' - '||NEW.DESCRICAO ||' ALTERADO'||HISTORICO;
     EXECUTE PROCEDURE SPI_HISTORICO('TBCASO_PAINEL', NEW.PAINEL_ID,FN_ELIPSES(:HISTORICO,500));
   END
END
^

SET TERM ; ^

/********************************************/
/********************************************/

ALTER TABLE TBCASO_PAINEL_CONF DROP STEP;

/********************************************/
/********************************************/
/********************************************/

ALTER TABLE TBCASO_PAINEL_CONF
    ADD STEP NUMERIC(15,4) DEFAULT 1;

COMMENT ON COLUMN TBCASO_PAINEL_CONF.STEP IS
'pasos para numeros';


UPDATE TBCASO_PAINEL_CONF
	SET STEP = STEP2;

/********************************************/
/********************************************/

SET TERM ^ ;

CREATE OR ALTER trigger ttbcaso_painel_conf_b01u for tbcaso_painel_conf
active after update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

HISTORICO = '';

    IF(OLD.ORDEM <> NEW.ORDEM)THEN
    BEGIN
       HISTORICO = HISTORICO||' ORDEM:'||OLD.ORDEM||'->'||NEW.ORDEM;
    END

    IF(OLD.DESCRICAO <> NEW.DESCRICAO)THEN
    BEGIN
       HISTORICO = HISTORICO||' DESC:'||OLD.DESCRICAO||'->'||NEW.DESCRICAO;
    END

    IF(OLD.TIPO <> NEW.TIPO)THEN
    BEGIN
       HISTORICO = HISTORICO||' TIPO:'||OLD.TIPO||'->'||NEW.TIPO;
    END

    IF(OLD.STATUS <> NEW.STATUS)THEN
    BEGIN
       HISTORICO = HISTORICO||' STATUS:'||OLD.STATUS||'->'||NEW.STATUS;
    END

    IF(OLD."DEFAULT" <> NEW."DEFAULT")THEN
    BEGIN
       HISTORICO = HISTORICO||' DEFAULT:'||OLD."DEFAULT"||'->'||NEW."DEFAULT";
    END

    IF(OLD."MIN" <> NEW."MIN")THEN
    BEGIN
       HISTORICO = HISTORICO||' MIN:'||OLD."MIN"||'->'||NEW."MIN";
    END

    IF(OLD."MAX" <> NEW."MAX")THEN
    BEGIN
       HISTORICO = HISTORICO||' MAX:'||OLD."MAX"||'->'||NEW."MAX";
    END

    IF(OLD.TAMANHO <> NEW.TAMANHO)THEN
    BEGIN
       HISTORICO = HISTORICO||' TAMANHO:'||OLD.TAMANHO||'->'||NEW.TAMANHO;
    END

    IF(OLD.TAM_PX_CAMPO <> NEW.TAM_PX_CAMPO)THEN
    BEGIN
       HISTORICO = HISTORICO||' TAM PX:'||OLD.TAM_PX_CAMPO||'->'||NEW.TAM_PX_CAMPO;
    END

    IF(OLD.REQUERED <> NEW.REQUERED)THEN
    BEGIN
       HISTORICO = HISTORICO||' REQ:'||OLD.REQUERED||'->'||NEW.REQUERED;
    END

    IF(OLD.VINCULO <> NEW.VINCULO)THEN
    BEGIN
       HISTORICO = HISTORICO||' VINCULO:'||OLD.VINCULO||'->'||NEW.VINCULO;
    END

    IF(OLD.STEP <> NEW.STEP)THEN
    BEGIN
       HISTORICO = HISTORICO||' STEP:'||OLD.STEP||'->'||NEW.STEP;
    END

    IF(OLD.GRUPO_ID <> NEW.GRUPO_ID)THEN
    BEGIN
       HISTORICO = HISTORICO||' AGRUP:'||OLD.GRUPO_ID||'->'||NEW.GRUPO_ID;
    END

    IF(OLD.VAR_NOME <> NEW.VAR_NOME)THEN
    BEGIN
       HISTORICO = HISTORICO||' VARIAVEL:'||OLD.VAR_NOME||'->'||NEW.VAR_NOME;
    END

    IF(OLD.CAMPO_GRAVAR <> NEW.CAMPO_GRAVAR)THEN
    BEGIN
       HISTORICO = HISTORICO||' GRAVAR:'||OLD.CAMPO_GRAVAR||'->'||NEW.CAMPO_GRAVAR;
    END

    IF(OLD.CAMPO_VISUALIZAR <> NEW.CAMPO_VISUALIZAR)THEN
    BEGIN
       HISTORICO = HISTORICO||' VISUALIZAR:'||OLD.CAMPO_VISUALIZAR||'->'||NEW.CAMPO_VISUALIZAR;
    END

    IF(OLD.AUTOLOAD <> NEW.AUTOLOAD)THEN
    BEGIN
       HISTORICO = HISTORICO||' AUTOLOAD:'||OLD.AUTOLOAD||'->'||NEW.AUTOLOAD;
    END

    IF(OLD.PARAM_EXEC <> NEW.PARAM_EXEC)THEN
    BEGIN
       HISTORICO = HISTORICO||' CAMPO PARAM:'||OLD.PARAM_EXEC||'->'||NEW.PARAM_EXEC;
    END

    IF(OLD.PARAM_UTL <> NEW.PARAM_UTL)THEN
    BEGIN
       HISTORICO = HISTORICO||' PARAM.PREENCHIMENTO:'||OLD.PARAM_UTL||'->'||NEW.PARAM_UTL;
    END

IF(HISTORICO <> '') THEN
   BEGIN
     HISTORICO = 'PAINEL:'|| FN_LPAD(NEW.ID,4,0)||' - '||NEW.DESCRICAO ||' ALTERADO'||HISTORICO;
     EXECUTE PROCEDURE SPI_HISTORICO('TBCASO_PAINEL', NEW.PAINEL_ID,FN_ELIPSES(:HISTORICO,500));
   END
END
^

SET TERM ; ^

/********************************************/
/********************************************/

ALTER TABLE TBCASO_PAINEL_CONF DROP STEP2;

/********************************************/
/********************************************/
/********************************************/

alter table TBCASO_PAINEL_CONF
alter ID position 1;

alter table TBCASO_PAINEL_CONF
alter PAINEL_ID position 2;

alter table TBCASO_PAINEL_CONF
alter ORDEM position 3;

alter table TBCASO_PAINEL_CONF
alter DESCRICAO position 4;

alter table TBCASO_PAINEL_CONF
alter TIPO position 5;

alter table TBCASO_PAINEL_CONF
alter STATUS position 6;

alter table TBCASO_PAINEL_CONF
alter "DEFAULT" position 7;

alter table TBCASO_PAINEL_CONF
alter "MIN" position 8;

alter table TBCASO_PAINEL_CONF
alter "MAX" position 9;

alter table TBCASO_PAINEL_CONF
alter STEP position 10;

alter table TBCASO_PAINEL_CONF
alter TAMANHO position 11;

alter table TBCASO_PAINEL_CONF
alter REQUERED position 12;

alter table TBCASO_PAINEL_CONF
alter VINCULO position 13;

alter table TBCASO_PAINEL_CONF
alter GRUPO_ID position 14;

alter table TBCASO_PAINEL_CONF
alter VAR_NOME position 15;

alter table TBCASO_PAINEL_CONF
alter CAMPO_GRAVAR position 16;

alter table TBCASO_PAINEL_CONF
alter CAMPO_VISUALIZAR position 17;

alter table TBCASO_PAINEL_CONF
alter AUTOLOAD position 18;

alter table TBCASO_PAINEL_CONF
alter TAM_PX_CAMPO position 19;

alter table TBCASO_PAINEL_CONF
alter PARAM_EXEC position 20;

alter table TBCASO_PAINEL_CONF
alter PARAM_UTL position 21;

