Advertisement
Guest User

Groups

a guest
Apr 17th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Grupos
  2. $(document).ready(function (){
  3.    
  4.     var idenprof = metodosprof.setidprof();
  5.    
  6.     var iden = {
  7.         identificacion: idenprof  
  8.     };
  9.    
  10.     $.ajax({
  11.             type: 'GET',
  12.             url:  '/upcphp/grupos.php',
  13.             data: iden
  14.             //async: false
  15.  
  16.             }).done(function(msg) {
  17.                
  18.                 var str = $.trim(msg);
  19.                
  20.                     if(str !== "0"){
  21.                        
  22.                         //console.log(str);
  23.                        
  24.                         var vector = (JSON.parse(str));
  25.                         var len = (vector.length);
  26.                         //console.log(len);
  27.                        
  28.                        
  29.                       function ArregloHorario(arreglo, tamano){
  30.  
  31.                             var asignaturas = [];
  32.  
  33.                             for(var i = 0; i < tamano; i++){
  34.  
  35.                                 var asignatura = new Object();
  36.  
  37.                                 var asignatura = {
  38.                                     codigo: arreglo[i].CodiAsig,
  39.                                     asignatura: arreglo[i].NombAsig+"-"+arreglo[i].Grupo,
  40.                                     identificacion: arreglo[i].CeduEstu,
  41.                                     nombre: arreglo[i].NombEstu,
  42.                                     apellido: arreglo[i].ApelEstu
  43.                                 };
  44.  
  45.                                 asignaturas.push(asignatura);
  46.  
  47.                             }
  48.  
  49.                             return asignaturas;
  50.  
  51.                         }
  52.  
  53.                         var Arreglog = ArregloHorario(vector, len);
  54.                         console.log(Arreglog);
  55.                        
  56.                       var base = metodos.getBD();
  57.                        
  58.                        
  59.                       //Crear tabla horario profesor  
  60.                       function TablaGrupos(database){
  61.  
  62.                           database.transaction(function (tx){
  63.  
  64.                               var sql = 'CREATE TABLE IF NOT EXISTS Grupos(asignatura text primary key, codigo text,\n\
  65.                                                                identificacion integer, nombre text, apellido text)';
  66.  
  67.                               tx.executeSql(sql);
  68.  
  69.                           });    
  70.  
  71.                        }
  72.                        TablaGrupos(base);
  73.                        
  74.                        
  75.                        /*Insertar Datos Horario Profesor con validacion*/
  76.                       function InsertDatosHoraProf(database, arreglo){
  77.  
  78.                            var prof = arreglo;
  79.                            var largo = prof.length;
  80.                            //console.log(largo);
  81.  
  82.                            database.transaction(function (tx) {
  83.  
  84.                                var consulta = 'SELECT * FROM Grupos';
  85.  
  86.                                    tx.executeSql(consulta, [], function (tx, results){                                          
  87.  
  88.                                        var mostrar = results.rows.length;                
  89.                                        var sql = 'INSERT INTO Grupos(asignatura, codigo, identificacion, nombre, apellido)\n\
  90.                                               VALUES(?,?,?,?,?)';
  91.                                        var sqldelete = 'DELETE FROM Grupos';
  92.  
  93.                                        if (mostrar === 0){
  94.  
  95.                                            for(var i = 0; i < largo; i++){
  96.                                                 tx.executeSql(sql, [prof[i].asignatura, prof[i].codigo, prof[i].identificacion,
  97.                                                                     prof[i].nombre, prof[i].apellido]);
  98.                                            }
  99.  
  100.                                        }else{
  101.  
  102.                                            tx.executeSql(sqldelete);
  103.  
  104.                                            for(var i = 0; i < largo; i++){
  105.                                                 tx.executeSql(sql, [prof[i].asignatura, prof[i].codigo, prof[i].identificacion,
  106.                                                                     prof[i].nombre, prof[i].apellido]);
  107.                                            }
  108.  
  109.                                        }
  110.  
  111.                                    });
  112.                             });
  113.  
  114.                        }
  115.  
  116.                        InsertDatosHoraProf(base, Arreglog);
  117.                        
  118.                     }
  119.                
  120.             });
  121.    
  122. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement