Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TDBSeekButton Customizado para um table Ola, Tenho um table montado para meus itens de produtos vendidos, estou tentando alimenta-lo usando um TseekButton, mas não estou conseguindo utilizar ele com variaveis vetor, alguem teria uma luz? ...
EN
TDBSeekButton Customizado para um table  
Ola,

Tenho um table montado para meus itens de produtos vendidos, estou tentando alimenta-lo usando um TseekButton, mas não estou conseguindo utilizar ele com variaveis vetor, alguem teria uma luz?

  1. <?php
  1. <?php
  2. class OServicosViewForm extends TPage {
  3.     private $form;
  4.     /**
  5.      * Constructor
  6.      */
  7.     public function __construct() {
  8.         parent::__construct();
  9.         // create form and table container
  10.         $this->form = new TForm;
  11.         $table = new TTable;
  12.         $table->addSection('thead');
  13.         $table->addRowSet(new TLabel('<b>Prod.ID</b>'), new TLabel('<b>Prod.Descr</b>'), new TLabel('<b>Qtdade</b>'), new TLabel('<b>V.Unit</b>'), new TLabel('<b>Total</b>'));
  14.         $this->form->add($table);
  15.         $table->addSection('tbody');
  16.         $produto_id = new TSeekButton('produto_id[]');
  17.         $produto_id->setSize(120);
  18.         
  19.         $obj = new ProdutosViewSeek;
  20.         $action = new TAction(array($obj'onReload'));
  21.         $produto_id->setAction($action);
  22.         $produto_ds = new TEntry('produto_ds[]');
  23.         $produto_ds->setSize(120);
  24.         $produto_ds->setEditable(false);
  25.         $produto_qt = new TEntry('produto_qt[]');
  26.         $produto_qt->setSize(120);
  27.         $produto_vu = new TEntry('produto_vu[]');
  28.         $produto_vu->setSize(120);
  29.         $produto_tt = new TEntry('produto_tt[]');
  30.         $produto_tt->setSize(120);
  31.         $produto_tt->setEditable(false);
  32.         $this->form->addField($produto_id);
  33.         $this->form->addField($produto_ds);
  34.         $this->form->addField($produto_qt);
  35.         $this->form->addField($produto_vu);
  36.         $this->form->addField($produto_tt);
  37.         // create delete button
  38.         $del = new TImage('fa:trash-o red');
  39.         $del->onclick 'ttable_remove_row(this)';
  40.         $table->addRowSet($produto_id$produto_ds$produto_qt$produto_vu$produto_tt$del);
  41.         // create add button
  42.         $add = new TButton('clone');
  43.         $add->setLabel('Add');
  44.         $add->setImage('fa:plus-circle green');
  45.         $add->addFunction('ttable_clone_previous_row(this)');
  46.         // create save button
  47.         $save TButton::create('save', array($this'onSave'), 'Save''fa:save blue');
  48.         $this->form->addField($save);
  49.         // add buttons in table
  50.         $table->addSection('tfoot');
  51.         //$table->addRowSet([$add, $save]);
  52.         $table->addRowSet([$add]);
  53.         //$panel = new TPanelGroup('Manual field list');
  54.         //$panel->add($this->form);
  55.         // wrap the page content using vertical box
  56.         $vbox = new TVBox;
  57.         //$vbox->add($panel);
  58.         $vbox = new TVBox;
  59.         $vbox->add($this->form);
  60.         parent::add($vbox);
  61.     }
  62.     /**
  63.      * Test save
  64.      */
  65.     public static function onSave($param) {
  66.         // show form values inside a window
  67.         $win TWindow::create('test'0.60.8);
  68.         $win->add('<pre>' str_replace("\n"'<br>'print_r($paramtrue)) . '</pre>');
  69.         $win->show();
  70.     }
  71. }
  72. ?>


  1. <?php
  1. <?php
  2. /**
  3.  * City Seek
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class ProdutosViewSeek extends TWindow {
  13.     private $form;      // form
  14.     private $datagrid;  // datagrid
  15.     private $pageNavigation;
  16.     private $loaded;
  17.     /**
  18.      * Class constructor
  19.      * Creates the page, the search form and the listing
  20.      */
  21.     public function __construct() {
  22.         parent::__construct();
  23.         parent::setSize(700500);
  24.         parent::setTitle('Pesquisa Registro');
  25.         new TSession;
  26.         // creates the form
  27.         $this->form = new TQuickForm('form_search_produtos');
  28.         $this->form->class 'tform';
  29.         $this->form->setFormTitle('Produtos');
  30.         // create the form fields
  31.         $descricao = new TEntry('descricao');
  32.         $descricao->setValue(TSession::getValue('descricao'));
  33.         $this->form->addQuickField('Descrição'$descricao200);
  34.         // define the form action
  35.         $this->form->addQuickAction('Pesquisa', new TAction(array($this'onSearch')), 'ico_find.png');
  36.         // creates a DataGrid
  37.         $this->datagrid = new TQuickGrid;
  38.         $this->datagrid->style 'width: 100%';
  39.         $this->datagrid->setHeight(230);
  40.         // creates the datagrid columns
  41.         $this->datagrid->addQuickColumn('Id''id''right'40);
  42.         $this->datagrid->addQuickColumn('Descrição''descricao''left'340);
  43.         $this->datagrid->addQuickColumn('Valor''valor''left'340);
  44.         // creates two datagrid actions
  45.         $this->datagrid->addQuickAction('Select', new TDataGridAction(array($this'onSelect')), 'id''ico_apply.png');
  46.         // create the datagrid model
  47.         $this->datagrid->createModel();
  48.         // creates the page navigation
  49.         $this->pageNavigation = new TPageNavigation;
  50.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  51.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  52.         // creates a container
  53.         $container = new TVBox;
  54.         $container->style 'width: 100%';
  55.         $container->add($this->form);
  56.         $container->add($this->datagrid);
  57.         $container->add($this->pageNavigation);
  58.         // add the container inside the page
  59.         parent::add($container);
  60.     }
  61.     /**
  62.      * method onSearch()
  63.      * Register the filter in the session when the user performs a search
  64.      */
  65.     function onSearch() {
  66.         // get the search form data
  67.         $data $this->form->getData();
  68.         // check if the user has filled the form
  69.         if (isset($data->descricao)) {
  70.             // creates a filter using what the user has typed
  71.             $filter = new TFilter('descricao''like'"%{$data->descricao}%");
  72.             // stores the filter in the session
  73.             TSession::setValue('produto_filter'$filter);
  74.             TSession::setValue('descricao'$data->descricao);
  75.             // fill the form with data again
  76.             $this->form->setData($data);
  77.         }
  78.         // redefine the parameters for reload method
  79.         $param = array();
  80.         $param['offset'] = 0;
  81.         $param['first_page'] = 1;
  82.         $this->onReload($param);
  83.     }
  84.     /**
  85.      * Load the datagrid with the database objects
  86.      */
  87.     function onReload($param NULL) {
  88.         try {
  89.             // open a transaction with database 'samples'
  90.             TTransaction::open('produtos');
  91.             // creates a repository for City
  92.             $repository = new TRepository('Produtos');
  93.             $limit 10;
  94.             // creates a criteria
  95.             $criteria = new TCriteria;
  96.             // default order
  97.             if (!isset($param['order'])) {
  98.                 $param['order'] = 'id';
  99.                 $param['direction'] = 'asc';
  100.             }
  101.             $criteria->setProperties($param); // order, offset
  102.             $criteria->setProperty('limit'$limit);
  103.             if (TSession::getValue('produto_filter')) {
  104.                 // add the filter stored in the session to the criteria
  105.                 $criteria->add(TSession::getValue('produto_filter'));
  106.             }
  107.             // load the objects according to the criteria
  108.             $produtos $repository->load($criteria);
  109.             $this->datagrid->clear();
  110.             if ($produtos) {
  111.                 foreach ($produtos as $produto) {
  112.                     // add the object inside the datagrid
  113.                     $this->datagrid->addItem($produto);
  114.                 }
  115.             }
  116.             // reset the criteria for record count
  117.             $criteria->resetProperties();
  118.             $count $repository->count($criteria);
  119.             $this->pageNavigation->setCount($count); // count of records
  120.             $this->pageNavigation->setProperties($param); // order, page
  121.             $this->pageNavigation->setLimit($limit); // limit
  122.             // close the transaction
  123.             TTransaction::close();
  124.             $this->loaded true;
  125.         } catch (Exception $e) { // in case of exception
  126.             // shows the exception error message
  127.             new TMessage('error'$e->getMessage());
  128.             // undo all pending operations
  129.             TTransaction::rollback();
  130.         }
  131.     }
  132.     /**
  133.      * Executed when the user chooses the record
  134.      */
  135.     public function onSelect($param) {
  136.         try {
  137.             $key $param['key'];
  138.             TTransaction::open('produtos');
  139.             // load the active record
  140.             $produto = new Produtos($key);
  141.             // closes the transaction
  142.             TTransaction::close();
  143.             $object = new StdClass;
  144.             $object->produto_id[] = $produto->id;
  145.             $object->produto_ds[] = $produto->descricao;
  146.             $object->produto_qt[] = 1;
  147.             $object->produto_vu[] = $produto->valor;
  148.             $object->produto_tt[] = $produto->valor;
  149.             TForm::sendData('form_OServicos'$object);
  150.             parent::closeWindow(); // closes the window
  151.         } catch (Exception $e) { // em caso de exceção
  152.             // clear fields
  153.             $object = new StdClass;
  154.             $object->produto_id ''//$produto->id;
  155.             $object->produto_ds ''//$produto->descricao;
  156.             $object->produto_qt ''//1;
  157.             $object->produto_vu ''//$produto->valor;
  158.             $object->produto_tt ''//$produto->valor;
  159.             TForm::sendData('form_OServicos'$object);
  160.             // undo pending operations
  161.             TTransaction::rollback();
  162.         }
  163.     }
  164.     /**
  165.      * Shows the page
  166.      */
  167.     function show() {
  168.         // if the datagrid was not loaded yet
  169.         if (!$this->loaded) {
  170.             $this->onReload();
  171.         }
  172.         parent::show();
  173.     }
  174. }
  175. ?>

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (1)


NR

Eduardo, sugiro usar outro componente para isso, veja:
adianti.com.br/framework_files/tutor/index.php?class=SaleMultiValueF

O SeekButton não transmite informações do campo original, por isso fica difícil identificar quais o campos deve preencher em um form vetorial.