Advertisement
Guest User

Solucion perfil

a guest
Apr 30th, 2016
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('perfilEstu', ['ionic', 'ngCordova'])
  2.        .controller('perfilEstudiante', perfilEstudiante)
  3.        .factory('obtenerPerfil', obtenerPerfil);
  4.  
  5.  
  6. perfilEstudiante.$inject = ['$scope', 'obtenerPerfil'];
  7.  
  8. function perfilEstudiante($scope, obtenerPerfil) {
  9.    
  10.     var Perfil, fila, i, l_perfil, db, sqlConsulta;
  11.    
  12.     obtenerPerfil.datosPerfil().then(function(data){
  13.        
  14.         Perfil = data;
  15.        
  16.         $scope.Cedula = Perfil.cedula;
  17.         $scope.Nombre = Perfil.nombre;
  18.         $scope.Apellido = Perfil.apellido;
  19.         $scope.Rol = Perfil.Rol;
  20.         $scope.Facultad = Perfil.facultad;
  21.         $scope.Programa = Perfil.programa;
  22.         $scope.Semestre = Perfil.semestre;
  23.        
  24.                
  25.     });
  26.        
  27.    
  28.    
  29.    
  30. };
  31.  
  32.  
  33. obtenerPerfil.$inject = ['$cordovaSQLite', '$q'];
  34.  
  35. function obtenerPerfil($cordovaSQLite, $q) {
  36.    
  37.  
  38.     return {
  39.        
  40.         datosPerfil: function (){
  41.            
  42.             var sqlConsulta, db, perfil, datos, l_perfil, i, fila;
  43.        
  44.         //deferObject =  deferObject || $q.defer();
  45.         sqlConsulta = "SELECT * FROM Estudiante"
  46.         perfil = {};
  47.        
  48.         db = $cordovaSQLite.openDB({ name: "unicesar.db" });
  49.        
  50.         perfil = $cordovaSQLite.execute(db, sqlConsulta, []).then(function(resultado) {
  51.            
  52.             l_perfil = resultado.rows.length;
  53.            
  54.             for(i=0 ; i<l_perfil ; i++){
  55.                
  56.                 fila = resultado.rows.item(i);
  57.                
  58.                 datos = {
  59.                  
  60.                     cedula: fila.Cedula,
  61.                     nombre: fila.Nombre,
  62.                     apellido: fila.Apellido,
  63.                     rol: "Estudiante",
  64.                     facultad: fila.Facultad,
  65.                     programa: fila.Programa,
  66.                     semestre: fila.Semestre
  67.                    
  68.                    
  69.                 };
  70.                
  71.             }
  72.            
  73.            
  74.             return datos;
  75.            
  76.         }, function (err) {
  77.             console.error(err);
  78.         });  
  79.        
  80.        
  81.         return perfil;
  82.            
  83.         }
  84.        
  85.     };
  86.    
  87. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement