Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Alternativa ao TDBSeekButton Senhores, boa noite, estou com um problema referente ao componente TDBSeekButton. É o seguinte, tenho um formulário que captura dados de uma determinada classe para preencher outra classe que faz associação com minha classe principal, a qual dá origem ao formulário. O problema é que o TDBSeekButton tem uma limitação de parâmetros de busca e na hora de inserir no multifield ele não co...
TS
Alternativa ao TDBSeekButton  
Fechado
Senhores,

boa noite, estou com um problema referente ao componente TDBSeekButton. É o seguinte, tenho um formulário que captura dados de uma determinada classe para preencher outra classe que faz associação com minha classe principal, a qual dá origem ao formulário. O problema é que o TDBSeekButton tem uma limitação de parâmetros de busca e na hora de inserir no multifield ele não consegue capturar alguns dados que são necessários para a funcionalidade do formulário. A dúvida é a seguinte, existe algum componente que posso utilizar como alternativa ao TDBSeekButton, para capturar todos os dados necessários?

Fico no aguardo, desde já grato.
Segue abaixo o código do formulário:

  1. <?php
  2. class FrmMestreReproducao extends TPage
  3. {
  4.    protected $form;
  5.    
  6.    public function __construct(){
  7.    
  8.        parent::__construct();
  9.        
  10.        $this->form = new TForm('FrmMestreReproducao');
  11.        $this->form->class 'tform';
  12.        parent::include_css('app/resources/custom-frame.css');
  13.        
  14.        $tbl_reproducao = new TTable;
  15.        $tbl_matrizes = new TTable;
  16.        $tbl_dados_primarios = new TTable;
  17.        $tbl_estatisticas = new TTable;
  18.        $tbl_matriz2 = new TTable;
  19.        $tbl_dados_primarios->styçe='background:whiteSmoke;';
  20.        $hbox1 = new THBox;
  21.        $hbox2 = new THBox;
  22.        $hbox3 = new THBox;
  23.        
  24.        $tbl_reproducao->style='Width:100%;';
  25.        $tbl_dados_primarios->style='width:100%';
  26.        $tbl_matrizes->style='width:100%';
  27.        $tbl_estatisticas->style='width:100%';
  28.        $tbl_matriz2->style='width:100%';
  29.        $this->form->add($tbl_reproducao);
  30.        
  31.        
  32.        $tbl_reproducao->addRowSet( new TLabel('Reprodução'), '''','' )->class 'tformtitle';
  33.        $tbl_reproducao->addRowSet($hbox1);
  34.        $tbl_reproducao->addRowSet($hbox2);
  35.        $tbl_reproducao->addRowSet($hbox3);
  36.        
  37.        $hbox1->add($tbl_dados_primarios);
  38.        $hbox1->add($tbl_estatisticas);
  39.        $hbox2->add($tbl_matrizes);
  40.        $hbox2->add($tbl_matriz2);
  41.        $this->form->add($tbl_reproducao);
  42.        
  43.        $frame_matrizes = new TFrame(NULL290);
  44.        $frame_matrizes->setLegend('Matrizes');
  45.        $frame_matrizes->style .= 'background:whiteSmoke;margin: 4px';
  46.        
  47.        $frame_incubadora = new TFrame(NULL290);
  48.        $frame_incubadora->setLegend('Incubadora');
  49.        $frame_incubadora->style .= ';margin: 4px';
  50.        
  51.             
  52.                    
  53.        2249Reproducao        = new THidden('idReproducao');
  54.        $codigo              = new TEntry('codigo');
  55.        $dataInicioReproducao     = new TDate('dataInicioReproducao');
  56.        $temperatura        = new TEntry('temperatura');
  57.        $equipeReproducao   = new TEntry('equipeReproducao');
  58.        $climaDia           = new TEntry('climaDia');
  59.        $pesoTotMatFemea    = new TEntry('pesoTotMatFemea');
  60.        $pesoTotMatMacho    = new TEntry('pesoTotMatMacho');
  61.        $qtdeMatFemea       = new TEntry('qtdeMatFemea');
  62.        $qtdeMatMacho       = new TEntry('qtdeMatMacho');
  63.        $pesoGeralMatriz    = new TEntry('pesoGeralMatriz');
  64.        $totalGeralHormonio = new TEntry('totalGeralHormonio');
  65.        $dataFinalReproducao = new TDate('dataFinalReproducao');
  66.        $reproducao_incubadoras  = new TDBRadioGroup('reproducao_incubadoras','dbwf','Incubadora','idIncubadora','descIncubadora');
  67.        2249Matriz           = new  ">TDBSeekButton('idMatriz','dbwf',$this->form->getName(),'Matriz','numeroChipMatriz','matrizes_id','matrizes_numeroChipMatriz');
  68.        //$matriz             = new TEntry('matriz');
  69.        $numero             = new TEntry('numeroChipMatriz');
  70.        $pesoMatriz         = new TEntry('pesoMatriz');
  71.        2249entMatriz        = new TEntry('identMatriz');
  72.        $sexoMatriz         = new TEntry('sexoMatriz');
  73.        $multi_matrizes     = new TMultiField('matrizes');
  74.        $txEclosao          = new TEntry('txEclosao');
  75.        $txFecundacao       = new TEntry('txFecundacao');
  76.        
  77.        
  78.        if (!empty(2249Reproducao))
  79.         {
  80.             2249Reproducao->setEditable(FALSE);
  81.         }
  82.         
  83.        $scroll = new TScroll;
  84.        $scroll->setSize(290240);
  85.        $scroll->add$reproducao_incubadoras  );
  86.        $frame_incubadora->add($scroll);
  87.        $frame_matrizes->add($multi_matrizes);
  88.        //$matriz->setEditable(false);
  89.        
  90.        
  91.        $codigo->setSize('50%');
  92.        $temperatura->setSize('100%');
  93.        $equipeReproducao->setSize('100%');
  94.        $climaDia->setSize('100%');
  95.        $pesoTotMatFemea->setSize('100%');
  96.        $pesoTotMatMacho->setSize('100%');
  97.        $totalGeralHormonio->setSize('100%');
  98.        $qtdeMatFemea->setSize('100%');
  99.        $qtdeMatMacho->setSize('100%');
  100.        $pesoGeralMatriz->setSize('100%');
  101.        $numero->setEditable(false);
  102.        $sexoMatriz->setEditable(false);
  103.        $dataInicioReproducao->date2br;
  104.        
  105.        $multi_matrizes->setHeight(120);
  106.        
  107.        $multi_matrizes->setClass('Matriz');
  108.        $multi_matrizes->addField('id','Matriz'2249Matriz,60);
  109.        $multi_matrizes->addField('numeroChipMatriz','Numero'$numero60,'center');
  110.        $multi_matrizes->addField('identMatriz','Identificação',2249entMatriz,140);
  111.        $multi_matrizes->addField('pesoMatriz','Peso Atual'$pesoMatriz,80);
  112.        $matriz1 = new Matriz();
  113.        try{
  114.            TTransaction::open('dbwf');
  115.            $matriz1->load('id'); 
  116.            var_dump($numero->getValue());          
  117.            TTransaction::close();
  118.        }
  119.        catch(Exception $e){
  120.        
  121.            new TMessage('error','<b>Erro ao gravar o Registro!</b>'$e->getMessage());
  122.        }
  123.        $sexoMatriz->setValue($matriz1->sexoMatriz);
  124.        $multi_matrizes->addField('sexoMatriz','Sexo',$sexoMatriz,60);
  125.        $multi_matrizes->setOrientation('vertical');
  126.        
  127.        $row $tbl_dados_primarios->addRow();
  128.        $row->addCell(new TLabel('Nº:'))->style='width:150px';
  129.        $row->addcell($codigo);
  130.        $tbl_dados_primarios->addRowSet(new TLabel('INICIO'.': ' ),    $dataInicioReproducao);
  131.        $tbl_dados_primarios->addRowSet(new TLabel('TEMPERATURA'.': ' ),    $temperatura);
  132.        $tbl_dados_primarios->addRowSet(new TLabel('EQUIPE'.': '),    $equipeReproducao);
  133.        $tbl_dados_primarios->addRowSet(new TLabel('CLIMA DO DIA'.': '),    $climaDia);
  134.        //$tbl_dados_primarios->addRowSet(new TLabel('FINAL'.': '),    $dataFinalReproducao);
  135.        
  136.        $row $tbl_estatisticas->addRow();
  137.        $row->addCell(new TLabel('TAXA DE ECLOSÃO:'))->style='width:150px';
  138.        $row->addCell($txEclosao);
  139.        $tbl_estatisticas->addRowSet(new TLabel('TAXA DE FECUNDAÇÃO'.': '),    $txFecundacao);
  140.        $tbl_estatisticas->addRowSet(new TLabel('FINAL'.': '),    $dataFinalReproducao);
  141.        //$tbl_estatisticas->addRowSet(new TLabel('TOTAL MACHOS'.': '),    $qtdeMatMacho);
  142.        $row $tbl_matrizes->addRow();
  143.        $row->addCell(new TLabel('TOTAL FÊMEAS: '))->style='width:150px';
  144.        $row->addCell($qtdeMatFemea);
  145.        $tbl_matrizes->addRowSet(new TLabel('TOTAL MACHOS'.': '),    $qtdeMatMacho);
  146.        $tbl_matrizes->addRowSet(new TLabel('TOTAL HORMÔNIO'.': '),    $totalGeralHormonio);
  147.               
  148.        $row $tbl_matriz2->addRow();
  149.        $row->addCell(new TLabel('PESO FÊMEAS'.': '))->style='width:150px';
  150.        $row->addCell($pesoTotMatFemea);
  151.        $tbl_matriz2->addRowSet(new TLabel('PESO MACHOS'.': '),    $pesoTotMatMacho);
  152.        $tbl_matriz2->addRowSet(new TLabel('TOTAL MATRIZES'.': '),    $pesoGeralMatriz);
  153.        
  154.        $hbox3->add($frame_matrizes)->style .='vertical-align:top';
  155.        $hbox3->add($frame_incubadora)->style .='vertical-align:top';
  156.        
  157.        $save_button=new TButton('save');
  158.        $save_button->setAction(new TAction(array($this'onSave')), _t('Save'));
  159.        $save_button->setImage('fa:floppy-o');
  160.         
  161.         // create an new button (edit with no parameters)
  162.         $new_button=new TButton('new');
  163.         $new_button->setAction(new TAction(array($this'onEdit')), _t('New'));
  164.         $new_button->setImage('fa:plus-square green');
  165.         
  166.         $list_button=new TButton('list');
  167.         $list_button->setAction(new TAction(array('SystemUserList','onReload')), _t('Back to the listing'));
  168.         $list_button->setImage('fa:table blue');
  169.         
  170.         // define the form fields
  171.         $this->form->setFields(array(2249Reproducao$equipeReproducao$txEclosao$codigo$dataInicioReproducao$dataFinalReproducao$temperatura$climaDia$pesoTotMatFemea$pesoTotMatMacho,
  172.         $qtdeMatFemea$qtdeMatMacho$pesoGeralMatriz$txFecundacao$totalGeralHormonio$reproducao_incubadoras$multi_matrizes$save_button$new_button$list_button));
  173.         
  174.         $buttons = new THBox;
  175.         $buttons->add($save_button);
  176.         $buttons->add($new_button);
  177.         $buttons->add($list_button);
  178.         $row=$tbl_reproducao->addRow();
  179.         $row->class 'tformaction';
  180.         $row->addCell$buttons );
  181.         $container = new TTable;
  182.         $container->style 'width: 80%';
  183.         //$container->addRow()->addCell(new TXMLBreadCrumb('menu.xml', 'SystemUserList'));
  184.         $container->addRow()->addCell($this->form);
  185.         // add the form to the page
  186.         parent::add($container);
  187.        
  188.    }
  189.    public function onSave(){
  190.    
  191.        try{
  192.        
  193.            TTransaction::open('dbwf');
  194.            TTransaction::setLogger(new TLoggerTXT('C:\\log.txt'));
  195.            TTransaction::log('Inserir Reproducao ');
  196.            $this->form->validate();
  197.                               
  198.            $object $this->form->getData('Reproducao');
  199.            $data $this->form->getData();
  200.           
  201.            
  202.            if($data->matrizes)
  203.            {
  204.                
  205.                foreach($data->matrizes as $mat)
  206.                {
  207.                  $matriz = new Matriz($mat->id); 
  208.                  $reproducao_matriz = new RepMatriz();
  209.                  $reproducao_matriz->matriz $matriz;
  210.                  $reproducao_matriz->pesoMatriz $mat->pesoMatriz;
  211.                  $reproducao_matriz->identMatriz $mat->identMatriz;
  212.                  $object->addRepMatriz($reproducao_matriz);  
  213.                  
  214.                }
  215.               
  216.            }
  217.            if($data->reproducao_incubadoras)
  218.            {
  219.                
  220.                $incubadora = new Incubadora($data->reproducao_incubadoras);
  221.                $object->addIncubadora($incubadora);
  222.                   
  223.            
  224.            }
  225.            $data Reproducao::calcular();
  226.            
  227.            $object->store();
  228.            //$object1->store();
  229.            $object->clearParts();
  230.            
  231.            TTransaction::close();
  232.            new TMessage('info','Registro Gravado com sucesso!');
  233.        }
  234.        catch(Exception $e){
  235.        
  236.            new TMessage('error','<b>Erro ao gravar o Registro!</b>'$e->getMessage());
  237.            TTransaction::rollback();
  238.        }
  239.    
  240.    }
  241.    public function onEdit($param)
  242.    {
  243.    
  244.        try
  245.        {
  246.        
  247.            if(isset($param['key'])){
  248.            
  249.                $key $param['key'];
  250.                
  251.                TTransaction::open('dbwf');
  252.                
  253.                $incubadoras = array();
  254.                
  255.                
  256.                $object->matrizes $object->getRepMatrizes();
  257.                
  258.                $this->form->setData($object);
  259.                TTransaction::close();
  260.            }   
  261.        
  262.        }
  263.        catch(Exception $e)
  264.        {
  265.            new TMessage('Erro '.$e->getMessage());
  266.            TTransaction::rollback();
  267.        }
  268.    
  269.    }
  270.     
  271. }
  272. ?>

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (3)


AC

Thiago, se entendi bem o que você quer, é algo como isso:

www.adianti.com.br/framework_files/tutor/index.php?class=POSFormView

Tu seleciona o produto e ele preenche vários campos do formulário.
TS

Isso mesmo Alexandre, é pq preciso fazer alguns cálculos, mas esses cálculos dependem de quais campos serão preenchidos
PD

Nesse exemplo é usada datagrid no lugar de multifield. Se você usar o setExitAction() do seek e pegar o ID do objeto selecionado, com base no Id, você instancia o objeto e pega o resto...

Abs,