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


Alguém pode verificar onde está o erro.


Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework 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. ?>