Inscrições abertas para nosso Webinar anual Adianti Framework 2024!
Clique aqui para saber mais
TDatagrid não mostra os dados Estou com um formulario com um TSeekButton para selecionar os alunos. Quando seleciono um aluno a TDataGrid não mostra os dados do aluno. Segue o codigo do form: ...
RC
TDatagrid não mostra os dados  
Estou com um formulario com um TSeekButton para selecionar os alunos.
Quando seleciono um aluno a TDataGrid não mostra os dados do aluno.
Segue o codigo do form:
  1. <?php
  2. /**
  3.  * AcompanhamentoFormList Registration
  4.  * @author  <your name here>
  5.  */
  6. class AcompanhamentoFormList extends TPage
  7. {
  8.     protected $form// form
  9.     protected $datagrid// datagrid
  10.     protected $pageNavigation;
  11.     protected $loaded
  12.     
  13.     /**
  14.      * Class constructor
  15.      * Creates the page and the registration form
  16.      */
  17.     function __construct()
  18.     {
  19.         parent::__construct();
  20.         
  21.         // creates the form
  22.         $this->form = new TQuickForm('form_Acompanhamento');
  23.         $this->form->class 'tform'// CSS class
  24.         $this->form->setFormTitle('Acompanhamento'); // define the form title
  25.         
  26.         // create the form fields
  27.         $id                             = new TEntry('id');
  28.         $id->setEditable(FALSE);
  29.         
  30.         $data_cadastro                  = new TDate('data_cadastro');
  31.         $data_cadastro->setMask('dd-mm-yyyy');
  32.         $data_cadastro->setValue(date('d/m/Y'));
  33.         
  34.         $criteria = new TCriteria(new TFilter('ativo''='TRUE));
  35.         $aluno_id = new  ">TDBSeekButton('aluno_id''elainelins''form_Acompanhamento''Aluno''nome''aluno_id''aluno_nome'$criteria);
  36.         $aluno_id->setSize(90); 
  37.         $changeAction = new TAction( array($this'onChangeAction') );        
  38.         $changeAction->setParameter('key'$aluno_id->getValue);
  39.         $aluno_id->setExitAction($changeAction);
  40.                 
  41.            
  42.            /*    
  43.         $aluno_id     = new TEntry('aluno_id');
  44.         $aluno_id->setEditable(FALSE); 
  45.         $aluno_id->setSize(100);
  46.         */
  47.                                                                    
  48.         $aluno_nome = new TEntry('aluno_nome');
  49.         $aluno_nome->setEditable(FALSE);
  50.         $aluno_nome->setSize(250);                 
  51.         
  52.         $peso                            = new TSpinner('peso');
  53.         $peso->setRange(40.0140.00.1); 
  54.         
  55.         $pa                             = new TEntry('pa');
  56.         $abdomen                        = new TEntry('abdomen');
  57.         $quadril                        = new TEntry('quadril');
  58.         $flex                           = new TEntry('flex');
  59.         $observacao                     = new TEntry('observacao');                
  60.         // add the fields
  61.         $this->form->addQuickField('id'$id,  110);
  62.         $this->form->addQuickField('data cadastro'$data_cadastro,  90, new TRequiredValidator );        
  63.         $this->form->addQuickFields('Aluno', array($aluno_id$aluno_nome));       
  64.         $this->form->addQuickField('peso'$peso,  105);
  65.         $this->form->addQuickField('pa'$pa,  110);
  66.         $this->form->addQuickField('abdomen'$abdomen,  110);
  67.         $this->form->addQuickField('quadril'$quadril,  110);
  68.         $this->form->addQuickField('flex'$flex110);
  69.         $this->form->addQuickField('observacao'$observacao360);         
  70.         // create the form actions
  71.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'ico_save.png');
  72.         $this->form->addQuickAction(_t('New'),  new TAction(array($this'onEdit')), 'ico_new.png');
  73.         
  74.         // creates a DataGrid
  75.         $this->datagrid = new TQuickGrid;
  76.         $this->datagrid->setHeight(320);
  77.         
  78.         // creates the datagrid columns
  79.         $id             $this->datagrid->addQuickColumn('id''id''left'100);
  80.         $data_cadastro     $this->datagrid->addQuickColumn('Data Cadastro''data_cadastro''left'100);
  81.         //$aluno_id     = $this->datagrid->addQuickColumn('Aluno', 'aluno_id', 'left', 100);
  82.         //$aluno_nome     = $this->datagrid->addQuickColumn('Aluno', 'aluno_nome', 'left', 200);
  83.         $peso             $this->datagrid->addQuickColumn('peso''peso''left'100);
  84.         $pa             $this->datagrid->addQuickColumn('pa''pa''left'100);
  85.         $abdomen         $this->datagrid->addQuickColumn('abdomen''abdomen''left'100);
  86.         $quadril         $this->datagrid->addQuickColumn('quadril''quadril''left'100);
  87.         $flex             $this->datagrid->addQuickColumn('flex''flex''left'100);
  88.         $observacao     $this->datagrid->addQuickColumn('observacao''observacao''left'200);
  89.         
  90.         // create the datagrid actions
  91.         $edit_action   = new TDataGridAction(array($this'onEdit'));
  92.         $delete_action = new TDataGridAction(array($this'onDelete'));
  93.         
  94.         // add the actions to the datagrid
  95.         $this->datagrid->addQuickAction(_t('Edit'), $edit_action'id''ico_edit.png');
  96.         $this->datagrid->addQuickAction(_t('Delete'), $delete_action'id''ico_delete.png');
  97.         
  98.         // create the datagrid model
  99.         $this->datagrid->createModel();
  100.         
  101.         // creates the page navigation
  102.         $this->pageNavigation = new TPageNavigation;
  103.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  104.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  105. /*        
  106.         // create the datagrid model
  107.         $this->datagrid->createModel();
  108.         
  109.         // creates the page navigation
  110.         $this->pageNavigation = new TPageNavigation;
  111.         $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  112.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  113. */        
  114.         // create the page container
  115.         $container TVBox::pack$this->form$this->datagrid$this->pageNavigation);
  116.         parent::add($container);
  117.     }
  118.     /**
  119.      * method onReload()
  120.      * Load the datagrid with the database objects
  121.      */
  122.     function onReload($param NULL)
  123.     {        
  124.         try
  125.         {                        
  126.             $this->datagrid->clear();
  127.             
  128.             if(isset($param['key']))
  129.             {                                                        
  130.                 // open a transaction with database 'elainelins'
  131.                 TTransaction::open('elainelins');
  132.                 
  133.                 // creates a repository for Acompanhamento
  134.                 $repository = new TRepository('Acompanhamento');
  135.                 $limit 10;
  136.                 // creates a criteria
  137.                 $criteria = new TCriteria;
  138.                 $id $param['key'];                                        
  139.                 $criteria->add(new TFilter('aluno_id''='$id));
  140.                 
  141.                 // default order
  142.                 if (empty($param['order']))
  143.                 {
  144.                     $param['order'] = 'id';
  145.                     $param['direction'] = 'asc';
  146.                 }
  147.                 $criteria->setProperties($param); // order, offset
  148.                 $criteria->setProperty('limit'$limit);
  149.                 
  150.                 if (TSession::getValue('Acompanhamento_filter'))
  151.                 {
  152.                     // add the filter stored in the session to the criteria
  153.                     $criteria->add(TSession::getValue('Acompanhamento_filter'));
  154.                 }
  155.                 
  156.                 // load the objects according to criteria
  157.                 $objects $repository->load($criteria);            
  158. //print_r($objects);die;                                                                
  159.                 if ($objects)
  160.                 {
  161.                     // iterate the collection of active records
  162.                     foreach ($objects as $object)
  163.                     {                     
  164.                         // add the object inside the datagrid
  165.                         $this->datagrid->addItem($object);
  166.                     }                                  
  167.                 }
  168.                 
  169.                 // reset the criteria for record count
  170.                 $criteria->resetProperties();
  171.                 $count$repository->count($criteria);
  172.                 
  173.                 $this->pageNavigation->setCount($count); // count of records
  174.                 $this->pageNavigation->setProperties($param); // order, page
  175.                 $this->pageNavigation->setLimit($limit); // limit
  176.                 
  177.                 // close the transaction
  178.                 TTransaction::close();                                
  179.             }
  180.                         
  181.             $this->loaded true
  182.         }
  183.         catch (Exception $e// in case of exception
  184.         {
  185.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  186.             TTransaction::rollback(); // undo all pending operations
  187.         }
  188.     }
  189.     
  190.     
  191.     /**
  192.      * method onEdit()
  193.      * Executed whenever the user clicks at the edit button da datagrid
  194.      */
  195.     function onEdit($param)
  196.     {
  197.         try
  198.         {
  199.             if (isset($param['key']))
  200.             {
  201.                 // get the parameter $key
  202.                 $key=$param['key'];                
  203.                 // open a transaction with database 'elainelins'
  204.                 TTransaction::open('elainelins');                
  205.                 // instantiates object Aluno
  206.                 $object = new Acompanhamento($key);     
  207.                 
  208.                 //transforma os dados necessarios                
  209.                 $object->data_cadastro      TDate::date2br($object->data_cadastro);                
  210.                                            
  211.                 // fill the form with the active record data
  212.                 $this->form->setData($object);                
  213.                 // close the transaction
  214.                 TTransaction::close();
  215.             }
  216.             else
  217.             {
  218.                 $this->form->clear();
  219.             }
  220.         }
  221.         catch (Exception $e// in case of exception
  222.         {
  223.             // shows the exception error message
  224.             new TMessage('error''<b>Error</b> ' $e->getMessage());            
  225.             // undo all pending operations
  226.             TTransaction::rollback();
  227.         }
  228.     }
  229.     
  230.     /**
  231.      * method onDelete()
  232.      * executed whenever the user clicks at the delete button
  233.      * Ask if the user really wants to delete the record
  234.      */
  235.     function onDelete($param)
  236.     {
  237.         // define the delete action
  238.         $action = new TAction(array($this'Delete'));
  239.         $action->setParameters($param); // pass the key parameter ahead
  240.         
  241.         // shows a dialog to the user
  242.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  243.     }
  244.     
  245.     /**
  246.      * method Delete()
  247.      * Delete a record
  248.      */
  249.     function Delete($param)
  250.     {
  251.         try
  252.         {
  253.             // get the parameter $key
  254.             $key=$param['key'];
  255.             
  256.             TTransaction::open('elainelins'); // open the transaction
  257.             $object = new Acompanhamento($keyFALSE); // instantiates the Active Record
  258.             $object->delete(); // deletes the object
  259.             TTransaction::close(); // close the transaction
  260.             
  261.             $this->onReload$param ); // reload the listing
  262.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted')); // success message
  263.         }
  264.         catch (Exception $e// in case of exception
  265.         {
  266.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  267.             TTransaction::rollback(); // undo all pending operations
  268.         }
  269.     }
  270.     
  271.     /**
  272.      * method onSave()
  273.      * Executed whenever the user clicks at the save button
  274.      */
  275.     function onSave()
  276.     {
  277.         try
  278.         {
  279.             TTransaction::open('elainelins'); // open a transaction with database
  280.             
  281.             // get the form data into an active record Acompanhamento
  282.             $object $this->form->getData('Acompanhamento');
  283.             $this->form->validate(); // form validation
  284.             
  285.             $object->data_cadastro TDate::date2us($object->data_cadastro);
  286.             
  287.             $object->store(); // stores the object
  288.             
  289.             $object->data_cadastro TDate::date2br($object->data_cadastro);
  290.             $this->form->setData($object); // fill the form with the active record data
  291.             TTransaction::close(); // close the transaction
  292.             
  293.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved')); // success message
  294.             $param['key'] = $object->aluno_id;
  295.             $this->onReload($param); // reload the listing 
  296.         }
  297.         catch (Exception $e// in case of exception
  298.         {
  299.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  300.             TTransaction::rollback(); // undo all pending operations
  301.         }
  302.     }
  303.     
  304.     /**
  305.      * method onLoad()
  306.      * 
  307.      */
  308.     public function onLoad($param NULL)
  309.     {
  310.         $this->loaded FALSE
  311.         try
  312.         {           
  313.             if (isset($param['key']))
  314.             {                
  315.                 $key=$param['key']; // get the parameter $key
  316.                 TTransaction::open('elainelins'); // open a transaction with the database
  317.                 $aluno = new Aluno($key); // instantiates the Active Record
  318. //print_r($aluno);die;                              
  319.                 
  320.                 $object = new stdClass;
  321.                 $object->aluno_id   $aluno->id;
  322.                 $object->aluno_nome $aluno->nome
  323.                 $this->form->setData($object);                
  324.                 $this->onReload($param);   
  325.                 TTransaction::close(); // close the transaction                                                                
  326.             }
  327.             else
  328.             {
  329.                 $this->form->clear(); 
  330.                 $this->datagrid->clear();
  331.             }
  332.         }
  333.         catch (Exception $e// in case of exception
  334.         {
  335.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  336.             TTransaction::rollback(); // undo all pending operations
  337.         }
  338.     }
  339.     
  340.     
  341.     public static function onChangeAction($param)
  342.     {    
  343.         $param['key'] = $param['aluno_id'];
  344.         
  345. //print_r($param);die;             
  346.         TApplication::loadPage'AcompanhamentoFormList''onLoad', (array)$param );         
  347.     }
  348.     
  349.     /**
  350.      * method show()
  351.      * Shows the page e seu conteúdo
  352.      */
  353.     function show()
  354.     {                
  355.         // check if the datagrid is already loaded
  356.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  357.         {
  358.             $this->onReloadfunc_get_arg(0) );
  359.         }
  360.                 
  361.         parent::show();
  362.     }
  363. }
  364. ?>


Alguém pode verificar onde está o erro.


Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (1)


WJ

cade o chamamento da class TRecord???

tente usar

  1. <?php
  2.         parent::setDatabase('nome_do_banco');            // defines the database
  3.         parent::setActiveRecord('nome_class_active_record');   // defines the active record
  4.         parent::setDefaultOrder('id''asc');         // defines the default order
  5. ?>