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

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)      => string 'dt_saida_porto' (length=14)      => string 'dt_previsao' (length=11)      => string 'transportadora' (length=14)      => string 'modal' (length=5)      => string 'status' (length=6)      => string 'motorista_id' (length=12)      => string 'cavalo_id' (length=9)      => string 'carreta_id' (length=10)
  3. ?>
NR

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