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


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