Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.25 KB | None | 0 0
  1. formulario.$inject = ['$scope', 'obtenerDatos', '$state', '$timeout'];
  2.  
  3. function formulario($scope, obtenerDatos, $state, $timeout) {
  4.  
  5. $scope.login = function() {
  6.  
  7. var datos, datosRespuesta;
  8.  
  9. datos = {
  10. Usuario: $scope.usuariotxt,
  11. Password: $scope.passwordtxt
  12. };
  13.  
  14. if (typeof datos.usuario === 'undefined' && typeof datos.Password === 'undefined') {
  15.  
  16. $scope.respuesta = "Los campos estan vacios";
  17.  
  18. } else {
  19.  
  20. $state.go('Loading');
  21.  
  22. obtenerDatos.Autenticacion(datos).then(function(response) {
  23.  
  24. if (response.data) {
  25.  
  26. datosRespuesta = response.data;
  27.  
  28. if (datosRespuesta === "Usuario no registrado" ||
  29. datosRespuesta === "Contraseña incorrecta") {
  30.  
  31. $scope.respuesta = datosRespuesta
  32.  
  33. $timeout(function() {
  34. $scope.respuesta = datosRespuesta;
  35. $state.go('login');
  36. }, 1000);
  37.  
  38.  
  39. } else {
  40.  
  41.  
  42. obtenerDatos.setDatosUsuarios(datosRespuesta);
  43.  
  44. if (datosRespuesta.estudiante) {
  45. obtenerDatos.insertarDatosEstu(datosRespuesta);
  46. } else {
  47. obtenerDatos.insertarDatosDoc(datosRespuesta);
  48. };
  49.  
  50.  
  51. $state.go('Loading');
  52.  
  53. $timeout(function() {
  54. $state.go(datosRespuesta.estudiante ? 'menuestu' : 'menuprof');
  55. }, 3000);
  56.  
  57. };
  58.  
  59.  
  60. } else {
  61.  
  62. console.log(response.status);
  63. $scope.respuesta = "Error en la solicitud";
  64. $state.go('login');
  65.  
  66. };
  67.  
  68. });
  69.  
  70. };
  71.  
  72. };
  73.  
  74. };
  75.  
  76. obtenerDatos.$inject = ['$http', '$httpParamSerializer', '$cordovaSQLite'];
  77.  
  78. var datosIngreso, datosUsuario;
  79.  
  80. function Autenticacion(datos) {
  81.  
  82. var url = 'http://190.109.185.138/Apipedro/api/login';
  83.  
  84. return $http.post(url, $httpParamSerializer(datos), {
  85. headers: {
  86. 'Content-Type': 'application/x-www-form-urlencoded'
  87. }
  88. });
  89.  
  90. };
  91.  
  92. function getDatos(info) {
  93. datosIngreso = info;
  94. };
  95.  
  96. function setDatos() {
  97. return datosIngreso;
  98. };
  99.  
  100. /*Estudiante*/
  101.  
  102. function insertarDatosEstu(datosRespuesta) {
  103.  
  104. var db, Perfil, Horario, row, crearTablaPerfil, guardarPerfil, crearTablaHorario, guardarHorario, eliminarPerfil, dropPerfil, dropHorario, Usuario, largo, i;
  105.  
  106. datosUsuario = datosRespuesta;
  107.  
  108. Perfil = datosRespuesta.estudiante;
  109. Horario = datosRespuesta.materias;
  110. largo = Horario.length;
  111.  
  112. crearTablaPerfil = "CREATE TABLE IF NOT EXISTS Estudiante(Cedula integer primary key, Nombre text, Apellido text, Rol integer, Facultad text, Programa text, Semestre integer)";
  113.  
  114. guardarPerfil = "INSERT INTO Estudiante(Cedula, Nombre, Apellido, Rol, Facultad, Programa, Semestre) VALUES(?,?,?,?,?,?,?)";
  115.  
  116. crearTablaHorario = "CREATE TABLE IF NOT EXISTS Horario(Codigo text primary key, Grupo integer," +
  117. "Nombre text, Creditos integer, Dia text, Hora text, Lugar text," +
  118. "Nota1 float, Nota2 float, Nota3 float)";
  119.  
  120. guardarHorario = "INSERT INTO Horario(Codigo, Grupo, Nombre, Creditos, Dia, Hora, Lugar, Nota1, Nota2, Nota3) n
  121. VALUES(?,?,?,?,?,?,?,?,?,?)";
  122.  
  123. dropPerfil = "DROP TABLE Estudiante";
  124. dropHorario = "DROP TABLE Horario"
  125.  
  126. db = $cordovaSQLite.openDB({
  127. name: "unicesar.db"
  128. });
  129.  
  130.  
  131. $cordovaSQLite.execute(db, dropPerfil);
  132. $cordovaSQLite.execute(db, dropHorario);
  133.  
  134. $cordovaSQLite.execute(db, crearTablaPerfil);
  135. $cordovaSQLite.execute(db, crearTablaHorario);
  136.  
  137. $cordovaSQLite.execute(db, guardarPerfil, [Perfil.CeduEstu, Perfil.NombEstu, Perfil.ApelEstu, Perfil.RolEstu, Perfil.FacuEstu, Perfil.ProgEstu, Perfil.Semestre]);
  138.  
  139. for (i = 0; i < largo; i++) {
  140.  
  141. $cordovaSQLite.execute(db, guardarHorario, [Horario[i].CodiAsig, Horario[i].Grupo, Horario[i].NombAsig, Horario[i].Creditos, Horario[i].DiaAsig, Horario[i].HoraAsig, Horario[i].LugarAsig, Horario[i].Nota1, Horario[i].Nota2, Horario[i].Nota3]);
  142.  
  143. }
  144.  
  145. Usuario = "Estudiante";
  146. return Usuario;
  147.  
  148. };
  149.  
  150. /*Docente*/
  151.  
  152. function insertarDatosDoc(datosRespuesta) {
  153.  
  154. var db, Perfil, Horario, row, crearTablaPerfil_P, guardarPerfil_P, crearTablaHorario_P, guardarHorario_P, crearTablaGrupo,
  155. insertarGrupos, dropPerfil_P, dropHorario_P, dropGrupos, Usuario, Largo_Horario, Lista, Largo_Grupo, i, k, Cantidad_Estu,
  156. Nombre_Asig, Asig_Grupo, Asig_Nsp, Grupo, Grupos;
  157.  
  158. datosUsuario = datosRespuesta;
  159.  
  160. Perfil = datosRespuesta.profesor;
  161. Horario = datosRespuesta.materias;
  162. Largo_Horario = Horario.length;
  163.  
  164. Grupos = [];
  165. Grupo = {};
  166.  
  167. crearTablaPerfil_P = "CREATE TABLE IF NOT EXISTS Profesor(Cedula integer primary key, Nombre text, Apellido text, Rol integer," +
  168. " Facultad text, Programa text)";
  169.  
  170. guardarPerfil_P = "INSERT INTO Profesor(Cedula, Nombre, Apellido, Rol, Facultad, Programa) VALUES(?,?,?,?,?,?)";
  171.  
  172. crearTablaHorario_P = "CREATE TABLE IF NOT EXISTS HorarioP(Codigo text primary key, Grupo integer, Nombre text, Creditos integer," +
  173. " Dia text, Hora text, Lugar text)";
  174.  
  175. guardarHorario_P = "INSERT INTO HorarioP(Codigo, Grupo, Nombre, Creditos, Dia, Hora, Lugar) VALUES(?,?,?,?,?,?,?)";
  176.  
  177. crearTablaGrupo = "CREATE TABLE IF NOT EXISTS GruposP(Fila integer primary key, Cedula text, Nombre text," +
  178. " Apellido text, Nota1 float, Nota2 float, Nota3 float, Habilitacion float, Grupoasig text)";
  179.  
  180. insertarGrupos = "INSERT INTO GruposP(Fila, Cedula, Nombre, Apellido, Nota1, Nota2, Nota3, Habilitacion, Grupoasig)" +
  181. "VALUES(?,?,?,?,?,?,?,?,?)";
  182.  
  183. dropPerfil_P = "DROP TABLE Profesor";
  184. dropHorario_P = "DROP TABLE HorarioP";
  185. dropGrupos = "DROP TABLE GruposP";
  186.  
  187. Cantidad_Estu = 0;
  188.  
  189. db = $cordovaSQLite.openDB({
  190. name: "unicesar.db"
  191. });
  192.  
  193. $cordovaSQLite.execute(db, dropPerfil_P);
  194. $cordovaSQLite.execute(db, dropHorario_P);
  195. $cordovaSQLite.execute(db, dropGrupos);
  196.  
  197. $cordovaSQLite.execute(db, crearTablaPerfil_P);
  198. $cordovaSQLite.execute(db, crearTablaHorario_P);
  199. $cordovaSQLite.execute(db, crearTablaGrupo);
  200.  
  201. $cordovaSQLite.execute(db, guardarPerfil_P, [Perfil.CeduProf, Perfil.NombProf, Perfil.ApelProf, Perfil.RolProf, Perfil.FacuProf,
  202. Perfil.ProgProf
  203. ]);
  204.  
  205. for (i = 0; i < Largo_Horario; i++) {
  206.  
  207. $cordovaSQLite.execute(db, guardarHorario_P, [Horario[i].CodiAsig, Horario[i].Grupo, Horario[i].NombAsig,
  208. Horario[i].Creditos, Horario[i].DiaAsig, Horario[i].HoraAsig, Horario[i].LugarAsig
  209. ]);
  210.  
  211. Lista = Horario[i].Listado
  212. Largo_Grupo = Lista.length;
  213.  
  214. Nombre_Asig = Horario[i].NombAsig;
  215. Asig_Nsp = Nombre_Asig.replace(/s+/g, '');
  216. Asig_Grupo = (Asig_Nsp + Horario[i].Grupo);
  217.  
  218. Grupo = {
  219. Nombre: Asig_Nsp + '-' + Horario[i].Grupo,
  220. Codigo: Asig_Grupo
  221. };
  222.  
  223. Grupos.push(Grupo);
  224.  
  225.  
  226. for (k = 0; k < Largo_Grupo; k++) {
  227.  
  228. Cantidad_Estu = Cantidad_Estu + 1;
  229.  
  230. $cordovaSQLite.execute(db, insertarGrupos, [Cantidad_Estu, Lista[k].CeduEstu, Lista[k].NombEstu, Lista[k].ApelEstu,
  231. Lista[k].Nota1, Lista[k].Nota2, Lista[k].Nota3, Lista[k].Habilitacion, Asig_Grupo
  232. ]);
  233.  
  234. }
  235.  
  236. }
  237.  
  238. localStorage.setItem('GruposProf', JSON.stringify(Grupos));
  239.  
  240. Usuario = "Docente";
  241. return Usuario;
  242.  
  243. };
  244.  
  245.  
  246. function getDatosUsuarios() {
  247. return datosUsuario;
  248. };
  249.  
  250.  
  251. return {
  252. Autenticacion: Autenticacion,
  253. getDatos: getDatos,
  254. setDatos: setDatos,
  255. insertarDatosEstu: insertarDatosEstu,
  256. insertarDatosDoc: insertarDatosDoc,
  257. getDatosUsuarios: getDatosUsuarios
  258. };
  259.  
  260. };
  261.  
  262. angular.module('loadingPage', ['ionic', 'loginApp'])
  263. .controller('mostrarMensaje', mostrarMensaje)
  264. .factory('obtenerVista', obtenerVista);
  265.  
  266. mostrarMensaje.$inject = ['$scope', 'obtenerVista', '$state', '$timeout', 'obtenerDatos'];
  267.  
  268. function mostrarMensaje($scope, obtenerVista, $state, $timeout, obtenerDatos) {
  269.  
  270. var vista_Anterior, datosRespuesta;
  271.  
  272. vista_Anterior = obtenerVista.nombreVista();
  273. console.log(vista_Anterior.stateName);
  274.  
  275. datosRespuesta = obtenerDatos.getDatosUsuarios();
  276.  
  277. $timeout(function() {
  278. $state.go(datosRespuesta.estudiante ? 'menuestu' : 'menuprof');
  279. }, 3000);
  280.  
  281. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement