Botao Salvar formulario Studio Prezados Estou utilizando a versão studio criei os botões de editar, salvar no formulário na grid coloco os botões de editar, deletar porem quando vou fazer alguma edição ao gravar ele cria um novo registro deveria alterar apenas, será que alguém pode me dizer onde estou errando segue o código. ...
FC
Botao Salvar formulario Studio  
Fechado
Prezados

Estou utilizando a versão studio criei os botões de editar, salvar no formulário na grid
coloco os botões de editar, deletar porem quando vou fazer alguma edição ao gravar ele cria um novo registro
deveria alterar apenas, será que alguém pode me dizer onde estou errando segue o código.


<?php/** * UsuariosForm Registration * @author  <your name here> */class UsuariosForm extends TPage{    private $form;    private $datagrid;    private $pageNavigation;    private $loaded;        /**     * Class constructor     * Creates the page and the registration form     */    function __construct()    {        parent::__construct();                // creates the form        $this->form = new TForm('form_Usuarios');                try        {            // TUIBuilder object            $ui = new TUIBuilder(500,500);            $ui->setController($this);            $ui->setForm($this->form);                        // reads the xml form            $ui->parseFile('app/forms/FrmUsuarios.form.xml');                        // get the interface widgets            $fields = $ui->getWidgets();            // look for the TDataGrid object            foreach ($fields as $name => $field)            {                if ($field instanceof TDataGrid)                {                    $this->datagrid = $field;                    $this->pageNavigation = $this->datagrid->getPageNavigation();                }            }                        // add the TUIBuilder panel inside the TForm object            $this->form->add($ui);            // set form fields from interface fields            $this->form->setFields($ui->getFields());        }        catch (Exception $e)        {            new TMessage('error', $e->getMessage());        }                // add the form to the page        parent::add($this->form);    }        /**     * method onEdit()     * Executed whenever the user clicks at the edit button da datagrid     */    function onEdit($param)    {        try        {            if (isset($param['key']))            {                // get the parameter $key                $key=$param['key'];                                // open a transaction with database 'BcoGED'                TTransaction::open('BcoGED');                                // instantiates object Usuarios                $object = new Usuarios($key);                                // fill the form with the active record data                $this->form->setData($object);                                // close the transaction                TTransaction::close();            }            else            {                $this->form->clear();            }        }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', '<b>Error</b> ' . $e->getMessage());                        // undo all pending operations            TTransaction::rollback();        }    }    /**     * method onDelete()     * executed whenever the user clicks at the delete button     * Ask if the user really wants to delete the record     */    function onDelete($param)    {        // get the parameter $key        $key=$param['key'];                // define two actions        $action = new TAction(array($this, 'Delete'));                // define the action parameters        $action->setParameter('key', $key);                // shows a dialog to the user        new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);    }        /**     * method Delete()     * Delete a record     */    function Delete($param)    {        try        {            // get the parameter $key            $key=$param['key'];            // open a transaction with database 'BcoGED'            TTransaction::open('BcoGED');                        // instantiates object Usuarios            $object = new Usuarios($key);                        // deletes the object from the database            $object->delete();                        // close the transaction            TTransaction::close();                        // reload the listing            $this->onReload();            // shows the success message            new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'));        }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', '<b>Error</b> ' . $e->getMessage());            // undo all pending operations            TTransaction::rollback();        }    }    /**     * method onSave()     * Executed whenever the user clicks at the save button     */    function onSave()    {        try        {            // open a transaction with database 'BcoGED'            TTransaction::open('BcoGED');                        // get the form data into an active record Usuarios            $object = $this->form->getData('Usuarios');                        // form validation            $this->form->validate();                        // stores the object            $object->store();                        // set the data back to the form            $this->form->setData($object);                        // close the transaction            TTransaction::close();                        // shows the success message            new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));            // reload the listing        }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', '<b>Error</b> ' . $e->getMessage());            // undo all pending operations            TTransaction::rollback();        }    }    /**     * method onEdi()     * Executed whenever the user clicks at the edit button da datagrid     */    function onEdi($param)    {        try        {            if (isset($param['key']))            {                // get the parameter $key                $key=$param['key'];                                // open a transaction with database 'BcoGED'                TTransaction::open('BcoGED');                                // instantiates object Usuarios                $object = new Usuarios($key);                                // fill the form with the active record data                $this->form->setData($object);                                // close the transaction                TTransaction::close();            }            else            {                $this->form->clear();            }        }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', '<b>Error</b> ' . $e->getMessage());                        // undo all pending operations            TTransaction::rollback();        }    }    /**     * method onSave()     * Executed whenever the user clicks at the save button     */     /**     * method onReload()     * Load the datagrid with the database objects     */    function onReload($param = NULL)    {        try        {            // open a transaction with database 'BcoGED'            TTransaction::open('BcoGED');                        // creates a repository for Usuarios            $repository = new TRepository('Usuarios');            $limit = 10;            // creates a criteria            $criteria = new TCriteria;            $criteria->setProperties($param); // order, offset            $criteria->setProperty('limit', $limit);                        if (TSession::getValue('Usuarios_filter'))            {                // add the filter stored in the session to the criteria                $criteria->add(TSession::getValue('Usuarios_filter'));            }                        // load the objects according to criteria            $objects = $repository->load($criteria);                        $this->datagrid->clear();            if ($objects)            {                // iterate the collection of active records                foreach ($objects as $object)                {                    // add the object inside the datagrid                    $this->datagrid->addItem($object);                }            }                        // reset the criteria for record count            $criteria->resetProperties();            $count= $repository->count($criteria);                        $this->pageNavigation->setCount($count); // count of records            $this->pageNavigation->setProperties($param); // order, page            $this->pageNavigation->setLimit($limit); // limit                        // close the transaction            TTransaction::close();            $this->loaded = true;        }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', '<b>Error</b> ' . $e->getMessage());            // undo all pending operations            TTransaction::rollback();        }    }        /**     * method show()     * Shows the page     */    function show()    {        // check if the datagrid is already loaded        if (!$this->loaded)        {            $this->onReload();        }        parent::show();    }      }

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)


FC

Eu acredito que vc não está passando o "id" ao salvar, o campo id tem que estar no form senão senão ele entende que não existe e cria um novo registro.
FC

Felipe isso mesmo muito obrigado funcionou !! Porém existe uma forma para esse campo que coloquei no formulário não aparecer para o usuário
FC

Use campo do tipo THidden
FC

Não deu certo ele continua na tela.
PD

Oi Flavio,

Cria o THidden via programação e adiciona no designer:
www.adianti.com.br/forum/pt/view_516?acrescentando-um-thtmleditor-ao

Att,
Pablo