Example #1
0
        public void guardarCentroSeccion(CentroEducativo centro, Seccion sec)
        {
            SqlConnection con = new SqlConnection(Conexion.Cadena);

            try
            {
                if (centroSeccionSelect(centro, sec))
                {
                    return;
                }
                con.Open();
                string sql = "PA_CentroSeccionInsert";

                SqlCommand comando = new SqlCommand(sql, con);
                comando.CommandType = System.Data.CommandType.StoredProcedure;
                comando.Parameters.AddWithValue("@idCentro", centro.Codigo);
                comando.Parameters.AddWithValue("@idSeccion", sec.Id);

                comando.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.Close();
            }
        }
Example #2
0
        public bool centroSeccionSelect(CentroEducativo centro, Seccion sec)
        {
            SqlConnection con = new SqlConnection(Conexion.Cadena);

            try
            {
                con.Open();
                string     sql     = "PA_CentroSeccionSelect";
                SqlCommand comando = new SqlCommand(sql, con);

                comando.Parameters.AddWithValue("@idCentro", centro.Codigo);
                comando.Parameters.AddWithValue("@idSeccion", sec.Id);

                comando.CommandType = System.Data.CommandType.StoredProcedure;

                SqlDataReader reader = comando.ExecuteReader();

                while (reader.Read())
                {
                    return(true);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.Close();
            }

            return(false);
        }
Example #3
0
        public bool Save(CentroEducativo centroEducativo)
        {
            var result = (from centro in cnn.Table <CentroEducativo>().AsEnumerable <CentroEducativo>()
                          where centro.IDCentroEducativo == centroEducativo.IDCentroEducativo
                          select centro).ToList();

            if (result.Count == 0)
            {
                try
                {
                    cnn.Insert(centroEducativo);

                    return(true);
                }
                catch { return(false); }
            }
            else
            {
                try
                {
                    cnn.Update(centroEducativo);

                    return(true);
                }
                catch { return(false); }
            }
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("Id,IdDepartamento,IdMunicipio,IdDistrito,IdBodega,IdZona,Nivel,Nombre,Direccion,Telefono,Estado,NombreContacto,CorreoContacto,TelefonoContacto,Ninos,Ninas,Total,FechaCreacion,FechaModificacion")] CentroEducativo centroEducativo)
        {
            if (!(CentroEducativoExists(centroEducativo.Id)))
            {
                if (ModelState.IsValid)
                {
                    centroEducativo.FechaCreacion     = DateTime.Now;
                    centroEducativo.FechaModificacion = DateTime.Now;
                    _context.Add(centroEducativo);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            else
            {
                ModelState.AddModelError("Centro duplicado", "Ya existe un Centro Educativo con el Código ingresado.");
            }

            ViewData["IdDepartamento"] = new SelectList(_context.Departamento, "Id", "Nombre", centroEducativo.IdDepartamento);
            ViewData["IdBodega"]       = new SelectList(_context.Bodega.Where(x => x.IdDepartamento == centroEducativo.IdDepartamento), "Id", "Nombre", centroEducativo.IdBodega);
            ViewData["IdDistrito"]     = new SelectList(_context.Distrito.Where(x => x.IdDepartamento == centroEducativo.IdDepartamento), "Id", "Nombre", centroEducativo.IdDistrito);
            ViewData["IdMunicipio"]    = new SelectList(_context.Municipio.Where(x => x.DepartamentoId == centroEducativo.IdDepartamento), "Id", "Nombre", centroEducativo.IdMunicipio);
            ViewData["IdZona"]         = new SelectList(_context.Zona, "Id", "Nombre", centroEducativo.IdZona);
            return(View(centroEducativo));
        }
        public void eliminarCentro(CentroEducativo centro)
        {
            SqlConnection con = new SqlConnection(Conexion.Cadena);

            try
            {
                new CentroSeccionDatos().eliminarUnCentroYTodasLasSecciones(centro);
                con.Open();

                string sql = "PA_CentroEducativoDelete";

                SqlCommand comando = new SqlCommand(sql, con);
                comando.CommandType = System.Data.CommandType.StoredProcedure;

                comando.Parameters.AddWithValue("@id", centro.Codigo);

                comando.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.Close();
            }
        }
        public void actualizarCentro(CentroEducativo centro)
        {
            SqlConnection con = new SqlConnection(Conexion.Cadena);

            try
            {
                con.Open();
                string sql = "PA_CentroEducativoUpdate";

                SqlCommand comando = new SqlCommand(sql, con);
                comando.CommandType = System.Data.CommandType.StoredProcedure;

                comando.Parameters.AddWithValue("@id", centro.Codigo);
                comando.Parameters.AddWithValue("@nombre", centro.Nombre);
                comando.ExecuteNonQuery();
                foreach (var item in centro.listaSeciones)
                {
                    new CentroSeccionDatos().guardarCentroSeccion(centro, item);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.Close();
            }
        }
Example #7
0
        public IActionResult Put([FromBody] CentroEducativo centro, int id)
        {
            if (centro.Id != id)
            {
                return(BadRequest());
            }

            context.Entry(centro).State = EntityState.Modified;
            context.SaveChanges();
            return(Ok());
        }
Example #8
0
        public IActionResult Post([FromBody] CentroEducativo centro)
        {
            if (ModelState.IsValid)
            {
                context.CentrosEducativos.Add(centro);
                context.SaveChanges();

                return(new CreatedAtRouteResult("centroCreado", new { id = centro.Id }, centro));
            }
            return(BadRequest(ModelState));
        }
Example #9
0
 private void btnEliminar_Click(object sender, EventArgs e)
 {
     if (dataGridCentroEducativo.SelectedRows.Count > 0)
     {
         if (MessageBox.Show(null, "Desea elminar el centro seleccionado?", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             centro = (CentroEducativo)dataGridCentroEducativo.SelectedRows[0].DataBoundItem;
             centroLogica.eliminarCentro(centro);
             refrescar();
         }
     }
 }
Example #10
0
        private void dataGridCentroEducativo_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridCentroEducativo.SelectedRows.Count > 0)
            {
                centro         = (CentroEducativo)dataGridCentroEducativo.SelectedRows[0].DataBoundItem;
                txtCodigo.Text = centro.Codigo.ToString();
                txtNombre.Text = centro.Nombre;

                dataGridSeccion.DataSource = centroLogica.seleccionarCentro(centro).listaSeciones;
            }
            deshablitar();
        }
Example #11
0
        private void selecionarComboCentro(CentroEducativo centro)
        {
            for (int i = 0; i < cmbCentroEducativo.Items.Count; i++)
            {
                cmbCentroEducativo.SelectedIndex = i;

                if (((CentroEducativo)cmbCentroEducativo.SelectedItem).Codigo.Equals(centro.Codigo))
                {
                    return;
                }
            }
        }
Example #12
0
        public void guardarCentro(CentroEducativo centro)
        {
            CentroEducativoDatos datos = new CentroEducativoDatos();

            if (datos.seleccionarCentro(centro) == null)
            {
                datos.guardarCentro(centro);
            }
            else
            {
                datos.actualizarCentro(centro);
            }
        }
Example #13
0
        /// <summary>
        /// retorna todos los centros mas un comodin
        /// </summary>
        /// <returns></returns>
        public List <CentroEducativo> seleccionarTodosCentrosConComodin()
        {
            CentroEducativo miCentro = new CentroEducativo();

            miCentro.Nombre = "Todos";
            miCentro.Codigo = -1;
            CentroEducativoDatos   datos = new CentroEducativoDatos();
            List <CentroEducativo> lista = datos.seleccionarTodos();

            lista.Insert(0, miCentro);

            return(lista);
        }
        public object GetCentroEducativo(int id)
        {
            CentroEducativo centroE = new CentroEducativo();

            if (centroELogic.ObtenerCentroEPorId(id).MyObjGen == null)
            {
                return(centroELogic.ObtenerCentroEPorId(id).Message);
            }
            else
            {
                centroE = centroELogic.ObtenerCentroEPorId(id).MyObjGen;
                return(centroE);
            }
        }
Example #15
0
        public void Delete(CentroEducativo centroEducativo)
        {
            var result = (from centro in cnn.Table <CentroEducativo>().AsEnumerable <CentroEducativo>()
                          where centro.IDCentroEducativo == centroEducativo.IDCentroEducativo
                          select centroEducativo).ToList();

            if (result.Count == 1)
            {
                cnn.Delete(centroEducativo);
            }
            else
            {
                throw new Exception("Item not found");
            }
        }
Example #16
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            CentroEducativo miCentro = new CentroEducativo();

            miCentro.Nombre = txtNombre.Text;
            if (txtNombre.Text == "")
            {
                errorProviderNombreCentro.SetError(txtNombre, "Nombre del centro requerido");
                txtNombre.Focus();
                return;
            }
            errorProviderNombreCentro.Clear();
            if (txtCodigo.Text != "")
            {
                if (MessageBox.Show(null, "Seguro que desea modificar este registro", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    try
                    {
                        miCentro.Codigo = Convert.ToInt32(txtCodigo.Text);
                        centroLogica.guardarCentro(miCentro);
                        MessageBox.Show("se modifico correctamente");
                    }
                    catch (Exception a)
                    {
                        MessageBox.Show("error al modificar " + a);
                    }
                }
            }
            else
            {
                try
                {
                    centroLogica.guardarCentro(miCentro);
                    MessageBox.Show("Se agrego correctamente");
                }
                catch (Exception i)
                {
                    MessageBox.Show("error al agregar nuevo registro " + i);
                }
            }
            refrescar();
            deshablitar();
        }
        public CentroEducativo seleccionarCentro(int id)
        {
            CentroEducativo micentro = null;
            SqlConnection   con      = new SqlConnection(Conexion.Cadena);

            try
            {
                con.Open();
                string     sql     = "PA_centroEducativoselect";
                SqlCommand comando = new SqlCommand(sql, con);
                comando.Parameters.AddWithValue("@id", id);
                comando.CommandType = System.Data.CommandType.StoredProcedure;

                SqlDataReader reader = comando.ExecuteReader();

                while (reader.Read())
                {
                    micentro               = new CentroEducativo();
                    micentro.Codigo        = (int)reader["id"];
                    micentro.Nombre        = reader["nombre"].ToString();
                    micentro.listaSeciones = new CentroSeccionDatos().seleccionarPorCentro(micentro);
                    //agregarlista Secciones
                    return(micentro);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.Close();
            }

            return(micentro);
        }
        public List <CentroEducativo> seleccionarTodos()
        {
            List <CentroEducativo> listaCentros = new List <CentroEducativo>();
            SqlConnection          con          = new SqlConnection(Conexion.Cadena);

            try
            {
                con.Open();
                string     sql     = "PA_centroEducativoselectAll";
                SqlCommand comando = new SqlCommand(sql, con);

                comando.CommandType = System.Data.CommandType.StoredProcedure;

                SqlDataReader reader = comando.ExecuteReader();

                while (reader.Read())
                {
                    CentroEducativo micentro = new CentroEducativo();
                    micentro.Codigo        = (int)reader["id"];
                    micentro.Nombre        = reader["nombre"].ToString();
                    micentro.listaSeciones = new CentroSeccionDatos().seleccionarPorCentro(micentro);
                    //agregarlista Secciones
                    listaCentros.Add(micentro);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.Close();
            }

            return(listaCentros);
        }
Example #19
0
        public List <Seccion> seleccionarPorCentro(CentroEducativo centro)
        {
            List <Seccion> lista = new List <Seccion>();
            SqlConnection  con   = new SqlConnection(Conexion.Cadena);

            try
            {
                con.Open();
                string     sql     = "PA_CentroSeccionSelectidCentro";
                SqlCommand comando = new SqlCommand(sql, con);

                comando.Parameters.AddWithValue("@idCentro", centro.Codigo);

                comando.CommandType = System.Data.CommandType.StoredProcedure;

                SqlDataReader reader = comando.ExecuteReader();

                while (reader.Read())
                {
                    Seccion sec = new Seccion();
                    sec.Id = reader["idSeccion"].ToString();

                    lista.Add(sec);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.Close();
            }

            return(lista);
        }
Example #20
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,IdDepartamento,IdMunicipio,IdDistrito,IdBodega,IdZona,Nivel,Nombre,Direccion,Telefono,Estado,NombreContacto,CorreoContacto,TelefonoContacto,Ninos,Ninas,Total,FechaCreacion,FechaModificacion")] CentroEducativo centroEducativo)
        {
            if (id != centroEducativo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    centroEducativo.FechaModificacion = DateTime.Now;
                    _context.Update(centroEducativo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CentroEducativoExists(centroEducativo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["IdDepartamento"] = new SelectList(_context.Departamento, "Id", "Nombre", centroEducativo.IdDepartamento);
            ViewData["IdBodega"]       = new SelectList(_context.Bodega.Where(x => x.IdDepartamento == centroEducativo.IdDepartamento), "Id", "Nombre", centroEducativo.IdBodega);
            ViewData["IdDistrito"]     = new SelectList(_context.Distrito.Where(x => x.IdDepartamento == centroEducativo.IdDepartamento), "Id", "Nombre", centroEducativo.IdDistrito);
            ViewData["IdMunicipio"]    = new SelectList(_context.Municipio.Where(x => x.DepartamentoId == centroEducativo.IdDepartamento), "Id", "Nombre", centroEducativo.IdMunicipio);
            ViewData["IdZona"]         = new SelectList(_context.Zona, "Id", "Nombre", centroEducativo.IdZona);
            return(View(centroEducativo));
        }
Example #21
0
 /// <summary>
 /// Elimina la Relacion Entre un Centro y Una Seccion
 /// </summary>
 public void eliminarSecciondeUnCentro(CentroEducativo centro, Seccion sec)
 {
     new CentroSeccionDatos().eliminarCentroSeccion(centro, sec);
 }
Example #22
0
        public CentroEducativo seleccionarCentro(CentroEducativo centro)
        {
            CentroEducativoDatos datos = new CentroEducativoDatos();

            return(datos.seleccionarCentro(centro));
        }
Example #23
0
 public void eliminarCentro(CentroEducativo centro)
 {
     new CentroEducativoDatos().eliminarCentro(centro);
 }
        /// <summary>
        /// Crea un Usuario segun el tipo,segun los parametros
        /// </summary>
        /// <param name="cedula"></param>
        /// <param name="nombre"></param>
        /// <param name="primerApellido"></param>
        /// <param name="segundoApellido"></param>
        /// <param name="fechaNacimiento"></param>
        /// <param name="genero"></param>
        /// <param name="password"></param>
        /// <param name="numeroTelefono"></param>
        /// <param name="email"></param>
        /// <param name="centro"></param>
        /// <param name="seccion"></param>
        /// <param name="tipo">enum con el tipo de usuario</param>
        /// <returns></returns>
        public Usuario crearUsuario(string cedula, string nombre, string primerApellido, string segundoApellido,
                                    DateTime fechaNacimiento, Genero genero, string numeroTelefono, string email, CentroEducativo centro, Seccion seccion, TipoUsuario tipo)
        {
            Usuario miUsuario = null;

            switch (tipo)
            {
            case TipoUsuario.Profesor:
                miUsuario = new Profesor();
                ((Profesor)miUsuario).CentroEducativo = centro;
                break;

            case TipoUsuario.Estudiante:
                miUsuario = new Estudiante();
                ((Estudiante)miUsuario).CentroEducativo = centro;
                ((Estudiante)miUsuario).Seccion         = seccion;
                break;

            case TipoUsuario.Administrador:
                miUsuario = new Administrador();
                break;

            default:
                break;
            }
            miUsuario.Cedula            = cedula;
            miUsuario.Nombre            = nombre;
            miUsuario.primerApellido    = primerApellido;
            miUsuario.SegundoApellido   = segundoApellido;
            miUsuario.FechaNacimiento   = fechaNacimiento;
            miUsuario.Genero            = genero;
            miUsuario.Password          = new UsuarioLogica().crearContrasenas();
            miUsuario.NumeroTelefono    = numeroTelefono;
            miUsuario.CorreoElectronico = email;

            return(miUsuario);
        }
Example #25
0
        public async Task <JsonResult> Import(IFormFile formFile, CancellationToken cancellationToken)
        {
            if (formFile == null || formFile.Length <= 0)
            {
                return(Json(Response <List <ImportarCE> > .GetResult(-1, "El archivo se encuentra vacío")));
            }

            if (!Path.GetExtension(formFile.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
            {
                return(Json(Response <List <ImportarMuestra> > .GetResult(-2, "Tipo de archivo no soportado")));
            }
            List <ImportarCE>      items = new List <ImportarCE>();
            List <CentroEducativo> centroEducativosNew = new List <CentroEducativo>();
            List <CentroEducativo> centroEducativosUpd = new List <CentroEducativo>();

            using (var stream = new MemoryStream())
            {
                await formFile.CopyToAsync(stream, cancellationToken);

                using (var package = new ExcelPackage(stream))
                {
                    ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
                    var            rowCount  = worksheet.Dimension.Rows;
                    try
                    {
                        int    errors = 0;
                        string message;
                        int?   departamento, municipio, distrito, zona;
                        for (int row = 2; row <= rowCount; row++)
                        {
                            ImportarCE      item            = new ImportarCE();
                            CentroEducativo centroEducativo = new CentroEducativo();
                            string          codnivel        = worksheet.Cells[row, 12].Text;
                            item.Codigo     = (worksheet.Cells[row, 4].Text == "" ? null : worksheet.Cells[row, 4].Text) + codnivel;
                            centroEducativo = _context.CentroEducativo.Where(x => x.Id == item.Codigo).FirstOrDefault();
                            //cargar lista que se mostrará en el mantenimiento
                            item.Departamento     = (worksheet.Cells[row, 1].Text == "" ? null : worksheet.Cells[row, 1].Text);;
                            item.Municipio        = (worksheet.Cells[row, 2].Text == "" ? null : worksheet.Cells[row, 2].Text);
                            item.Distrito         = (worksheet.Cells[row, 3].Text == "" ? null : worksheet.Cells[row, 3].Text);
                            item.Zona             = (worksheet.Cells[row, 8].Text == "" ? null : worksheet.Cells[row, 8].Text);
                            item.Nivel            = (worksheet.Cells[row, 11].Text == "" ? null : worksheet.Cells[row, 11].Text);
                            item.Nombre           = (worksheet.Cells[row, 6].Text == "" ? null : worksheet.Cells[row, 6].Text);
                            item.Direccion        = (worksheet.Cells[row, 7].Text == "" ? null : worksheet.Cells[row, 7].Text);
                            item.Telefono         = (worksheet.Cells[row, 15].Text == "" ? null : worksheet.Cells[row, 15].Text);
                            item.NombreContacto   = (worksheet.Cells[row, 12].Text == "" ? null : worksheet.Cells[row, 12].Text);
                            item.TelefonoContacto = (worksheet.Cells[row, 16].Text == "" ? null : worksheet.Cells[row, 16].Text);
                            item.CorreoContacto   = (worksheet.Cells[row, 17].Text == "" ? null : worksheet.Cells[row, 17].Text);
                            item.Ninos            = int.Parse((worksheet.Cells[row, 19].Text == "" ? null : worksheet.Cells[row, 18].Text));
                            item.Ninas            = int.Parse((worksheet.Cells[row, 18].Text == "" ? null : worksheet.Cells[row, 19].Text));
                            item.Total            = int.Parse((worksheet.Cells[row, 20].Text == "" ? null : worksheet.Cells[row, 20].Text));
                            if (centroEducativo != null)
                            {
                                centroEducativo.Direccion        = item.Direccion;
                                centroEducativo.NombreContacto   = item.NombreContacto;
                                centroEducativo.TelefonoContacto = item.TelefonoContacto;
                                centroEducativo.Telefono         = item.Telefono;
                                centroEducativo.Ninas            = item.Ninas;
                                centroEducativo.Ninos            = item.Ninos;
                                centroEducativo.Total            = item.Ninos;
                                centroEducativo.CorreoContacto   = item.CorreoContacto;
                                centroEducativosUpd.Add(centroEducativo);
                                centroEducativo.FechaModificacion = DateTime.Now;
                            }
                            else
                            {
                                centroEducativo    = new CentroEducativo();
                                centroEducativo.Id = item.Codigo;
                                departamento       = _context.Departamento.Where(x => x.Nombre.TrimEnd().TrimStart() == item.Departamento).FirstOrDefault()?.Id;
                                municipio          = _context.Municipio.Where(x => x.Nombre.TrimEnd().TrimStart() == item.Municipio).FirstOrDefault()?.Id;
                                zona     = _context.Zona.Where(x => x.Nombre.TrimEnd().TrimStart() == item.Zona).FirstOrDefault()?.Id;
                                distrito = _context.Zona.Where(x => x.Id == int.Parse(item.Distrito)).FirstOrDefault()?.Id;
                                if (departamento != null)
                                {
                                    centroEducativo.IdDepartamento = departamento.Value;
                                }
                                if (municipio != null)
                                {
                                    centroEducativo.IdMunicipio = municipio.Value;
                                }
                                if (zona != null)
                                {
                                    centroEducativo.IdZona = zona.Value;
                                }
                                if (distrito != null)
                                {
                                    centroEducativo.IdDistrito = distrito.Value;
                                }
                                centroEducativo.Nombre           = item.Nombre;
                                centroEducativo.Direccion        = item.Nombre;
                                centroEducativo.Telefono         = item.Telefono;
                                centroEducativo.NombreContacto   = item.NombreContacto;
                                centroEducativo.TelefonoContacto = item.TelefonoContacto;
                                centroEducativo.CorreoContacto   = item.CorreoContacto;
                                centroEducativo.Ninos            = item.Ninos;
                                centroEducativo.Ninas            = item.Ninas;
                                centroEducativo.Total            = item.Ninas;
                                centroEducativo.Nivel            = item.Nivel;
                                centroEducativosNew.Add(centroEducativo);
                                centroEducativo.Estado            = true;
                                centroEducativo.FechaCreacion     = DateTime.Now;
                                centroEducativo.FechaModificacion = DateTime.Now;
                            }

                            TryValidateModel(centroEducativo);
                            var res = ModelState.IsValid;
                            if (res == false)
                            {
                                errors += 1;
                                message = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
                            }
                            else
                            {
                                message = "Ok";
                            }

                            item.resultado = message;
                            items.Add(item);

                            ModelState.Clear();
                        }
                        if (errors == 0)
                        {
                            if (centroEducativosNew.Count > 0)
                            {
                                _context.AddRange(centroEducativosNew);
                                _context.SaveChanges();
                            }
                            if (centroEducativosNew.Count > 0)
                            {
                                _context.UpdateRange(centroEducativosUpd);
                                _context.SaveChanges();
                            }
                            return(Json(Response <List <ImportarCE> > .GetResult(0, "OK", items)));
                        }
                    }
                    catch (Exception e)
                    {
                        return(Json(Response <List <ImportarCE> > .GetResult(-2, e.Message, items)));
                    }
                }
            }
            return(Json(Response <List <ImportarCE> > .GetResult(0, "OK", items)));
        }