Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * GnrSacForm Registration
- * @author <your name here>
- */
- class GnrSacForm extends TPage
- {
- protected $form; // form
- protected $gnr_cpfcnpj;
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new TForm('form_GnrSac');
- $this->form->class = 'tform'; // CSS class
- $this->form->style = 'width: 100%';
- // add a table inside form
- $table = new TTable;
- $table-> width = '100%';
- $this->form->add($table);
- // add a row for the form title
- $row = $table->addRow();
- $row->class = 'tformtitle'; // CSS class
- $row->addCell( new TLabel('Manter Sacado') )->colspan = 2;
- // create the form fields
- $gnr_id = new TEntry('gnr_id');
- $gnr_id_ext = new TEntry('gnr_id_ext');
- $gnr_nome = new TEntry('gnr_nome');
- //$gnr_tipo = new TCombo('gnr_tipo');
- //$gnr_tipo = new TRadioGroup('gnr_tipo');
- $this->gnr_cpfcnpj = new TEntry('gnr_cpfcnpj');
- $gnr_cep = new TSeekButton('gnr_cep');
- $gnr_tipo = new TRadioGroup('gnr_tipo');
- $gnr_tipo->setLayout('horizontal');
- $items = array();
- $items[1] = 'CNPJ';
- $items[2] = 'CPF';
- $gnr_tipo->addItems($items);
- $gnr_tipo->setValue(1);
- // set exit action for tipocadastro
- $change_action = new TAction(array($this, 'onChangeAction'));
- $gnr_tipo->setChangeAction($change_action);
- /* $gnr_tipo_items = array();
- $gnr_tipo_items['F'] ='Física';
- $gnr_tipo_items['J'] ='Jurídica';
- $gnr_tipo->addItems($gnr_tipo_items);*/
- // define the sizes
- $gnr_id->setSize(100);
- $gnr_id_ext->setSize(100);
- $gnr_nome->setSize(200);
- $gnr_tipo->setSize(200);
- $gnr_cpfcnpj->setSize(100);
- $gnr_cep->setSize(200);
- // validations
- $gnr_id_ext->addValidation('ID Externo', new TRequiredValidator);
- $gnr_nome->addValidation('Nome', new TRequiredValidator);
- $gnr_tipo->addValidation('Tipo Pessoa', new TRequiredValidator);
- $gnr_cpfcnpj->addValidation('CPF/CNPJ', new TRequiredValidator);
- $gnr_cep->addValidation('CEP', new TRequiredValidator);
- // add one row for each form field
- $table->addRowSet( new TLabel('ID:'), $gnr_id );
- $table->addRowSet( $label_gnr_id_ext = new TLabel('ID Externo:'), $gnr_id_ext );
- $table->addRowSet( $label_gnr_nome = new TLabel('Nome:'), $gnr_nome );
- $table->addRowSet( $label_gnr_tipo = new TLabel('Tipo Pessoa:'), $gnr_tipo );
- $table->addRowSet( $label_gnr_cpfcnpj = new TLabel('CPF/CNPJ:'), $gnr_cpfcnpj );
- $table->addRowSet( $label_gnr_cep = new TLabel('CEP:'), $gnr_cep );
- $change_action = new TAction(array($this, 'onChangeAction'));
- $gnr_tipo->setChangeAction($change_action);
- $this->form->setFields(array($gnr_id,$gnr_id_ext,$gnr_nome,$gnr_tipo,$gnr_cpfcnpj,$gnr_cep));
- // create the form actions
- $save_button = TButton::create('save', array($this, 'onSave'), _t('Save'), 'ico_save.png');
- $new_button = TButton::create('new', array($this, 'onEdit'), _t('New'), 'ico_new.png');
- $this->form->addField($save_button);
- $this->form->addField($new_button);
- $buttons_box = new THBox;
- $buttons_box->add($save_button);
- $buttons_box->add($new_button);
- // add a row for the form action
- $row = $table->addRow();
- $row->class = 'tformaction'; // CSS class
- $row->addCell($buttons_box)->colspan = 2;
- $container = new TTable;
- $container->style = 'width: 80%';
- $container->addRow()->addCell(new TXMLBreadCrumb('menu.xml','GnrSacList'));
- $container->addRow()->addCell($this->form);
- parent::add($container);
- }
- public static function onChangeAction($param)
- {
- try{
- $obj = new StdClass;
- $checked = $param['gnr_tipo'];
- new TMessage('error', '<b>Error</b> ' .$param['gnr_tipo'] );
- if ($checked == 1){
- $this->gnr_cpfcnpj->setMask('99.999.999/9999-99'); // aqui da erro
- }
- else{
- $this->gnr_cpfcnpj->setMask('999.999.999-99'); // aqui tambem da erro
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- //TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * method onSave()
- * Executed whenever the user clicks at the save button
- */
- function onSave()
- {
- try
- {
- TTransaction::open('permission'); // open a transaction
- // get the form data into an active record GnrSac
- $object = $this->form->getData('GnrSac');
- $this->form->validate(); // form validation
- $object->store(); // stores the object
- $this->form->setData($object); // keep form data
- TTransaction::close(); // close the transaction
- // shows the success message
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * method onEdit()
- * Executed whenever the user clicks at the edit button da datagrid
- */
- function onEdit($param)
- {
- try
- {
- if (isset($param['key']))
- {
- $key=$param['key']; // get the parameter $key
- TTransaction::open('permission'); // open a transaction
- $object = new GnrSac($key); // instantiates the Active Record
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement