Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Formulário com relacionamento de agregação Alguém pode me ajudar ou dar dicas de como criar Formulário com relacionamento de agregação? Os Models já estão prontos, mas não consegui visualizar como criar os Formulários. Estou fazendo pelo Adianti Studio. Obrigado pela atenção....
HS
Formulário com relacionamento de agregação  
Fechado
Alguém pode me ajudar ou dar dicas de como criar Formulário com relacionamento de agregação?

Os Models já estão prontos, mas não consegui visualizar como criar os Formulários. Estou fazendo pelo Adianti Studio.

Obrigado pela atenção.

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (4)


PD

posta a UML ai
HS

Não tenho UML, é só um teste para conhecer a ferramenta, mas o caso é o mesmo da Aplicação Biblioteca dos exemplos do site, entre as tabelas book e subject, existe a tabela BookSubject, que relaciona as duas. Precisava saber como retornar os subjects de book, fazendo diretamente pelo Studio.
CG

Bom dia,

Estou fazendo uma tela que utiliza agregação.

Para isso, voce tem duas opções:
1 - Desenhar a tela no Adianti usando o form designer;
2 - Fazer na "unha", que eu acho mais fácil.

Segue um exemplo de código feito manualmente.

  1. <?php 
  2. class NotaFiscalForm extends TStandardForm{
  3.     protected $notebook// notebook wrapper
  4.     protected $form// master form
  5.     protected $innerform// detail form
  6.     
  7.     /**
  8.      * Class constructor
  9.      * Creates the page and the registration form
  10.      */
  11.     function __construct(){
  12.         parent::__construct();
  13.         
  14.        //FORM MESTRE
  15.        //NOTA FISCAL
  16.         $this->form = new TQuickForm('form_nota_fiscal');
  17.         parent::setDatabase('livraria');
  18.         parent::setActiveRecord('NotaFiscal');
  19.         
  20.         $notafiscal_id = new TEntry('notafiscal_id');
  21.         $notafiscal_id->setEditable(FALSE);
  22.         
  23.         $numero = new TEntry('numero');
  24.         $emissao = new TDate('emissao');
  25.         //$emissao->setMask('dd/mm/yyyy');
  26.         
  27.         /*
  28.         $remetente_id = new TEntry('remetente_id');
  29.         $destinatario_id = new TEntry('destinatario_id');
  30. */
  31.         
  32.         $destinatario_id = new TSeekButton('destinatario_id');
  33.         $nomedestinatario = new TEntry('nomedestinatario');
  34.         $nomedestinatario->setEditable(FALSE);
  35.         
  36.         $remetente_id = new TSeekButton('remetente_id');
  37.         $nomeremetente = new TEntry('nomeremetente');
  38.         $nomeremetente->setEditable(FALSE);
  39.         
  40.         $obj1 =  new TStandardSeek;
  41.         
  42.         $action1 = new TAction(array($obj1'onSetup'));
  43.         
  44.         $action1->setParameter('database','livraria');
  45.         $action1->setParameter('parent','form_nota_fiscal');
  46.         $action1->setParameter('model','RemententeDestinatario');
  47.         $action1->setParameter('display_field','nome');
  48.         $action1->setParameter('receive_key','remetente_id');
  49.         $action1->setParameter('receive_field','nomeremetente');
  50.          
  51.         $remetente_id->setAction($action1);
  52.         
  53.         
  54.         $obj2 =  new TStandardSeek;
  55.         
  56.         $action2 = new TAction(array($obj2'onSetup'));
  57.         
  58.         $action2->setParameter('database','livraria');
  59.         $action2->setParameter('parent','form_nota_fiscal');
  60.         $action2->setParameter('model','RemententeDestinatario');
  61.         $action2->setParameter('display_field','nome');
  62.         $action2->setParameter('receive_key','destinatario_id');
  63.         $action2->setParameter('receive_field','nomedestinatario');
  64.                 
  65.         
  66.         $destinatario_id->setAction($action2);
  67.         
  68.         
  69.         
  70.         $this->form->addQuickField('Id'$notafiscal_id,  100);
  71.         $this->form->addQuickField('Número'$numero,  200);
  72.         $this->form->addQuickField('Emissão'$emissao,  80);
  73.         $this->form->addQuickField('Remetente'$remetente_id,  80);
  74.         $this->form->addQuickField('Nome Remetente'$nomeremetente,  200);
  75.         $this->form->addQuickField('Destinatário'$destinatario_id,  80);
  76.         $this->form->addQuickField('Nome Destinatario'$nomedestinatario,  200);
  77.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'ico_save.png');
  78.         $this->form->addQuickAction(_t('New'), new TAction(array($this'onEdit')), 'ico_new.png');
  79.         $this->form->addQuickAction(_t('List'), new TAction(array('NotaFiscalList''onReload')), 'ico_datagrid.png');
  80.         
  81.         
  82.         
  83.         //FORM DETALHE
  84.         //ITEM DA NOTA FISCAL
  85.         
  86.         $this->innerform = new TQuickForm('form_item_nota');
  87.         
  88.         
  89.         $iditemnota = new TEntry('iditemnota');
  90.         $iditemnota->setEditable(FALSE);
  91.         
  92.         $descricao = new TEntry('descricao');
  93.         $quantidade = new TEntry('quantidade');
  94.         $valorunitario = new TEntry('valorunitario');
  95.         $valortotal = new TEntry('valortotal');
  96.         
  97.         $this->innerform->addQuickField('Id Item',$iditemnota,100);
  98.         $this->innerform->addQuickField('Descrição',$descricao,200);
  99.         $this->innerform->addQuickField('Quantidade',$quantidade,200);
  100.         $this->innerform->addQuickField('Valor Unitário',$valorunitario,200);
  101.         $this->innerform->addQuickField('Valor Total',$valortotal,200);
  102.         
  103.         $this->innerform->addQuickAction(_t('Save'), new TAction(array($this'onBacklogSave')), 'ico_save.png');
  104.         $this->innerform->addQuickAction(_t('New'), new TAction(array($this'onBacklogEdit')), 'ico_new.png');
  105.         
  106.         $this->datagrid = new TQuickGrid;
  107.         $this->datagrid->setHeight(320);
  108.         
  109.         $id $this->datagrid->addQuickColumn('Id Item''iditemnota''left'80);
  110.         $descricao $this->datagrid->addQuickColumn('Descrição''descricao''left'200);
  111.         $quantidade $this->datagrid->addQuickColumn('Quantidade''quantidade''left'200);
  112.         $valorunitario $this->datagrid->addQuickColumn('Valor Unitário''valorunitario''left'200);
  113.         $valortotal $this->datagrid->addQuickColumn('Valor Total''valortotal''left'200);
  114.         
  115.         $this->datagrid->addQuickAction(_t('Edit'), new TDataGridAction(array($this'onBacklogEdit')), 'iditemnota''ico_edit.png');
  116.         $this->datagrid->addQuickAction(_t('Delete'), new TDataGridAction(array($this'onDelete')), 'iditemnota''ico_delete.png');
  117.         $this->datagrid->createModel();
  118.         
  119.         $this->pageNavigation = new TPageNavigation;
  120.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  121.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  122.         
  123.         $table = new TTable;
  124.         $table->addRow()->addCell($this->innerform);
  125.         $table->addRow()->addCell($this->datagrid);
  126.         $table->addRow()->addCell($this->pageNavigation);
  127.         
  128.         $this->notebook = new TNotebook;
  129.         $this->notebook->setSize(600,400);
  130.         $this->notebook->appendPage('Nota Fiscal',$this->form);
  131.         $this->notebook->appendPage('Item Nota',$table);
  132.         
  133.         parent::add($this->notebook);         
  134.         
  135.     }
  136.     public function onSave(){
  137.         $object parent::onSave();
  138.         TSession::setValue('notafiscal_id',$object->id);
  139.         $object->emissao TDate::date2us($object->emissao);
  140.         TSession::setValue('emissao',$object->emissao);
  141.         
  142.         $this->notebook->setCurrentPage(0);
  143.         
  144.     }
  145.     
  146.     Public function onEdit($param){
  147.         
  148.         if(isset($param['key'])){
  149.             TSession::setValue('notafiscal_id',$param['key']);
  150.             
  151.         }else{
  152.             TSession::setValue('notafiscal_id',NULL);
  153.         }
  154.         
  155.         parent::onEdit($param);
  156.         $this->onReload();
  157.         $this->notebook->setCurrentPage(0);
  158.         
  159.     }
  160.    function onBacklogSave()
  161.     {
  162.         try
  163.         {
  164.             TTransaction::open('livraria'); // open a transaction
  165.             
  166.             // get the form data into an active record Backlog
  167.             $object $this->innerform->getData('ItemNotaFiscal');
  168.             $object->notafiscal_id =  TSession::getValue('notafiscal_id');
  169.             
  170.             $this->innerform->validate(); // form validation
  171.             $object->store(); // stores the object
  172.             $this->innerform->setData($object); // keep the form filled
  173.             TTransaction::close(); // close the transaction
  174.             
  175.             new TMessage('info'TAdiantiCoreTranslator::translate('Registro Salvo'));
  176.             $this->onReload(); // reload the listing
  177.             
  178.             $this->notebook->setCurrentPage(1);
  179.         }
  180.         catch (Exception $e)
  181.         {
  182.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  183.             TTransaction::rollback();
  184.         }
  185.     }
  186.     public function onBacklogEdit($param)
  187.     {
  188.         // load the MASTER object
  189.         parent::onEdit(array('key'=> TSession::getValue('notafiscal_id')));
  190.         
  191.         if (isset($param['key']))
  192.         {
  193.             try
  194.             {
  195.                 TTransaction::open('livraria');
  196.                 $bl = new ItemNotaFiscal($param['key']);
  197.                 $pid $bl->notafiscal_id;
  198.                 TTransaction::close();
  199.                 
  200.                 // load the DETAIL object
  201.                 $this->innerform->setData($bl);
  202.             }
  203.             catch (Exception $e// in case of exception
  204.             {
  205.                 new TMessage('error''<b>Error</b> ' $e->getMessage());
  206.                 TTransaction::rollback();
  207.             }
  208.         }
  209.         
  210.         $this->notebook->setCurrentPage(1);
  211.     }
  212.     
  213.     function onReload($param NULL)
  214.     {
  215.         try
  216.         {
  217.             parent::onEdit(array('key'=> TSession::getValue('notafiscal_id')));
  218.             $this->notebook->setCurrentPage(1);
  219.             
  220.             TTransaction::open('livraria'); // open a transaction
  221.             $repository = new TRepository('ItemNotaFiscal'); // creates a repository
  222.             $limit 10;
  223.             // creates a criteria
  224.             $criteria = new TCriteria;
  225.             $criteria->setProperties($param); // order, offset
  226.             $criteria->setProperty('limit'$limit);
  227.             
  228.             $criteria->add(new TFilter('notafiscal_id''='TSession::getValue('notafiscal_id')));
  229.             // load the objects according to criteria
  230.             $objects $repository->load($criteria);
  231.             
  232.             $this->datagrid->clear();
  233.             if ($objects)
  234.             {
  235.                 foreach ($objects as $object)
  236.                 {
  237.                     $this->datagrid->addItem($object); // add the detail inside the datagrid
  238.                 }
  239.             }
  240.             
  241.             // reset the criteria for record count
  242.             $criteria->resetProperties();
  243.             $count$repository->count($criteria);
  244.             
  245.             $this->pageNavigation->setCount($count); // count of records
  246.             $this->pageNavigation->setProperties($param); // order, page
  247.             $this->pageNavigation->setLimit($limit); // limit
  248.             
  249.             // close the transaction
  250.             TTransaction::close();
  251.             $this->loaded true;
  252.         }
  253.         catch (Exception $e)
  254.         {
  255.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  256.             TTransaction::rollback();
  257.         }
  258.     }
  259.     
  260.     function onDelete($param)
  261.     {
  262.         // define the delete action
  263.         $action = new TAction(array($this'Delete'));
  264.         $action->setParameters($param); // pass the key parameter ahead
  265.         
  266.         // shows a dialog to the user
  267.         new TQuestion(TAdiantiCoreTranslator::translate('Confirma a exclusão deste registro ?'), $action);
  268.     }        
  269.     
  270.     function Delete($param)
  271.     {
  272.         try
  273.         {
  274.             $key $param['key']; // get the parameter $key
  275.             
  276.             TTransaction::open('livraria'); // open a transaction
  277.             $object = new ItemNotaFiscal($key);
  278.             $object->delete(); // deletes the object from the database
  279.             TTransaction::close(); // close the transaction
  280.             
  281.             $this->onReload(); // reload the listing
  282.             // shows the success message
  283.             new TMessage('info'TAdiantiCoreTranslator::translate('Registro foi excluído'));
  284.         }
  285.         catch (Exception $e)
  286.         {
  287.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  288.             TTransaction::rollback();
  289.         }
  290.     }    
  291.     
  292.     
  293.     
  294.     function show()
  295.     {
  296.         // check if the datagrid is already loaded
  297.         if (!$this->loaded)
  298.         {
  299.             $this->onReloadfunc_get_arg(0) );
  300.         }
  301.         parent::show();
  302.     }
  303. }
  304. ?>
PD

Caro Henrique,

Você pode fazer agregação de diferentes formas. Nesse primeiro exemplo funciona com TCheckGroup:
www.adianti.com.br/framework_files/tutor/index.php?class=CustomerFor

Mas você poderia fazer também com TMultiField, adicionando ocorrências de outros objetos.

No primeiro exemplo, você pode fazer o TCheckGroup ou TDBCheckGroup no Studio e posteriormente tratar o salvamento ou o carregamento das informações relacionadas nos método onSave() e onEdit(). O Studio gera um código padrão de salvamento e carregamento, não tratando relações mais complexas. Para essas, você terá de digitar algumas linhas de código na control.

Att,
Pablo