コード例 #1
0
        public void AgregarFila(FormaFarmaceutica formaFarmaceutica)
        {
            DataGridViewRow r = ConstruirFila();

            SetearFila(r, formaFarmaceutica);
            AñadirFila(r);
        }
コード例 #2
0
        private void tslAgregar_Click(object sender, EventArgs e)
        {
            frmFormasFarmaceuticasAE frm = new frmFormasFarmaceuticasAE(this);

            frm.Text = "Nueva Forma farmaceutica";
            DialogResult dr = frm.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                try
                {
                    FormaFarmaceutica formaFarmaceutica = frm.GetFormaFarmaceutica();
                    if (!_servicio.Existe(formaFarmaceutica))
                    {
                        _servicio.Guardar(formaFarmaceutica);
                        DataGridViewRow r = ConstruirFila();
                        SetearFila(r, formaFarmaceutica);
                        AñadirFila(r);
                        MessageBox.Show("Registro Agregado");
                    }
                    else
                    {
                        MessageBox.Show("Forma farmaceutica repetida");
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }
        }
コード例 #3
0
        private void tslBorrar_Click(object sender, EventArgs e)
        {
            if (dgvDatos.SelectedRows.Count > 0)
            {
                DataGridViewRow   r = dgvDatos.SelectedRows[0];
                FormaFarmaceutica formaFarmaceutica = (FormaFarmaceutica)r.Tag;

                DialogResult dr = MessageBox.Show(this, $"¿Desea dar de baja la forma farmaceutica {formaFarmaceutica.Descripcion}?",
                                                  "Confirmar Baja",
                                                  MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    if (!_servicio.EstaRelacionado(formaFarmaceutica))
                    {
                        try
                        {
                            _servicio.Borrar(formaFarmaceutica.FormaFarmaceuticaId);
                            dgvDatos.Rows.Remove(r);
                            MessageBox.Show("Registro borrado");
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show("El registro esta relacionado, no se puede borrar");
                    }
                }
            }
        }
コード例 #4
0
 private void tslEditar_Click(object sender, EventArgs e)
 {
     if (dgvDatos.SelectedRows.Count > 0)
     {
         DataGridViewRow   r = dgvDatos.SelectedRows[0];
         FormaFarmaceutica formaFarmaceutica = (FormaFarmaceutica)r.Tag;
         formaFarmaceutica = _servicio.GetFormaFarmaceuticaPorId(formaFarmaceutica.FormaFarmaceuticaId);
         frmFormasFarmaceuticasAE frm = new frmFormasFarmaceuticasAE();
         frm.Text = "Editar FormaFarmaceutica";
         frm.SetFormaFarmaceutica(formaFarmaceutica);
         DialogResult dr = frm.ShowDialog(this);
         if (dr == DialogResult.OK)
         {
             try
             {
                 formaFarmaceutica = frm.GetFormaFarmaceutica();
                 if (!_servicio.Existe(formaFarmaceutica))
                 {
                     _servicio.Guardar(formaFarmaceutica);
                     SetearFila(r, formaFarmaceutica);
                     MessageBox.Show("Registro Editado");
                 }
                 else
                 {
                     MessageBox.Show("FormaFarmaceutica Repetida");
                 }
             }
             catch (Exception exception)
             {
                 MessageBox.Show(exception.Message);
             }
         }
     }
 }
コード例 #5
0
        private void tsbNuevo_Click(object sender, EventArgs e)
        {
            frmFormaFarmaceuticaAE frm = new frmFormaFarmaceuticaAE();

            frm.Text = "Agregar Forma Farmaceutica";
            DialogResult dr = frm.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                try
                {
                    FormaFarmaceutica forma = frm.GetFormaFarmaceutica();
                    if (!servicio.Existe(forma))
                    {
                        servicio.Agregar(forma);
                        var r = ConstruirFila();
                        SetearFila(r, forma);
                        AgregarFila(r);
                        MessageBox.Show("Forma farmaceutica agregada", "Mensaje",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Forma farmaceutica repetida... Alta denegada", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #6
0
 public bool Existe(FormaFarmaceutica formaFarmaceutica)
 {
     try
     {
         SqlCommand comando;
         if (formaFarmaceutica.FormaFarmaceuticaId == 0)
         {
             string cadenaComando = "SELECT FormaFarmaceuticaId, Descripcion FROM FormasFarmaceuticas WHERE Descripcion=@nombre";
             comando = new SqlCommand(cadenaComando, _sqlConnection);
             comando.Parameters.AddWithValue("@nombre", formaFarmaceutica.Descripcion);
         }
         else
         {
             string cadenaComando = "SELECT FormaFarmaceuticaId, Descripcion FROM FormasFarmaceuticas WHERE Descripcion=@nombre AND FormaFarmaceuticaid<>@id";
             comando = new SqlCommand(cadenaComando, _sqlConnection);
             comando.Parameters.AddWithValue("@nombre", formaFarmaceutica.Descripcion);
             comando.Parameters.AddWithValue("@id", formaFarmaceutica.FormaFarmaceuticaId);
         }
         SqlDataReader reader = comando.ExecuteReader();
         return(reader.HasRows);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #7
0
 private void tsbBorrar_Click(object sender, EventArgs e)
 {
     if (dgvDatos.SelectedRows.Count > 0)
     {
         DataGridViewRow   r     = dgvDatos.SelectedRows[0];
         FormaFarmaceutica forma = (FormaFarmaceutica)r.Tag;
         DialogResult      dr    = MessageBox.Show($"¿Desea borrar de la lista a {forma.Descripcion}?",
                                                   "Confirmar Baja",
                                                   MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Question);
         if (dr == DialogResult.Yes)
         {
             try
             {
                 if (!servicio.EstaRelacionado(forma))
                 {
                     servicio.Borrar(forma);
                     dgvDatos.Rows.Remove(r);
                     MessageBox.Show("Forma farmaceutica Borrada", "Mensaje",
                                     MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
                 else
                 {
                     MessageBox.Show("Forma farmaceutica con registros asociados \nBaja Denegada", "Error",
                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             catch (Exception exception)
             {
                 MessageBox.Show(exception.Message, "Error",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
コード例 #8
0
 public void Guardar(FormaFarmaceutica formaFarmaceutica)
 {
     if (formaFarmaceutica.FormaFarmaceuticaId == 0)
     {
         try
         {
             string     cadenaComando = "INSERT INTO FormasFarmaceuticas VALUES(@nombre)";
             SqlCommand comando       = new SqlCommand(cadenaComando, _sqlConnection);
             comando.Parameters.AddWithValue("@nombre", formaFarmaceutica.Descripcion);
             comando.ExecuteNonQuery();
             cadenaComando = "SELECT @@IDENTITY";
             comando       = new SqlCommand(cadenaComando, _sqlConnection);
             formaFarmaceutica.FormaFarmaceuticaId = (int)(decimal)comando.ExecuteScalar();
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
     else
     {
         try
         {
             string     cadenaComando = "UPDATE FormasFarmaceuticas SET Descripcion=@nombre WHERE FormaFarmaceuticaId=@id";
             SqlCommand comando       = new SqlCommand(cadenaComando, _sqlConnection);
             comando.Parameters.AddWithValue("@nombre", formaFarmaceutica.Descripcion);
             comando.Parameters.AddWithValue("@id", formaFarmaceutica.FormaFarmaceuticaId);
             comando.ExecuteNonQuery();
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
 }
コード例 #9
0
 public bool Existe(FormaFarmaceutica formaFarmaceutica)
 {
     if (formaFarmaceutica.FormaFarmaceuticaId == 0)
     {
         return(_context.FormasFarmaceuticas.Any(f => f.Descripcion == formaFarmaceutica.Descripcion));
     }
     return(_context.FormasFarmaceuticas.Any(f => f.Descripcion == formaFarmaceutica.Descripcion &&
                                             f.FormaFarmaceuticaId == formaFarmaceutica.FormaFarmaceuticaId));
 }
コード例 #10
0
 public bool EstaRelacionado(FormaFarmaceutica formaFarmaceutica)
 {
     try
     {
         return(_context.Medicamentos.Any(f => f.FormaFarmaceuticaId == formaFarmaceutica.FormaFarmaceuticaId));
     }
     catch (Exception)
     {
         throw new Exception("Error al verificar si està relacionada una Forma Farmacèutica");
     }
 }
コード例 #11
0
 public bool Existe(FormaFarmaceuticaEditDto formaFarmaceuticaDto)
 {
     try
     {
         FormaFarmaceutica formaFarmaceutica = _mapper.Map <FormaFarmaceutica>(formaFarmaceuticaDto);
         return(_repositorio.Existe(formaFarmaceutica));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #12
0
        private void Okbtn_Click(object sender, EventArgs e)
        {
            if (ValidarDatos())
            {
                if (forma == null)
                {
                    forma = new FormaFarmaceutica();
                }

                forma.Descripcion = FormaFarmaceuticaTextBox.Text.Trim();
                DialogResult      = DialogResult.OK;
            }
        }
コード例 #13
0
 public void Borrar(FormaFarmaceutica forma)
 {
     try
     {
         string     cadenaComando = "DELETE FROM FormasFarmaceuticas WHERE FormaFarmaceuticaID=@id";
         SqlCommand comando       = new SqlCommand(cadenaComando, cn);
         comando.Parameters.AddWithValue("@id", forma.FormaFarmaceuticaID);
         comando.ExecuteNonQuery();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #14
0
 public void Guardar(FormaFarmaceuticaEditDto formaFarmaceuticaDto)
 {
     try
     {
         FormaFarmaceutica formaFarmaceutica = _mapper.Map <FormaFarmaceutica>(formaFarmaceuticaDto);
         _repositorio.Guardar(formaFarmaceutica);
         _unitOfWork.Save();
         formaFarmaceuticaDto.FormaFarmaceuticaId = formaFarmaceutica.FormaFarmaceuticaId;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #15
0
 public void Borrar(FormaFarmaceutica forma)
 {
     try
     {
         _conexion   = new ConexionBd();
         repositorio = new RepositorioFormaFarmaceutica(_conexion.AbrirConexion());
         repositorio.Borrar(forma);
         _conexion.CerrarConexion();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #16
0
 public void Agregar(FormaFarmaceuticaEditDto formaDto)
 {
     try
     {
         FormaFarmaceutica forma = mapper.Map <FormaFarmaceutica>(formaDto);
         _repositorio.Agregar(forma);
         _unitofwork.Save();
         formaDto.FormaFarmaceuticaId = forma.FormaFarmaceuticaId;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #17
0
 public bool EstaRelacionado(FormaFarmaceutica forma)
 {
     try
     {
         _conexion   = new ConexionBd();
         repositorio = new RepositorioFormaFarmaceutica(_conexion.AbrirConexion());
         var estaRelacionado = repositorio.EstaRelacionado(forma);
         _conexion.CerrarConexion();
         return(estaRelacionado);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #18
0
 public bool Existe(FormaFarmaceutica forma)
 {
     try
     {
         _conexion   = new ConexionBd();
         repositorio = new RepositorioFormaFarmaceutica(_conexion.AbrirConexion());
         var existe = repositorio.Existe(forma);
         _conexion.CerrarConexion();
         return(existe);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #19
0
 public bool EstaRelacionado(FormaFarmaceutica formaFarmaceutica)
 {
     try
     {
         var CadenaComando = "SELECT FormaFarmaceuticaId FROM Medicamentos WHERE FormaFarmaceuticaId=@id";
         var Comando       = new SqlCommand(CadenaComando, _sqlConnection);
         Comando.Parameters.AddWithValue("@id", formaFarmaceutica.FormaFarmaceuticaId);
         var reader = Comando.ExecuteReader();
         return(reader.HasRows);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #20
0
        public bool Existe(FormaFarmaceutica forma)
        {
            try
            {
                var cadenaComando = "SELECT FormaFarmaceuticaID, Descripcion FROM FormasFarmaceuticas WHERE Descripcion=@nombre";
                var comando       = new SqlCommand(cadenaComando, cn);
                comando.Parameters.AddWithValue("@nombre", forma.Descripcion);
                var reader = comando.ExecuteReader();
                return(reader.HasRows);
            }

            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #21
0
        public bool Existe(FormaFarmaceutica formaFarmaceutica)
        {
            try
            {
                if (formaFarmaceutica.FormaFarmaceuticaId == 0)
                {
                    return(_context.FormaFarmaceuticas.Any(ff => ff.Descripcion == formaFarmaceutica.Descripcion));
                }

                return(_context.FormaFarmaceuticas.Any(ff => ff.Descripcion == formaFarmaceutica.Descripcion && ff.FormaFarmaceuticaId == formaFarmaceutica.FormaFarmaceuticaId));
            }
            catch (Exception)
            {
                throw new Exception("Error al verificar si existe una Forma Farmacèutica");
            }
        }
コード例 #22
0
        public static void CargarComboFormasFarmaceuticas(ref ComboBox cbo)
        {
            ServicioFormaFarmaceutica servicioFormaFarmaceutica = new ServicioFormaFarmaceutica();

            cbo.DataSource = null;
            List <FormaFarmaceutica> lista = servicioFormaFarmaceutica.GetLista();
            var defaultFormaFarmaceutica   = new FormaFarmaceutica {
                FormaFarmaceuticaId = 0, Descripcion = "[Seleccione]"
            };

            lista.Insert(0, defaultFormaFarmaceutica);
            cbo.DataSource    = lista;
            cbo.DisplayMember = "Descripcion";
            cbo.ValueMember   = "FormaFarmaceuticaId";
            cbo.SelectedIndex = 0;
        }
コード例 #23
0
        private void btnAceptar_Click(object sender, System.EventArgs e)
        {
            if (ValidarDatos())
            {
                if (formaFarmaceutica == null)
                {
                    formaFarmaceutica = new FormaFarmaceutica();
                }

                formaFarmaceutica.Descripcion = txtFormaFarmaceutica.Text;
                if (ValidarObjeto())
                {
                    if (!_esEdicion)
                    {
                        try
                        {
                            _servicio.Guardar(formaFarmaceutica);
                            if (frm != null)
                            {
                                frm.AgregarFila(formaFarmaceutica);
                            }
                            MessageBox.Show("Registro Guardado", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            DialogResult dr = MessageBox.Show("¿Desea dar de alta otro registro?", "Confirmar",
                                                              MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == DialogResult.No)
                            {
                                DialogResult = DialogResult.Cancel;
                            }
                            else
                            {
                                InicializarControles();
                            }
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.Message);
                        }
                    }
                    else
                    {
                        DialogResult = DialogResult.OK;
                    }
                }
            }
        }
コード例 #24
0
 public void Agregar(FormaFarmaceutica forma)
 {
     try
     {
         string     cadenaComando = "INSERT INTO FormasFarmaceuticas VALUES (@forma)";
         SqlCommand comando       = new SqlCommand(cadenaComando, cn);
         comando.Parameters.AddWithValue("@forma", forma.Descripcion);
         comando.ExecuteNonQuery();
         cadenaComando = "SELECT @@Identity";
         comando       = new SqlCommand(cadenaComando, cn);
         int id = (int)(decimal)comando.ExecuteScalar();
         forma.FormaFarmaceuticaID = id;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #25
0
 public bool EstaRelacionado(FormaFarmaceutica forma)
 {
     try
     {
         var cadenaComando = "SELECT COUNT(*) FROM Medicamentos WHERE FormaFarmaceuticaID=@id";
         var comando       = new SqlCommand(cadenaComando, cn);
         comando.Parameters.AddWithValue("@id", forma.FormaFarmaceuticaID);
         int cantidadRegistros = (int)comando.ExecuteScalar();
         if (cantidadRegistros > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #26
0
 public void Agregar(FormaFarmaceutica formaFarmaceutica)
 {
     try
     {
         if (formaFarmaceutica.FormaFarmaceuticaId == 0)
         {
             _context.FormasFarmaceuticas.Add(formaFarmaceutica);
         }
         else
         {
             var tipoDb = _context.FormasFarmaceuticas.SingleOrDefault(f => f.FormaFarmaceuticaId == formaFarmaceutica.FormaFarmaceuticaId);
             tipoDb.Descripcion           = formaFarmaceutica.Descripcion;
             _context.Entry(tipoDb).State = EntityState.Modified;
         }
     }
     catch (Exception)
     {
         throw new Exception("Error al Guardar/Editar la forma farmaceutica");
     }
 }
コード例 #27
0
        public void Guardar(FormaFarmaceutica formaFarmaceutica)
        {
            try
            {
                if (formaFarmaceutica.FormaFarmaceuticaId == 0)
                {
                    _context.FormaFarmaceuticas.Add(formaFarmaceutica);
                }
                else
                {
                    var formaFarmaceuticaInDb = _context.FormaFarmaceuticas.Find(formaFarmaceutica.FormaFarmaceuticaId);
                    formaFarmaceuticaInDb.Descripcion           = formaFarmaceutica.Descripcion;
                    _context.Entry(formaFarmaceuticaInDb).State = EntityState.Modified;
                }

                //_context.SaveChanges();
            }
            catch (Exception)
            {
                throw new Exception("Error al intentar Agregar/Editar una Forma Farmacèutica");
            }
        }
コード例 #28
0
        public List <FormaFarmaceutica> GetLista()
        {
            List <FormaFarmaceutica> lista = new List <FormaFarmaceutica>();

            try
            {
                string        cadenaComando = "SELECT FormaFarmaceuticaId, Descripcion FROM FormasFarmaceuticas";
                SqlCommand    comando       = new SqlCommand(cadenaComando, _sqlConnection);
                SqlDataReader reader        = comando.ExecuteReader();
                while (reader.Read())
                {
                    FormaFarmaceutica formaFarmaceutica = ConstruirFormaFarmaceutica(reader);
                    lista.Add(formaFarmaceutica);
                }
                reader.Close();
                return(lista);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #29
0
 public FormaFarmaceutica GetFormaPorId(int id)
 {
     try
     {
         FormaFarmaceutica forma         = null;
         string            cadenaComando = "SELECT FormaFarmaceuticaID, Descripcion FROM FormasFarmaceuticas WHERE FormaFarmaceuticaID=@id";
         SqlCommand        comando       = new SqlCommand(cadenaComando, cn);
         comando.Parameters.AddWithValue("id", id);
         SqlDataReader reader = comando.ExecuteReader();
         if (reader.HasRows)
         {
             reader.Read();
             forma = ConstruirForma(reader);
         }
         reader.Close();
         return(forma);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
コード例 #30
0
        private void tsbEditar_Click(object sender, EventArgs e)
        {
            if (dgvDatos.SelectedRows.Count > 0)
            {
                DataGridViewRow   r     = dgvDatos.SelectedRows[0];
                FormaFarmaceutica forma = (FormaFarmaceutica)r.Tag;

                frmFormaFarmaceuticaAE frm = new frmFormaFarmaceuticaAE();
                frm.Text = "Editar Tipo De Documento";
                frm.SetFormaFarmaceutica(forma);
                DialogResult dr = frm.ShowDialog(this);
                if (dr == DialogResult.OK)
                {
                    try
                    {
                        forma = frm.GetFormaFarmaceutica();
                        if (!servicio.Existe(forma))
                        {
                            servicio.Guardar(forma);
                            SetearFila(r, forma);
                            MessageBox.Show("Forma Farmaceutica Editada", "Mensaje",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Forma Farmaceutica Duplicada... Alta denegada", "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message, "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                }
            }
        }