示例#1
0
 public function onSave()
 {
     try {
         // open a transaction with database
         TTransaction::open($this->database);
         // get the form data
         $object = $this->form->getData($this->activeRecord);
         // validate data
         $this->form->validate();
         // stores the object
         $object->store();
         // fill the form with the active record data
         $this->form->setData($object);
         // close the transaction
         TTransaction::close();
         // shows the success message
         //new TMessage('info', AdiantiCoreTranslator::translate('Record saved'));
         parent::add(new TAlert('info', AdiantiCoreTranslator::translate('Record saved')));
         $this->form->clear();
         return $object;
     } catch (Exception $e) {
         // get the form data
         $object = $this->form->getData($this->activeRecord);
         // fill the form with the active record data
         $this->form->setData($object);
         // shows the exception error message
         new TMessage('error', $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
 function onEdit($param)
 {
     try {
         TTransaction::open(APPLICATION_NAME);
         if (isset($param['key'])) {
             //recebe codigo
             $key = $param['key'];
             //abre cidade com codigo recebido
             $cidade = new cidade($key);
             $this->form->setData($cidade);
             // fill the form with the active record data
             //abre UF com codigo da UF da cidade
             $uf = $cidade->get_uf();
             //exibe o nome da UF no formulário
             $this->nomeuf->setValue($uf->nome);
             //$this->onReload( $param ); // reload sale items list
             TTransaction::close();
             // close transaction
         } else {
             $this->form->clear();
             //$this->onReload( $param );
         }
     } catch (Exception $e) {
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         TTransaction::rollback();
     }
 }
 /**
  * method onEdit()
  * Executed whenever the user clicks at the edit button da datagrid
  * @param  $param An array containing the GET ($_GET) parameters
  */
 public function onEdit($param)
 {
     try {
         if (isset($param['key'])) {
             // get the parameter $key
             $key = $param['key'];
             // open a transaction with database
             TTransaction::open($this->database);
             $class = $this->activeRecord;
             // instantiates object
             $object = new $class($key);
             // fill the form with the active record data
             $this->form->setData($object);
             // close the transaction
             TTransaction::close();
             return $object;
         } else {
             $this->form->clear();
         }
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
 /**
  * Search by the given word inside a model
  */
 public static function onSearch($param = null)
 {
     $key = $param['key'];
     $seed = APPLICATION_NAME . 's8dkld83kf73kf094';
     $hash = md5("{$seed}{$param['database']}{$param['key']}{$param['column']}{$param['model']}");
     $operator = $param['operator'] ? $param['operator'] : 'like';
     $mask = $param['mask'];
     if ($hash == $param['hash']) {
         try {
             TTransaction::open($param['database']);
             $repository = new TRepository($param['model']);
             $criteria = new TCriteria();
             if ($param['criteria']) {
                 $criteria = unserialize(base64_decode(str_replace(array('-', '_'), array('+', '/'), $param['criteria'])));
             }
             $column = $param['column'];
             if (stristr(strtolower($operator), 'like') !== FALSE) {
                 $filter = new TFilter($column, $operator, "NOESC:'%{$param['value']}%'");
             } else {
                 $filter = new TFilter($column, $operator, "NOESC:'{$param['value']}'");
             }
             $criteria->add($filter);
             $criteria->setProperty('order', $param['orderColumn']);
             $criteria->setProperty('limit', 1000);
             $collection = $repository->load($criteria, FALSE);
             $items = array();
             if ($collection) {
                 foreach ($collection as $object) {
                     $k = $object->{$key};
                     $array_object = $object->toArray();
                     $maskvalues = $mask;
                     foreach ($array_object as $property => $value) {
                         $maskvalues = str_replace('{' . $property . '}', $value, $maskvalues);
                     }
                     $c = $maskvalues;
                     if ($k != null && $c != null) {
                         if (utf8_encode(utf8_decode($c)) !== $c) {
                             $c = utf8_encode($c);
                         }
                         if (!empty($k) && !empty($c)) {
                             $items[] = "{$k}::{$c}";
                         }
                     }
                 }
             }
             $ret = array();
             $ret['result'] = $items;
             echo json_encode($ret);
             TTransaction::close();
         } catch (Exception $e) {
             $ret = array();
             $ret['result'] = array("1::" . $e->getMessage());
             echo json_encode($ret);
         }
     }
 }
 /**
  * Search by the given word inside a model
  */
 public static function onSearch($param = null)
 {
     $seed = APPLICATION_NAME . 's8dkld83kf73kf094';
     $hash = md5("{$seed}{$param['database']}{$param['column']}{$param['model']}");
     $operator = $param['operator'] ? $param['operator'] : 'like';
     if ($hash == $param['hash']) {
         try {
             TTransaction::open($param['database']);
             $repository = new TRepository($param['model']);
             $criteria = new TCriteria();
             if ($param['criteria']) {
                 $criteria = unserialize(base64_decode($param['criteria']));
             }
             $column = $param['column'];
             if (stristr(strtolower($operator), 'like') !== FALSE) {
                 $filter = new TFilter($column, $operator, "NOESC:'%{$param['query']}%'");
             } else {
                 $filter = new TFilter($column, $operator, "NOESC:'{$param['query']}'");
             }
             $criteria->add($filter);
             $criteria->setProperty('order', $param['orderColumn']);
             $criteria->setProperty('limit', 1000);
             $collection = $repository->load($criteria, FALSE);
             $items = array();
             if ($collection) {
                 foreach ($collection as $object) {
                     $c = $object->{$column};
                     if ($c != null) {
                         if (utf8_encode(utf8_decode($c)) !== $c) {
                             $c = utf8_encode($c);
                         }
                         if (!empty($c)) {
                             $items[] = $c;
                         }
                     }
                 }
             }
             $ret = array();
             $ret['query'] = 'Unit';
             $ret['suggestions'] = $items;
             echo json_encode($ret);
             TTransaction::close();
         } catch (Exception $e) {
             $ret = array();
             $ret['query'] = 'Unit';
             $ret['suggestions'] = array($e->getMessage());
             echo json_encode($ret);
         }
     } else {
         $ret = array();
         $ret['query'] = 'Unit';
         $ret['suggestions'] = NULL;
         echo json_encode($ret);
     }
 }
示例#6
0
 /**
  * Returns the SELECT statement as an string according to the database driver
  * @param $prepared Return a prepared Statement
  */
 public function getInstruction($prepared = FALSE)
 {
     $conn = TTransaction::get();
     $driver = $conn->getAttribute(PDO::ATTR_DRIVER_NAME);
     if (in_array($driver, array('mssql', 'dblib', 'sqlsrv'))) {
         return $this->getSqlServerInstruction($prepared);
     }
     if (in_array($driver, array('oci', 'oci8'))) {
         return $this->getOracleInstruction($prepared);
     } else {
         return $this->getStandardInstruction($prepared);
     }
 }
示例#7
0
 /**
  * Transform the value according to its PHP type
  * before send it to the database
  * @param $value    Value to be transformed
  * @param $prepared If the value will be prepared
  * @return       Transformed Value
  */
 private function transform($value, $prepared = FALSE)
 {
     // store just scalar values (string, integer, ...)
     if (is_scalar($value)) {
         // if is a string
         if (is_string($value) and !empty($value)) {
             if ($prepared) {
                 $preparedVar = ':par_' . uniqid();
                 $this->preparedVars[$preparedVar] = $value;
                 $result = $preparedVar;
             } else {
                 $conn = TTransaction::get();
                 $result = $conn->quote($value);
             }
         } else {
             if (is_bool($value)) {
                 $result = $value ? 'TRUE' : 'FALSE';
             } else {
                 if ($value !== '') {
                     if ($prepared) {
                         $preparedVar = ':par_' . uniqid();
                         $this->preparedVars[$preparedVar] = $value;
                         $result = $preparedVar;
                     } else {
                         $result = $value;
                     }
                 } else {
                     $result = "NULL";
                 }
             }
         }
     } else {
         if (is_null($value)) {
             $result = "NULL";
         }
     }
     return $result;
 }
示例#8
0
 public function __construct()
 {
     //$this->objReader = new PHPExcel_Reader_Excel2007();
     //$this->objReader->setReadDataOnly(true);
     TTransaction::open('saciq');
     try {
         $this->referencia = array();
         $rep = new TRepository('Referencia');
         $import_name = $rep->load();
         if ($import_name) {
             foreach ($import_name as $value) {
                 $this->referencia[$value->nome] = $value->referencia;
             }
         } else {
             throw new Exception('Arquivo de configuração inválido');
         }
         TTransaction::close();
     } catch (Exception $ex) {
         new TMessage('error', $ex->getMessage());
         TTransaction::rollback();
     }
     //$objReader->setReadDataOnly(true);
 }
 function onEdit($param)
 {
     try {
         TTransaction::open(APPLICATION_NAME);
         if (isset($param['key'])) {
             //abre contabancaria com codigo recebido da listagem
             $contabancaria = new contabancaria($param['key']);
             $this->form->setData($contabancaria);
             // fill the form with the active record data
             //exibe FK no formulario
             $this->nomecidade->setValue($contabancaria->get_cidade()->nome);
             $this->nomebanco->setValue($contabancaria->get_banco()->nome);
             $this->descricaotipocontabancaria->setValue($contabancaria->get_tipocontabancaria()->descricao);
             TTransaction::close();
             // close transaction
         } else {
             $this->form->clear();
         }
     } catch (Exception $e) {
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         TTransaction::rollback();
     }
 }
示例#10
0
 /**
  * Class Constructor
  * @param  $name     widget's name
  * @param  $database database name
  * @param  $model    model class name
  * @param  $key      table field to be used as key in the combo
  * @param  $value    table field to be listed in the combo
  * @param  $ordercolumn column to order the fields (optional)
  * @param  $criteria criteria (TCriteria object) to filter the model (optional)
  */
 public function __construct($name, $database, $model, $key, $value, $ordercolumn = NULL, TCriteria $criteria = NULL)
 {
     // executes the parent class constructor
     parent::__construct($name);
     if (empty($database)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'database', __CLASS__));
     }
     if (empty($model)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'model', __CLASS__));
     }
     if (empty($key)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'key', __CLASS__));
     }
     if (empty($value)) {
         throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'value', __CLASS__));
     }
     // carrega objetos do banco de dados
     TTransaction::open($database);
     // instancia um repositório de Estado
     $repository = new TRepository($model);
     if (is_null($criteria)) {
         $criteria = new TCriteria();
     }
     $criteria->setProperty('order', isset($ordercolumn) ? $ordercolumn : $key);
     // carrega todos objetos
     $collection = $repository->load($criteria, FALSE);
     // adiciona objetos na combo
     if ($collection) {
         $items = array();
         foreach ($collection as $object) {
             $items[$object->{$key}] = $object->{$value};
         }
         parent::addItems($items);
     }
     TTransaction::close();
 }
示例#11
0
 /**
  * method onGenerate()
  * Executed whenever the user clicks at the generate button
  */
 function onGenerate()
 {
     try {
         // open a transaction with database 'saciq'
         TTransaction::open('saciq');
         //TTransaction::setLogger(new TLoggerTXT("c:\\array\\LOG" . date("Ymd-His") . ".txt"));
         // get the form data into an active record
         $formdata = $this->form->getData();
         $validadeI = $formdata->validadeI;
         $validadeF = TDate::date2us($formdata->validadeF);
         if (!$validadeI === 0) {
             $validadeI = '0';
         } else {
             $validadeI = TDate::date2us($validadeI);
         }
         $this->form->validate();
         $repository = new TRepository('Srp');
         $criteria = new TCriteria();
         $param['order'] = 'id';
         $param['direction'] = 'desc';
         $criteria->setProperties($param);
         if ($formdata->numeroProcessoI != '' && $formdata->numeroProcessoF != '') {
             $criteria->add(new TFilter('numeroProcesso', 'BETWEEN', "{$formdata->numeroProcessoI}", "{$formdata->numeroProcessoF}"));
         }
         if ($formdata->validadeI != '' && $formdata->validadeF != '') {
             $criteria->add(new TFilter('validade', 'between', "{$validadeI}", "{$validadeF}"));
         }
         if ($formdata->numeroSRPI != '' && $formdata->numeroSRPF != '') {
             $criteria->add(new TFilter('numeroSRP', 'between', "{$formdata->numeroSRPI}", "{$formdata->numeroSRPF}"));
         }
         if ($formdata->numeroIRPI != '' && $formdata->numeroIRPF != '') {
             $criteria->add(new TFilter('numeroIRP', 'between', "{$formdata->numeroIRPI}", "{$formdata->numeroIRPF}"));
         }
         $imprimeZero = true;
         if (isset($formdata->itensZero)) {
             if ($formdata->itensZero === '0') {
                 $imprimeZero = false;
             }
         }
         $srps = $repository->load($criteria, true);
         if ($srps) {
             $this->pdf = new FPDF();
             $this->pdf->AliasNbPages();
             $this->pdf->SetMargins(10, 10, 10);
             $this->pdf->setHeaderCallback(array($this, 'header'));
             $this->pdf->setFooterCallback(array($this, 'footer'));
             $this->pdf->AddPage();
             foreach ($srps as $srp) {
                 $this->data = $srp;
                 $this->srpHeader($imprimeZero);
                 $this->srpItens($imprimeZero);
             }
             if (!file_exists("app/output/RelatorioSrp.pdf") or is_writable("app/output/RelatorioSrp.pdf")) {
                 $this->pdf->Output("app/output/RelatorioSrp.pdf");
             } else {
                 throw new Exception('Permissão negada' . ': ' . "app/output/RelatorioSrp.pdf");
             }
             parent::openFile("app/output/RelatorioSrp.pdf");
             //new TMessage('info', 'Relatório gerado. Por favor, habilite o pop-up do seu browser.');
         } else {
             new TMessage('error', 'Nenhum registro encontrado');
         }
         // fill the form with the active record data
         $this->form->setData($formdata);
         // close the transaction
         TTransaction::close();
     } catch (Exception $e) {
         // in case of exception
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }
示例#12
0
 /**
  * Select the register by ID and return the information to the main form
  *     When using onblur signal, AJAX passes all needed parameters via GET
  *     instead of calling onSetup before.
  */
 public static function onSelect($param)
 {
     $key = $param['key'];
     $database = isset($param['database']) ? $param['database'] : TSession::getValue('standard_seek_database');
     $receive_key = isset($param['receive_key']) ? $param['receive_key'] : TSession::getValue('standard_seek_receive_key');
     $receive_field = isset($param['receive_field']) ? $param['receive_field'] : TSession::getValue('standard_seek_receive_field');
     $display_field = isset($param['display_field']) ? $param['display_field'] : TSession::getValue('standard_seek_display_field');
     $parent = isset($param['parent']) ? $param['parent'] : TSession::getValue('standard_seek_parent');
     try {
         TTransaction::open($database);
         // load the active record
         $model = isset($param['model']) ? $param['model'] : TSession::getValue('standard_seek_model');
         $activeRecord = new $model($key);
         $pk = constant("{$model}::PRIMARYKEY");
         $object = new StdClass();
         $object->{$receive_key} = isset($activeRecord->{$pk}) ? $activeRecord->{$pk} : '';
         $object->{$receive_field} = isset($activeRecord->{$display_field}) ? $activeRecord->{$display_field} : '';
         TTransaction::close();
         TForm::sendData($parent, $object);
         parent::closeWindow();
         // closes the window
     } catch (Exception $e) {
         // clear fields
         $object = new StdClass();
         $object->{$receive_key} = '';
         $object->{$receive_field} = '';
         TForm::sendData($parent, $object);
         // undo all pending operations
         TTransaction::rollback();
     }
 }
示例#13
0
 /**
  * Returns the LAST Object ID from database
  * @return      An Integer containing the LAST Object ID from database
  * @exception   Exception if there's no active transaction opened
  */
 public function getLastID()
 {
     $pk = $this->getPrimaryKey();
     // get the connection of the active transaction
     if ($conn = TTransaction::get()) {
         // instancia instrução de SELECT
         $sql = new TSqlSelect();
         $sql->addColumn("max({$pk}) as {$pk}");
         $sql->setEntity($this->getEntity());
         // register the operation in the LOG file
         TTransaction::log($sql->getInstruction());
         $result = $conn->Query($sql->getInstruction());
         // retorna os dados do banco
         $row = $result->fetch();
         return $row[0];
     } else {
         // if there's no active transaction opened
         throw new Exception(AdiantiCoreTranslator::translate('No active transactions') . ': ' . __METHOD__ . ' ' . $this->getEntity());
     }
 }
示例#14
0
 /**
  * method onEdit()
  * Executed whenever the user clicks at the edit button da datagrid
  */
 function onEdit($param)
 {
     try {
         if (isset($param['key'])) {
             // get the parameter $key
             $key = $param['key'];
             // abre transacao com banco 'saciq'
             TTransaction::open('saciq');
             // instancia um objeto do tipo Grupo
             $object = new Grupo($key);
             $object->programs = $object->getFuncionalidades();
             // fill the form with the active record data
             $this->form->setData($object);
             // close the transaction
             TTransaction::close();
         } else {
             $this->form->clear();
         }
         $this->onReload($param);
     } catch (Exception $e) {
         // Em caso de erro
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }
示例#15
0
 public function onSave($param)
 {
     try {
         $this->form_requisicao->validate();
         // validate form data
         $form_requisicao_data = $this->form_requisicao->getData();
         $form_requisicao = TSession::getValue('form_requisicao');
         $form_requisicao->numeroProcesso = $form_requisicao_data->numeroProcesso;
         $form_requisicao->emissao = $form_requisicao_data->emissao;
         $requisicao_itens = TSession::getValue('requisicao_itens');
         if (!isset($requisicao_itens) || count($requisicao_itens) == 0) {
             new TMessage('error', 'Insira ao menos 1 item');
             return;
         }
         TTransaction::open('saciq');
         //TTransaction::setLogger(new \Adianti\Log\TLoggerTXT("c:\\array\\LOG".date("Ymd-His").".txt"));
         if ($requisicao_itens) {
             $id = isset($form_requisicao->id) ? $form_requisicao->id : NULL;
             $requisicao = new Requisicao($id);
             // create a new Sale
             $requisicao->clearParts();
             $requisicao->numeroProcesso = $form_requisicao->numeroProcesso;
             $requisicao->emissao = TDate::date2us($form_requisicao->emissao);
             //if (!$requisicao->emissao){
             //    $requisicao->emissao = date("Y-m-d");
             //}
             $requisicao->aprovado = 0;
             $requisicao->srp = new Srp(TSession::getValue("SRP_id"));
             foreach ($requisicao_itens as $item) {
                 $item_requisicao = new Item($item->item_id);
                 $item_requisicao->justificativa = $item->justificativa;
                 $item_requisicao->quantidade = $item->quantidade;
                 $item_requisicao->prazoEntrega = $item->prazoEntrega;
                 $item_requisicao->quantidade = str_replace('.', '', $item->quantidade);
                 $item_requisicao->quantidade = str_replace(',', '.', $item->quantidade);
                 $requisicao->addItem($item_requisicao);
                 // add the item to the Sale
             }
             $requisicao->store();
             // store the Sale
             TSession::delValue('requisicao_itens');
             TSession::delValue('form_requisicao');
             TSession::delValue('SRP_id');
             new TMessage('info', 'Requisição salva');
         }
         TTransaction::close();
         $this->onReload();
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
     }
 }
 /**
  * method Delete()
  * Delete a record
  */
 function Delete($param)
 {
     try {
         $key = $param['key'];
         // get the parameter $key
         TTransaction::open('saciq');
         // open a transaction with database
         $object = new Cessao($key, FALSE);
         // instantiates the Active Record
         $object->delete();
         // deletes the object from the database
         TTransaction::close();
         // close the transaction
         $this->onReload($param);
         // reload the listing
         new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'));
         // success message
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }
示例#17
0
 function onReload($param = null)
 {
     $this->datagrid->clear();
     $key = $param['key'];
     if (!isset($key)) {
         $value = TSession::getValue('srp_form_view_key');
         if (!isset($value)) {
             return;
         }
         $key = $value;
     }
     try {
         TTransaction::open('saciq');
         $srp = new Srp($key);
         if (!isset($srp)) {
             TTransaction::close();
             return;
         }
         $object = new stdClass();
         $object->id = $srp->id;
         $object->numeroSRP = $srp->numeroSRP;
         $object->numeroIRP = $srp->numeroIRP;
         $object->numeroProcesso = $srp->numeroProcesso;
         $object->uasg = $srp->uasg;
         $object->validade = TDate::date2br($srp->validade);
         $object->nome = $srp->nome;
         $object->natureza = $srp->natureza->descricao;
         foreach ($srp->getItems() as $item) {
             $row = $this->datagrid->addItem($item);
         }
         TForm::sendData('SrpFormView', $object);
         TTransaction::close();
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }
示例#18
0
 /**
  * method Delete()
  * Deleta o registro
  */
 function Delete($param)
 {
     try {
         // pega o parametro $key
         $key = $param['key'];
         // abre uma transacao com o banco 'saciq'
         TTransaction::open('saciq');
         // instancia o objeto Grupo
         $object = new Grupo($key);
         // deleta os objetos do banco de dados
         $object->delete();
         // fecha a transacao
         TTransaction::close();
         // recarrega a listagem
         $this->onReload($param);
         // mostra menssagem de sucesso
         new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'));
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }
 /**
  * method onEdit()
  * Executed whenever the user clicks at the edit button da datagrid
  */
 public function onEdit($param)
 {
     try {
         if (isset($param['key'])) {
             // get the parameter $key
             $key = $param['key'];
             // open a transaction with database
             TTransaction::open($this->database);
             $class = $this->activeRecord;
             // instantiates object
             $object = new $class($key);
             if ($object->system_user_id == TSession::getValue("userid")) {
                 $this->form->setData($object);
                 // fill the form with the active record data
             } else {
                 new TMessage('error', '<b>Registro não encontrado</b> ');
             }
             // close the transaction
             TTransaction::close();
             $this->onReload($param);
         } else {
             $this->form->clear();
         }
     } catch (Exception $e) {
         // in case of exception
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
示例#20
0
 /**
  * method onEdit()
  * Executed whenever the user clicks at the edit button da datagrid
  */
 function onEdit($param)
 {
     try {
         if (isset($param['key'])) {
             // get the parameter $key
             $key = $param['key'];
             // open a transaction with database 'saciq'
             TTransaction::open('saciq');
             // instantiates object Usuario
             $object = new Usuario($key);
             unset($object->senha);
             $grupos = array();
             if ($grupos_db = $object->getUsuarioGrupos()) {
                 foreach ($grupos_db as $grupo) {
                     $grupos[] = $grupo->id;
                 }
             }
             $object->funcionalidades = $object->getUsuarioFuncionalidades();
             $object->grupos = $grupos;
             // fill the form with the active record data
             $this->form->setData($object);
             // close the transaction
             TTransaction::close();
         } else {
             $this->form->clear();
         }
     } catch (Exception $e) {
         // Em caso de erro
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }
示例#21
0
 /**
  * method onEdit
  * Edit a record data
  */
 function onEdit($param)
 {
     try {
         if (isset($param['key'])) {
             // open a transaction with database 'samples'
             TTransaction::open('sobcontrole');
             // load the Active Record according to its ID
             $pessoa = new pessoa($param['key']);
             // load the contacts (composition)
             $pessoa->listacontatos = $pessoa->getContatos();
             // fill the form with the active record data
             $this->form->setData($pessoa);
             // close the transaction
             TTransaction::close();
         } else {
             $this->form->clear();
         }
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b>' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
示例#22
0
 /**
  * method deleteCollection()
  * Delete many records
  */
 public function deleteCollection($param)
 {
     // decode json with record id's
     $selected = json_decode($param['selected']);
     try {
         TTransaction::open($this->database);
         if ($selected) {
             // delete each record from collection
             foreach ($selected as $id) {
                 $class = $this->activeRecord;
                 $object = new $class();
                 $object->delete($id);
             }
             $posAction = new TAction(array($this, 'onReload'));
             $posAction->setParameters($param);
             new TMessage('info', AdiantiCoreTranslator::translate('Records deleted'), $posAction);
         }
         TTransaction::close();
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
         TTransaction::rollback();
     }
 }
示例#23
0
 function onImportFile()
 {
     $data = $this->form->getData();
     $this->importacao = new Importar();
     $this->importacao->loadFile($data->file);
     $this->importacao->setActiveRow(3);
     try {
         TTransaction::open('saciq');
         $criteria = new TCriteria();
         $criteria->add(new TFilter('numeroSRP', '=', $this->importacao->getNroSRP()));
         $criteria->add(new TFilter('numeroIRP', '=', $this->importacao->getNroIRP()));
         $criteria->add(new TFilter('numeroProcesso', '=', $this->importacao->getNumeroProcesso()));
         $criteria->add(new TFilter('uasg', '=', $this->importacao->getUasgGerenciadora()));
         $criteria->add(new TFilter('validade', '=', $this->importacao->getValidadeAta()));
         $repositorySrp = new TRepository('Srp');
         $count = $repositorySrp->count($criteria);
         if ($count > 0) {
             $RepSRP = $repositorySrp->load($criteria);
             $RepSRP[0]->delete();
         }
         $srp = null;
         while (!$this->importacao->eof()) {
             if (!$this->importacao->isValidRow()) {
                 $this->importacao->nextRow();
                 continue;
             }
             $natureza = $this->LoadObjectByField('Natureza', 'descricao', $this->importacao->getNaturezaDespesa());
             if (!isset($natureza)) {
                 $natureza = new Natureza();
                 $natureza->descricao = $this->importacao->getNaturezaDespesa();
                 $natureza->store();
             }
             $subelemento = $this->LoadObjectByField('Subelemento', 'descricao', $this->importacao->getDescricaoSubElemento());
             if (!isset($subelemento)) {
                 $subelemento = new Subelemento();
                 $subelemento->id = $this->importacao->getNumeroSubElemento();
                 $subelemento->descricao = $this->importacao->getDescricaoSubElemento();
                 $subelemento->store();
             }
             $fornecedor = $this->LoadObjectByField('Fornecedor', 'cnpj', $this->importacao->getCNPJ());
             if (!isset($fornecedor)) {
                 $fornecedor = new Fornecedor();
                 $fornecedor->nome = $this->importacao->getFornecedor();
                 $fornecedor->cnpj = $this->importacao->getCNPJ();
                 $fornecedor->store();
             }
             if (!isset($srp)) {
                 $srp = new Srp();
                 $srp->numeroSRP = $this->importacao->getNroSRP();
                 $srp->numeroIRP = $this->importacao->getNroIRP();
                 $srp->numeroProcesso = $this->importacao->getNumeroProcesso();
                 $srp->uasg = $this->importacao->getUasgGerenciadora();
                 $srp->validade = $this->importacao->getValidadeAta();
                 $srp->nome = $this->importacao->getNomeProcesso();
                 $srp->natureza = $natureza;
             }
             $item = new Item();
             $item->numeroItem = $this->importacao->getItem();
             $item->descricaoSumaria = $this->importacao->getDescricaoSumaria();
             $item->descricaoCompleta = $this->importacao->getDescricaoCompleta();
             $item->descricaoPosLicitacao = $this->importacao->getDescricaoPosLicitacao();
             $item->unidadeMedida = $this->importacao->getUnidadeDeMedida();
             $item->marca = $this->importacao->getMarca();
             $item->valorUnitario = $this->importacao->getValorUnitarioLicitado();
             $item->quantidadeDisponivel = $this->importacao->getOrgao(CAMPUS);
             $item->estoqueDisponivel = $item->quantidadeDisponivel;
             $item->fabricante = $this->importacao->getFabricante();
             $item->fornecedor = $fornecedor;
             $item->subelemento = $subelemento;
             $srp->addItem($item);
             $this->importacao->nextRow();
         }
         $srp->store();
         new TMessage('info', 'Planilha importada com sucesso');
         TTransaction::close();
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
     $this->notebook->setCurrentPage(0);
     $this->form->setData($data);
     $this->step->select('Seleção');
 }
示例#24
0
 /**
  * Return the amount of objects that satisfy a given criteria
  * @param $criteria  An TCriteria object, specifiyng the filters
  * @return           An Integer containing the amount of objects that satisfy the criteria
  */
 public function count(TCriteria $criteria = NULL)
 {
     if (!$criteria) {
         $criteria = isset($this->criteria) ? $this->criteria : new TCriteria();
     }
     // creates a SELECT statement
     $sql = new TSqlSelect();
     $sql->addColumn('count(*)');
     $sql->setEntity($this->getEntity());
     // assign the criteria to the SELECT statement
     $sql->setCriteria($criteria);
     // get the connection of the active transaction
     if ($conn = TTransaction::get()) {
         // register the operation in the LOG file
         TTransaction::log($sql->getInstruction());
         $dbinfo = TTransaction::getDatabaseInfo();
         // get dbinfo
         if (isset($dbinfo['prep']) and $dbinfo['prep'] == '1') {
             $result = $conn->prepare($sql->getInstruction(TRUE), array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
             $result->execute($criteria->getPreparedVars());
         } else {
             // executes the SELECT statement
             $result = $conn->query($sql->getInstruction());
         }
         if ($result) {
             $row = $result->fetch();
         }
         // returns the result
         return $row[0];
     } else {
         // if there's no active transaction opened
         throw new Exception(AdiantiCoreTranslator::translate('No active transactions') . ': ' . __METHOD__ . ' ' . $this->getEntity());
     }
 }
示例#25
0
 public function onGenerate($param)
 {
     //var_dump($param);
     $this->B = 0;
     $this->I = 0;
     $this->U = 0;
     $this->HREF = '';
     $data = $this->form->getData();
     $id = $data->cessao_id;
     $this->pdf = new FPDF();
     $this->pdf->AliasNbPages();
     setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
     try {
         TTransaction::open('saciq');
         $this->form->validate();
         $cessao = new Cessao($id);
         $itens_list = $cessao->getItems();
         if (count($itens_list) == 0) {
             new TMessage('error', 'Nenhum item encontrado na cessão');
             $this->form->sendData('doc_cessao_form', $data);
             return;
         }
         $memorando = utf8_decode($data->memorando);
         $emissao = TDate::date2us($data->emissao);
         $repository = new TRepository('Campus');
         $criteria = new TCriteria();
         $criteria->add(new TFilter('sigla', '=', CAMPUS));
         $campus_list = $repository->load($criteria);
         $campus = $campus_list[0];
         $this->cidade = $campus->nome;
         $destino = strtoupper($data->campusNome);
         $this->gerente = $data->gerente;
         $this->diretor = $data->diretor;
         $emissao = strtotime($emissao);
         $mes = ucfirst(strftime('%B', $emissao));
         $emissao = $this->cidade . ', ' . strftime(" %d de {$mes} de %Y.", $emissao);
         $srp = $cessao->srp->numeroSRP;
         $natureza = $cessao->srp->natureza->descricao;
         $nomeSrp = $cessao->srp->nome;
         //$this->pdf->Open();
         $this->pdf->SetMargins(25, 20, 25);
         $this->pdf->setHeaderCallback(array($this, 'Header'));
         //$this->pdf->setFooterCallback(array($this, 'Footer'));
         $this->pdf->AddPage();
         $this->pdf->SetFont('Times', '', 12);
         //$this->pdf->Cell(15);
         $this->pdf->Cell(0, 5, "{$memorando}", 0, 1);
         $this->pdf->Ln(10);
         $this->pdf->Cell(0, 5, $emissao, 0, 0, 'R');
         $this->pdf->Ln(10);
         $this->pdf->Cell(0, 5, utf8_decode('À'), 0, 1);
         $this->pdf->Cell(0, 5, utf8_decode("GERÊNCIA ADMINISTRATIVA DO CAMPUS {$destino}"));
         $this->pdf->Ln(10);
         $this->pdf->SetFont('Times', 'B', 12);
         $this->pdf->MultiCell(0, 5, utf8_decode("ASSUNTO: CESSÃO DE QUANTITATIVO - SRP {$srp} - {$natureza} - {$nomeSrp}"));
         $this->pdf->SetFont('Times', '', 12);
         $this->pdf->Ln(15);
         $this->pdf->SetX(21);
         $this->WriteHTML(utf8_decode("1.Conforme solicitação, autorizamos a utilização do quantitativo abaixo referido," . "referente a estimativa do Câmpus Capivari para a <B>SRP {$srp} - {$natureza} - {$nomeSrp}</B>"));
         $this->pdf->Ln(10);
         //cabecalho da tabela
         $y = $this->pdf->GetY();
         $x = $this->pdf->GetX();
         $this->pdf->SetFont('Times', 'B', 12);
         $width = array(18, 107, 38);
         $this->pdf->MultiCell($width[0], 10, utf8_decode('ITEM'), 1, 'C');
         $this->pdf->SetXY($x += $width[0], $y);
         $this->pdf->MultiCell($width[1], 10, utf8_decode("DESCRIÇÃO"), 1, 'C');
         $this->pdf->SetXY($x += $width[1], $y);
         $this->pdf->MultiCell($width[2], 10, utf8_decode('QUANT.'), 1, 'C');
         $this->pdf->SetFont('Times', '', 12);
         $this->pdf->ln(0);
         $y = $this->pdf->GetY();
         $x = $this->pdf->GetX();
         usort($itens_list, array("DocCessaoForm", "cmp"));
         //preencher a tabela
         foreach ($itens_list as $item) {
             $numeroItem = $item->numeroItem;
             $descricaoSumaria = substr($item->descricaoSumaria, 0, 80);
             $quantidade = $item->quantidade;
             $t1 = $this->pdf->GetStringWidth($descricaoSumaria);
             $tamanhoTexto = $t1;
             $tamanhoDesc = $width[1];
             $qtdLinha = 1;
             $offset = 0;
             $atualSize = 0;
             while (true) {
                 $pos = strpos($descricaoSumaria, ' ', $offset);
                 if ($pos === FALSE) {
                     while ($tamanhoTexto > $tamanhoDesc) {
                         $qtdLinha++;
                         $tamanhoTexto -= $tamanhoDesc;
                     }
                     break;
                 }
                 $textCompare = substr($descricaoSumaria, $offset, $pos - $offset);
                 $textSize = $this->pdf->GetStringWidth($textCompare . ' ');
                 if ($textSize + $atualSize > $tamanhoDesc) {
                     $qtdLinha++;
                     $tamanhoTexto -= $atualSize;
                     $atualSize = 0;
                 } else {
                     $atualSize += $textSize;
                     $offset = $pos + 1;
                 }
             }
             if ($qtdLinha == 1) {
                 $qtdLinha = 2;
             }
             $alturaLinha = 5 * $qtdLinha;
             if ($this->pdf->GetY() + $alturaLinha > 280) {
                 $this->pdf->Cell(array_sum($width), 0, '', 'T');
                 $this->pdf->AddPage();
                 $y = $this->pdf->GetY();
                 $x = $this->pdf->GetX();
             }
             $this->pdf->MultiCell($width[0], $alturaLinha, utf8_decode($numeroItem), 'LRT', 'C');
             $this->pdf->SetXY($x += $width[0], $y);
             $this->pdf->MultiCell($width[1], 5, utf8_decode($descricaoSumaria), 'LRT', 'J');
             $this->pdf->SetXY($x += $width[1], $y);
             $this->pdf->MultiCell($width[2], $alturaLinha, utf8_decode($quantidade), 'LRT', 'C');
             $this->pdf->Ln(0);
             $y = $this->pdf->GetY();
             $x = $this->pdf->GetX();
         }
         $this->pdf->Cell(array_sum($width), 0, '', 'T');
         if ($this->pdf->GetY() + $alturaLinha > 210) {
             $this->pdf->AddPage();
             $this->ImprimiNoRodape = false;
         } else {
             $this->ImprimiNoRodape = true;
         }
         $this->Footer();
         if (!file_exists("app/output/doc.pdf") or is_writable("app/output/doc.pdf")) {
             $this->pdf->Output("app/output/doc.pdf");
         } else {
             throw new Exception('Permissão negada' . ': ' . "app/output/doc.pdf");
         }
         parent::openFile('app/output/doc.pdf');
         $this->form->sendData('doc_cessao_form', $data);
         TTransaction::close();
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }
 /**
  * Executed when the user chooses the record
  */
 public function onSelect($param)
 {
     try {
         $key = $param['key'];
         TTransaction::open('sobcontrole');
         // load the active record
         $tipocontato = new tipocontato($key);
         //var_dump($tipocontato);
         // closes the transaction
         TTransaction::close();
         $object = new StdClass();
         $object->tipocontato_idtipocontato = $tipocontato->idtipocontato;
         $object->tipocontato_descricao = $tipocontato->descricao;
         TForm::sendData('form_seek_sample', $object);
         parent::closeWindow();
         // closes the window
     } catch (Exception $e) {
         // clear fields
         $object = new StdClass();
         $object->tipocontato_idtipocontato = '';
         $object->tipocontato_descricao = '';
         TForm::sendData('form_seek_sample', $object);
         // undo pending operations
         TTransaction::rollback();
     }
 }
示例#27
0
 public function onSelect($param)
 {
     try {
         if (!$param['key']) {
             return;
         }
         if (!TSession::getValue('SRP_id') && !$this->continue) {
             $this->closeWindow();
             new TMessage('error', 'Número SRP Inválido');
             $this->message = false;
             return;
         }
         $key = $param['key'];
         TTransaction::open('saciq');
         //TTransaction::setLogger(new TLoggerTXT('c:\array\file.txt'));
         $repository = new TRepository('Item');
         $criteria = new TCriteria();
         $criteria->add(new TFilter('numeroItem', '=', $key));
         if (TSession::getValue('SRP_id')) {
             $criteria->add(new TFilter('srp_id', '=', TSession::getValue('SRP_id')));
         }
         $itens = $repository->load($criteria);
         if (count($itens) > 0) {
             $item = $itens[0];
             $itens_o = TSession::getValue('cessao_itens_o');
             if (isset($itens_o) && isset($itens_o[$item->numeroItem])) {
                 $item->estoqueDisponivel += $itens_o[$item->numeroItem]->quantidade;
             }
             if ($item->estoqueDisponivel == 0) {
                 $obj = new stdClass();
                 $obj->numeroItem = '';
                 $obj->item_id = '';
                 $obj->numeroItem = '';
                 $obj->descricaoSumaria = '';
                 $obj->valorUnitario = '';
                 //$obj->quantidade = '';
                 $obj->prazoEntrega = '60 Dias';
                 $obj->justificativa = '';
                 TForm::sendData('form_itens', $obj);
                 $this->closeWindow();
                 new TMessage('error', 'Item sem quantidade disponível');
                 $this->message = false;
                 return;
             }
             $obj = new stdClass();
             $obj->item_id = $item->id;
             if (strpos($item->descricaoSumaria, '–')) {
                 $item->descricaoSumaria = str_replace('–', '-', $item->descricaoSumaria);
                 $item->store();
             }
             $obj->numeroItem = $item->numeroItem;
             $obj->descricaoSumaria = $item->descricaoSumaria;
             $obj->valorUnitario = $item->valorUnitario;
             TForm::sendData('form_itens', $obj);
             parent::closeWindow();
         } else {
             $obj = new stdClass();
             $obj->item_id = '';
             $obj->numeroItem = '';
             $obj->descricaoSumaria = '';
             $obj->valorUnitario = '';
             //$obj->quantidade = '';
             $obj->prazoEntrega = '60 Dias';
             $obj->justificativa = '';
             TForm::sendData('form_itens', $obj);
             parent::closeWindow();
         }
         TTransaction::close();
     } catch (Exception $e) {
         $obj = new stdClass();
         $obj->item_id = '';
         $obj->descricaoSumaria = '';
         $obj->valorUnitario = '';
         $obj->quantidade = '';
         $obj->prazoEntrega = '60 Dias';
         $obj->justificativa = '';
         TForm::sendData('form_itens', $obj);
         TTransaction::rollback();
     }
 }
示例#28
0
 /**
  * method onReload()
  * Load the datagrid with the database objects
  */
 function onReload($param = NULL)
 {
     try {
         // open a transaction with database 'saciq'
         TTransaction::open('saciq');
         //TTransaction::setLogger(new TLoggerTXT('c:\array\file.txt'));
         // creates a repository for Requisicao
         $repository = new TRepository('Requisicao');
         $limit = 10;
         // creates a criteria
         $criteria = new TCriteria();
         // default order
         if (empty($param['order'])) {
             $param['order'] = 'id';
             $param['direction'] = 'asc';
         }
         $criteria->setProperties($param);
         // order, offset
         $criteria->setProperty('limit', $limit);
         $criteria->add(new TFilter('aprovado', '=', '1'));
         if (TSession::getValue('RequisicaoList_filter_numeroProcesso')) {
             $criteria->add(TSession::getValue('RequisicaoList_filter_numeroProcesso'));
             // add the session filter
         }
         // load the objects according to criteria
         $objects = $repository->load($criteria, FALSE);
         $this->datagrid->clear();
         if ($objects) {
             // iterate the collection of active records
             foreach ($objects as $object) {
                 if ($object->srp->estaVencida()) {
                     continue;
                 }
                 $object->emissao = TDate::date2br($object->emissao);
                 $object->numeroSRP = $object->srp->numeroSRP;
                 $this->datagrid->addItem($object);
             }
         }
         // close the transaction
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }
示例#29
0
 public function onSelect($param)
 {
     try {
         //var_dump($param);
         $key = $param['key'];
         if (!$key) {
             return;
         }
         TTransaction::open('saciq');
         //$srp = new Srp($key);
         $repository = new TRepository('Srp');
         $criteria = new TCriteria();
         $criteria->add(new TFilter('numeroSRP', '=', $key));
         $srps = $repository->load($criteria);
         if (count($srps) > 0) {
             $srp = $srps[0];
         }
         if ($srp->estaVencida()) {
             new TMessage('error', 'SRP Vencida!');
             return;
         }
         $oldSRP = NULL;
         if ($oldSRP != TSession::getValue('SRP_id')) {
             $oldSRP = TSession::getValue('SRP_id');
         }
         if ($oldSRP != $srp->id) {
             if (TSession::getValue('cessao_itens')) {
                 $reloadForm = true;
             }
             TSession::delValue('cessao_itens');
             $obj = new stdClass();
             $obj->numeroItem = '';
             $obj->descricaoSumaria = '';
             $obj->valorUnitario = '';
             $obj->quantidade = '';
             //$obj->prazoEntrega = '60 Dias';
             //$obj->justificativa = '';
             TForm::sendData('form_itens', $obj);
         }
         TSession::setValue('SRP_id', $srp->id);
         $obj = new stdClass();
         $obj->numeroSRP = $srp->numeroSRP;
         $obj->nome = $srp->nome;
         $obj->numeroProcessoOrigem = $srp->numeroProcesso;
         $obj->uasg = $srp->uasg;
         $obj->validade = TDate::date2br($srp->validade);
         TForm::sendData('form_cessao', $obj);
         TSession::setValue('form_cessao', $obj);
         if (isset($reloadForm) && $reloadForm) {
             TScript::create("__adianti_load_page2('engine.php?class=CessaoForm');");
             //new TScript("__adianti_load_page('engine?class=CessaoForm');");
         }
         //AdiantiCoreApplication::executeMethod('CessaoForm','onReload');
         TTransaction::close();
         parent::closeWindow();
     } catch (Exception $e) {
         $obj = new stdClass();
         $obj->numeroSRP = '';
         $obj->nome = '';
         $obj->numeroProcesso = '';
         $obj->uasg = '';
         $obj->validade = '';
         TForm::sendData('cessao_form', $obj);
         TTransaction::rollback();
     }
 }
示例#30
0
 /**
  * method onReload()
  * Load the datagrid with the database objects
  */
 function onReload($param = NULL)
 {
     try {
         // open a transaction with database 'saciq'
         TTransaction::open('saciq');
         // creates a repository for Subelemento
         $repository = new TRepository('Subelemento');
         $limit = 10;
         // creates a criteria
         $criteria = new TCriteria();
         // default order
         if (empty($param['order'])) {
             $param['order'] = 'id';
             $param['direction'] = 'asc';
         }
         $criteria->setProperties($param);
         // order, offset
         $criteria->setProperty('limit', $limit);
         if (TSession::getValue('SubelementoList_filter_descricao')) {
             $criteria->add(TSession::getValue('SubelementoList_filter_descricao'));
             // add the session filter
         }
         // load the objects according to criteria
         $objects = $repository->load($criteria, FALSE);
         $this->datagrid->clear();
         if ($objects) {
             // iterate the collection of active records
             foreach ($objects as $object) {
                 // add the object inside the datagrid
                 $this->datagrid->addItem($object);
             }
         }
         // reset the criteria for record count
         $criteria->resetProperties();
         $count = $repository->count($criteria);
         $this->pageNavigation->setCount($count);
         // count of records
         $this->pageNavigation->setProperties($param);
         // order, page
         $this->pageNavigation->setLimit($limit);
         // limit
         // close the transaction
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         if ($e->getCode() == 23000) {
             new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente');
         } else {
             if ($e->getCode() == 0) {
                 new TMessage('error', '<b>Error</b> <br>' . $e->getMessage());
             } else {
                 new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode());
             }
         }
         // desfazer todas as operacoes pendentes
         TTransaction::rollback();
     }
 }