Lançado Adianti Framework 7.6!
Clique aqui para saber mais
tDBSeekButton "customizado" nao traz seleção Boom dia, Crieu este tdbseek customizado, mas o select nao esta funcionando, o que estou errando? ...
EN
tDBSeekButton "customizado" nao traz seleção  
Boom dia,

Crieu este tdbseek customizado, mas o select nao esta funcionando, o que estou errando?

  1. <?php
  2. /**
  3.  * City Seek
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class RacasViewSeek extends TWindow {
  13.     private $form;      // form
  14.     private $datagrid;  // datagrid
  15.     private $pageNavigation;
  16.     private $loaded;
  17.     /**
  18.      * Class constructor
  19.      * Creates the page, the search form and the listing
  20.      */
  21.     public function __construct() {
  22.         parent::__construct();
  23.         parent::setSize(800500);
  24.         parent::setTitle('Pesquisa Raças');
  25.         new TSession;
  26.         // creates the form
  27.         $this->form = new TQuickForm('form_search_racas');
  28.         $this->form->class 'tform';
  29.         $this->form->setFormTitle('Raças');
  30.         // create the form fields
  31.         $descricao = new TEntry('descricao');
  32.         $descricao->setValue(Tsession::getValue('descricao'));
  33.         $banho = new TEntry('banho');
  34.         $banho->setNumericMask(2',''.'TRUE);
  35.         $banho->setValue(Tsession::getValue('banho'));
  36.         
  37.         $tosa = new TEntry('tosa');
  38.         $tosa->setNumericMask(2',''.'TRUE);
  39.         $tosa->setValue(Tsession::getValue('tosa'));
  40.         $higienica = new TEntry('higienica');
  41.         $higienica->setNumericMask(2',''.'TRUE);
  42.         $higienica->setValue(Tsession::getValue('higienica'));
  43.         $tesoura = new TEntry('tesoura');
  44.         $tesoura->setNumericMask(2',''.'TRUE);
  45.         $tesoura->setValue(Tsession::getValue('tesoura'));
  46.         // add the form fields
  47.         $this->form->addQuickField('Raça'$descricao200);
  48.         // define the form action
  49.         $this->form->addQuickAction('Filtro', new TAction(array($this'onSearch')), 'ico_find.png');
  50.         // creates a DataGrid
  51.         $this->datagrid = new TQuickGrid;
  52.         $this->datagrid->style 'width: 100%';
  53.         $this->datagrid->setHeight(300);
  54.         //$this->datagrid->enablePopover('Raça', 'Raça {descricao}');
  55.         // creates the datagrid columns
  56.         $this->datagrid->addQuickColumn('Id''id''right'15);
  57.         $this->datagrid->addQuickColumn('Raça''descricao''left'30);
  58.         $this->datagrid->addQuickColumn('Banho''banho''left'15);
  59.         $this->datagrid->addQuickColumn('Tosa''tosa''left'15);
  60.         $this->datagrid->addQuickColumn('Higienica''higienica''left'15);
  61.         $this->datagrid->addQuickColumn('Tesoura''tesoura''left'15);
  62.         // creates two datagrid actions
  63.         $this->datagrid->addQuickAction('Select', new TDataGridAction(array($this'onSelect')), 'id''ico_apply.png');
  64.         // create the datagrid model
  65.         $this->datagrid->createModel();
  66.         // creates the page navigation
  67.         $this->pageNavigation = new TPageNavigation;
  68.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  69.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  70.         // creates a container
  71.         $container = new TVBox;
  72.         $container->style 'width: 100%';
  73.         $container->add($this->form);
  74.         $container->add($this->datagrid);
  75.         $container->add($this->pageNavigation);
  76.         // add the container inside the page
  77.         parent::add($container);
  78.     }
  79.    
  80.     /**
  81.      * method onSearch()
  82.      * Register the filter in the session when the user performs a search
  83.      */
  84.     function onSearch() {
  85.         // get the search form data
  86.         $data $this->form->getData();
  87.         // check if the user has filled the form
  88.         if (isset($data->descricao)) {
  89.             // creates a filter using what the user has typed
  90.             $filter = new TFilter('descricao''like'"%{$data->descricao}%");
  91.             // stores the filter in the session
  92.             TSession::setValue('racas_filter'$filter);
  93.             TSession::setValue('racas_descricao'$data->descricao);
  94.             // fill the form with data again
  95.             $this->form->setData($data);
  96.         }
  97.         // redefine the parameters for reload method
  98.         $param = array();
  99.         $param['offset'] = 0;
  100.         $param['first_page'] = 1;
  101.         $this->onReload($param);
  102.     }
  103.     /**
  104.      * Load the datagrid with the database objects
  105.      */
  106.     function onReload($param NULL) {
  107.         try {
  108.             // open a transaction with database 'samples'
  109.             TTransaction::open('racas');
  110.             // creates a repository for City
  111.             $repository = new TRepository('Racas');
  112.             $limit 10;
  113.             // creates a criteria
  114.             $criteria = new TCriteria;
  115.             // default order
  116.             if (!isset($param['order'])) {
  117.                 $param['order'] = 'descricao';
  118.                 $param['direction'] = 'asc';
  119.             }
  120.             $criteria->setProperties($param); // order, offset
  121.             $criteria->setProperty('limit'$limit);
  122.             if (TSession::getValue('racas_filter')) {
  123.                 // add the filter stored in the session to the criteria
  124.                 $criteria->add(TSession::getValue('racas_filter'));
  125.             }
  126.             // load the objects according to the criteria
  127.             $racas $repository->load($criteria);
  128.             $this->datagrid->clear();
  129.             if ($racas) {
  130.                 foreach ($racas as $raca) {
  131.                     // add the object inside the datagrid
  132.                     $this->datagrid->addItem($raca);
  133.                 }
  134.             }
  135.             // reset the criteria for record count
  136.             $criteria->resetProperties();
  137.             $count $repository->count($criteria);
  138.             $this->pageNavigation->setCount($count); // count of records
  139.             $this->pageNavigation->setProperties($param); // order, page
  140.             $this->pageNavigation->setLimit($limit); // limit
  141.             // close the transaction
  142.             TTransaction::close();
  143.             $this->loaded true;
  144.         } catch (Exception $e) { // in case of exception
  145.             // shows the exception error message
  146.             new TMessage('error'$e->getMessage());
  147.             // undo all pending operations
  148.             TTransaction::rollback();
  149.         }
  150.     }
  151.     /**
  152.      * Executed when the user chooses the record
  153.      */
  154.     public function onSelect($param) {
  155.         try {
  156.             $key $param['key'];
  157.             TTransaction::open('Racas');
  158.             // load the active record
  159.             $raca = new Racas($key);
  160.             // closes the transaction
  161.             TTransaction::close();
  162.             $object = new StdClass;
  163.             $object->id        $raca->id;
  164.             $object->descricao $raca->descricao;
  165.             TForm::sendData('form_seek_racas'$object);
  166.             parent::closeWindow(); // closes the window
  167.         } catch (Exception $e) { // em caso de exceção
  168.             // clear fields
  169.             $object = new StdClass;
  170.             $object->id '';
  171.             $object->descricao '';
  172.             TForm::sendData('form_seek_racas'$object);
  173.             // undo pending operations
  174.             TTransaction::rollback();
  175.         }
  176.     }
  177.     /**
  178.      * Shows the page
  179.      */
  180.     function show() {
  181.         // if the datagrid was not loaded yet
  182.         if (!$this->loaded) {
  183.             $this->onReload();
  184.         }
  185.         parent::show();
  186.     }
  187. }
  188. ?>

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 (2)


NR

Eduardo, em primeiro lugar habilite os erros do php para garantir que não seja nenhum problema nesse sentido.

A função que envia os dados para o formulário é a TForm::sendData, sendo que o primeiro parâmetro corresponde ao nome do formulário que vai receber as informações. Confirme se o nome do formulário é mesmo "form_seek_racas".
EN

Nataniel Rabaioli:, valeuuuuuuu era isso!!!