Example #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            string fechaParametro = dpFecha.Value.ToShortDateString();
            string mensajes       = "";

            if (String.IsNullOrEmpty(txtId.Text))
            {
                mensajes = "Esta seguro de Guardar Nuevo Registro";
            }
            else
            {
                mensajes = "Esta seguro de Editar el Registro con ID " + txtId.Text;
            }
            DialogResult dialogo = MessageBox.Show(mensajes, "Comfirmar", MessageBoxButtons.OKCancel);

            if (dialogo == DialogResult.OK)
            {
                var context = new PruebaEntities();
                var u       = context.Fecha.Where(fecha => fecha.fecha == fechaParametro).Count();
                if (u < 1)
                {
                    guardar();
                }
                else
                {
                    MessageBox.Show("ERROR ! Ya existe un registro con al misma fecha");
                }
            }
        }
Example #2
0
        private void guardar()
        {
            var     context = new PruebaEntities();
            Persona persona = context.Persona.Find(cbPersona.SelectedValue);

            // Si la caja de texto está vacía, se tratará de una inserción
            if (String.IsNullOrEmpty(txtId.Text))
            {
                try
                {
                    // Creamos un nuevo usuario y lo añadimos, guardando a continuación los cambios
                    Asueto asueto = new Asueto
                    {
                        id          = 0,
                        fechaInicio = dpFechaInicio.Value.ToShortDateString(),
                        fechaFin    = dpFechaFin.Value.ToShortDateString(),
                        tipo        = cbTipo.Text,
                        Persona     = persona
                    };
                    context.Asueto.Add(asueto);
                    context.SaveChanges();
                    cargar();
                    MessageBox.Show("REGISTRO NUEVO EXITOSO!");
                }
                catch (Exception)
                {
                    throw;
                }
            }

            // En caso contrario, se tratará de una modificación
            else
            {
                try
                {
                    int id = int.Parse(txtId.Text);
                    // Recuperamos el usuario cuyo identificador coincida con el de la caja de texto
                    Asueto u = context.Asueto.Where(asueto => asueto.id == id).First();

                    // Modificamos el contenido
                    u.fechaInicio = dpFechaInicio.Value.ToShortDateString();
                    u.fechaFin    = dpFechaFin.Value.ToShortDateString();
                    u.tipo        = cbTipo.Text;
                    u.Persona     = persona;

                    // Guardamos los cambios
                    context.SaveChanges();
                    cargar();
                    MessageBox.Show("ACTUALIZACION EXITOSA!");
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #3
0
        private void guardar()
        {
            var context = new PruebaEntities();



            // Si la caja de texto está vacía, se tratará de una inserción
            if (String.IsNullOrEmpty(txtId.Text))
            {
                try
                {
                    // Creamos un nuevo usuario y lo añadimos, guardando a continuación los cambios
                    Fecha fecha = new Fecha
                    {
                        id    = 0,
                        fecha = dpFecha.Value.ToShortDateString(),
                        tipo  = "M"
                    };
                    context.Fecha.Add(fecha);
                    context.SaveChanges();
                    cargar();
                    MessageBox.Show("REGISTRO NUEVO EXITOSO!");
                }
                catch (Exception)
                {
                    throw;
                }
            }

            // En caso contrario, se tratará de una modificación
            else
            {
                try
                {
                    int id = int.Parse(txtId.Text);
                    // Recuperamos el usuario cuyo identificador coincida con el de la caja de texto
                    Fecha u = context.Fecha.Where(fecha => fecha.id == id).First();

                    // Modificamos el contenido
                    u.fecha = dpFecha.Value.ToShortDateString();

                    // Guardamos los cambios
                    context.SaveChanges();
                    cargar();
                    MessageBox.Show("ACTUALIZACION EXITOSA!");
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #4
0
        private void guardar()
        {
            var context = new PruebaEntities();

            // Si la caja de texto está vacía, se tratará de una inserción
            if (String.IsNullOrEmpty(txtId.Text))
            {
                try
                {
                    // Creamos un nuevo usuario y lo añadimos, guardando a continuación los cambios
                    Categoria categoria = new Categoria
                    {
                        id     = 0,
                        nombre = txtNombre.Text,
                    };
                    context.Categoria.Add(categoria);
                    context.SaveChanges();
                    cargar();
                    MessageBox.Show("REGISTRO EXITOSO!");
                }
                catch (Exception)
                {
                    throw;
                }
            }

            // En caso contrario, se tratará de una modificación
            else
            {
                try
                {
                    int id = int.Parse(txtId.Text);
                    // Recuperamos el usuario cuyo identificador coincida con el de la caja de texto
                    Categoria u = context.Categoria.Where(categoria => categoria.id == id).First();

                    // Modificamos el contenido
                    u.nombre = txtNombre.Text;

                    // Guardamos los cambios
                    context.SaveChanges();
                    cargar();
                    MessageBox.Show("ACTUALIZACION EXITOSA!");
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #5
0
        private void agregarLista()
        {
            var            context       = new PruebaEntities();
            Area_Categoria areaCategoria = new Area_Categoria
            {
                mañana       = (long)nMañana.Value,
                tarde        = (long)nTarde.Value,
                noche        = (long)nNoche.Value,
                categoria_id = Convert.ToInt64(cbCategoria.SelectedValue)
            };

            listaAreaCategoria.Add(areaCategoria);
            dgvCategoria.DataSource = null;
            dgvCategoria.DataSource = listaAreaCategoria;
        }
Example #6
0
        private void eliminar()
        {
            var context = new PruebaEntities();

            if (!String.IsNullOrEmpty(txtId.Text))
            {
                // Recuperamos el usuario cuyo identificador coincida con el de la caja de texto
                int     id = int.Parse(txtId.Text);
                Persona u  = context.Persona.Where(persona => persona.id == id).First();

                // Lo eliminamos y salvamos los cambios
                context.Persona.Remove(u);
                context.SaveChanges();
                cargar();
            }
        }
Example #7
0
        private void calcular()
        {
            var    context = new PruebaEntities();
            string fecha1  = dpFecha.Value.ToShortDateString();

            var result = context.Fecha.Where(fecha => fecha.id > 1);

            foreach (var r in result)
            {
                DateTime fecha = Convert.ToDateTime(r.fecha);
                if (fecha >= dpFechaInicio.Value && fecha <= dpFechaFin.Value)
                {
                    MessageBox.Show("sdkfnh");
                }
            }
        }
Example #8
0
        private void cargar()
        {
            // Eliminamos el handler del evento RowEnter para evitar que se dispare al
            // realizar la búsqueda

            dataGridView1.RowEnter -= dataGrid_RowEnter;

            // Instanciamos el contexto y cargamos un listado de usuarios
            var context = new PruebaEntities();
            var users   =
                from user in context.Persona
                orderby user.id descending
                select user;

            // Cargamos el grid con los datos
            dataGridView1.DataSource = users.ToList();

            // Restauramos el handler del evento
            dataGridView1.RowEnter += dataGrid_RowEnter;
        }
Example #9
0
        private void guardar(DateTime inicio, string tipo)
        {
            // Creamos un nuevo usuario y lo añadimos, guardando a continuación los cambios
            string fechaParametro = inicio.ToShortDateString();
            var    context        = new PruebaEntities();
            var    u = context.Fecha.Where(fecha => fecha.fecha == fechaParametro).Count();

            if (u < 1)
            {
                Fecha fecha = new Fecha
                {
                    id    = 0,
                    fecha = fechaParametro,
                    tipo  = tipo
                };
                context.Fecha.Add(fecha);
                context.SaveChanges();
                cargar();
                MessageBox.Show("REGISTRO EXITOSO!" + fechaParametro);
            }
        }
Example #10
0
        private void generar()
        {
            var inicio = dpFechaInicio.Value;
            var fin    = dpFechaFin.Value;

            int cantidadDias = fin.Subtract(inicio).Days + 1;
            var diasSabado   = new[] { DayOfWeek.Saturday };
            var diasDomingo  = new[] { DayOfWeek.Sunday };

            do
            {
                if (inicio.DayOfWeek == DayOfWeek.Saturday || inicio.DayOfWeek == DayOfWeek.Sunday)
                {
                    guardar(inicio, "A");
                }

                inicio = inicio.AddDays(1);
            } while (!(inicio > fin));

            var context = new PruebaEntities();
        }
Example #11
0
        private void cargar()
        {
            // Eliminamos el handler del evento RowEnter para evitar que se dispare al
            // realizar la búsqueda

            dgv.RowEnter -= dataGrid_RowEnter;

            string fechaInicio = dpFechaInicio.Value.ToShortDateString();
            string fechaFin    = dpFechaFin.Value.ToShortDateString();

            // Instanciamos el contexto y cargamos un listado de usuarios
            var context = new PruebaEntities();
            var users   =
                from user in context.Fecha
                orderby user.fecha descending
                select user;

            // Cargamos el grid con los datos
            dgv.DataSource = users.ToList();

            // Restauramos el handler del evento
            dgv.RowEnter += dataGrid_RowEnter;
        }
Example #12
0
        private void guardar()
        {
            var contexto = new PruebaEntities();

            try
            {
                Area area = new Area
                {
                    nombre = txtNombre.Text,
                };

                contexto.Area.Add(area);
                foreach (Area_Categoria item in listaAreaCategoria)
                {
                    item.Area = area;
                    contexto.Area_Categoria.Add(item);
                }
                contexto.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #13
0
        private void guardar()
        {
            var       context   = new PruebaEntities();
            Categoria categoria = context.Categoria.Find(cbCategoria.SelectedValue);
            int       codigo    = int.Parse(txtCodigo.Text);
            int       activo    = 0;

            if (cbActivo.Checked)
            {
                activo = 1;
            }

            // Si la caja de texto está vacía, se tratará de una inserción
            if (String.IsNullOrEmpty(txtId.Text))
            {
                try
                {
                    // Creamos un nuevo usuario y lo añadimos, guardando a continuación los cambios
                    Persona persona = new Persona
                    {
                        id        = 0,
                        nombre    = txtNombre.Text,
                        paterno   = txtPaterno.Text,
                        materno   = txtMaterno.Text,
                        codigo    = codigo,
                        activo    = activo,
                        Categoria = categoria
                    };
                    context.Persona.Add(persona);
                    context.SaveChanges();
                    cargar();
                    MessageBox.Show("REGISTRO EXITOSO!");
                }
                catch (Exception)
                {
                    throw;
                }
            }

            // En caso contrario, se tratará de una modificación
            else
            {
                try
                {
                    int id = int.Parse(txtId.Text);
                    // Recuperamos el usuario cuyo identificador coincida con el de la caja de texto
                    Persona u = context.Persona.Where(persona => persona.id == id).First();

                    // Modificamos el contenido
                    u.codigo    = codigo;
                    u.nombre    = txtNombre.Text;
                    u.paterno   = txtPaterno.Text;
                    u.materno   = txtMaterno.Text;
                    u.activo    = activo;
                    u.Categoria = categoria;

                    // Guardamos los cambios
                    context.SaveChanges();
                    cargar();
                    MessageBox.Show("ACTUALIZACION EXITOSA!");
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }