public void ObtenerAlumnos() { // A consultar ! try { CrearConexionMoodle(); string query = "SELECT id, firstname, lastname, email, city, country, lastaccess, lastlogin FROM liceoin1_mood391.mo_user where deleted=0 and suspended=0 ;"; // Prepara la conexión MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection); commandDatabase.CommandTimeout = 60; // Ejecuta la consultas MySqlDataReader reader = commandDatabase.ExecuteReader(); // Hasta el momento todo bien, es decir datos obtenidos // IMPORTANTE :# // Si la consulta retorna un resultado, se usa el siguiente proceso para obtener datos if (reader.HasRows) { while (reader.Read()) { // Hacer algo con cada fila obtenida string[] row = { reader.GetString(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5), reader.GetString(6), reader.GetString(7) }; tblEstudiante estudiante = new tblEstudiante(); estudiante.nombres = row[1].ToString(); estudiante.primerApellido = row[2]; estudiante.segundoApellido = ""; estudiante.nie = ""; var nuevo = (from e in db.tblEstudiante select e.idAlumno).Max() + 1; estudiante.codigo = (estudiante.nombres.Substring(0, 1) + estudiante.primerApellido.Substring(0, 1) + nuevo.ToString("D5")).Replace(" ", ""); estudiante.correo = row[3].ToString(); estudiante.departamento = row[4]; //validar campos no null y crear codigo estudiante var OldRegister = (from e in db.tblEstudiante where e.correo == estudiante.correo select e).FirstOrDefault(); if (OldRegister == null) { db.tblEstudiante.Add(estudiante); db.SaveChanges(); } } } else { Console.WriteLine("No se encontraron datos."); } // Cerrar la conexión databaseConnection.Close(); } catch (Exception ex) { // Mostrar cualquier excepción } }
public ActionResult FileUpload(HttpPostedFileBase file) { if (file != null) { EmpleadosDB1Entities db = new EmpleadosDB1Entities(); string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/Images/" + ImageName); file.SaveAs(physicalPath); tblEstudiante estudiante = new tblEstudiante(); estudiante.Nombres = Request.Form["Nombres"]; estudiante.Apellidos = Request.Form["Apellidos"]; estudiante.Direccion = Request.Form["Direccion"]; estudiante.Telefono = Request.Form["Telefono"]; estudiante.Cedula = Request.Form["Cedula"]; estudiante.ImagenUrl = ImageName; if (TryValidateModel(estudiante)) { db.tblEstudiante.Add(estudiante); db.SaveChanges(); return(RedirectToAction("../home/Detalle/")); } else { return(View("../home/Estudiantes", estudiante)); } } return(RedirectToAction("../home/Detalle/")); }
private void Button_Click(object sender, RoutedEventArgs e) { tblEstudiante marcado = EditarEstudianteGrid.SelectedItem as tblEstudiante; if (marcado != null) { ActualizarEstudiantes actualizarEsudiantes = new ActualizarEstudiantes(marcado); actualizarEsudiantes.ShowDialog(); } else { MessageBox.Show("Debes marcar o seleccionar un estudiante"); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { tblEstudiante marcado = EditarEstudianteGrid.SelectedItem as tblEstudiante; if (marcado == null) { MessageBox.Show("Debes marcar o seleccionar un estudiante"); } else if (MessageBoxResult.Yes == MessageBox.Show("Estas seguro", "Quieres borrar este estudiante", MessageBoxButton.YesNo, MessageBoxImage.Exclamation)) { Administrador.borrarEstudiante(marcado); Window_Loaded(null, null); } }
public ActualizarEstudiantes(tblEstudiante p_estudiante) { InitializeComponent(); this.estudiante = p_estudiante; }
private void btnAgregar_Click(object sender, RoutedEventArgs e) { float promedio; bool resultado = true; if (txtNombre.Text.Trim().Length == 0) { MessageBox.Show("Digite el nombre del estudiante.", "Nombre Invalido", MessageBoxButton.OK, MessageBoxImage.Warning); txtNombre.Focus(); resultado = false; } if (txtApellido.Text.Trim().Length == 0) { MessageBox.Show("Digite el Apellido del estudiante.", "Apellido Invalido", MessageBoxButton.OK, MessageBoxImage.Warning); txtApellido.Focus(); resultado = false; } if (rdbHombre.IsChecked == false && rdbMujer.IsChecked == false) { MessageBox.Show("Seleccione el sexo del estudiante.", "Sexo Invalido", MessageBoxButton.OK, MessageBoxImage.Warning); rdbHombre.Focus(); rdbHombre.IsChecked = true; resultado = false; } if (float.TryParse(txtPromedio.Text, out promedio) == false) { MessageBox.Show("El promedio debe ser un numero.", "Valor Invalido", MessageBoxButton.OK, MessageBoxImage.Warning); txtPromedio.Focus(); resultado = false; } if (resultado) { try { tblEstudiante estudiante = new tblEstudiante(); estudiante.Nombre = txtNombre.Text.Trim(); estudiante.Apellido = txtApellido.Text.Trim(); if (rdbHombre.IsChecked == true) { estudiante.Sexo = 'H'; } else { estudiante.Sexo = 'M'; } estudiante.Promedio = promedio; Administrador.agregarEstudiantes(estudiante); MessageBox.Show("El estudiante: " + estudiante.Apellido + " fue agregado al sistema"); ClearControles(this); txtNombre.Focus(); } catch (Exception ex) { MessageBox.Show("Error al agregar estudiante", ex.ToString()); throw; } } }
public JsonResult AddEstudiante(string codigo, string nombres, string primerApellido, string segundoApellido, string fechaNacimiento, string sexo, string nie, string lugarNacimiento, string numeroPartidaNacimiento, string tomo, string folio, string libro, string coddpto, string departamento, string codmuni, string municipio, string direccion, string institucionProcedencia, string gradoIngreso, int idResponsable, string correo, string status, HttpPostedFileBase file) { JsonResult jr = new JsonResult(); try { bool sae = false; string adjunto = ""; if (file != null) { var ruta = (from p in db.tbl_Parametros where p.IdParametro == 10 select p.Parametro).FirstOrDefault(); adjunto = "IMG_" + codigo + Path.GetExtension(file.FileName); //file.SaveAs(Path.GetTempPath() + adjunto); //file.SaveAs("C:\\Users\\drivas\\Documents\\Visual Studio 2019\\Projects\\SRALI\\SRALI\\Resources\\FotosEstudiantes\\" + adjunto); file.SaveAs(ruta + adjunto); //var data = SaveImage.SendImage(adjunto, Path.GetTempPath() + adjunto).ToString(); } //buscamos la clave mayor + 1 en sae de la tabla clie01 para asignarsela a este nuevo estudiante var maxid = sync.GetMaxIdSAEStudent() + 1; var clavesaestudent = sync.SetClaveStudent(maxid); tblEstudiante Estudiante = new tblEstudiante(); Estudiante.codigo = codigo; Estudiante.nombres = nombres; Estudiante.primerApellido = primerApellido; Estudiante.segundoApellido = segundoApellido; Estudiante.fechaNacimiento = Convert.ToDateTime(fechaNacimiento); Estudiante.sexo = sexo; Estudiante.nie = nie; Estudiante.lugarNacimiento = lugarNacimiento; Estudiante.numeroPartidaNacimiento = numeroPartidaNacimiento; Estudiante.tomo = tomo; Estudiante.folio = folio; Estudiante.libro = libro; Estudiante.departamento = coddpto; Estudiante.municipio = codmuni; Estudiante.direccion = direccion; Estudiante.institucionProcedencia = institucionProcedencia; Estudiante.gradoIngreso = Convert.ToInt32(gradoIngreso); Estudiante.archivofoto = adjunto; Estudiante.idResponsable = idResponsable; Estudiante.correo = correo; Estudiante.codigoSAE = clavesaestudent; Estudiante.Status = status; Estudiante.fechaCreacion = DateTime.Now; Estudiante.creadoPor = Session["IdUsurio"].ToString(); db.tblEstudiante.Add(Estudiante); db.SaveChanges(); //guardamos el estudiante en sae CLIE01 esae = new CLIE01(); esae.CLAVE = clavesaestudent; esae.STATUS = "A"; esae.NOMBRE = primerApellido + " " + segundoApellido + " " + nombres; esae.CALLE = direccion; esae.MUNICIPIO = municipio; esae.ESTADO = departamento; esae.PAIS = "EL SALVADOR"; esae.CLASIFIC = ""; esae.IMPRIR = "S"; esae.MAIL = "S"; esae.NIVELSEC = 0; esae.ENVIOSILEN = "N"; esae.CON_CREDITO = "N"; esae.DIASCRED = 0; esae.LIMCRED = 0; esae.SALDO = 0; esae.TIPO_EMPRESA = "M"; esae.MATRIZ = sync.SetClaveStudent(maxid); esae.PROSPECTO = "N"; esae.DES_IMPU1 = "N"; esae.DES_IMPU2 = "N"; esae.DES_IMPU3 = "N"; esae.DES_IMPU4 = "N"; esae.DES_PER = "N"; esae.LAT_GENERAL = 0; esae.LON_GENERAL = 0; esae.LAT_ENVIO = 0; esae.LON_ENVIO = 0; dbsae.CLIE01.Add(esae); dbsae.SaveChanges(); //agregamos el registro de campos libres CLIE_CLIB01 clib = new CLIE_CLIB01(); clib.CVE_CLIE = clavesaestudent; dbsae.CLIE_CLIB01.Add(clib); dbsae.SaveChanges(); sae = true; var Estudiantes = db.SP_ObtenerEstudiantes().ToList(); jr.Data = new { Estudiantes = Estudiantes, Res = true, Sae = sae }; return(jr); } catch (Exception ex) { var Estudiantes = db.SP_ObtenerEstudiantes().ToList(); jr.Data = new { Estudiantes = Estudiantes, Res = false }; return(jr); } }
public ActionResult ImportData(HttpPostedFileBase file) // El nombre del parámetro debe ser el mismo al del elemento que lo envía (<input />) { string filePath = string.Empty; Random rnd = new Random(); if (file != null && file.ContentLength > 0) { string path = Server.MapPath("~/Uploads/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } filePath = path + "PP" + rnd.Next(100000).ToString() + ".xlsx"; // Le generamos un nombre en base a un número aleatorio entre 0 y 100,000 file.SaveAs(filePath); SLDocument sheet = new SLDocument(filePath); int idRow = 2; while (!string.IsNullOrEmpty(sheet.GetCellValueAsString(idRow, 1))) { try { tblEstudiante registro = new tblEstudiante(); registro.codigo = sheet.GetCellValueAsString(idRow, 1); registro.nombres = sheet.GetCellValueAsString(idRow, 2); registro.primerApellido = sheet.GetCellValueAsString(idRow, 3); registro.segundoApellido = sheet.GetCellValueAsString(idRow, 4); registro.fechaNacimiento = Convert.ToDateTime(sheet.GetCellValueAsString(idRow, 5)); //registro.edad = Convert.ToInt32(sheet.GetCellValueAsString(idRow, 6)); registro.sexo = sheet.GetCellValueAsString(idRow, 7); registro.nie = sheet.GetCellValueAsString(idRow, 8); registro.lugarNacimiento = sheet.GetCellValueAsString(idRow, 9); registro.numeroPartidaNacimiento = sheet.GetCellValueAsString(idRow, 10); registro.tomo = sheet.GetCellValueAsString(idRow, 11); registro.folio = sheet.GetCellValueAsString(idRow, 12); registro.libro = sheet.GetCellValueAsString(idRow, 13); registro.departamento = sheet.GetCellValueAsString(idRow, 14); registro.municipio = sheet.GetCellValueAsString(idRow, 14); registro.direccion = sheet.GetCellValueAsString(idRow, 15); registro.institucionProcedencia = sheet.GetCellValueAsString(idRow, 16); registro.gradoIngreso = Convert.ToInt32(sheet.GetCellValueAsString(idRow, 17)); registro.correo = sheet.GetCellValueAsString(idRow, 18); var OldItem = (from p in db.tblEstudiante where p.codigo == registro.codigo select p).FirstOrDefault(); if (OldItem == null) { db.tblEstudiante.Add(registro); db.SaveChanges(); } } catch (Exception e) { return(RedirectToAction("Index")); } idRow++; } try { if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); // Eliminamos el archivo } } catch (Exception e) { return(RedirectToAction("Index")); } return(RedirectToAction("Index")); } else { //return View(); return(RedirectToAction("Index")); } }