public bool ReingresaListaEspera(Int32 _listaEspera)
            {
                try
                {
                    MED_ListaEspera _espera = new MED_ListaEspera();
                    //ESTAS 2 LINEAS DE ABAJO ES IMPORTANTE PARA PODER MODIFICAR SOLO ALGUNOS CAMPOS
                    _Mod.Configuration.AutoDetectChangesEnabled = false;
                    _Mod.Configuration.ValidateOnSaveEnabled    = false;

                    _espera.espera_id       = _listaEspera;
                    _espera.fechaEgreso     = null;
                    _espera.motivoEgreso_id = null;

                    //AHORA MARCO LOS CAMPOS QUE SE MODIFICAN
                    _Mod.MED_ListaEspera.Attach(_espera);
                    _Mod.Entry(_espera).Property(m => m.fechaEgreso).IsModified     = true;
                    _Mod.Entry(_espera).Property(m => m.motivoEgreso_id).IsModified = true;

                    // **** ACTUALIZO LA TABLA
                    _Mod.SaveChanges();

                    return(true);
                }

                catch (Exception ex)
                {
                    return(false);
                }
            }
예제 #2
0
        private void btnGrabar_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidaConfirmacion())
                {
                    MED_ListaEspera _espera = new MED_ListaEspera();

                    _espera.confirmaCama          = true;
                    _espera.espera_id             = _listaEsperaId;
                    _espera.sedeSugerida          = Convert.ToInt32(comboBoxSede.SelectedValue);
                    _espera.responsable           = textBoxResponsable.Text;
                    _espera.vinculo               = textBoxVinculo.Text;
                    _espera.telefonos             = textBoxTelefonos.Text;
                    _espera.fechaConfirmacionCama = dateTimePickerConfirma.Value;
                    if (cboHabitacionDesocupada.SelectedIndex > 0)
                    {
                        _espera.habitacion_id = Convert.ToInt32(cboHabitacionDesocupada.SelectedValue);
                    }
                    else
                    {
                        MessageBox.Show("Debe seleccionar una habitación", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    //ESTAS 2 LINEAS DE ABAJO ES IMPORTANTE PARA PODER MODIFICAR SOLO ALGUNOS CAMPOS
                    _Mod.Configuration.AutoDetectChangesEnabled = false;
                    _Mod.Configuration.ValidateOnSaveEnabled    = false;

                    //AHORA MARCO LOS CAMPOS QUE SE MODIFICAN
                    _Mod.MED_ListaEspera.Attach(_espera);

                    _Mod.Entry(_espera).Property(m => m.confirmaCama).IsModified          = true;
                    _Mod.Entry(_espera).Property(m => m.sedeSugerida).IsModified          = true;
                    _Mod.Entry(_espera).Property(m => m.responsable).IsModified           = true;
                    _Mod.Entry(_espera).Property(m => m.vinculo).IsModified               = true;
                    _Mod.Entry(_espera).Property(m => m.telefonos).IsModified             = true;
                    _Mod.Entry(_espera).Property(m => m.fechaConfirmacionCama).IsModified = true;
                    //if (cboHabitacionDesocupada.SelectedIndex > 0)
                    //{
                    _Mod.Entry(_espera).Property(m => m.habitacion_id).IsModified = true;
                    //}

                    _Mod.SaveChanges();
                    MessageBox.Show("Cama confirmada correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    EnviarMail(_listaEsperaId);
                    Close();
                }
            }

            catch (Exception ex)

            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
            public bool ListaNew(MED_ListaEspera _lista, List <MED_ListaEsperaModulo> _listModulos, List <MED_PuntajeAdicionalListaEspera> _listFactor, List <MED_CultivosListaEspera> _cultivos)
            {
                try
                {
                    _Mod.MED_ListaEspera.Add(_lista);

                    int _idListaGenerada = _lista.espera_id;

                    foreach (MED_ListaEsperaModulo item in _listModulos)
                    {
                        item.espera_id = _idListaGenerada;
                        _Mod.MED_ListaEsperaModulo.Add(item);
                    }


                    if (_cultivos.Count > 0)
                    {
                        foreach (MED_CultivosListaEspera item in _cultivos)
                        {
                            item.espera_id = _idListaGenerada;
                            _Mod.MED_CultivosListaEspera.Add(item);
                        }
                    }

                    if (_listFactor.Count > 0)
                    {
                        foreach (MED_PuntajeAdicionalListaEspera item in _listFactor)
                        {
                            item.espera_id = _idListaGenerada;
                            _Mod.MED_PuntajeAdicionalListaEspera.Add(item);
                        }
                    }

                    _Mod.SaveChanges();

                    return(true);
                }

                catch (Exception ex)
                {
                    return(false);
                }
            }
            public bool ListaUpdate(MED_ListaEspera _lista, List <MED_ListaEsperaModulo> _listModulos, List <MED_PuntajeAdicionalListaEspera> _listFactor, List <MED_CultivosListaEspera> _cultivos)
            {
                try
                {
                    //PRIMERO BORRO LOS MODULOS Y CARGO TODOS DE NUEVO..
                    var _remove = (from P in _Mod.MED_ListaEsperaModulo where P.espera_id == _lista.espera_id select P).ToList();
                    foreach (var item in _remove)
                    {
                        _Mod.MED_ListaEsperaModulo.Remove(item);
                    }

                    //LUEGO INSERTO TODOS DE NUEVO
                    foreach (MED_ListaEsperaModulo item in _listModulos)
                    {
                        item.espera_id = _lista.espera_id;
                        _Mod.MED_ListaEsperaModulo.Add(item);
                    }

                    //ACTUALIZO OTROS FACTORES DE PUNTAJE... PUEDE ESTAR AGREGANDO O BORRANDO.....
                    //PRIMERO BORRO LOS QUE TENGA ASIGNADO
                    var _removeFactor = (from F in _Mod.MED_PuntajeAdicionalListaEspera where F.espera_id == _lista.espera_id select F).ToList();
                    foreach (var item in _removeFactor)
                    {
                        _Mod.MED_PuntajeAdicionalListaEspera.Remove(item);
                    }
                    //AHORA SI LA LISTA TIENE DATOS.. INSERTRO LOS NUEVOS
                    if (_listFactor.Count > 0)
                    {
                        foreach (MED_PuntajeAdicionalListaEspera item in _listFactor)
                        {
                            item.espera_id = _lista.espera_id;
                            _Mod.MED_PuntajeAdicionalListaEspera.Add(item);
                        }
                    }
                    //FIN FACTOR PUNTAJE ADICIONAL

                    //ACTUALIZO TABLAS DE CULTIVOS
                    var _removeCultivos = (from F in _Mod.MED_CultivosListaEspera where F.espera_id == _lista.espera_id select F).ToList();
                    foreach (var item in _removeCultivos)
                    {
                        _Mod.MED_CultivosListaEspera.Remove(item);
                    }
                    //AHORA INSERTO NUEVOS
                    if (_cultivos.Count > 0)
                    {
                        foreach (MED_CultivosListaEspera item in _cultivos)
                        {
                            item.espera_id = _lista.espera_id;
                            _Mod.MED_CultivosListaEspera.Add(item);
                        }
                    }
                    //FIN CULTIVOS

                    //ACTUALIZO TABLA LISTA DE ESPERA
                    _Mod.Entry(_lista).State = System.Data.Entity.EntityState.Modified;

                    _Mod.SaveChanges();

                    return(true);
                }

                catch (Exception ex)
                {
                    return(false);
                }
            }
            public bool IngresaPaciente(Pacientes _pac, List <MED_PacienteModulo> _listModPac, Int32 _listaEsperaId, bool _reingreso, int _pacienteIdIM)
            {
                using (var dbContextTransaction = _Mod.Database.BeginTransaction())
                {
                    try
                    {
                        if (!_reingreso)
                        {
                            //ESTAS 2 LINEAS DE ABAJO ES IMPORTANTE PARA PODER MODIFICAR SOLO ALGUNOS CAMPOS
                            _Mod.Configuration.AutoDetectChangesEnabled = false;
                            _Mod.Configuration.ValidateOnSaveEnabled    = false;

                            // ******   INSERTO EN TABLA PACIENTE ****************
                            _Mod.Pacientes.Add(_pac);

                            // ******  AHORA INSERTO LOS MODULOS SELECCIONADOS ************
                            foreach (MED_PacienteModulo item in _listModPac)
                            {
                                item.paciente_id = _pac.paciente_id; //ESTO PORQUE EL EF DEVUELVE EL ID CREAEDO EN EL MISMO OBJETO
                                _Mod.MED_PacienteModulo.Add(item);
                            }
                            // ***** AHORA ACTUALIZO LA TABLA MED_LISTAESPERA, PARA MARCAR QUE EGRESÓ *****
                            MED_ListaEspera _espera = new MED_ListaEspera();
                            _espera.fechaEgreso = Convert.ToDateTime(DateTime.Now); //fecha de egreso
                                                                                    //_espera.obs = obs;                                      // OJOOOO VER SI ESTO ESTA BIEN DE MODIFICAR LAS OBS
                            _espera.espera_id     = _listaEsperaId;                 // id lista espera
                            _espera.habitacion_id = _pac.habitacion_id;             // habitacion id.. puede venir en null

                            //AHORA MARCO LOS CAMPOS QUE SE MODIFICAN
                            _Mod.MED_ListaEspera.Attach(_espera);
                            _Mod.Entry(_espera).Property(m => m.fechaEgreso).IsModified   = true;
                            _Mod.Entry(_espera).Property(m => m.habitacion_id).IsModified = true;

                            // **** ACTUALIZO LAS TABLAS
                            _Mod.SaveChanges();
                            dbContextTransaction.Commit();
                            return(true);
                        }

                        // *************  ES UN REINGRESO ****************************************
                        if (_reingreso)
                        {
                            //ESTAS 2 LINEAS DE ABAJO ES IMPORTANTE PARA PODER MODIFICAR SOLO ALGUNOS CAMPOS
                            _Mod.Configuration.AutoDetectChangesEnabled = false;
                            _Mod.Configuration.ValidateOnSaveEnabled    = false;

                            //ACTUALIZO LA TABLA DE PACIENTES
                            _pac.paciente_id = _pacienteIdIM;

                            _Mod.Pacientes.Attach(_pac);
                            _Mod.Entry(_pac).Property(m => m.habitacion_id).IsModified  = true;
                            _Mod.Entry(_pac).Property(m => m.fechaIngreso).IsModified   = true;
                            _Mod.Entry(_pac).Property(m => m.responsabe).IsModified     = true;
                            _Mod.Entry(_pac).Property(m => m.vinculo).IsModified        = true;
                            _Mod.Entry(_pac).Property(m => m.telefono).IsModified       = true;
                            _Mod.Entry(_pac).Property(m => m.diagnostico_id).IsModified = true;
                            _Mod.Entry(_pac).Property(m => m.sede_id).IsModified        = true;
                            _Mod.Entry(_pac).Property(m => m.usuario_id).IsModified     = true;

                            //BORRO TODOS LOS MODULOS ASIGNADOS ANTERIORMENTE
                            //PRIMERO BORRO LOS QUE TENGA ASIGNADO
                            var _removeModulo = (from F in _Mod.MED_PacienteModulo where F.paciente_id == _pacienteIdIM select F).ToList();
                            foreach (var item in _removeModulo)
                            {
                                _Mod.MED_PacienteModulo.Remove(item);
                            }

                            //FIN BORRA MODULOS

                            // ******  AHORA INSERTO LOS MODULOS SELECCIONADOS ************
                            foreach (MED_PacienteModulo item in _listModPac)
                            {
                                item.paciente_id = _pac.paciente_id; //ESTO PORQUE EL EF DEVUELVE EL ID CREAEDO EN EL MISMO OBJETO
                                _Mod.MED_PacienteModulo.Add(item);
                            }

                            // ***** AHORA ACTUALIZO LA TABLA MED_LISTAESPERA, PARA MARCAR QUE EGRESÓ *****
                            MED_ListaEspera _espera = new MED_ListaEspera();
                            _espera.fechaEgreso = Convert.ToDateTime(DateTime.Now); //fecha de egreso
                            //_espera.obs = obs;       // OJOOOO VER SI ESTO ESTA BIEN DE MODIFICAR LAS OBS
                            _espera.espera_id     = _listaEsperaId;                 // id lista espera
                            _espera.habitacion_id = _pac.habitacion_id;             // habitacion id.. puede venir en null

                            //AHORA MARCO LOS CAMPOS QUE SE MODIFICAN
                            _Mod.MED_ListaEspera.Attach(_espera);
                            _Mod.Entry(_espera).Property(m => m.fechaEgreso).IsModified   = true;
                            _Mod.Entry(_espera).Property(m => m.habitacion_id).IsModified = true;

                            // **** ACTUALIZO LAS TABLAS
                            _Mod.SaveChanges();
                            dbContextTransaction.Commit();

                            return(true);
                        }

                        return(true);
                    }

                    catch (Exception)
                    {
                        dbContextTransaction.Rollback();
                        return(false);
                    }
                }
            }