CG
Erro botão TSeekButton
Fechado
Bom dia,
Sou iniciante no Framework, e estou implementando um cadastro de nota fiscal (mestre / detalhe).
Preciso implementar o botão "Seek" semelhante ao do exemplo Tutor.
Porém ao instanciar a Classe que abre a window para selecionar o registro que eu quero, ocorre o erro "Fatal error: Class 'RemetenteDestinatarioSeek' not found in C:wampwwwnotafiscalappcontrolNotaFiscalForm.class.php on line 34".
Porém no código estou instanciando a Classe corretamente, conforme código abaixo:
Código da window:
Sou iniciante no Framework, e estou implementando um cadastro de nota fiscal (mestre / detalhe).
Preciso implementar o botão "Seek" semelhante ao do exemplo Tutor.
Porém ao instanciar a Classe que abre a window para selecionar o registro que eu quero, ocorre o erro "Fatal error: Class 'RemetenteDestinatarioSeek' not found in C:wampwwwnotafiscalappcontrolNotaFiscalForm.class.php on line 34".
Porém no código estou instanciando a Classe corretamente, conforme código abaixo:
function __construct(){
parent::__construct();
//FORM MESTRE
//NOTA FISCAL
$this->form = new TQuickForm('form_nota_fiscal');
parent::setDatabase('livraria');
parent::setActiveRecord('NotaFiscal');
$notafiscal_id = new TEntry('notafiscal_id');
$notafiscal_id->setEditable(FALSE);
$numero = new TEntry('numero');
$emissao = new TDate('emissao');
//$emissao->setMask('dd/mm/yyyy');
$remetente_id = new TEntry('remdest_nome1');
$destinatario_id = new TEntry('destinatario_id');
$remdest_id1 = new TSeekButton('remdest_id1');
//$remdest_id2 = new TSeekButton('city_id1');
$remetente_id->setEditable(FALSE);
<b> $obj = new RemetenteDestinatarioSeek; </b>
/*
$action = new TAction(array($obj, 'onReload'));
$remdest_id1->setAction($action);
*/
$this->form->addQuickField('Id', $notafiscal_id, 100);
$this->form->addQuickField('Número', $numero, 200);
$this->form->addQuickField('Emissão', $emissao, 80);
$this->form->addQuickField('Remetente', $remetente_id, 80);
$this->form->addQuickField('Nome do Remetente', $remdest_id1, 80);
$this->form->addQuickField('Destinatário', $destinatario_id, 80);
[....]
Código da window:
class RemententeDestinatarioSeek 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_rem_dest_seek');
// creates the table
$table = new TTable;
// add the table inside the form
$this->form->add($table);
// create the form fields
$name= new TEntry('nome');
// keep the session value
$name->setValue(TSession::getValue('nome'));
// add the field inside the table
$row=$table->addRow();
$row->addCell(new TLabel('Nome:'));
$row->addCell($name);
// create a find button
$find_button = new TButton('Buscar');
// define the button action
$find_button->setAction(new TAction(array($this, 'onSearch')), 'Search');
$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($name, $find_button));
// create the datagrid
$this->datagrid = new TDataGrid;
// create the datagrid columns
778 = new TDataGridColumn('id', 'Id', 'right', 70);
$name = new TDataGridColumn('Nome', 'nome', 'left', 220);
$state = new TDataGridColumn('CNPJ', 'cnpj', 'left', 80);
$order1= new TAction(array($this, 'onReload'));
$order2= new TAction(array($this, 'onReload'));
$order1->setParameter('order', 'id');
$order2->setParameter('order', 'nome');
// define the column actions
778->setAction($order1);
$name->setAction($order2);
// add the columns inside the datagrid
$this->datagrid->addColumn(778);
$this->datagrid->addColumn($name);
$this->datagrid->addColumn($state);
// 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->name))
{
// cria um filtro pelo conteúdo digitado
$filter = new TFilter('nome', 'like', "%{$data->nome}%");
// armazena o filtro na seção
TSession::setValue('test_remdest_filter', $filter);
TSession::setValue('test_remdest_name', $data->nome);
// 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('livraria');
// create a repository for RemententeDestinatário table
$repository = new TRepository('RemententeDestinatario');
$limit = 10;
// creates a criteria
$criteria = new TCriteria;
$criteria->setProperties($param); // order, offset
$criteria->setProperty('limit', $limit);
if (TSession::getValue('test_remdest_filter'))
{
// filter by remetente destinatário nome
$criteria->add(TSession::getValue('test_remdest_filter'));
}
// load the objects according to the criteria
$pessoas = $repository->load($criteria);
$this->datagrid->clear();
if ($cities)
{
foreach ($pessoas as $pessoa)
{
// add the objects inside the datagrid
$this->datagrid->addItem($pessoa);
}
}
// 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('livraria');
// load the active record
$remdest = new RemententeDestinatario($key);
// closes the transaction
TTransaction::close();
$object = new StdClass;
$object->remdest_id1 = $remdest->id;
$object->remdest_nome1 = $remdest->nome;
TForm::sendData('form_seek_sample', $object);
parent::closeWindow(); // closes the window
}
catch (Exception $e) // em caso de exceção
{
// clear fields
$object = new StdClass;
$object->remdest_id1 = '';
$object->remdest_nome1 = '';
TForm::sendData('form_seek_sample', $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();
}
}
a class RemententeDestinatarioSeek esta salva na pasta control como
RemententeDestinatarioSeek.class.php?
da uma olhada nesse componente
https://github.com/ale-php/TComponetes/blob/master/PForm/PStandartSeek.class.php
muito facil de usar
Opa,
Beleza meu caro.
Vou testar seu código, e qualquer coisa eu te falo.
Valeu!!
Progs Desenvolvimento,
Ficou show de bola!!
Parabéns!
é sempre bom ajudar, em breve farei masi componetes, uteis aceito sugestoes