Formulário Mestre/Detalhe Olá Pessoal, Estou recebendo esta mensagem quando tento salvar um registro no Formulário Mestre/Detalhe Alguém sabe me dizer o problema ? Agradeço a ajuda Abaixo segue o código todo do CarregamentoForm.class.php ...
IU
Formulário Mestre/Detalhe  
Olá Pessoal,

Estou recebendo esta mensagem quando tento salvar um registro no Formulário Mestre/Detalhe

Alguém sabe me dizer o problema ?

Agradeço a ajuda

Abaixo segue o código todo do CarregamentoForm.class.php

 
  1. <?php
  2. /**
  3. * CarregamentoForm Master/Detail
  4. * @author <your name here>
  5. */
  6. class CarregamentoForm extends TPage
  7. {
  8. protected $form; // form
  9. protected $table_details;
  10. protected $detail_row;
  11. /**
  12. * Class constructor
  13. * Creates the page and the registration form
  14. */
  15. function __construct($param)
  16. {
  17. parent::__construct($param);
  18. // creates the form
  19. $this->form = new TForm('form_Carregamento');
  20. $this->form->class = 'tform'; // CSS class
  21. $table_master = new TTable;
  22. $table_master->width = '100%';
  23. $table_master->addRowSet( new TLabel('Carregamento'), '', '')->class = 'tformtitle';
  24. // add a table inside form
  25. $table_general = new TTable;
  26. $table_general->width = '100%';
  27. $frame_general = new TFrame;
  28. $frame_general->class = 'tframe tframe-custom';
  29. $frame_general->setLegend('Carregamento');
  30. $frame_general->style = 'background:whiteSmoke';
  31. $frame_general->add($table_general);
  32. $frame_details = new TFrame;
  33. $frame_details->class = 'tframe tframe-custom';
  34. $frame_details->style = 'background:whiteSmoke';
  35. $frame_details->setLegend('CarregamentoImportacao');
  36. $table_master->addRow()->addCell( $frame_general )->colspan=2;
  37. $row = $table_master->addRow();
  38. $row->addCell( $frame_details );
  39. $this->form->add($table_master);
  40. // master fields
  41. $carregamento_id = new TEntry('carregamento_id');
  42. $dt_saida_porto = new TDate('dt_saida_porto');
  43. $dt_previsao = new TDate('dt_previsao');
  44. $transportadora = new TCombo('transportadora');
  45. $transportadorai = array();
  46. $transportadorai['I'] = 'ITRI';
  47. $transportadorai['R'] = 'RODOTECH';
  48. $transportadora->addItems($transportadorai);
  49. $modal = new TCombo('modal');
  50. $modali = array();
  51. $modali['M'] = 'MULTIMODAL';
  52. $modali['R'] = 'RODOVIÁRIO';
  53. $modal->addItems($modali);
  54. $status = new TCombo('status');
  55. $statusi = array();
  56. $statusi['S'] = 'SIM';
  57. $statusi['N'] = 'NÃO';
  58. $status->addItems($statusi);
  59. $motorista_id = new TDBCombo('motorista_id', 'itisu420_sistema2', 'Motorista', 'motorista_id', '{motorista_nome} - {cnh_validade}');
  60. $cavalo_id = new TDBCombo('cavalo_id', 'itisu420_sistema2', 'Cavalo', 'cavalo_id', '{cavalo} - {cor} - {ano}');
  61. $carreta_id = new TDBCombo('carreta_id', 'itisu420_sistema2', 'Carreta', 'carreta_id', '{carreta} - {cor} - {ano}');
  62. // máscaras
  63. $dt_saida_porto->setMask('dd/mm/yyyy');
  64. $dt_previsao->setMask('dd/mm/yyyy');
  65. $transportadora->enableSearch();
  66. $modal->enableSearch();
  67. $status->enableSearch();
  68. $motorista_id->enableSearch();
  69. $cavalo_id->enableSearch();
  70. $carreta_id->enableSearch();
  71. // sizes
  72. $carregamento_id->setSize('200');
  73. $dt_saida_porto->setSize('200');
  74. $dt_previsao->setSize('200');
  75. $transportadora->setSize('200');
  76. $modal->setSize('200');
  77. $status->setSize('200');
  78. $motorista_id->setSize('300');
  79. $cavalo_id->setSize('300');
  80. $carreta_id->setSize('300');
  81. if (!empty($carregamento_id))
  82. {
  83. $carregamento_id->setEditable(FALSE);
  84. }
  85. // add form fields to be handled by form
  86. $this->form->addField($carregamento_id);
  87. $this->form->addField($dt_saida_porto);
  88. $this->form->addField($dt_previsao);
  89. $this->form->addField($transportadora);
  90. $this->form->addField($modal);
  91. $this->form->addField($status);
  92. $this->form->addField($motorista_id);
  93. $this->form->addField($cavalo_id);
  94. $this->form->addField($carreta_id);
  95. // add form fields to the screen
  96. $table_general->addRowSet( new TLabel('Carregamento Id'), $carregamento_id );
  97. $table_general->addRowSet( new TLabel('Dt Saida Porto'), $dt_saida_porto );
  98. $table_general->addRowSet( new TLabel('Dt Previsao'), $dt_previsao );
  99. $table_general->addRowSet( new TLabel('Transportadora'), $transportadora );
  100. $table_general->addRowSet( new TLabel('Modal'), $modal );
  101. $table_general->addRowSet( new TLabel('Status'), $status );
  102. $table_general->addRowSet( new TLabel('Motorista Id'), $motorista_id );
  103. $table_general->addRowSet( new TLabel('Cavalo Id'), $cavalo_id );
  104. $table_general->addRowSet( new TLabel('Carreta Id'), $carreta_id );
  105. // detail
  106. $this->table_details = new TTable;
  107. $this->table_details-> width = '100%';
  108. $frame_details->add($this->table_details);
  109. $this->table_details->addSection('thead');
  110. $row = $this->table_details->addRow();
  111. // detail header
  112. $row->addCell( new TLabel('Importacao Id') );
  113. // create an action button (save)
  114. $save_button=new TButton('save');
  115. $save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
  116. $save_button->setImage('fa:circle red fa-lg');//('ico_save.png');
  117. // create an new button (edit with no parameters)
  118. $new_button=new TButton('new');
  119. $new_button->setAction(new TAction(array($this, 'onClear')), _t('New'));
  120. $new_button->setImage('fa:file fa-lg');//('ico_new.png');
  121. // define form fields
  122. $this->form->addField($save_button);
  123. $this->form->addField($new_button);
  124. $table_master->addRowSet( array($save_button, $new_button), '', '')->class = 'tformaction'; // CSS class
  125. $this->detail_row = 0;
  126. // create the page container
  127. $container = new TVBox;
  128. $container->style = 'width: 100%';
  129. //$container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  130. $container->add($this->form);
  131. parent::add($container);
  132. }
  133. /**
  134. * Executed whenever the user clicks at the edit button da datagrid
  135. */
  136. function onEdit($param)
  137. {
  138. try
  139. {
  140. TTransaction::open('itisu420_sistema2');
  141. if (isset($param['key']))
  142. {
  143. $key = $param['key'];
  144. $object = new Carregamento($key);
  145. $object->dt_saida_porto = TDate::date2br($object->dt_saida_porto);
  146. $object->dt_previsao = TDate::date2br($object->dt_previsao);
  147. $this->form->setData($object);
  148. $items = CarregamentoImportacao::where('carregamento_id', '=', $key)->load();
  149. $this->table_details->addSection('tbody');
  150. if ($items)
  151. {
  152. foreach($items as $item )
  153. {
  154. $this->addDetailRow($item);
  155. }
  156. // create add button
  157. $add = new TButton('clone');
  158. $add->setLabel('Adicionar');
  159. $add->setImage('fa:plus');
  160. $add->addFunction('ttable_clone_previous_row(this)');
  161. // add buttons in table
  162. $this->table_details->addRowSet([$add]);
  163. }
  164. else
  165. {
  166. $this->onClear($param);
  167. }
  168. TTransaction::close(); // close transaction
  169. }
  170. }
  171. catch (Exception $e) // in case of exception
  172. {
  173. new TMessage('error', $e->getMessage());
  174. TTransaction::rollback();
  175. }
  176. }
  177. /**
  178. * Add detail row
  179. */
  180. public function addDetailRow($item)
  181. {
  182. $uniqid = mt_rand(1000000, 9999999);
  183. // create fields
  184. $importacao_id = new TDBMultiSearch('importacao_id[]', 'itisu420_sistema2', 'Importacao', 'importacao_id', 'conteiner');
  185. //$importacao_id = new TEntry('importacao_id[]');
  186. $importacao_id->setMaxSize(1);
  187. $importacao_id->setMinLength(1);
  188. // set id's
  189. $importacao_id->setId('importacao_id_'.$uniqid);
  190. // set sizes
  191. $importacao_id->setSize('50%');
  192. // set mask
  193. $importacao_id->setMask('{conteiner} ({importacao_id})');
  194. // set row counter
  195. $importacao_id->{'data-row'} = $this->detail_row;
  196. // set value
  197. if (!empty($item->importacao_id)) { $importacao_id->setValue( $item->importacao_id ); }
  198. // create delete button
  199. $del = new TImage('fa:ban red fa-lg');
  200. $del->onclick = 'ttable_remove_row(this)';
  201. $row = $this->table_details->addRow();
  202. // add cells
  203. $row->addCell($importacao_id);
  204. $row->addCell( $del );
  205. $row->{'data-row'} = $this->detail_row;
  206. // add form field
  207. $this->form->addField($importacao_id);
  208. $this->detail_row ++;
  209. }
  210. /**
  211. * Clear form
  212. */
  213. public function onClear($param)
  214. {
  215. $this->table_details->addSection('tbody');
  216. $this->addDetailRow( new stdClass );
  217. // create add button
  218. $add = new TButton('clone');
  219. $add->setLabel('Adicionar');
  220. $add->setImage('fa:plus');
  221. $add->addFunction('ttable_clone_previous_row(this)');
  222. // add buttons in table
  223. $this->table_details->addRowSet([$add]);
  224. }
  225. /**
  226. * Save the Carregamento and the CarregamentoImportacao's
  227. */
  228. public static function onSave($param)
  229. {
  230. try
  231. {
  232. TTransaction::open('itisu420_sistema2');
  233. $id = (int) $param['carregamento_id'];
  234. $master = new Carregamento;
  235. $master->fromArray( $param);
  236. $master->dt_saida_porto = TDate::date2us($master->dt_saida_porto);
  237. $master->dt_previsao = TDate::date2us($master->dt_previsao);
  238. $master->store(); // save master object
  239. // delete details
  240. CarregamentoImportacao::where('carregamento_id', '=', $master->carregamento_id)->delete();
  241. if( !empty($param['importacao_id']) AND is_array($param['importacao_id']) )
  242. {
  243. foreach( $param['importacao_id'] as $row => $importacao_id)
  244. {
  245. if (!empty($importacao_id))
  246. {
  247. $detail = new CarregamentoImportacao;
  248. $detail->carregamento_id = $master->carregamento_id;
  249. $detail->importacao_id = $param['importacao_id'][$row];
  250. $detail->store();
  251. }
  252. }
  253. }
  254. $data = new stdClass;
  255. $data->carregamento_id = $master->carregamento_id;
  256. $master->dt_saida_porto = TDate::date2br($master->dt_saida_porto);
  257. $master->dt_previsao = TDate::date2br($master->dt_previsao);
  258. TForm::sendData('form_Carregamento', $data);
  259. TTransaction::close(); // close the transaction
  260. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  261. }
  262. catch (Exception $e) // in case of exception
  263. {
  264. new TMessage('error', $e->getMessage());
  265. TTransaction::rollback();
  266. }
  267. }
  268. }

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


IU

Em anexo está a mensagem de erro.
NR

Erro do banco de dados. Você chegou a exibir os sqls que estão sendo gerados para analisar?
IU

Oi Nataniel, Vou verificar

com o sql_dump já consigo ver onde se encontra o problema ?
IU

Segue var_dump:
 
  1. <?php
  2. C:\wamp64\www\itisu420\sistema2\app\control\carregamento\CarregamentoForm.class.php:291:object(Carregamento)[7] private 'carreta' => null private 'cavalo' => null private 'motorista' => null private 'carregamento_importacaos' => null protected 'data' => array (size=9) 'carregamento_id' => string '1' (length=1) 'dt_saida_porto' => string '01/06/2017' (length=10) 'dt_previsao' => string '02/06/2017' (length=10) 'transportadora' => string 'R' (length=1) 'modal' => string 'R' (length=1) 'status' => string 'S' (length=1) 'motorista_id' => string '1' (length=1) 'cavalo_id' => string '2' (length=1) 'carreta_id' => string '2' (length=1) protected 'vdata' => null protected 'attributes' => array (size=8) 0 => string 'dt_saida_porto' (length=14) 1 => string 'dt_previsao' (length=11) 2 => string 'transportadora' (length=14) 3 => string 'modal' (length=5) 4 => string 'status' (length=6) 5 => string 'motorista_id' (length=12) 6 => string 'cavalo_id' (length=9) 7 => string 'carreta_id' (length=10)
  3. ?>
NR

Me refiro ao retorno do sql:
 
  1. <?php
  2. TTransaction::setLogger(new TLoggerSTD());
  3. ?>