Data desconfigurada na na Datagrid e no formulário Olá pessoal. Alguém poderia me ajudar a resolver dois erros que estou tendo? Criei um formulário de cadastro de consulta, onde no mesmo tem um campo do tipo TDate! Acontece que quando eu salvo e clico no botão "Voltar para a listagem", a data aparece na Datagrid de forma desconfigurada... E se eu carregar o formulário em modo de edição e clicar na tecla F5 para atualizar a página, a ...
RC
Data desconfigurada na na Datagrid e no formulário  
Fechado
Olá pessoal. Alguém poderia me ajudar a resolver dois erros que estou tendo?

Criei um formulário de cadastro de consulta, onde no mesmo tem um campo do tipo TDate! Acontece que quando eu salvo e clico no botão "Voltar para a listagem", a data aparece na Datagrid de forma desconfigurada...

E se eu carregar o formulário em modo de edição e clicar na tecla F5 para atualizar a página, a data no campo fica desconfigurada também!

Vou enviar a imagem das telas e o meu código pra que possam me ajudar!


Meus arquivos:
 
  1. <?php
  2. class SystemAgendaForm extends TStandardForm {
  3. protected $form;
  4. function __construct() {
  5. parent::__construct();
  6. $this->form = new TQuickForm('form_SystemAgenda');
  7. $this->form->setFormTitle('Agenda');
  8. $this->form->class = 'tform';
  9. // defines the database
  10. parent::setDatabase('permission');
  11. // defines the active record
  12. parent::setActiveRecord('SystemAgenda');
  13. 1508 = new TEntry('id');
  14. $exame = new TEntry('exame');
  15. $paciente = new TEntry('paciente');
  16. $dataconsulta = new TDate('dataconsulta');
  17. 1508->setEditable(false);
  18. $dataconsulta->setMask("dd/mm/yyyy");
  19. // add the fields
  20. $this->form->addQuickField('ID', 1508, 50);
  21. $this->form->addQuickField('Exame' . ': ', $exame, 200);
  22. $this->form->addQuickField('Paciente' . ': ', $paciente, 200);
  23. $this->form->addQuickField('Data' . ': ', $dataconsulta, 200);
  24. // validations
  25. $exame->addValidation(_t('Exame'), new TRequiredValidator);
  26. $paciente->addValidation(('Paciente'), new TRequiredValidator);
  27. $dataconsulta->addValidation(('Data'), new TRequiredValidator);
  28. // add form actions
  29. $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'ico_save.png');
  30. $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onEdit')), 'ico_new.png');
  31. $this->form->addQuickAction(_t('Back to the listing'), new TAction(array('SystemAgendaList', 'onReload')), 'ico_datagrid.png');
  32. $container = new TTable;
  33. $container->style = 'width: 80%';
  34. $container->addRow()->addCell(new TXMLBreadCrumb('menu.xml', 'SystemAgendaList'));
  35. $container->addRow()->addCell($this->form);
  36. // add the form to the page
  37. parent::add($container);
  38. }
  39. function onSave() {
  40. try {
  41. // open a transaction with database 'una'
  42. TTransaction::open('permission');
  43. // get the form data into an active record Alunos
  44. $object = $this->form->getData('SystemAgenda');
  45. // form validation
  46. $this->form->validate();
  47. // stores the object
  48. $object->dataconsulta = TDate::date2us($object->dataconsulta);
  49. $object->store();
  50. // set the data back to the form
  51. //$this->form->setData($object);
  52. TTransaction::close();
  53. // shows the success message
  54. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  55. $this->form->clear();
  56. // reload the listing
  57. } catch (Exception $e) { // in case of exception
  58. // shows the exception error message
  59. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  60. // undo all pending operations
  61. TTransaction::rollback();
  62. }
  63. }
  64. function onEdit($param) {
  65. try {
  66. if (isset($param['key'])) {
  67. $key = $param['key'];
  68. TTransaction::open('permission');
  69. $object = new SystemAgenda($key);
  70. $object->dataconsulta = TDate::date2br($object->dataconsulta);
  71. $object->store();
  72. $this->form->setData($object);
  73. TTransaction::close();
  74. } else {
  75. $this->form->clear();
  76. }
  77. } catch (Exception $e) {
  78. new TMessage('error', 'Error ' . $e->getMessage());
  79. TTransaction::rollback();
  80. }
  81. }
  82. }
  83. ?>




 
  1. <?php
  2. /**
  3. * SystemAgendaList Listing
  4. * @author <your name here>
  5. */
  6. class SystemAgendaList extends TPage {
  7. private $form; // registration form
  8. private $datagrid; // listing
  9. private $pageNavigation;
  10. private $loaded;
  11. /**
  12. * Class constructor
  13. * Creates the page, the form and the listing
  14. */
  15. public function __construct() {
  16. parent::__construct();
  17. // creates the form
  18. $this->form = new TForm('form_search_SystemAgenda');
  19. $this->form->class = 'tform';
  20. // creates a table
  21. $table = new TTable;
  22. $table->style = 'width:100%';
  23. $table->addRowSet(new TLabel('Agenda'), '')->class = 'tformtitle';
  24. // add the table inside the form
  25. $this->form->add($table);
  26. // create the form fields
  27. $exame = new TEntry('exame');
  28. $exame->setValue(TSession::getValue('SystemAgenda_name'));
  29. $paciente = new TEntry('paciente');
  30. $paciente->setValue(TSession::getValue('SystemAgenda_control'));
  31. // add rows for the filter fields
  32. $row = $table->addRowSet(new TLabel('Exame' . ': '), $exame);
  33. $row = $table->addRowSet(new TLabel('Paciente' . ': '), $paciente);
  34. // create two action buttons to the form
  35. $find_button = new TButton('find');
  36. $new_button = new TButton('new');
  37. // define the button actions
  38. $find_button->setAction(new TAction(array($this, 'onSearch')), _t('Find'));
  39. $find_button->setImage('ico_find.png');
  40. $new_button->setAction(new TAction(array('SystemAgendaForm', 'onEdit')), _t('New'));
  41. $new_button->setImage('ico_new.png');
  42. // define wich are the form fields
  43. $this->form->setFields(array($exame, $paciente, $find_button, $new_button));
  44. $container = new THBox;
  45. $container->add($find_button);
  46. $container->add($new_button);
  47. $row = $table->addRow();
  48. $row->class = 'tformaction';
  49. $cell = $row->addCell($container);
  50. $cell->colspan = 2;
  51. // creates a DataGrid
  52. $this->datagrid = new TDataGrid;
  53. $this->datagrid->style = 'width: 100%';
  54. $this->datagrid->setHeight(320);
  55. // creates the datagrid columns
  56. 1508 = new TDataGridColumn('id', 'ID', 'right');
  57. $exame = new TDataGridColumn('exame', 'Exame', 'left');
  58. $paciente = new TDataGridColumn('paciente', 'Paciente', 'left');
  59. $data_consulta = new TDataGridColumn('dataconsulta', 'Data Consulta', 'left', 100);
  60. // add the columns to the DataGrid
  61. $this->datagrid->addColumn(1508);
  62. $this->datagrid->addColumn($exame);
  63. $this->datagrid->addColumn($paciente);
  64. $this->datagrid->addColumn($data_consulta);
  65. // creates the datagrid column actions
  66. $order_id = new TAction(array($this, 'onReload'));
  67. $order_id->setParameter('order', 'id');
  68. 1508->setAction($order_id);
  69. $order_exame = new TAction(array($this, 'onReload'));
  70. $order_exame->setParameter('order', 'exame');
  71. $exame->setAction($order_exame);
  72. $order_paciente = new TAction(array($this, 'onReload'));
  73. $order_paciente->setParameter('order', 'paciente');
  74. $paciente->setAction($order_paciente);
  75. $order_data_consulta = new TAction(array($this, 'onReload'));
  76. $order_data_consulta->setParameter('order', 'dataconsulta');
  77. $data_consulta->setAction($order_paciente);
  78. // inline editing
  79. $exame_edit = new TDataGridAction(array($this, 'onInlineEdit'));
  80. $exame_edit->setField('id');
  81. $exame->setEditAction($exame_edit);
  82. $paciente_edit = new TDataGridAction(array($this, 'onInlineEdit'));
  83. $paciente_edit->setField('id');
  84. $paciente->setEditAction($paciente_edit);
  85. // creates two datagrid actions
  86. $action1 = new TDataGridAction(array('SystemAgendaForm', 'onEdit'));
  87. $action1->setLabel(_t('Edit'));
  88. $action1->setImage('ico_edit.png');
  89. $action1->setField('id');
  90. $action2 = new TDataGridAction(array($this, 'onDelete'));
  91. $action2->setLabel(_t('Delete'));
  92. $action2->setImage('ico_delete.png');
  93. $action2->setField('id');
  94. // add the actions to the datagrid
  95. $this->datagrid->addAction($action1);
  96. $this->datagrid->addAction($action2);
  97. // create the datagrid model
  98. $this->datagrid->createModel();
  99. // creates the page navigation
  100. $this->pageNavigation = new TPageNavigation;
  101. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  102. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  103. // creates the page structure using a table
  104. $table = new TTable;
  105. $table->style = 'width: 80%';
  106. $table->addRow()->addCell(new TXMLBreadCrumb('menu.xml', __CLASS__));
  107. $table->addRow()->addCell($this->form);
  108. $table->addRow()->addCell($this->datagrid);
  109. $table->addRow()->addCell($this->pageNavigation);
  110. // add the table inside the page
  111. parent::add($table);
  112. }
  113. /**
  114. * method onInlineEdit()
  115. * Inline record editing
  116. * @param $param Array containing:
  117. * key: object ID value
  118. * field name: object attribute to be updated
  119. * value: new attribute content
  120. */
  121. function onInlineEdit($param) {
  122. try {
  123. // get the parameter $key
  124. $field = $param['field'];
  125. $key = $param['key'];
  126. $value = $param['value'];
  127. // open a transaction with database 'permission'
  128. TTransaction::open('permission');
  129. // instantiates object SystemAgenda
  130. $object = new SystemAgenda($key);
  131. // deletes the object from the database
  132. $object->{$field} = $value;
  133. $object->store();
  134. // close the transaction
  135. TTransaction::close();
  136. // reload the listing
  137. $this->onReload($param);
  138. // shows the success message
  139. new TMessage('info', "Registro Atualizado com Sucesso!");
  140. } catch (Exception $e) { // in case of exception
  141. // shows the exception error message
  142. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  143. // undo all pending operations
  144. TTransaction::rollback();
  145. }
  146. }
  147. /**
  148. * method onSearch()
  149. * Register the filter in the session when the user performs a search
  150. */
  151. function onSearch() {
  152. // get the search form data
  153. $data = $this->form->getData();
  154. TSession::setValue('SystemProgram_name_filter', NULL);
  155. TSession::setValue('SystemAgenda_name', '');
  156. TSession::setValue('SystemProgram_control_filter', NULL);
  157. TSession::setValue('SystemAgenda_control', '');
  158. TSession::setValue('AlunosListPess_filter_datanascimento', NULL);
  159. // check if the user has filled the form
  160. if ($data->exame) {
  161. // creates a filter using what the user has typed
  162. $filter = new TFilter('exame', 'like', "%{$data->exame}%");
  163. // stores the filter in the session
  164. TSession::setValue('SystemProgram_name_filter', $filter);
  165. TSession::setValue('SystemAgenda_name', $data->exame);
  166. }
  167. if ($data->paciente) {
  168. // creates a filter using what the user has typed
  169. $filter = new TFilter('paciente', 'like', "%{$data->paciente}%");
  170. // stores the filter in the session
  171. TSession::setValue('SystemProgram_control_filter', $filter);
  172. TSession::setValue('SystemAgenda_control', $data->paciente);
  173. }
  174. if (isset($data->dataconsulta) AND ( $data->dataconsulta)) {
  175. $filter = new TFilter('dataconsula', 'like', "%{$data->dataconsula}%"); // create the filter
  176. TSession::setValue('AlunosListPess_filter_dt_nascimento', $filter); // stores the filter in the session
  177. }
  178. if (isset($data->dataconsulta) AND ( $data->dataconsulta)) {
  179. $filter = new TFilter('dataconsulta', 'like', "%{$data->dataconsulta}%"); // create the filter
  180. TSession::setValue('AlunosListPess_filter_datanascimento', $filter); // stores the filter in the session
  181. }
  182. // fill the form with data again
  183. $this->form->setData($data);
  184. $param = array();
  185. $param['offset'] = 0;
  186. $param['first_page'] = 1;
  187. $this->onReload($param);
  188. }
  189. /**
  190. * method onReload()
  191. * Load the datagrid with the database objects
  192. */
  193. function onReload($param = NULL) {
  194. try {
  195. // open a transaction with database 'permission'
  196. TTransaction::open('permission');
  197. // creates a repository for SystemProgram
  198. $repository = new TRepository('SystemAgenda');
  199. $limit = 5;
  200. // creates a criteria
  201. $criteria = new TCriteria;
  202. if (!isset($param['order'])) {
  203. $param['order'] = 'id';
  204. $param['direction'] = 'asc';
  205. }
  206. $criteria->setProperties($param); // order, offset
  207. $criteria->setProperty('limit', $limit);
  208. if (TSession::getValue('SystemProgram_name_filter')) {
  209. // add the filter stored in the session to the criteria
  210. $criteria->add(TSession::getValue('SystemProgram_name_filter'));
  211. }
  212. if (TSession::getValue('SystemProgram_control_filter')) {
  213. // add the filter stored in the session to the criteria
  214. $criteria->add(TSession::getValue('SystemProgram_control_filter'));
  215. }
  216. if (TSession::getValue('AlunosListPess_filter_dataconsulta')) {
  217. $criteria->add(TSession::getValue('AlunosListPess_filter_datanascimento')); // add the session filter
  218. }
  219. // load the objects according to criteria
  220. $objects = $repository->load($criteria);
  221. $this->datagrid->clear();
  222. if ($objects) {
  223. // iterate the collection of active records
  224. foreach ($objects as $object) {
  225. // add the object inside the datagrid
  226. $object->dataconsulta = TDate::date2br($object->dataconsulta);
  227. $this->datagrid->addItem($object);
  228. }
  229. }
  230. // reset the criteria for record count
  231. $criteria->resetProperties();
  232. $count = $repository->count($criteria);
  233. $this->pageNavigation->setCount($count); // count of records
  234. $this->pageNavigation->setProperties($param); // order, page
  235. $this->pageNavigation->setLimit($limit); // limit
  236. // close the transaction
  237. TTransaction::close();
  238. $this->loaded = true;
  239. } catch (Exception $e) { // in case of exception
  240. // shows the exception error message
  241. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  242. // undo all pending operations
  243. TTransaction::rollback();
  244. }
  245. }
  246. /**
  247. * method onDelete()
  248. * executed whenever the user clicks at the delete button
  249. * Ask if the user really wants to delete the record
  250. */
  251. function onDelete($param) {
  252. // define the delete action
  253. $action = new TAction(array($this, 'Delete'));
  254. $action->setParameters($param); // pass the key parameter ahead
  255. // shows a dialog to the user
  256. new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  257. }
  258. /**
  259. * method Delete()
  260. * Delete a record
  261. */
  262. function Delete($param) {
  263. try {
  264. // get the parameter $key
  265. $key = $param['key'];
  266. // open a transaction with database 'permission'
  267. TTransaction::open('permission');
  268. // instantiates object SystemProgram
  269. $object = new SystemAgenda($key);
  270. // deletes the object from the database
  271. $object->delete();
  272. // close the transaction
  273. TTransaction::close();
  274. // reload the listing
  275. $this->onReload($param);
  276. // shows the success message
  277. new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'));
  278. } catch (Exception $e) { // in case of exception
  279. // shows the exception error message
  280. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  281. // undo all pending operations
  282. TTransaction::rollback();
  283. }
  284. }
  285. /**
  286. * method show()
  287. * Shows the page
  288. */
  289. function show() {
  290. // check if the datagrid is already loaded
  291. if (!$this->loaded) {
  292. $this->onReload(func_get_arg(0));
  293. }
  294. parent::show();
  295. }
  296. }
  297. ?>




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)


MC

Existe um forum anterior que trata de um problema parecido.

www.adianti.com.br/forum/pt/view_1501?formatacao-campo-tdate-para-fo

Boa sorte.