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