PC
Localização e preenchimento
Preciso criar um formulário onde eu pesquiso algumas informações em uma tabela, insiro outras e todas as informações serão preenchidas no datagrid que posteriormente calcular alguns valor e gravar em uma tabela.
Escrevi dois códigos e nenhum funciona, será que alguém pode me dar um help?
Código 01
Código 02
Escrevi dois códigos e nenhum funciona, será que alguém pode me dar um help?
Código 01
- <?php
- class FormVendaProdutos extends TWindow
- {
- private $form;
- private $datagrid;
- private $loaded;
- private $pageNavigation;
- private $parentForm;
- function __construct()
- {
- parent::__construct();
- new TSession();
- //Cria os containers
- $notebook = new TNotebook(500,200);
- $this->form = new TForm('form_vendas');
- $table = new TTable;
- $this->form->add($table);
- $notebook->appendPage('Vendas de Produtos', $this->form);
- // Cria o componente de busca
- $id = new TSeekButton('id');
- $id->setValue(TSession::getValue('id_produto'));
- $codigo = new TEntry('codigo');
- $obj = new TStandardSeek;
- $action = new TAction(array($obj, 'onSetup'));
- $action->setParameter('database', 'loja');
- $action->setParameter('parent', 'form_vendas');
- $action->setParameter('model', 'produtos');
- $action->setParameter('display_field', 'codigo');
- $action->setParameter('receive_key', 'id');
- $action->setParameter('receive_field', 'codigo');
- $id->setAction($action);
- $row=$table->addRow();
- $row->addCell(new TLabel('Produto'));
- $row->addCell($id);
- $row=$table->addRow();
- $row->addCell(new TLabel('Código'));
- $row->addCell($codigo);
- $carrega_button = new TButton('load');
- $carrega_button->setAction(new TAction(array($this,'onReload')),'Carregar Produtos');
- $row=$table->addRow();
- $row->addCell($carrega_button);
- $this->form->setFields(array($id,$codigo,$carrega_button));
- // Cria o datagrid
- $this->datagrid = new TDataGrid();
- $this->datagrid->setHeight(400);
- $codigo = new TDataGridColumn('codigo','Código','left', 30);
- $descricao = new TDataGridColumn('descricao','Descrição','left',200);
- $valnor = new TDataGridColumn('valnor','Normal',70);
- $valpro = new TDataGridColumn('valpro','Promoção',70);
- $valult = new TDataGridColumn('valult','Último',70);
- $this->datagrid->addColumn($codigo);
- $this->datagrid->addColumn($descricao);
- $this->datagrid->addColumn($valnor);
- $this->datagrid->addColumn($valpro);
- $this->datagrid->addColumn($valult);
- $this->datagrid->createModel();
- // add the form to the page
- $table = new TTable();
- $table->addRow()->addCell($this->form);
- $table->addRow()->addCell($this->datagrid);
- //$table->addRow()->addCell($this->pageNavigation);
- parent::add($table);
- }
- function onReload()
- {
- try {
- $data = $this->form->getData();
- TTransaction::open('loja');
- $conn = TTransaction::get();
- $repository = new TRepository('produtos');
- $limit=10;
- $criteria = new TCriteria();
- $criteria = $data;
- $produtos = $repository->load($criteria);
- // limpa datagrid
- $this->datagrid->clear();
- if ($produtos)
- {
- foreach ($produtos as $produto)
- {
- $this->datagrid->addItem($produto);
- }
- }
- $criteria->resetProperties();
- $count= $repository->count($criteria);
- //$this->pageNavigation->setCount($count);
- //$this->pageNavigation->setProperties($param);
- //$this->pageNavigation->setLimit($limit);
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e)
- {
- new TMessage('error', '<b>Error</b>' . $e->getMessage());
- TTransaction::rollback();
- }
- }
- /*
- function show()
- {
- if (!$this->loaded)
- {
- $this->onReload();
- }
- parent::show();
- }
- */
- }
- ?>
Código 02
- <?php
- /**
- * City Seek
- *
- * @version 1.0
- * @package samples
- * @subpackage tutor
- * @author Pablo Dall'Oglio
- * @copyright Copyright (c) 2006-2013 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- class FormVendaProd extends TWindow
- {
- private $form; // form
- private $datagrid; // datagrid
- private $pageNavigation;
- private $parentForm;
- private $loaded;
- /**
- * constructor method
- */
- public function __construct()
- {
- parent::__construct();
- new TSession;
- // creates the form
- $this->form = new TForm('form_venda_prod');
- // creates the table
- $table = new TTable;
- // add the table inside the form
- $this->form->add($table);
- // create the form fields
- $id= new TEntry('id');
- // keep the session value
- $id->setValue(TSession::getValue('id_produto'));
- // add the field inside the table
- $row=$table->addRow();
- $row->addCell(new TLabel('Código Produto:'));
- $row->addCell($id);
- // create a find button
- $find_button = new TButton('search');
- // define the button action
- $find_button->setAction(new TAction(array($this, 'onSearch')), 'Procurar');
- $find_button->setImage('ico_find.png');
- // add a row for the find button
- $row=$table->addRow();
- $row->addCell($find_button);
- // define wich are the form fields
- $this->form->setFields(array($id, $find_button));
- // create the datagrid
- $this->datagrid = new TDataGrid;
- // create the datagrid columns
- $id = new TDataGridColumn('id', 'Id', 'right', 70);
- $codigo = new TDataGridColumn('codigo', 'Codigo', 'left', 70);
- $descricao = new TDataGridColumn('descricao', 'Descrição', 'left', 250);
- $valnor = new TDataGridColumn('valnor', 'Normal', 'left', 100);
- $valpro = new TDataGridColumn('valpro', 'Promoção', 'left', 100);
- $valult = new TDataGridColumn('valult', 'Último', 'left', 100);
- $order1= new TAction(array($this, 'onReload'));
- $order2= new TAction(array($this, 'onReload'));
- $order1->setParameter('order', 'id');
- $order2->setParameter('order', 'descricao');
- // define the column actions
- $id->setAction($order1);
- $descricao->setAction($order2);
- // add the columns inside the datagrid
- $this->datagrid->addColumn($id);
- $this->datagrid->addColumn($codigo);
- $this->datagrid->addColumn($descricao);
- $this->datagrid->addColumn($valnor);
- $this->datagrid->addColumn($valpro);
- $this->datagrid->addColumn($valult);
- // create one datagrid action
- $action1 = new TDataGridAction(array($this, 'onSelect'));
- $action1->setLabel('Selecionar');
- $action1->setImage('ico_apply.png');
- $action1->setField('id');
- // add the action to the datagrid
- $this->datagrid->addAction($action1);
- // create the datagrid model
- $this->datagrid->createModel();
- // create the page navigator
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // create a table for layout
- $table = new TTable;
- // create a row for the form
- $row = $table->addRow();
- $row->addCell($this->form);
- // create a row for the datagrid
- $row = $table->addRow();
- $row->addCell($this->datagrid);
- // create a row for the page navigator
- $row = $table->addRow();
- $row->addCell($this->pageNavigation);
- // add the table inside the page
- parent::add($table);
- }
- /**
- * Register a filter in the session
- */
- function onSearch()
- {
- // get the form data
- $data = $this->form->getData();
- // check if the user has filled the fields
- if (isset($data->id))
- {
- // cria um filtro pelo conteúdo digitado
- $filter = new TFilter('id', '=', $data->id);
- // armazena o filtro na seção
- TSession::setValue('id', $filter);
- TSession::setValue('id', $data->id);
- // put the data back to the form
- $this->form->setData($data);
- }
- // redefine the parameters for reload method
- $param=array();
- $param['offset'] =0;
- $param['first_page']=1;
- $this->onReload($param);
- }
- /**
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL)
- {
- try
- {
- // start database transaction
- TTransaction::open('loja');
- // create a repository for City table
- $repository = new TRepository('produtos');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- if (TSession::getValue('id_produto'))
- {
- // filter by city name
- $criteria->add(TSession::getValue('id'));
- }
- // load the objects according to the criteria
- $produtos = $repository->load($criteria);
- $this->datagrid->clear();
- if ($produtos)
- {
- foreach ($produtos as $produto)
- {
- // add the objects inside the datagrid
- $this->datagrid->addItem($produto);
- }
- }
- // clear the criteria
- $criteria->resetProperties();
- $count= $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // commit and closes the database transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // exceptions
- {
- // show the error message
- new TMessage('error', '<b>Erro</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * Executed when the user chooses the record
- */
- function onSelect($param)
- {
- try
- {
- $key = $param['key'];
- TTransaction::open('loja');
- // load the active record
- $produtos = new Produtos($key);
- // closes the transaction
- TTransaction::close();
- $object = new StdClass;
- $object->produto_id1 = $produtos->id;
- $object->produto_name1 = $produtos->descricao;
- TForm::sendData('form_seek_produto', $object);
- parent::closeWindow(); // closes the window
- }
- catch (Exception $e) // em caso de exceção
- {
- // clear fields
- $object = new StdClass;
- $object->produto_id1 = '';
- $object->produro_name1 = '';
- TForm::sendData('form_seek_produto', $object);
- // undo pending operations
- TTransaction::rollback();
- }
- }
- /**
- * Shows the page
- */
- function show()
- {
- // if the datagrid was not loaded yet
- if (!$this->loaded)
- {
- $this->onReload();
- }
- parent::show();
- }
- }
- ?>
Paulo,
Como não temos o mesmo ambiente que você (tabelas, arquivos), você terá de ser mais específico na pergunta ;-)
abs,
Pablo
posta a UML e o descritivo do quer fazer