Carregando dados em uma grid de um TMultifield Pessoal, boa tarde, tenho uma classe controller chamada FrmMestreReproducao, nesta classe eu tenho uma agregação com uma classe incubadora e uma associação com a classe RepMatriz, que por sua vez tem uma associação com a classe Matriz. Os dados dessa classe RepMatriz é preenchido através de um TMultifield contendo um SeekButton que carrega os dados da matriz em questão e os registra em...
TS
Carregando dados em uma grid de um TMultifield  
Pessoal,

boa tarde, tenho uma classe controller chamada FrmMestreReproducao, nesta classe eu tenho uma agregação com uma classe incubadora e uma associação com a classe RepMatriz, que por sua vez tem uma associação com a classe Matriz. Os dados dessa classe RepMatriz é preenchido através de um TMultifield contendo um SeekButton que carrega os dados da matriz em questão e os registra em uma pequena grid. Para inserir os dados está tudo funcionando normalmente, o problema é na hora de editar, pois não está carregando as informações na grid do multifield, dei um var_dump no objeto dentro do metodo onEdit e ele está recebendo esses dados, mas não estou sabendo como jogá-los na grid do Multifield, alguem por acaso já passou por isso ou saiba como resolver? aqui abaixo está a classe:

 
  1. <?php
  2. class FrmMestreReproducao extends TPage
  3. {
  4. protected $form;
  5. private $form_matrizes;
  6. private $total;
  7. private $matgrid;
  8. public function __construct(){
  9. parent::__construct();
  10. TPage::include_css('app/resources/styles.css');
  11. // loads the mask javascript library
  12. TPage::include_js('app/lib/jquery/jquery.mask.js');
  13. TPage::include_js('app/lib/jquery/jquery.mask.min.js');
  14. $this->form = new TForm('FrmMestreReproducao');
  15. $this->form->class = 'tform';
  16. parent::include_css('app/resources/custom-frame.css');
  17. $tbl_reproducao = new TTable;
  18. $tbl_matrizes = new TTable;
  19. $tbl_dados_primarios = new TTable;
  20. $tbl_estatisticas = new TTable;
  21. $tbl_matriz2 = new TTable;
  22. $tbl_dados_primarios->styçe='background:whiteSmoke;';
  23. $hbox1 = new THBox;
  24. $hbox2 = new THBox;
  25. $hbox3 = new THBox;
  26. $tbl_reproducao->style='Width:100%;';
  27. $tbl_dados_primarios->style='width:100%';
  28. $tbl_matrizes->style='width:100%';
  29. $tbl_estatisticas->style='width:100%';
  30. $tbl_matriz2->style='width:100%';
  31. $this->form->add($tbl_reproducao);
  32. $tbl_reproducao->addRowSet( new TLabel('Reprodução'), '', '','' )->class = 'tformtitle';
  33. $tbl_reproducao->addRowSet($hbox1);
  34. $tbl_reproducao->addRowSet($hbox2);
  35. $tbl_reproducao->addRowSet($hbox3);
  36. $hbox1->add($tbl_dados_primarios);
  37. $hbox1->add($tbl_estatisticas);
  38. $hbox2->add($tbl_matrizes);
  39. $hbox2->add($tbl_matriz2);
  40. $this->form->add($tbl_reproducao);
  41. $frame_matrizes = new TFrame(NULL, 290);
  42. $frame_matrizes->setLegend('Matrizes');
  43. $frame_matrizes->style .= 'background:whiteSmoke;margin: 4px';
  44. $frame_incubadora = new TFrame(NULL, 290);
  45. $frame_incubadora->setLegend('Incubadora');
  46. $frame_incubadora->style .= ';margin: 4px';
  47. $idReproducao = new THidden('idReproducao');
  48. $codigo = new TEntry('codigo');
  49. $dataInicioReproducao = new TDate('dataInicioReproducao');
  50. $temperatura = new TEntry('temperatura');
  51. $equipeReproducao = new TEntry('equipeReproducao');
  52. $climaDia = new TEntry('climaDia');
  53. $pesoTotMatFemea = new TEntry('pesoTotMatFemea');
  54. $pesoTotMatMacho = new TEntry('pesoTotMatMacho');
  55. $qtdeMatFemea = new TEntry('qtdeMatFemea');
  56. $qtdeMatMacho = new TEntry('qtdeMatMacho');
  57. $pesoGeralMatriz = new TEntry('pesoGeralMatriz');
  58. $totalGeralHormonio = new TEntry('totalGeralHormonio');
  59. $dataFinalReproducao = new TDate('dataFinalReproducao');
  60. $reproducao_incubadoras = new TDBCheckGroup('reproducao_incubadoras','dbwf','Incubadora','idIncubadora','descIncubadora');
  61. $idMatriz = new ">TDBSeekButton('idMatriz','dbwf',$this->form->getName(),'Matriz','numeroChipMatriz','matrizes_id','matrizes_numeroChipMatriz');
  62. //$matriz = new TEntry('matriz');
  63. $numero = new TEntry('numeroChipMatriz');
  64. $pesoMatriz = new TEntry('pesoMatriz');
  65. $identMatriz = new TEntry('identMatriz');
  66. $sexoMatriz = new TEntry('sexoMatriz');
  67. $multi_matrizes = new TMultiField('matrizes');
  68. $txEclosao = new TEntry('txEclosao');
  69. $txFecundacao = new TEntry('txFecundacao');
  70. if (!empty($codigo))
  71. {
  72. $codigo->setEditable(FALSE);
  73. }
  74. $idMatriz->setExitAction(new TAction(array($this, 'onExitMatriz')));
  75. $scroll = new TScroll;
  76. $scroll->setSize(290, 240);
  77. $scroll->add( $reproducao_incubadoras );
  78. $frame_incubadora->add($scroll);
  79. $frame_matrizes->add($multi_matrizes);
  80. //$matriz->setEditable(false);
  81. $codigo->setSize('50%');
  82. $temperatura->setSize('100%');
  83. $equipeReproducao->setSize('100%');
  84. $climaDia->setSize('100%');
  85. $pesoTotMatFemea->setSize('100%');
  86. $pesoTotMatMacho->setSize('100%');
  87. $totalGeralHormonio->setSize('100%');
  88. $qtdeMatFemea->setSize('100%');
  89. $qtdeMatMacho->setSize('100%');
  90. $pesoGeralMatriz->setSize('100%');
  91. $numero->setEditable(false);
  92. $sexoMatriz->setSize(40);
  93. $sexoMatriz->setEditable(false);
  94. $dataInicioReproducao->date2br;
  95. $multi_matrizes->setHeight(120);
  96. $multi_matrizes->setClass('Matriz');
  97. $multi_matrizes->addField('id','Matriz', $idMatriz,60);
  98. $multi_matrizes->addField('numeroChipMatriz','Numero', $numero, 60,'center');
  99. $multi_matrizes->addField('identMatriz','Identificação',$identMatriz,140);
  100. $multi_matrizes->addField('pesoMatriz','Peso Atual', $pesoMatriz,80);
  101. $multi_matrizes->addField('sexoMatriz','Sexo',$sexoMatriz,60,'center');
  102. $multi_matrizes->setOrientation('vertical');
  103. $row = $tbl_dados_primarios->addRow();
  104. $row->addCell(new TLabel('Nº:'))->style='width:75px';
  105. $row->addcell($codigo);
  106. $row->addCell(new TLabel(''))->style='width:75px';
  107. $row->addcell($idReproducao);
  108. $tbl_dados_primarios->addRowSet(new TLabel('INICIO'.': ' ), $dataInicioReproducao);
  109. $tbl_dados_primarios->addRowSet(new TLabel('TEMPERATURA'.': ' ), $temperatura);
  110. $tbl_dados_primarios->addRowSet(new TLabel('EQUIPE'.': '), $equipeReproducao);
  111. $tbl_dados_primarios->addRowSet(new TLabel('CLIMA DO DIA'.': '), $climaDia);
  112. //$tbl_dados_primarios->addRowSet(new TLabel('FINAL'.': '), $dataFinalReproducao);
  113. $row = $tbl_estatisticas->addRow();
  114. $row->addCell(new TLabel('TAXA DE ECLOSÃO:'))->style='width:150px';
  115. $row->addCell($txEclosao);
  116. $tbl_estatisticas->addRowSet(new TLabel('TAXA DE FECUNDAÇÃO'.': '), $txFecundacao);
  117. $tbl_estatisticas->addRowSet(new TLabel('FINAL'.': '), $dataFinalReproducao);
  118. //$tbl_estatisticas->addRowSet(new TLabel('TOTAL MACHOS'.': '), $qtdeMatMacho);
  119. $row = $tbl_matrizes->addRow();
  120. $row->addCell(new TLabel('TOTAL FÊMEAS: '))->style='width:150px';
  121. $row->addCell($qtdeMatFemea);
  122. $tbl_matrizes->addRowSet(new TLabel('TOTAL MACHOS'.': '), $qtdeMatMacho);
  123. $tbl_matrizes->addRowSet(new TLabel('TOTAL HORMÔNIO'.': '), $totalGeralHormonio);
  124. $row = $tbl_matriz2->addRow();
  125. $row->addCell(new TLabel('PESO FÊMEAS'.': '))->style='width:150px';
  126. $row->addCell($pesoTotMatFemea);
  127. $tbl_matriz2->addRowSet(new TLabel('PESO MACHOS'.': '), $pesoTotMatMacho);
  128. $tbl_matriz2->addRowSet(new TLabel('TOTAL MATRIZES'.': '), $pesoGeralMatriz);
  129. $hbox3->add($frame_matrizes)->style .='vertical-align:top';
  130. $hbox3->add($frame_incubadora)->style .='vertical-align:top';
  131. $save_button=new TButton('save');
  132. $save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
  133. $save_button->setImage('fa:floppy-o');
  134. // create an new button (edit with no parameters)
  135. $new_button=new TButton('new');
  136. $new_button->setAction(new TAction(array('FrmReproducao', 'onClear')), _t('New'));
  137. $new_button->setImage('fa:plus-square green');
  138. $list_button=new TButton('list');
  139. $list_button->setAction(new TAction(array('FrmListaReproducao','onReload')), _t('Back to the listing'));
  140. $list_button->setImage('fa:table blue');
  141. // define the form fields
  142. $this->form->setFields(array($idReproducao, $equipeReproducao, $txEclosao, $codigo, $dataInicioReproducao, $dataFinalReproducao, $temperatura, $climaDia, $pesoTotMatFemea, $pesoTotMatMacho,
  143. $qtdeMatFemea, $qtdeMatMacho, $pesoGeralMatriz, $txFecundacao, $totalGeralHormonio, $reproducao_incubadoras, $multi_matrizes, $save_button, $new_button, $list_button));
  144. $buttons = new THBox;
  145. $buttons->add($save_button);
  146. $buttons->add($new_button);
  147. $buttons->add($list_button);
  148. $row=$tbl_reproducao->addRow();
  149. $row->class = 'tformaction';
  150. $row->addCell( $buttons );
  151. $container = new TTable;
  152. $container->style = 'width: 80%';
  153. //$container->addRow()->addCell(new TXMLBreadCrumb('menu.xml', 'SystemUserList'));
  154. $container->addRow()->addCell($this->form);
  155. // add the form to the page
  156. parent::add($container);
  157. }
  158. public function onSave(){
  159. try{
  160. TTransaction::open('dbwf');
  161. TTransaction::setLogger(new TLoggerTXT('C:log.txt'));
  162. TTransaction::log('Inserir Reproducao ');
  163. $this->form->validate();
  164. $object = $this->form->getData('Reproducao');
  165. $data = $this->form->getData();
  166. if($data->matrizes)
  167. {
  168. //$rep_matrizes = array();
  169. foreach($data->matrizes as $mat)
  170. {
  171. $matriz = new Matriz($mat->id);
  172. $reproducao_matriz = new RepMatriz();
  173. $reproducao_matriz->matriz = $matriz;
  174. $reproducao_matriz->pesoMatriz = $mat->pesoMatriz;
  175. $reproducao_matriz->identMatriz = $mat->identMatriz;
  176. //$object->set_repMatriz($reproducao_matriz);
  177. $object->repMatriz = $reproducao_matriz;
  178. }
  179. //$object->repMatriz = $rep_matrizes;
  180. }
  181. if($data->reproducao_incubadoras)
  182. {
  183. foreach ($data->reproducao_incubadoras as $incubadora)
  184. {
  185. $object->addIncubadora(new Incubadora($incubadora));
  186. }
  187. }
  188. //$data = Reproducao::calcular();
  189. $object->store();
  190. $object->clearParts();
  191. TTransaction::close();
  192. new TMessage('info','Registro Gravado com sucesso!');
  193. }
  194. catch(Exception $e){
  195. new TMessage('error','<b>Erro ao gravar o Registro! </b>'. $e->getMessage());
  196. $this->form->setData( $this->form->getData() );
  197. TTransaction::rollback();
  198. }
  199. }
  200. public function onEdit($param)
  201. {
  202. try
  203. {
  204. if(isset($param['key']))
  205. {
  206. $key = $param['key'];
  207. TTransaction::open('dbwf');
  208. TTransaction::setLogger(new TLoggerTXT('C:Carregar_log.txt'));
  209. TTransaction::log('Carregar Reproducao ');
  210. $object = new Reproducao($key);
  211. $incubadoras = $object->getIncubadoras();
  212. $repmatrizes = $object->repMatriz;
  213. // var_dump($repmatrizes);
  214. $reproducao_incubadoras = array();
  215. if($incubadoras)
  216. {
  217. foreach($incubadoras as $incubadora){
  218. $reproducao_incubadoras[] = $incubadora->idIncubadora;
  219. }
  220. }
  221. $object->reproducao_incubadoras = $reproducao_incubadoras;
  222. $object->codigo = str_pad($object->codigo, 10,"0", STR_PAD_LEFT);
  223. $reproducao_matrizes = array();
  224. if($repmatrizes)
  225. {
  226. foreach($repmatrizes as $repmatriz)
  227. {
  228. //$reproducao_matrizes[$repmatriz] = $value;
  229. //$object->matrizes_id = $repmatriz->idMatriz;
  230. //$object->matrizes_numeroChipMatriz = $repmatriz->matriz->numeroChipMatriz;
  231. //$object->matrizes_identMatriz = $repmatriz->identMatriz;
  232. //$object->matrizes_pesoMatriz = $repmatriz->pesoMatriz;
  233. //$object->matrizes_sexoMatriz = $repmatriz->matriz->sexoMatriz;
  234. /*var_dump($object->matrizes_identMatriz);*/
  235. $reproducao_matrizes[] = $repmatriz;
  236. }
  237. $object->matrizes = $reproducao_matrizes;
  238. //var_dump($object->matrizes_sexoMatriz);
  239. $object->matrizes_sexoMatriz = TMultiField::setValue($object->matrizes_sexoMatriz);
  240. }
  241. $this->form->setData($object);
  242. TTransaction::close();
  243. }
  244. }
  245. catch(Exception $e)
  246. {
  247. new TMessage('error','<b>Erro ao gravar o Registro!</b>'. $e->getMessage());
  248. TTransaction::rollback();
  249. }
  250. }
  251. public static function onExitMatriz($param)
  252. {
  253. $idMatriz = $param['key'];
  254. //$sexoMatriz = (double) str_replace(',','.', $param['sexoMatriz']);
  255. try
  256. {
  257. TTransaction::open('dbwf');
  258. $matriz = new Matriz($idMatriz);
  259. $obj = new StdClass;
  260. $obj->matrizes_sexoMatriz = $matriz->sexoMatriz;
  261. TTransaction::close();
  262. TForm::sendData('FrmMestreReproducao', $obj);
  263. }
  264. catch(Exception $e)
  265. {
  266. }
  267. }
  268. public static function onCalcular($param)
  269. {
  270. }
  271. }
  272. ?>


Pablo,
fiz conforme você sugeriu no Post anterior, porém ele está carregando apenas os dados da classe RepMatriz, os da classe associada a esta classe não estão sendo carregados, pensei em passar manualmente dentro do array, por exemplo: "$reproducao_matrizes['matrizes_numeroChipMatriz'] = $repmatriz->matriz->numeroChipMatriz;" , porém o framework retorna erro. Meus recursos estão se esgotando.. rsrsrs.

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 (0)